main-testhelper.cc 2.3 KB

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