Home | History | Annotate | Download | only in unittests
      1 /*############################################################################
      2   # Copyright 2016-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 /*!
     17  * \file
     18  * \brief Main entry point for unit tests.
     19  */
     20 
     21 #include "epid/common-testhelper/testapp-testhelper.h"
     22 #include "gtest/gtest.h"
     23 
     24 int main(int argc, char** argv) {
     25   std::vector<std::string> positive;
     26   std::vector<std::string> negative;
     27   std::vector<char*> argv_new;
     28   argv_new.push_back(argv[0]);
     29   bool include_protected = false;
     30   bool print_help = false;
     31   for (int i = 1; i < argc; i++) {
     32     std::string arg(argv[i]);
     33     if (arg == std::string("--also_run_protected_tests")) {
     34       include_protected = true;
     35     } else if (arg == std::string("--help")) {
     36       print_help = true;
     37       argv_new.push_back(argv[i]);
     38     } else if (arg.compare(0, 15, "--gtest_filter=") == 0) {
     39       split_filter(&positive, &negative, arg.substr(15));
     40     } else {
     41       argv_new.push_back(argv[i]);
     42     }
     43   }
     44   if (!include_protected) {
     45     negative.push_back("*.*_PROTECTED_*");
     46     negative.push_back("*.PROTECTED_*");
     47   }
     48   std::string filter = join_filter(positive, negative);
     49   if (filter != "") {
     50     argv_new.push_back(&filter[0]);
     51   }
     52   int argc_new = (int)argv_new.size();
     53   argv_new.push_back(nullptr);
     54   testing::InitGoogleTest(&argc_new, argv_new.data());
     55   if (print_help) {
     56     printf("\n");
     57     printf("Custom Options:\n");
     58     printf("  --also_run_protected_tests\n");
     59     printf("    similar to --gtest_also_run_disabled_tests, but for\n");
     60     printf("    protected tests (PROTECTED_ instead of DISABLED_)\n");
     61     printf("\n");
     62     printf("Protected tests are tests where some data is protected\n");
     63     printf("(i.e. hidden) from the code and can only be used indirectly.\n");
     64   }
     65   return RUN_ALL_TESTS();
     66 }
     67