diff options
author | Adam Lesinski <adamlesinski@google.com> | 2014-01-23 18:17:42 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2014-01-27 10:31:04 -0800 |
commit | 282e181b58cf72b6ca770dc7ca5f91f135444502 (patch) | |
tree | e313e7ab30ff4679562efa37bde29cfcb9e375d3 /tools/aidl/options_test.cpp | |
parent | 7023df08f14ec5dee76ac54c03e870f84e297636 (diff) | |
download | frameworks_base-282e181b58cf72b6ca770dc7ca5f91f135444502.zip frameworks_base-282e181b58cf72b6ca770dc7ca5f91f135444502.tar.gz frameworks_base-282e181b58cf72b6ca770dc7ca5f91f135444502.tar.bz2 |
Revert "Move frameworks/base/tools/ to frameworks/tools/"
This reverts commit 9f6a119c8aa276432ece4fe2118bd8a3c9b1067e.
Diffstat (limited to 'tools/aidl/options_test.cpp')
-rw-r--r-- | tools/aidl/options_test.cpp | 291 |
1 files changed, 291 insertions, 0 deletions
diff --git a/tools/aidl/options_test.cpp b/tools/aidl/options_test.cpp new file mode 100644 index 0000000..bd106ce --- /dev/null +++ b/tools/aidl/options_test.cpp @@ -0,0 +1,291 @@ +#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; +} + |