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.i3test;
028:
029: import java.util.Vector;
030: import javax.microedition.midlet.*;
031:
032: /**
033: * The Integrated Internal Interface (i3) test framework.
034: */
035: public class Framework extends MIDlet implements Runnable {
036:
037: String argv[];
038: boolean listmode = false;
039: boolean selftest = false;
040: boolean verbose = false;
041: boolean error = false;
042: String testClass = null;
043: String filterString = null;
044: /** Indicates whether a thread running test cases has been started. */
045: private boolean started = false;
046:
047: void runTestCases(String[] nameArray) {
048: for (int i = 0; i < nameArray.length; i++) {
049: TestCase.runTestCase(nameArray[i]);
050: }
051: TestCase.report();
052: }
053:
054: void listTestCases(String[] nameArray) {
055: for (int i = 0; i < nameArray.length; i++) {
056: System.out.println(nameArray[i]);
057: }
058: }
059:
060: String[] doFilter(String[] nameArray, String filter) {
061: Vector vec = new Vector();
062:
063: for (int i = 0; i < nameArray.length; i++) {
064: if (filter == null || (nameArray[i].indexOf(filter) >= 0)) {
065: vec.addElement(nameArray[i]);
066: }
067: }
068:
069: String[] ret = new String[vec.size()];
070: vec.copyInto(ret);
071: return ret;
072: }
073:
074: public Framework() {
075: final int argc = 3;
076:
077: argv = new String[argc];
078: argv[0] = getAppProperty("arg-0");
079: argv[1] = getAppProperty("arg-1");
080: argv[2] = getAppProperty("arg-2");
081:
082: for (int a = 0; a < argc; a++) {
083: if (argv[a] == null) {
084: break;
085: } else if (argv[a].startsWith("-filter:")) {
086: filterString = argv[a].substring(8);
087: } else if ("-list".equals(argv[a])) {
088: listmode = true;
089: } else if ("-selftest".equals(argv[a])) {
090: selftest = true;
091: } else if ("-verbose".equals(argv[a])) {
092: verbose = true;
093: } else if (argv[a].startsWith("-")) {
094: System.err
095: .print("usage: i3test [option] [testclass]\n"
096: + "options:\n"
097: + " -filter:pattern "
098: + "runs tests whose names contain pattern\n"
099: + " -list prints a list of known tests\n"
100: + " -selftest runs the framework's self test\n"
101: + " -verbose enables verbose output\n"
102: + "Given a testclass argument, runs just that test.\n"
103: + "Without a testclass argument, runs all known tests.\n");
104: error = true;
105: break;
106: } else {
107: testClass = argv[a];
108: }
109: }
110:
111: TestCase.setVerbose(verbose);
112: }
113:
114: public void run() {
115: if (listmode) {
116: listTestCases(doFilter(Repository.testNames, filterString));
117: } else if (selftest) {
118: SelfTest.run();
119: } else if (testClass != null) {
120: runTestCases(new String[] { testClass });
121: } else {
122: runTestCases(doFilter(Repository.testNames, filterString));
123: }
124:
125: notifyDestroyed();
126: }
127:
128: public void startApp() {
129: if (error) {
130: notifyDestroyed();
131: } else if (!started) {
132: started = true;
133: new Thread(this ).start();
134: }
135: }
136:
137: public void pauseApp() {
138: }
139:
140: public void destroyApp(boolean unconditional) {
141: }
142: }
|