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