1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// Main entry point for unit tests.
17 /*! \file */
18
19 #include "epid/common-testhelper/testapp-testhelper.h"
20 #include "gtest/gtest.h"
21
main(int argc,char ** argv)22 int main(int argc, char** argv) {
23 std::vector<std::string> positive;
24 std::vector<std::string> negative;
25 std::vector<char*> argv_new;
26 argv_new.push_back(argv[0]);
27 bool include_protected = false;
28 bool print_help = false;
29 for (int i = 1; i < argc; i++) {
30 std::string arg(argv[i]);
31 if (arg == std::string("--also_run_protected_tests")) {
32 include_protected = true;
33 } else if (arg == std::string("--help")) {
34 print_help = true;
35 argv_new.push_back(argv[i]);
36 } else if (arg.compare(0, 15, "--gtest_filter=") == 0) {
37 split_filter(&positive, &negative, arg.substr(15));
38 } else {
39 argv_new.push_back(argv[i]);
40 }
41 }
42 if (!include_protected) {
43 negative.push_back("*.*_PROTECTED_*");
44 negative.push_back("*.PROTECTED_*");
45 }
46 std::string filter = join_filter(positive, negative);
47 if (filter != "") {
48 argv_new.push_back(&filter[0]);
49 }
50 int argc_new = (int)argv_new.size();
51 argv_new.push_back(nullptr);
52 testing::InitGoogleTest(&argc_new, argv_new.data());
53 if (print_help) {
54 printf("\n");
55 printf("Custom Options:\n");
56 printf(" --also_run_protected_tests\n");
57 printf(" similar to --gtest_also_run_disabled_tests, but for\n");
58 printf(" protected tests (PROTECTED_ instead of DISABLED_)\n");
59 printf("\n");
60 printf("Protected tests are tests where some data is protected\n");
61 printf("(i.e. hidden) from the code and can only be used indirectly.\n");
62 }
63 return RUN_ALL_TESTS();
64 }
65