TestReporterStdout.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "TestReporterStdout.h"
  2. #include <cstdio>
  3. #include "TestDetails.h"
  4. // cstdio doesn't pull in namespace std on VC6, so we do it here.
  5. #if defined(_MSC_VER) && (_MSC_VER == 1200)
  6. namespace std {}
  7. #endif
  8. #if defined(__ANDROID__)
  9. # include <android/log.h>
  10. # define outf(format, ...) __android_log_print(ANDROID_LOG_DEBUG, "", format, ##__VA_ARGS__)
  11. #else
  12. # define outf(format, ...) printf(format, ##__VA_ARGS__)
  13. #endif // defined(__ANDROID__)
  14. namespace UnitTest {
  15. void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure)
  16. {
  17. #if defined(__APPLE__) || defined(__GNUG__)
  18. char const* const errorFormat = "%s:%d: error: Failure in %s: %s\n";
  19. #else
  20. char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n";
  21. #endif
  22. using namespace std;
  23. outf(errorFormat, details.filename, details.lineNumber, details.testName, failure);
  24. }
  25. void TestReporterStdout::ReportTestStart(TestDetails const& /*test*/)
  26. {
  27. }
  28. void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float)
  29. {
  30. }
  31. void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount,
  32. int const failureCount, float secondsElapsed)
  33. {
  34. using namespace std;
  35. if (failureCount > 0)
  36. {
  37. outf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount);
  38. }
  39. else
  40. {
  41. outf("Success: %d tests passed.\n", totalTestCount);
  42. }
  43. outf("Test time: %.2f seconds.\n", secondsElapsed);
  44. }
  45. }