xml_output.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. int main(int argc, char** argv)
  5. {
  6. // Note: GoogleTestXML.cmake doesn't actually depend on Google Test as such;
  7. // it only mimicks the output file creation using the path passed to this
  8. // test without any content
  9. for (int i = 0; i < argc; i++) {
  10. std::string param(argv[i]);
  11. if (param.find("--gtest_list_tests") != std::string::npos) {
  12. // This actually defines the name of the file passed in the 2nd run
  13. std::cout << "GoogleTestXML." << std::endl;
  14. std::cout << " Foo" << std::endl;
  15. // When changing these names, make sure to adapt the folder creation
  16. // in GoogleTestXML.cmake
  17. std::cout << "GoogleTestXMLSpecial/cases." << std::endl;
  18. std::cout << " case/0 # GetParam() = 42" << std::endl;
  19. std::cout << " case/1 # GetParam() = \"string\"" << std::endl;
  20. std::cout << " case/2 # GetParam() = \"path/like\"" << std::endl;
  21. } else if (param.find("--gtest_output=xml:") != std::string::npos) {
  22. std::string::size_type split = param.find(":");
  23. std::string filepath = param.substr(split + 1);
  24. // The full file path is passed
  25. std::ofstream ostrm(filepath.c_str(), std::ios::binary);
  26. if (!ostrm) {
  27. std::cerr << "Failed to create file: " << filepath.c_str()
  28. << std::endl;
  29. return 1;
  30. }
  31. ostrm << "--gtest_output=xml: mockup file\n";
  32. }
  33. }
  34. return 0;
  35. }