1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.castor.xmlctf;
36
37 import java.io.File;
38
39 import junit.framework.Test;
40 import junit.framework.TestCase;
41
42
43
44
45
46
47
48
49
50 public class CastorTestSuiteRunner extends TestCase {
51
52
53
54
55
56 public static final String TEST_OUTPUT_ROOT = "../xmlctf/build/tests/output/";
57
58
59
60
61
62
63 private static final String TEST_ROOT_PROPERTY = "org.exolab.castor.tests.TestRoot";
64
65
66
67
68
69 private static String _testRoot;
70
71
72
73
74 private static final String HELP_ARG = "-help";
75
76
77
78
79 private static final String VERBOSE_ARG = "-verbose";
80
81
82
83
84 private static final String TEXT_MODE_ARG = "-text";
85
86
87
88
89 private static final String PRINT_STACK = "-printStack";
90
91
92
93
94 private static final String SEED_ARG = "-seed";
95
96
97
98
99
100
101 public CastorTestSuiteRunner(final String name) {
102 super(name);
103 }
104
105
106
107
108
109
110
111 public static Test suite() {
112 _testRoot = System.getProperty(TEST_ROOT_PROPERTY);
113
114 if (_testRoot.equals(".") || _testRoot.equals("..")) {
115
116 File tmp = new File(_testRoot);
117 try {
118 _testRoot = tmp.getCanonicalPath();
119 } catch (java.io.IOException iox) {
120 iox.printStackTrace();
121 System.exit(1);
122 }
123 } else if (_testRoot.startsWith("./") || _testRoot.startsWith(".\\")) {
124
125 _testRoot = _testRoot.substring(2);
126 }
127
128 File testRoot = new File(_testRoot);
129
130 if (!testRoot.exists()) {
131 System.out.println("\nUnable to locate the root directory for the test cases");
132 System.exit(1);
133 }
134 return new TestCaseAggregator(testRoot, TEST_OUTPUT_ROOT).suite();
135 }
136
137
138
139
140
141
142 public static void main(final String[] args) {
143 if (args.length == 0) {
144 error();
145 }
146
147 boolean text = processArguments(args);
148
149 if (System.getProperty(TEST_ROOT_PROPERTY) == null) {
150 error();
151 }
152
153 System.out.println("Pseudo-random number generator seed: " + RandomHelper.getSeed());
154
155 if (text) {
156 String[] testCaseName = {CastorTestSuiteRunner.class.getName()};
157 junit.textui.TestRunner.main(testCaseName);
158 } else {
159
160
161
162 }
163 }
164
165
166
167
168
169
170
171
172 private static boolean processArguments(final String[] args) {
173 boolean textModeJUnit = true;
174
175 for (int i = 0; i < args.length; ++i) {
176 String argument = args[i];
177 System.out.println("arg: '" + argument + "'");
178
179 if (argument.equals(VERBOSE_ARG)) {
180 System.out.println("Verbose on");
181 System.setProperty(TestCaseAggregator.VERBOSE_PROPERTY, "true");
182 } else if (argument.equals(PRINT_STACK)) {
183 System.out.println("Printing stack traces on error on.");
184 System.setProperty(TestCaseAggregator.PRINT_STACK_TRACE, "true");
185 } else if (argument.equals(TEXT_MODE_ARG)) {
186 System.out.println("Running in text mode.");
187 textModeJUnit = true;
188 } else if (argument.equals(SEED_ARG)) {
189
190 try {
191 long seed = Long.parseLong(args[++i]);
192 RandomHelper.setSeed(seed);
193 } catch (NumberFormatException nfe) {
194 System.out.println("Unable to parse the number for the seed");
195 error();
196 }
197 } else if (argument.equals(HELP_ARG)) {
198 usage();
199 System.exit(0);
200 } else if (System.getProperty(TEST_ROOT_PROPERTY) == null) {
201 System.setProperty(TEST_ROOT_PROPERTY, argument);
202 } else {
203 System.out.println("Unexpected command-line argument: '" + argument + "'");
204 error();
205 }
206 }
207 return textModeJUnit;
208 }
209
210
211
212
213 private static void error() {
214 usage();
215 System.exit(1);
216 }
217
218
219
220
221 private static void usage() {
222 System.out.println("Castor Testing Framework ");
223 System.out.println("------------------------ ");
224 System.out.println("argument: [" + VERBOSE_ARG + "] [" + TEXT_MODE_ARG + "] [" + PRINT_STACK
225 + "] [" + SEED_ARG + " <seed value>] <root test directory or a castor jar test file>");
226 System.out.println(" " + HELP_ARG + " : displays this screen.");
227 System.out
228 .println(" " + VERBOSE_ARG + " : give detailed execution information for the each test");
229 System.out.println(" " + TEXT_MODE_ARG + " : run the test without starting the swing gui");
230 System.out
231 .println(" " + PRINT_STACK + " : Print the full stack trace if an exception is thrown");
232 System.out.println(" " + SEED_ARG + " <seed value>: "
233 + "set a specific seed for the pseudo-random number generator");
234 }
235
236 }