FileDocCategorySizeDatePackage
TestNewSetCurrent.javaAPI DocphoneME MR2 API (J2ME)41625Wed May 02 18:00:22 BST 2007javax.microedition.lcdui

TestNewSetCurrent

public class TestNewSetCurrent extends com.sun.midp.i3test.TestCase
Tests proper behavior of Display.setCurrent() for a single midlet in the foreground. Various combinations of "normal" (i.e., non-Alert) Displayable instances are tested with the one-arg and two-arg Alert forms of the setCurrent() method. The notation used to name tests is as follows. The operations initiated by the tests are: N setCurrent(normal [non-Alert] Displayable) A setCurrent(Alert) 2 setCurrent(Alert, Displayable) D dismiss the current Alert Codes for context or waits for event processing are: 0 tests Display's initial state (current == null) _ wait for a screen-change event to be processed s suffix indicating a displayable is the same as a previous one For example, testA_2 first calls setCurrent(alert1), waits for the alert to become current, then calls setCurrent(alert2, disp1). Note that this notation doesn't include an initial setCurrentWait() call that is typically used to establish the initial state for the test. In such cases the initial displayable will be numbered zero, that is, disp0 or cv0. This is in contrast to displayables and alerts that are used in the operations being tested, which are numbered starting at one. Quite often it is necessary to execute code atomically on the event thread, that is, ensuring that no events are processed within a group of statements. Code running on the test thread is arbitrarily interleaved with code running on the event thread. For example, suppose Displayable d0 is current. If the following code were executed on the test thread, dpy.setCurrent(d1); dpy.setCurrent(alert); there would be a race condition between d1 becoming current and the call to setCurrent(alert). Runnable blocks are used to group a set of statements to be executed atomically. Runnable blocks are used in two different ways: using callSerially() and using await(). In both cases the run() method is executed on the event thread. This prevents any other events from being dispatched in the midst of the code of the run() method. For example: dpy.callSerially( new Runnable() { public void run() { // (1) } }); scl.await( new Runnable() { public void run() { // (2) } }); The code (1) is executed atomically on the event thread, and the calling thread continues. The code (2) is executed atomically on the event thread immediately after the next screen change occurs. The calling thread is blocked until the screen change occurs and the run() method has completed.

Fields Summary
Display
dpy
com.sun.midp.util.LiveTraceCallback
scl
boolean
thrown
Constructors Summary
Methods Summary
voidcheckCurrent(java.lang.String s, com.sun.midp.util.LcduiTestCanvas cv, boolean isCurrent)
Checks a variety of invariants on test canvas cv, depending upon whether the canvas should or should not be current.

        if (isCurrent) {
            assertTrue(s+".showCalled must be true", cv.showCalled());
            assertTrue(s+".isShown must be true", cv.isShown());
            assertSame(s+" must be current", cv, dpy.getCurrent());
        } else {
            assertFalse(s+".showCalled must be false", cv.showCalled());
            assertFalse(s+".isShown must be false", cv.isShown());
            assertNotSame(s+" must not be current", cv, dpy.getCurrent());
        }
    
voidcheckCurrent(java.lang.String s, Alert alert, boolean shouldBeCurrent)
Checks a variety of invariants on an alert, depending upon whether the alert should or should not be current.

        if (shouldBeCurrent) {
            assertTrue(s+".isShown must be true", alert.isShown());
            assertSame(s+" must be current", alert, dpy.getCurrent());
        } else {
            assertFalse(s+".isShown must be false", alert.isShown());
            assertNotSame(s+" must not be current", alert, dpy.getCurrent());
        }
    
voiddismiss(Alert alert)
Simulates dismissing an alert from this display. The logic here mimics the logic of what occurs when the Alert times out and executes its default (DISMISS) command. This allows tests to set the alert timeout to FOREVER and to call this function in the right sequence, without having to deal with timing issues.

        synchronized (Display.LCDUILock) {
            alert.lDismiss();
        }
    
voiddismissWait(Alert alert)
Dismisses the alert and then waits for the resulting screen-change event to be processed.

        dismiss(alert);
        scl.await();
    
voidfini()
Cleans up the test MIDlet.

        dpy.liveTracer.clear();
        scl.shutdown();
    
voidinit()
Creates the test MIDlet and get its display.

        dpy = new StubDisplay();
        scl = new LiveTraceCallback();
        dpy.liveTracer.add(Display.LTR_SCREENCHANGE_DONE, scl);
    
AlertmakeAlert(java.lang.String title)
Creates a new alert and sets its timeout to FOREVER so that it must be dismissed explicitly.

        Alert a = new Alert(title);
        a.setTimeout(Alert.FOREVER);
        return a;
    
public voidrunTests()
Runs all tests.

        init();
        try {
            declare("testInit");
            testInit();

            declare("test0A0A");
            test0A0A();

            declare("testN");
            testN();

            declare("testA");
            testA();

            declare("test2");
            test2();

            declare("testNN");
            testNN();

            declare("testNNsN");
            testNNsN();

            declare("testN_N");
            testN_N();

            declare("testN_NNs");
            testN_NNs();

            declare("testNA");
            testNA();

            declare("testN2");
            testN2();

            declare("testAN");
            testAN();

            declare ("testAND");
            testAND();

            declare("testA_N");
            testA_N();

            declare("testAA");
            testAA();

            declare("testAAs");
            testAAs();

            declare("testA_A");
            testA_A();

            declare("testA_As");
            testA_As();

            declare("testA2");
            testA2();

            declare("testA2s");
            testA2s();

            declare("testA_2");
            testA_2();

            declare("testA_2s");
            testA_2s();

            declare("test2N");
            test2N();

            declare("test2_N");
            test2_N();

            declare("test2A");
            test2A();

            declare("test2_A");
            test2_A();

            declare("test22");
            test22();

            declare("test2_2");
            test2_2();

            declare("test22s");
            test22s();

            declare("test2_2s");
            test2_2s();

            declare("testAlertAlert");
            testAlertAlert();

            declare("testA_NA");
            testA_NA();
        } finally {
            fini();
        }
    
voidsetCurrentWait(Displayable d)
Sets the Displayable to be current, waits for it to become visible, and returns.

        dpy.setCurrent(d);
        scl.await();
    
voidtest0A0A()
Case: 0A0A. Tests whether the system returns to the original (null) state after an alert. Does so twice in order to ensure that the first setCurrent doesn't have any side effects. WARNING: this must be run on a fresh display.

        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        assertNull("current null", dpy.getCurrent());

        setCurrentWait(alert1);
        checkCurrent("alert1", alert1, true);

        dismissWait(alert1);
        checkCurrent("alert1", alert1, false);
        assertNull("current null", dpy.getCurrent());

        setCurrentWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);

        dismissWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        assertNull("current null", dpy.getCurrent());
    
voidtest2()
Case: 2.

        LcduiTestCanvas cv0 = new LcduiTestCanvas();
        LcduiTestCanvas cv1 = new LcduiTestCanvas();
        Alert alert = makeAlert("alert");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.setCurrent(alert, cv1);
        scl.await();
        checkCurrent("cv0", cv0, false);
        checkCurrent("alert", alert, true);

        dismissWait(alert);
        checkCurrent("cv1", cv1, true);
        checkCurrent("alert", alert, false);
    
voidtest22()
Case: 22.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert1, cv1);
                    dpy.setCurrent(alert2, cv2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, true);
                    checkCurrent("alert2", alert2, false);
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, false);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, false);
                    checkCurrent("alert2", alert2, true);
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, false);
                }
            });

        // Dismiss alert1. Nothing should happen, since it has
        // been superseded by cv2.
        dismiss(alert1);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, false);

        dismissWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should never have been shown", cv1.wasShown());
    
voidtest22s()
Case 22s. Tests the behavior of two, two-arg setCurrent calls, where the alert in question is the same in both cases.

        final Alert alert = makeAlert("alert");
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert, cv1);
                    dpy.setCurrent(alert, cv2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, true);
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, false);
                }
            });

        // Dismiss alert, then cv2 should become current.

        dismissWait(alert);
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should never have been shown", cv1.wasShown());
    
voidtest2A()
Case: 2A.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        thrown = false;
        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert1, cv1);
                    try {
                        dpy.setCurrent(alert2);
                    } catch (IllegalArgumentException IAE) {
                        thrown = true;
                    }
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, true);
                    checkCurrent("alert2", alert2, false);
                    checkCurrent("cv1", cv1, false);
                    assertTrue("IAE should be thrown", thrown);
                }
            });

        dismissWait(alert1);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv1", cv1, true);
    
voidtest2N()
Case: 2N.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert, cv1);
                    dpy.setCurrent(cv2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, true);
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, false);
                }
            });
        
        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, false);
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, true);
                }
            });

        // Dismiss alert. Nothing should happen, since it has
        // been superseded by cv2.

        dismiss(alert);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should not have been shown", cv1.wasShown());
    
voidtest2_2()
Case: 2_2.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        dpy.setCurrent(alert1, cv1);
        scl.await();
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv1", cv1, false);

        dpy.setCurrent(alert2, cv2);
        scl.await();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, false);

        // Dismiss alert1. Nothing should happen, since it has
        // been superseded by cv2.

        dismiss(alert1);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, false);

        dismissWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should never have been shown", cv1.wasShown());
    
voidtest2_2s()
Case 2_2s. Tests the behavior of two, two-arg setCurrent calls, where the alert in question is the same in both cases.

        final Alert alert = makeAlert("alert");
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();

        dpy.setCurrent(alert, cv1);
        scl.await();
        checkCurrent("alert", alert, true);
        checkCurrent("cv1", cv1, false);

        // Call setCurrent again and dismiss the alert before
        // the event can be processed.

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert, cv2);
                    dismiss(alert);
                }
            });

        scl.await();
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should never have been shown", cv1.wasShown());
    
voidtest2_A()
Case: 2_A.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        dpy.setCurrent(alert1, cv1);

        scl.await();
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv1", cv1, false);

        thrown = false;
        try {
            dpy.setCurrent(alert2);
        } catch (IllegalArgumentException IAE) {
            thrown = true;
        }
        assertTrue("IAE should be thrown", thrown);

        dismissWait(alert1);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv1", cv1, true);
    
voidtest2_N()
Case: 2_N.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        dpy.setCurrent(alert, cv1);
        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, true);
                    checkCurrent("cv1", cv1, false);
                }
            });
        
        setCurrentWait(cv2);
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);

        // Dismiss alert. Nothing should happen, since it has
        // been superseded by cv2.
        dismiss(alert);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
        assertFalse("cv1 should not have been shown", cv1.wasShown());
    
voidtestA()
Case: A.

        LcduiTestCanvas cv0 = new LcduiTestCanvas();
        Alert alert = makeAlert("alert");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        setCurrentWait(alert);
        checkCurrent("alert", alert, true);
        checkCurrent("cv0", cv0, false);

        dismissWait(alert);
        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, true);
    
voidtestA2()
Case: A2.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert1);
                    dpy.setCurrent(alert2, cv1);
                }
            });
                    
        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, true);
                    checkCurrent("alert2", alert2, false);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, false);
                    checkCurrent("alert2", alert2, true);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                    dismiss(alert1);
                }
            });

        // Dismissing alert1 should do nothing, since it has
        // been superseded by alert2.

        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        dismissWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestA2s()
Case: A2s.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert1);
                    dpy.setCurrent(alert1, cv1);
                }
            });
                    
        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, true);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                }
            });

        // Ensure that the second setCurrent had no effect.

        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        dismissWait(alert1);
        checkCurrent("alert1", alert1, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestAA()
Case: AA.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        thrown = false;
        new SerialCallback(dpy) {
            public void run() {
                dpy.setCurrent(alert1);
                try {
                    dpy.setCurrent(alert2);
                } catch (IllegalArgumentException iae) {
                    thrown = true;
                }
            }
        }.invokeAndWait();

        scl.await();
        checkCurrent("alert1", alert1, true);
        assertTrue("IAE should be thrown", thrown);

        dismissWait(alert1);
        checkCurrent("cv0", cv0, true);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
    
voidtestAAs()
Case: AAs.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        thrown = false;
        new SerialCallback(dpy) {
            public void run() {
                dpy.setCurrent(alert1);
                try {
                    dpy.setCurrent(alert1);
                } catch (IllegalArgumentException iae) {
                    thrown = true;
                }
            }
        }.invokeAndWait();

        scl.await();
        checkCurrent("alert1", alert1, true);
        assertFalse("IAE should not be thrown", thrown);

        dismissWait(alert1);
        checkCurrent("cv0", cv0, true);
        checkCurrent("alert1", alert1, false);
    
voidtestAN()
Case: AN.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert);
                    dpy.setCurrent(cv1);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, true);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                }
            });

        dismissWait(alert);
        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestAND()
Case: AND. Tests alert timeout while it's shown, while another screen change event is in the queue.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(alert);
                    dpy.setCurrent(cv1);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, true);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                    dismiss(alert);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, false);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, true);
                }
            });

        // The setCurrent(cv1) call supersedes the
        // alert, so dismissing the alert should not
        // return to cv0.

        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestA_2()
Case: A_2.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.setCurrent(alert1);
        scl.await();
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv0", cv0, false);

        dpy.setCurrent(alert2, cv1);
        scl.await();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        // Dismiss alert1. Nothing should happen, since it has
        // been superseded by alert2.

        dismiss(alert1);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        dismissWait(alert2);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestA_2s()
Case: A_2s.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert1 = makeAlert("alert1");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        setCurrentWait(alert1);
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv0", cv0, false);

        // The two-arg call should update the next displayable
        // but should otherwise do nothing.
        dpy.setCurrent(alert1, cv1);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert1", alert1, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        dismissWait(alert1);
        checkCurrent("alert1", alert1, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestA_A()
Tests setCurrent(Alert) when an alert is already visible. Case: A_A.

        LcduiTestCanvas cv0 = new LcduiTestCanvas();
        Alert alert1 = makeAlert("alert1");
        Alert alert2 = makeAlert("alert2");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        setCurrentWait(alert1);
        checkCurrent("cv0", cv0, false);
        checkCurrent("alert1", alert1, true);

        thrown = false;
        try {
            dpy.setCurrent(alert2);
        } catch (IllegalArgumentException iae) {
            thrown = true;
        }
        assertTrue("IAE should be thrown", thrown);

        dismissWait(alert1);
        checkCurrent("cv0", cv0, true);
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
    
voidtestA_As()
Tests setCurrent on the same alert when it is already visible. Case: A_As.

        LcduiTestCanvas cv0 = new LcduiTestCanvas();
        Alert alert1 = makeAlert("alert1");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        setCurrentWait(alert1);
        checkCurrent("cv0", cv0, false);
        checkCurrent("alert1", alert1, true);

        thrown = false;
        try {
            dpy.setCurrent(alert1);
        } catch (IllegalArgumentException iae) {
            thrown = true;
        }
        assertFalse("IAE should not be thrown", thrown);

        dismissWait(alert1);
        checkCurrent("cv0", cv0, true);
        checkCurrent("alert1", alert1, false);
    
voidtestA_N()
Case: A_N.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.setCurrent(alert);
        scl.await();
        checkCurrent("alert", alert, true);
        checkCurrent("cv0", cv0, false);

        setCurrentWait(cv1);
        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);

        dismiss(alert);
        new SerialCallback(dpy).invokeAndWait();
        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestA_NA()
Case: A_NA.

        final Alert alert1 = makeAlert("alert1");
        final Alert alert2 = makeAlert("alert2");
        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();

        // establish initial conditions
        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.setCurrent(alert1);
        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, true);
                    checkCurrent("cv0", cv0, false);
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(alert2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, false);
                    checkCurrent("alert2", alert2, false);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, true);
                    dismiss(alert1);
                }
            });
        
        // Dismissing alert1 should be ignored since it has been
        // superseded by cv1; then alert2 should become current.

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert1", alert1, false);
                    checkCurrent("alert2", alert2, true);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, false);
                    dismiss(alert2);
                }
            });
        
        scl.await();
        checkCurrent("alert1", alert1, false);
        checkCurrent("alert2", alert2, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestAlertAlert()
Tests setCurrent(alert, alert). This is basically an API test.

        Alert alert1 = makeAlert("alert1");
        Alert alert2 = makeAlert("alert2");

        thrown = false;
        try {
            dpy.setCurrent(alert1, alert2);
        } catch (IllegalArgumentException iae) {
            thrown = true;
        }

        assertTrue("IAE should be thrown", thrown);
    
voidtestInit()
Tests whether the display has been initialized properly.

        assertNotNull("dpy must be non-null", dpy);
        assertNull("current must be null", dpy.getCurrent());
    
voidtestN()
Case: N.

        LcduiTestCanvas cv1 = new LcduiTestCanvas();
        setCurrentWait(cv1);
        checkCurrent("cv1", cv1, true);
    
voidtestN2()
Case: N2.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(alert, cv2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, false);
                    checkCurrent("cv1", cv1, true);
                    checkCurrent("cv2", cv2, false);
                }
            });

        scl.await();
        checkCurrent("alert", alert, true);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, false);

        dismissWait(alert);
        checkCurrent("alert", alert, false);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
    
voidtestNA()
Case: NA.

        final LcduiTestCanvas cv0 = new LcduiTestCanvas();
        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final Alert alert = makeAlert("alert");

        // establish initial conditions

        setCurrentWait(cv0);
        checkCurrent("cv0", cv0, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(alert);
                }
            });

        // wait for cv1 to become current

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("alert", alert, false);
                    checkCurrent("cv0", cv0, false);
                    checkCurrent("cv1", cv1, true);
                }
            });

        // wait for alert to become current

        scl.await();
        checkCurrent("alert", alert, true);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, false);

        dismissWait(alert);

        // This checks for the behavior reported as a CR in
        // CR 6225060: after the alert is dismissed, current
        // returns to cv0.
        // checkCurrent("alert", alert, false);
        // checkCurrent("cv0", cv0, true);
        // checkCurrent("cv1", cv1, false);

        // The following checks for behavior expected by most programs: after 
        // the alert is dismissed, cv1 should become current, 
        // because a setCurrent request on it was issued prior to the 
        // setCurrent request on the alert.

        checkCurrent("alert", alert, false);
        checkCurrent("cv0", cv0, false);
        checkCurrent("cv1", cv1, true);
    
voidtestNN()
Case: NN.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();

        // Use callSerially to make sure both setCurrent() calls
        // occur before the first screen-change event is processed.

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(cv2);
                }
            });

        // Use await(Runnable) to ensure that the assertion checks
        // are done after the first screen-change event and before
        // the second screen-change event.

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("cv1", cv1, true);
                    checkCurrent("cv2", cv2, false);
                }
            });

        scl.await();
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
    
voidtestNNsN()
Case: NNsN.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(cv1);
                    dpy.setCurrent(cv2);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("cv1", cv1, true);
                    checkCurrent("cv2", cv2, false);
                }
            });

        scl.await();
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
    
voidtestN_N()
Case: N_N.

        LcduiTestCanvas cv1 = new LcduiTestCanvas();
        LcduiTestCanvas cv2 = new LcduiTestCanvas();

        setCurrentWait(cv1);
        checkCurrent("cv1", cv1, true);

        setCurrentWait(cv2);
        checkCurrent("cv1", cv1, false);
        checkCurrent("cv2", cv2, true);
    
voidtestN_NNs()
Case: N_NNs.

        final LcduiTestCanvas cv1 = new LcduiTestCanvas();
        final LcduiTestCanvas cv2 = new LcduiTestCanvas();
        
        setCurrentWait(cv1);
        checkCurrent("cv1", cv1, true);

        dpy.callSerially(
            new Runnable() {
                public void run() {
                    dpy.setCurrent(cv2);
                    dpy.setCurrent(cv1);
                }
            });

        scl.await(
            new Runnable() {
                public void run() {
                    checkCurrent("cv1", cv1, false);
                    checkCurrent("cv2", cv2, true);
                }
            });

        scl.await();
        checkCurrent("cv1", cv1, true);
        checkCurrent("cv2", cv2, false);