4 const bool VERBOSE = false;
11 const char* systemSearchPath[8];
12 const char* localSearchPath[8];
13 const char* inputFileName;
14 language_t nativeLanguage;
16 const char* outputCPP;
17 const char* outputJava;
21 match_arrays(const char* const*expected, const vector<string> &got)
24 while (expected[count] != NULL) {
27 if (got.size() != count) {
30 for (int i=0; i<count; i++) {
31 if (got[i] != expected[i]) {
39 print_array(const char* prefix, const char* const*expected)
42 cout << prefix << *expected << endl;
48 print_array(const char* prefix, const vector<string> &got)
50 size_t count = got.size();
51 for (size_t i=0; i<count; i++) {
52 cout << prefix << got[i] << endl;
57 test(const Answer& answer)
60 while (answer.argv[argc]) {
67 int result = parse_options(argc, answer.argv, &options);
70 if (((bool)result) != ((bool)answer.result)) {
71 cout << "mismatch: result: got " << result << " expected " <<
72 answer.result << endl;
77 // if it failed, everything is invalid
82 if (!match_arrays(answer.systemSearchPath, options.systemSearchPath)) {
83 cout << "mismatch: systemSearchPath: got" << endl;
84 print_array(" ", options.systemSearchPath);
85 cout << " expected" << endl;
86 print_array(" ", answer.systemSearchPath);
91 if (!match_arrays(answer.localSearchPath, options.localSearchPath)) {
92 cout << "mismatch: localSearchPath: got" << endl;
93 print_array(" ", options.localSearchPath);
94 cout << " expected" << endl;
95 print_array(" ", answer.localSearchPath);
100 if (answer.inputFileName != options.inputFileName) {
101 cout << "mismatch: inputFileName: got " << options.inputFileName
102 << " expected " << answer.inputFileName << endl;
107 if (answer.nativeLanguage != options.nativeLanguage) {
108 cout << "mismatch: nativeLanguage: got " << options.nativeLanguage
109 << " expected " << answer.nativeLanguage << endl;
114 if (answer.outputH != options.outputH) {
115 cout << "mismatch: outputH: got " << options.outputH
116 << " expected " << answer.outputH << endl;
121 if (answer.outputCPP != options.outputCPP) {
122 cout << "mismatch: outputCPP: got " << options.outputCPP
123 << " expected " << answer.outputCPP << endl;
128 if (answer.outputJava != options.outputJava) {
129 cout << "mismatch: outputJava: got " << options.outputJava
130 << " expected " << answer.outputJava << endl;
137 const Answer g_tests[] = {
140 /* argv */ { "test", "-i/moof", "-I/blah", "-Ibleh", "-imoo", "inputFileName.aidl_cpp", NULL, NULL },
142 /* systemSearchPath */ { "/blah", "bleh", NULL, NULL, NULL, NULL, NULL, NULL },
143 /* localSearchPath */ { "/moof", "moo", NULL, NULL, NULL, NULL, NULL, NULL },
144 /* inputFileName */ "inputFileName.aidl_cpp",
145 /* nativeLanguage */ CPP,
152 /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", NULL, NULL, NULL, NULL },
154 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
155 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
156 /* inputFileName */ "inputFileName.aidl_cpp",
157 /* nativeLanguage */ CPP,
158 /* outputH */ "outputH",
164 /* argv */ { "test", "inputFileName.aidl_cpp", "-ocpp", "outputCPP", NULL, NULL, NULL, NULL },
166 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
167 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
168 /* inputFileName */ "inputFileName.aidl_cpp",
169 /* nativeLanguage */ CPP,
171 /* outputCPP */ "outputCPP",
176 /* argv */ { "test", "inputFileName.aidl_cpp", "-ojava", "outputJava", NULL, NULL, NULL, NULL },
178 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
179 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
180 /* inputFileName */ "inputFileName.aidl_cpp",
181 /* nativeLanguage */ CPP,
184 /* outputJava */ "outputJava"
188 /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", "-ocpp", "outputCPP", "-ojava", "outputJava" },
190 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
191 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
192 /* inputFileName */ "inputFileName.aidl_cpp",
193 /* nativeLanguage */ CPP,
194 /* outputH */ "outputH",
195 /* outputCPP */ "outputCPP",
196 /* outputJava */ "outputJava"
200 /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", "-oh", "outputH1", NULL, NULL },
202 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
203 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
204 /* inputFileName */ "",
205 /* nativeLanguage */ CPP,
212 /* argv */ { "test", "inputFileName.aidl_cpp", "-ocpp", "outputCPP", "-ocpp", "outputCPP1", NULL, NULL },
214 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
215 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
216 /* inputFileName */ "",
217 /* nativeLanguage */ CPP,
224 /* argv */ { "test", "inputFileName.aidl_cpp", "-ojava", "outputJava", "-ojava", "outputJava1", NULL, NULL },
226 /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
227 /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
228 /* inputFileName */ "",
229 /* nativeLanguage */ CPP,
238 main(int argc, const char** argv)
240 const int count = sizeof(g_tests)/sizeof(g_tests[0]);
244 for (int i=0; i<count; i++) {
247 cout << "---------------------------------------------" << endl;
248 const char* const* p = g_tests[i].argv;
254 cout << "---------------------------------------------" << endl;
256 matches[i] = test(g_tests[i]);
258 if (0 == matches[i]) {
259 cout << "passed" << endl;
261 cout << "failed" << endl;
263 result |= matches[i];
268 cout << "=============================================" << endl;
269 cout << "options_test summary" << endl;
270 cout << "=============================================" << endl;
273 cout << "passed" << endl;
275 cout << "failed the following tests:" << endl;
276 for (int i=0; i<count; i++) {
279 const char* const* p = g_tests[i].argv;