001: /**
002: *******************************************************************************
003: * Copyright (C) 2001-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */package com.ibm.icu.dev.test.sample;
007:
008: import com.ibm.icu.dev.test.ModuleTest;
009:
010: public class ModuleTestSample extends ModuleTest {
011: public static void main(String[] args) throws Exception {
012: new ModuleTestSample().run(args);
013: }
014:
015: ModuleTestSample() {
016: super ("com/ibm/icu/dev/data/testdata/", "Test");
017: }
018:
019: // standard loop, settings and cases
020: // public void Test01() {
021: // while (nextSettings()) {
022: // logln("--------");
023: // logln("String: " + settings.getString("aString"));
024: // if (settings.isDefined("anInt")) {
025: // logln("Int: " + settings.getInt("anInt"));
026: // }
027: // logln("Boolean: " + settings.getBoolean("aBoolean"));
028: //
029: // while (nextCase()) {
030: // logln(" ----");
031: // logln(" StringArray: " + printArray(testcase.getStringArray("aStringArray")));
032: // logln(" IntArray: " + printArray(testcase.getIntArray("anIntArray")));
033: // logln(" BooleanArray: " + printArray(testcase.getBooleanArray("aBooleanArray")));
034: // }
035: // }
036: // }
037: //
038: // // loop with just cases
039: // public void Test02() {
040: // while (nextCase()) {
041: // logln("----");
042: // logln("String: " + testcase.getString("aString"));
043: // logln("Int: " + testcase.getInt("anInt"));
044: // logln("Boolean: " + testcase.getBoolean("aBoolean"));
045: // }
046: // }
047:
048: // no cases, just uses info for test
049: public void Test03() {
050: // DataMap info = testInfo();
051: // if (info != null) {
052: //// logln(info.getString(TestDataModule.DESCRIPTION)); // standard
053: // logln(info.getString("Extra")); // test-specific
054: // }
055: // return;
056: }
057:
058: // no data, ModuleTest should not allow this to execute by default
059: public void Test04() {
060: errln("Test04 should not execute!");
061: }
062:
063: // special override of validateMethod allows Test05
064: // to execute even though it has no data in the module
065: protected boolean validateMethod(String methodName) {
066: return methodName.equals("Test05") ? true : super
067: .validateMethod(methodName);
068: }
069:
070: // no data, but override of validateMethod allows it to execute
071: public void Test05() {
072: logln("Test05 executed.");
073: }
074:
075: // // The test data contains an error in the third case. When getInt("Data") is
076: // // executed the error is logged and iteration stops.
077: // public void Test06() {
078: // while (nextCase()) {
079: // logln("----");
080: // logln("isGood: " + testcase.getString("IsGood"));
081: // logln(" Data: " + testcase.getInt("Data"));
082: // }
083: // }
084: //
085: // // The test using the data reports an error, which also automatically stops iteration.
086: // public void Test07() {
087: // while (nextSettings()) {
088: // int value = settings.getInt("Value");
089: // while (nextCase()) {
090: // int factor = testcase.getInt("Factor");
091: // float result = (float)value / factor;
092: // if (result != (int)result) {
093: // errln("the number '" + factor + "' is not a factor of the number '" + value + "'");
094: // } else {
095: // logln("'" + factor + "' is a factor of '" + value + "'");
096: // }
097: // }
098: // }
099: // }
100:
101: // // The number of data elements is incorrect
102: // public void Test08() {
103: // while (nextCase()) {
104: // int one = testcase.getInt("One");
105: // int two = testcase.getInt("Two");
106: // int three = testcase.getInt("Three");
107: // logln("got: " + one + ", " + two + ", " + three);
108: // }
109: // }
110: //
111: // public void Test09() {
112: // while (nextCase()) {
113: // int radix = testcase.getInt("Radix");
114: // int[] pow = testcase.getIntArray("Power");
115: // int[] val = testcase.getIntArray("Value");
116: // logln("radix: " + radix + " pow: " + printArray(pow) + " val: " + printArray(val));
117: // for (int i = 0; i < pow.length; ++i) {
118: // if (val[i] != (int)Math.pow(radix, pow[i])) {
119: // errln("radix: " + radix + " to power " + pow[i] + " != " + val[i]);
120: // break;
121: // }
122: // }
123: // }
124: // }
125:
126: // utility print functions to display the data from the resource
127: String printArray(String[] a) {
128: StringBuffer buf = new StringBuffer("String[] {");
129: for (int i = 0; i < a.length; ++i) {
130: if (i != 0) {
131: buf.append(",");
132: }
133: buf.append(" " + a[i]);
134: }
135: buf.append(" }");
136: return buf.toString();
137: }
138:
139: String printArray(int[] a) {
140: StringBuffer buf = new StringBuffer("int[] {");
141: for (int i = 0; i < a.length; ++i) {
142: if (i != 0) {
143: buf.append(",");
144: }
145: buf.append(" " + a[i]);
146: }
147: buf.append(" }");
148: return buf.toString();
149: }
150:
151: String printArray(boolean[] a) {
152: StringBuffer buf = new StringBuffer("boolean[] {");
153: for (int i = 0; i < a.length; ++i) {
154: if (i != 0) {
155: buf.append(",");
156: }
157: buf.append(" " + a[i]);
158: }
159: buf.append(" }");
160: return buf.toString();
161: }
162:
163: /* (non-Javadoc)
164: * @see com.ibm.icu.dev.test.ModuleTest#processModules()
165: */
166: protected void processModules() {
167: // TODO Auto-generated method stub
168:
169: }
170: }
|