001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.main;
028:
029: import java.lang.Thread;
030:
031: import com.sun.midp.i3test.NamsTestCase;
032:
033: public class TestNamsStartMidlet extends NamsTestCase {
034:
035: static final int WAIT_SEC = 10;
036: static final int WAIT_MS = 1000 * WAIT_SEC;
037: // was 3, but problems with starting new isolate for 3rd dummy
038: static final int NUMBER = 2;
039:
040: int dummyId[];
041:
042: public TestNamsStartMidlet() {
043: dummyId = new int[3];
044: }
045:
046: boolean delay() {
047: boolean result = true;
048: try {
049: Thread.currentThread().sleep(WAIT_MS);
050: } catch (InterruptedException e) {
051: result = false;
052: }
053: ;
054: return result;
055: }
056:
057: void runTestDisplay() {
058: boolean wait_status;
059: int i, j;
060:
061: declare("test FG/BG Display");
062:
063: for (i = 0; i < NUMBER; ++i) {
064: dummyId[i] = NamsManager.startInternalMidlet(
065: "com.sun.midp.main.DummyNamsMIDlet" + (i + 1),
066: true, true);
067: wait_status = namsNotifier.waitForState(dummyId[i],
068: NamsStorage.NAMS_STATE_PAUSED, WAIT_MS);
069: assertTrue(" Wait interrupted !", wait_status);
070: }
071:
072: for (i = 0; i < NUMBER; ++i) {
073: NamsManager.midletResume(dummyId[i]);
074: wait_status = namsNotifier.waitForState(dummyId[i],
075: NamsStorage.NAMS_STATE_ACTIVE, WAIT_MS);
076: assertTrue(" Wait interrupted !", wait_status);
077:
078: NamsManager.midletSetForeground(dummyId[i]);
079: wait_status = namsNotifier.waitForFG(dummyId[i], WAIT_MS);
080: assertTrue(" Wait interrupted !", wait_status);
081:
082: for (j = 0; j < NUMBER; ++j) {
083: if (i == j) {
084: assertTrue("#" + (i + 1) + " Dummy" + (j + 1)
085: + " in FG", NamsStorage
086: .getDisplayStatus(dummyId[j]));
087: assertFalse(
088: "#" + (i + 1) + " Dummy" + (j + 1)
089: + " state !",
090: (NamsStorage.getMIDletState(dummyId[j]) == NamsStorage.NAMS_STATE_PAUSED));
091: } else
092: assertFalse("#" + (i + 1) + " Dummy" + (j + 1)
093: + " in BG", NamsStorage
094: .getDisplayStatus(dummyId[j]));
095: }
096: }
097:
098: delay();
099:
100: for (i = 0; i < NUMBER; ++i) {
101: NamsManager.midletPause(dummyId[i]);
102: wait_status = namsNotifier.waitForState(dummyId[i],
103: NamsStorage.NAMS_STATE_PAUSED, WAIT_MS);
104: assertTrue(" Wait interrupted !", wait_status);
105: }
106: for (i = 0; i < NUMBER; ++i) {
107: assertFalse("#Paused Dummy" + (i + 1) + " in BG !",
108: NamsStorage.getDisplayStatus(dummyId[i]));
109: assertTrue(
110: "#Paused Dummy" + (i + 1) + " state !",
111: (NamsStorage.getMIDletState(dummyId[i]) == NamsStorage.NAMS_STATE_PAUSED));
112: }
113:
114: delay();
115:
116: for (i = 0; i < NUMBER; ++i) {
117: NamsManager.midletDestroy(dummyId[i]);
118: wait_status = namsNotifier.waitForState(dummyId[i],
119: NamsStorage.NAMS_STATE_DESTROYED, WAIT_MS);
120: assertTrue(" Wait interrupted !", wait_status);
121: }
122: for (i = 0; i < NUMBER; ++i) {
123: assertFalse("#Destroyed Dummy" + (i + 1) + " in BG !",
124: NamsStorage.getDisplayStatus(dummyId[i]));
125: assertTrue(
126: "#Destroyed Dummy" + (i + 1) + " state !",
127: (NamsStorage.getMIDletState(dummyId[i]) == NamsStorage.NAMS_STATE_DESTROYED));
128: }
129:
130: delay();
131: }
132:
133: public void runTests() {
134: runTestDisplay();
135: }
136:
137: }
|