flush_script_test.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. int main(int argc, char** argv)
  5. {
  6. // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
  7. // it only requires that we produces output in the expected format when
  8. // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
  9. // to test the module without actually needing Google Test.
  10. if (argc > 2 && std::string(argv[1]) == "--gtest_list_tests" &&
  11. std::string(argv[2]).find("--gtest_output=json:") != std::string::npos) {
  12. std::cout << "flush_script_test.\n";
  13. std::string output_param(argv[2]);
  14. std::string::size_type split = output_param.find(":");
  15. std::string filepath = output_param.substr(split + 1);
  16. // The full file path is passed
  17. std::ofstream ostrm(filepath.c_str(), std::ios::binary);
  18. if (!ostrm) {
  19. std::cerr << "Failed to create file: " << filepath.c_str() << std::endl;
  20. return 1;
  21. }
  22. size_t const flushThreshold = 50000;
  23. size_t const flushAfter = 4;
  24. size_t const testCaseNum = 3 * flushAfter;
  25. ostrm << "{\n"
  26. " \"tests\": 4,\n"
  27. " \"name\": \"AllTests\",\n"
  28. " \"testsuites\": [\n"
  29. " {\n"
  30. " \"name\": \"flush_script_test\",\n"
  31. " \"tests\": 12,\n"
  32. " \"testsuite\": [";
  33. std::string testName(flushThreshold / flushAfter, 'T');
  34. for (size_t i = 1; i <= testCaseNum; ++i) {
  35. std::cout << " t" << i << testName.c_str() << "\n";
  36. if (i != 1)
  37. ostrm << ",";
  38. ostrm << "\n"
  39. " {\n"
  40. " \"name\": \"t"
  41. << i << testName.c_str()
  42. << "\",\n"
  43. " \"file\": \"file2.cpp\",\n"
  44. " \"line\": 47\n"
  45. " }";
  46. }
  47. ostrm << "\n"
  48. " ]\n"
  49. " }\n"
  50. " ]\n"
  51. "}";
  52. }
  53. return 0;
  54. }