1 #include "TestReporterStdout.h"
2 #include <cstdio>
3 
4 #include "TestDetails.h"
5 
6 #ifdef _XBOX_ONE
7 #include <windows.h>
8 #include <assert.h>
9 #endif
10 
11 // cstdio doesn't pull in namespace std on VC6, so we do it here.
12 #if defined(UNITTEST_WIN32) && (_MSC_VER == 1200)
13 	namespace std {}
14 #endif
15 
16 namespace UnitTest {
17 
ReportFailure(TestDetails const & details,char const * failure)18 void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure)
19 {
20 #ifdef _XBOX_ONE
21 	details;
22 	failure;
23 	OutputDebugStringA("Failed ");
24 	OutputDebugStringA(failure);
25 	OutputDebugStringA("\n");
26 	//assert(false);
27 #else
28 
29     using namespace std;
30 #if defined(__APPLE__) || defined(__GNUG__)
31     char const* const errorFormat = "%s:%d:%d: error: Failure in %s: %s\n";
32     fprintf(stderr, errorFormat, details.filename, details.lineNumber, 1, details.testName, failure);
33 #else
34     char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n";
35     fprintf(stderr, errorFormat, details.filename, details.lineNumber, details.testName, failure);
36 #endif
37 #endif
38 }
39 
ReportTestStart(TestDetails const & details)40 void TestReporterStdout::ReportTestStart(TestDetails const& details/*test*/)
41 {
42 #ifdef _XBOX_ONE
43 	OutputDebugStringA("\n=> Test: ");
44 	OutputDebugStringA(details.testName);
45 	OutputDebugStringA("\n");
46 #else
47 	printf("\n=> Test: %s\n", details.testName);
48 #endif
49 }
50 
ReportTestFinish(TestDetails const &,float delta)51 void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float delta)
52 {
53 #ifdef _XBOX_ONE
54 	char msg[128];
55 	sprintf(msg, "=> Finished in %3.2f sec\n", delta);
56 	OutputDebugStringA(msg);
57 #else
58 	printf("=> Finished in %3.2f sec\n", delta);
59 #endif
60 }
61 
ReportSummary(int const totalTestCount,int const failedTestCount,int const failureCount,float const secondsElapsed)62 void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount,
63                                        int const failureCount, float const secondsElapsed)
64 {
65 	using namespace std;
66 
67     if (failureCount > 0)
68         printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount);
69     else
70         printf("Success: %d tests passed.\n", totalTestCount);
71 
72 #ifdef _XBOX_ONE
73 	char msg[128];
74 	sprintf(msg, "Test time: %.2f seconds.\n", secondsElapsed);
75 	OutputDebugStringA(msg);
76 #else
77     printf("Test time: %.2f seconds.\n", secondsElapsed);
78 #endif
79 }
80 
81 }
82