diff options
author | Mike Lockwood <lockwood@google.com> | 2013-08-28 09:44:17 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2013-08-28 09:44:17 -0700 |
commit | 9f6a119c8aa276432ece4fe2118bd8a3c9b1067e (patch) | |
tree | 1391656f9ad624aa99d4c7d2880d38121801a424 /tools/aidl/options_test.cpp | |
parent | 647b6f5ed276bf93d95e5801e5e8af2802ef5fbb (diff) | |
download | frameworks_base-9f6a119c8aa276432ece4fe2118bd8a3c9b1067e.zip frameworks_base-9f6a119c8aa276432ece4fe2118bd8a3c9b1067e.tar.gz frameworks_base-9f6a119c8aa276432ece4fe2118bd8a3c9b1067e.tar.bz2 |
Move frameworks/base/tools/ to frameworks/tools/
Change-Id: I3ffafdab27cc4aca256c3a5806b630795b75d5c8
Diffstat (limited to 'tools/aidl/options_test.cpp')
-rw-r--r-- | tools/aidl/options_test.cpp | 291 |
1 files changed, 0 insertions, 291 deletions
diff --git a/tools/aidl/options_test.cpp b/tools/aidl/options_test.cpp deleted file mode 100644 index bd106ce..0000000 --- a/tools/aidl/options_test.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include <iostream> -#include "options.h" - -const bool VERBOSE = false; - -using namespace std; - -struct Answer { - const char* argv[8]; - int result; - const char* systemSearchPath[8]; - const char* localSearchPath[8]; - const char* inputFileName; - language_t nativeLanguage; - const char* outputH; - const char* outputCPP; - const char* outputJava; -}; - -bool -match_arrays(const char* const*expected, const vector<string> &got) -{ - int count = 0; - while (expected[count] != NULL) { - count++; - } - if (got.size() != count) { - return false; - } - for (int i=0; i<count; i++) { - if (got[i] != expected[i]) { - return false; - } - } - return true; -} - -void -print_array(const char* prefix, const char* const*expected) -{ - while (*expected) { - cout << prefix << *expected << endl; - expected++; - } -} - -void -print_array(const char* prefix, const vector<string> &got) -{ - size_t count = got.size(); - for (size_t i=0; i<count; i++) { - cout << prefix << got[i] << endl; - } -} - -static int -test(const Answer& answer) -{ - int argc = 0; - while (answer.argv[argc]) { - argc++; - } - - int err = 0; - - Options options; - int result = parse_options(argc, answer.argv, &options); - - // result - if (((bool)result) != ((bool)answer.result)) { - cout << "mismatch: result: got " << result << " expected " << - answer.result << endl; - err = 1; - } - - if (result != 0) { - // if it failed, everything is invalid - return err; - } - - // systemSearchPath - if (!match_arrays(answer.systemSearchPath, options.systemSearchPath)) { - cout << "mismatch: systemSearchPath: got" << endl; - print_array(" ", options.systemSearchPath); - cout << " expected" << endl; - print_array(" ", answer.systemSearchPath); - err = 1; - } - - // localSearchPath - if (!match_arrays(answer.localSearchPath, options.localSearchPath)) { - cout << "mismatch: localSearchPath: got" << endl; - print_array(" ", options.localSearchPath); - cout << " expected" << endl; - print_array(" ", answer.localSearchPath); - err = 1; - } - - // inputFileName - if (answer.inputFileName != options.inputFileName) { - cout << "mismatch: inputFileName: got " << options.inputFileName - << " expected " << answer.inputFileName << endl; - err = 1; - } - - // nativeLanguage - if (answer.nativeLanguage != options.nativeLanguage) { - cout << "mismatch: nativeLanguage: got " << options.nativeLanguage - << " expected " << answer.nativeLanguage << endl; - err = 1; - } - - // outputH - if (answer.outputH != options.outputH) { - cout << "mismatch: outputH: got " << options.outputH - << " expected " << answer.outputH << endl; - err = 1; - } - - // outputCPP - if (answer.outputCPP != options.outputCPP) { - cout << "mismatch: outputCPP: got " << options.outputCPP - << " expected " << answer.outputCPP << endl; - err = 1; - } - - // outputJava - if (answer.outputJava != options.outputJava) { - cout << "mismatch: outputJava: got " << options.outputJava - << " expected " << answer.outputJava << endl; - err = 1; - } - - return err; -} - -const Answer g_tests[] = { - - { - /* argv */ { "test", "-i/moof", "-I/blah", "-Ibleh", "-imoo", "inputFileName.aidl_cpp", NULL, NULL }, - /* result */ 0, - /* systemSearchPath */ { "/blah", "bleh", NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { "/moof", "moo", NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "inputFileName.aidl_cpp", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "", - /* outputJava */ "" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", NULL, NULL, NULL, NULL }, - /* result */ 0, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "inputFileName.aidl_cpp", - /* nativeLanguage */ CPP, - /* outputH */ "outputH", - /* outputCPP */ "", - /* outputJava */ "" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-ocpp", "outputCPP", NULL, NULL, NULL, NULL }, - /* result */ 0, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "inputFileName.aidl_cpp", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "outputCPP", - /* outputJava */ "" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-ojava", "outputJava", NULL, NULL, NULL, NULL }, - /* result */ 0, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "inputFileName.aidl_cpp", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "", - /* outputJava */ "outputJava" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", "-ocpp", "outputCPP", "-ojava", "outputJava" }, - /* result */ 0, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "inputFileName.aidl_cpp", - /* nativeLanguage */ CPP, - /* outputH */ "outputH", - /* outputCPP */ "outputCPP", - /* outputJava */ "outputJava" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-oh", "outputH", "-oh", "outputH1", NULL, NULL }, - /* result */ 1, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "", - /* outputJava */ "" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-ocpp", "outputCPP", "-ocpp", "outputCPP1", NULL, NULL }, - /* result */ 1, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "", - /* outputJava */ "" - }, - - { - /* argv */ { "test", "inputFileName.aidl_cpp", "-ojava", "outputJava", "-ojava", "outputJava1", NULL, NULL }, - /* result */ 1, - /* systemSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* localSearchPath */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - /* inputFileName */ "", - /* nativeLanguage */ CPP, - /* outputH */ "", - /* outputCPP */ "", - /* outputJava */ "" - }, - -}; - -int -main(int argc, const char** argv) -{ - const int count = sizeof(g_tests)/sizeof(g_tests[0]); - int matches[count]; - - int result = 0; - for (int i=0; i<count; i++) { - if (VERBOSE) { - cout << endl; - cout << "---------------------------------------------" << endl; - const char* const* p = g_tests[i].argv; - while (*p) { - cout << " " << *p; - p++; - } - cout << endl; - cout << "---------------------------------------------" << endl; - } - matches[i] = test(g_tests[i]); - if (VERBOSE) { - if (0 == matches[i]) { - cout << "passed" << endl; - } else { - cout << "failed" << endl; - } - result |= matches[i]; - } - } - - cout << endl; - cout << "=============================================" << endl; - cout << "options_test summary" << endl; - cout << "=============================================" << endl; - - if (!result) { - cout << "passed" << endl; - } else { - cout << "failed the following tests:" << endl; - for (int i=0; i<count; i++) { - if (matches[i]) { - cout << " "; - const char* const* p = g_tests[i].argv; - while (*p) { - cout << " " << *p; - p++; - } - cout << endl; - } - } - } - - return result; -} - |