Re: RFR: 8333403: Write a test to check various components events are triggered properly [v5]

2024-07-12 Thread Ravi Gupta
On Fri, 5 Jul 2024 20:20:29 GMT, Alexey Ivanov  wrote:

>> Ravi Gupta has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   8333403: Review comments fixed
>
> test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 164:
> 
>> 162: robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
>> 163: 
>> 164: // Hide all components and check if the ComponentEvent is 
>> triggered
> 
> Is it really what's going on here? Where do you hide all the components?

Here we performed testing for component events  (resized, moved, hidden and 
shown) are triggered properly when components are enable/disabled.

I removed the commented line

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19521#discussion_r1675560055


Re: RFR: 8333403: Write a test to check various components events are triggered properly [v5]

2024-07-12 Thread Ravi Gupta
On Fri, 5 Jul 2024 20:12:09 GMT, Alexey Ivanov  wrote:

>> Ravi Gupta has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   8333403: Review comments fixed
>
> test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 56:
> 
>> 54: 
>> 55: private static Frame frame;
>> 56: private static int DELAY = 500;
> 
> Suggestion:
> 
> private static final int DELAY = 500;
> 
> It's a constant, isn't it?

yes its constant.

> test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 66:
> 
>> 64: private volatile static Dimension compSize;
>> 65: private volatile static ArrayList events =
>> 66: new ArrayList<>();
> 
> Marking a list as `volatile` is not enough to access the contents of the list 
> from different threads, you have to use a synchronized collection and iterate 
> over `events` while holding the lock.

modified as below 

private volatile static java.util.List events =
Collections.synchronizedList(new ArrayList());

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19521#discussion_r1675520625
PR Review Comment: https://git.openjdk.org/jdk/pull/19521#discussion_r1675519953


Re: RFR: 8333403: Write a test to check various components events are triggered properly [v5]

2024-07-05 Thread Alexey Ivanov
On Thu, 4 Jul 2024 10:25:38 GMT, Ravi Gupta  wrote:

>> This testcase checks for the following assertions for Component events:
>> 
>> 1. When components are resized, moved, hidden and shown the respective 
>> events are triggered.
>> 2. When the components are hidden/disabled also,the component events like 
>> resized/moved are triggered.
>> 3. When a hidden component is hidden again, or a visible component is shown 
>> again, the events should not be fired.
>> 4. When a window is minimized/restored then hidden and shown component 
>> events should be triggered.
>> 
>> Testing:
>> Tested using Mach5(20 times per platform) in macos,linux and windows and got 
>> all pass.
>
> Ravi Gupta has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   8333403: Review comments fixed

Changes requested by aivanov (Reviewer).

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 56:

> 54: 
> 55: private static Frame frame;
> 56: private static int DELAY = 500;

Suggestion:

private static final int DELAY = 500;

It's a constant, isn't it?

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 58:

> 56: private static int DELAY = 500;
> 57: private static Robot robot;
> 58: private volatile static Component[] components;

Why does the  `components` array need to be `volatile`?

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 62:

> 60: private volatile static boolean componentShown = false;
> 61: private volatile static boolean componentMoved = false;
> 62: private volatile static boolean componentResized = false;

Assigning the default value is redundant…

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 66:

> 64: private volatile static Dimension compSize;
> 65: private volatile static ArrayList events =
> 66: new ArrayList<>();

Marking a list as `volatile` is not enough to access the contents of the list 
from different threads, you have to use a synchronized collection and iterate 
over `events` while holding the lock.

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 141:

> 139: EventQueue.invokeAndWait(ComponentEventTest::initializeGUI);
> 140: robot.delay(DELAY);
> 141: robot.waitForIdle();

Suggestion:

robot.waitForIdle();
robot.delay(DELAY);

Delaying before `waitForIdle` doesn't make much sense… The tests use 
`waitForIdle` followed by `delay` to ensure all the events are handled and then 
to add additional time… just in case.

If you call `waitForIdle` after `delay`, the chances are high that 
`waitForIdle` returns immediately because there are no pending events already 
(they're handled when the thread has been sleeping).

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 164:

> 162: robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
> 163: 
> 164: // Hide all components and check if the ComponentEvent is 
> triggered

Is it really what's going on here? Where do you hide all the components?

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 181:

> 179: System.err.print("Events triggered are: ");
> 180: for (int j = 0; j < events.size();
> 181: System.err.print(events.get(j) + "; "), j++);

This is very confusing. Move printing into the body of the `for`-loop:
Suggestion:

for (int j = 0; j < events.size(); j++) {
System.err.print(events.get(j) + "; ");
}

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 184:

> 182: System.err.println();
> 183: throw new RuntimeException(
> 184: "FAIL: ComponentEvent triggered when frame is 
> iconified");

You're repeating these lines of code over and over again — create a helper 
method for printing the events.

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 282:

> 280: throw new RuntimeException(
> 281: "FAIL: ComponentResized not triggered for "
> 282: + components[i].getClass());

Choose one style… At line 267, you pass the message on the same line; here you 
wrap the message to next line immediately.

It's more common to keep the first part of the string on the same line and wrap 
the string as necessary.

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 291:

> 289: resetFrame();
> 290: });
> 291: robot.delay(DELAY);

So, you're repeating the same tests as above? Why can't you use a loop?


for (boolean state : new boolean[] {true, false}) {
currentComponent.setEnabled(state);
doTests();
}

test/jdk/java/awt/event/ComponentEvent/ComponentEventTest.java line 377:

> 375: }
> 376: 
> 377: private static void resetFrame() {

Suggestion:

private static void revalidateFrame() {

`revalidateFrame` is a

Re: RFR: 8333403: Write a test to check various components events are triggered properly [v5]

2024-07-04 Thread Ravi Gupta
> This testcase checks for the following assertions for Component events:
> 
> 1. When components are resized, moved, hidden and shown the respective events 
> are triggered.
> 2. When the components are hidden/disabled also,the component events like 
> resized/moved are triggered.
> 3. When a hidden component is hidden again, or a visible component is shown 
> again, the events should not be fired.
> 4. When a window is minimized/restored then hidden and shown component events 
> should be triggered.
> 
> Testing:
> Tested using Mach5(20 times per platform) in macos,linux and windows and got 
> all pass.

Ravi Gupta has updated the pull request incrementally with one additional 
commit since the last revision:

  8333403: Review comments fixed

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19521/files
  - new: https://git.openjdk.org/jdk/pull/19521/files/9a3e95f1..6fc17f93

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19521&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19521&range=03-04

  Stats: 5 lines in 1 file changed: 0 ins; 5 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/19521.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19521/head:pull/19521

PR: https://git.openjdk.org/jdk/pull/19521