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.test;
028:
029: import com.sun.cldc.isolate.Isolate;
030: import com.sun.cldc.isolate.IsolateStartupException;
031: import com.sun.cldchi.test.Reflect;
032: import com.sun.midp.i3test.*;
033:
034: public class TestReflect extends TestCase {
035:
036: static final String slave = "com.sun.midp.test.ReflectSlave";
037:
038: Isolate iso;
039:
040: void setUp() {
041:
042: // Make sure we can find the slave class. This isn't strictly
043: // necessary, but it serves as a useful cross-check to ensure
044: // that the class is visible to both the master and slave
045: // isolates. It also helps if the classname is wrong for
046: // some reason: you get a useful error message instead of
047: // an obscure isolate startup error.
048:
049: try {
050: Class.forName(slave);
051: } catch (ClassNotFoundException cnfe) {
052: throw new RuntimeException(
053: "Class.forName() can't find slave class " + slave);
054: }
055:
056: // Initialize the isolate synchronization mechanism.
057: // This must be done before the other isolate is started.
058: // This must be called ONLY in the "master" isolate.
059:
060: IsolateSynch.init();
061:
062: // Create the slave isolate and start it.
063:
064: try {
065: iso = new Isolate(slave, new String[0]);
066: iso.start();
067: } catch (IsolateStartupException ise) {
068: throw new RuntimeException("can't start isolate");
069: }
070:
071: // Wait for the slave isolate to become ready.
072:
073: IsolateSynch.awaitReady();
074: }
075:
076: void tearDown() {
077: // Tell the other isolate to continue.
078:
079: IsolateSynch.signalContinue();
080:
081: // Alternatively, kill the other isolate instead of
082: // telling it to continue. Do one or the other, but not both.
083: /* iso.exit(0); */
084:
085: // Wait for the other isolate to exit.
086: iso.waitForExit();
087:
088: // Clean up isolate synchronization mechanism.
089:
090: IsolateSynch.fini();
091: }
092:
093: void testOne() {
094: setUp();
095: int x = Reflect.getStaticIntValue(iso, slave, "integerValue");
096: assertEquals(17, ReflectSlave.integerValue);
097: assertEquals(42, x);
098: tearDown();
099: }
100:
101: public void runTests() {
102: declare("one");
103: testOne();
104: }
105: }
|