diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fd50a45be..848bec1f1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,7 +371,7 @@ file(GLOB_RECURSE ORCT2_RIDE_DEP_SOURCES "src/ride/ride_data.c" "src/ride/track_ file(GLOB_RECURSE ORCT2_PAINT_TEST_SOURCES "PaintTest/*.c" "PaintTest/*.cpp" "PaintTest/*.h") add_executable(test-paint ${ORCT2_RIDE_SOURCES} ${ORCT2_RIDE_DEP_SOURCES} ${ORCT2_PAINT_TEST_SOURCES}) -set_target_properties(test-paint PROPERTIES COMPILE_FLAGS "-DUSE_GTEST -DNO_VEHICLES") +set_target_properties(test-paint PROPERTIES COMPILE_FLAGS "-DNO_VEHICLES") set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 0) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index f92ee74b64..e7cd26d521 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 00EFEE721CF1D80B0035213B /* NetworkKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00EFEE701CF1D80B0035213B /* NetworkKey.cpp */; }; 791166FB1D7486EF005912EA /* NetworkServerAdvertiser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */; }; 8594C0601D885CF600235E93 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; }; + 85AFA2111D7DB83E00221B42 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85AFA20F1D7DB83E00221B42 /* main.cpp */; }; C612A8991D64825300B634CA /* vehicle_data.c in Sources */ = {isa = PBXBuildFile; fileRef = C612A8971D64825300B634CA /* vehicle_data.c */; }; C61FB7201CF6180C004CE991 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38BA1CF3006400659A24 /* libssl.dylib */; }; C61FB7211CF618BA004CE991 /* libssl.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38BA1CF3006400659A24 /* libssl.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; @@ -491,6 +492,8 @@ 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkServerAdvertiser.cpp; sourceTree = ""; }; 791166FA1D7486EF005912EA /* NetworkServerAdvertiser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkServerAdvertiser.h; sourceTree = ""; }; 8594C05F1D885CF600235E93 /* track_data_old.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = track_data_old.c; sourceTree = ""; }; + 85AFA20F1D7DB83E00221B42 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 85AFA2101D7DB83E00221B42 /* main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = main.h; sourceTree = ""; }; C612A8971D64825300B634CA /* vehicle_data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vehicle_data.c; sourceTree = ""; }; C612A8981D64825300B634CA /* vehicle_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vehicle_data.h; sourceTree = ""; }; C61FB7221CF86356004CE991 /* NetworkUser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkUser.cpp; sourceTree = ""; usesTabs = 0; }; @@ -1151,10 +1154,10 @@ isa = PBXGroup; children = ( C64FDAC41D6DA55E00F259B9 /* compat.c */, - C64FDAC71D6DA72400F259B9 /* main.c */, - C64FDAC91D6DA92D00F259B9 /* data.c */, C64FDAC91D6DA92D00F259B9 /* data.c */, + 85AFA20F1D7DB83E00221B42 /* main.cpp */, C64FDAC71D6DA72400F259B9 /* main.c */, + 85AFA2101D7DB83E00221B42 /* main.h */, ); path = PaintTest; sourceTree = ""; @@ -2359,6 +2362,7 @@ C64FDA651D6D9A2100F259B9 /* bobsleigh_coaster.c in Sources */, C64FDA661D6D9A2100F259B9 /* compact_inverted_coaster.c in Sources */, C64FDA671D6D9A2100F259B9 /* corkscrew_roller_coaster.c in Sources */, + 85AFA2111D7DB83E00221B42 /* main.cpp in Sources */, C64FDA681D6D9A2100F259B9 /* flying_roller_coaster.c in Sources */, C64FDA691D6D9A2100F259B9 /* giga_coaster.c in Sources */, C64FDA6A1D6D9A2100F259B9 /* heartline_twister_coaster.c in Sources */, @@ -3079,6 +3083,7 @@ C64FDA621D6D99F400F259B9 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; D497D0731C20FD52002BF46A /* Build configuration list for PBXProject "OpenRCT2" */ = { isa = XCConfigurationList; diff --git a/PaintTest/main.c b/PaintTest/main.c index 3902a8b4bd..cd029696cf 100644 --- a/PaintTest/main.c +++ b/PaintTest/main.c @@ -750,24 +750,3 @@ void initHooks() { addhook(0x00663105, (int) intercept_metal_a_supports, 0, (int[]) {EAX, EBX, EDX, EDI, EBP, END}, 0, EAX); addhook(0x00663584, (int) intercept_metal_b_supports, 0, (int[]) {EAX, EBX, EDX, EDI, EBP, END}, 0, EAX); } - -#if !defined(USE_GTEST) - -int main(int argc, const char *argv[]) { - initHooks(); - - bool success = true; - for (int i = 0; i < 91; i++) { - if (!rideIsImplemented(i)) { - continue; - } - - if (!testRide(i)) { - success = false; - } - } - - return success ? 0 : 1; -} - -#endif diff --git a/PaintTest/gtest.cpp b/PaintTest/main.cpp similarity index 54% rename from PaintTest/gtest.cpp rename to PaintTest/main.cpp index 802f959415..648e14ddde 100644 --- a/PaintTest/gtest.cpp +++ b/PaintTest/main.cpp @@ -14,8 +14,6 @@ *****************************************************************************/ #pragma endregion -#ifdef USE_GTEST - #include #include #include @@ -38,10 +36,70 @@ extern const utf8string RideNames[91]; extern const utf8string TrackNames[256]; extern const utf8string FlatTrackNames[256]; +enum CLIColour { + RED, + GREEN, +}; + +bool gTestColor = true; + +bool CStringEquals(const char *lhs, const char *rhs) { + if (lhs == NULL) return rhs == NULL; + + if (rhs == NULL) return false; + + return strcmp(lhs, rhs) == 0; +} + +bool ShouldUseColor() { + if (gTestColor == false) { + return false; + } + + const char* const term = getenv("TERM"); + const bool term_supports_color = + CStringEquals(term, "xterm") || + CStringEquals(term, "xterm-color") || + CStringEquals(term, "xterm-256color") || + CStringEquals(term, "screen") || + CStringEquals(term, "screen-256color") || + CStringEquals(term, "tmux") || + CStringEquals(term, "tmux-256color") || + CStringEquals(term, "rxvt-unicode") || + CStringEquals(term, "rxvt-unicode-256color") || + CStringEquals(term, "linux") || + CStringEquals(term, "cygwin"); + + return term_supports_color; +} + +const char* GetAnsiColorCode(CLIColour color) { + switch (color) { + case RED: return "1"; + case GREEN: return "2"; + default: return NULL; + }; +} + +void ColouredPrintF(CLIColour colour, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + + if(!ShouldUseColor()) { + vprintf(fmt, args); + va_end(args); + return; + } + + printf("\033[0;3%sm", GetAnsiColorCode(colour)); + vprintf(fmt, args); + printf("\033[m"); + va_end(args); +} + int main(int argc, char *argv[]) { std::vector testCases; - bool gTestColor = true; for (int i = 0; i < argc; ++i) { char *arg = argv[i]; if (strcmp(arg, "--gtest_color=no") == 0) { @@ -49,10 +107,6 @@ int main(int argc, char *argv[]) { } } - const utf8 *ansiRed = gTestColor ? "\x1b[31m" : ""; - const utf8 *ansiGreen = gTestColor ? "\x1b[32m" : ""; - const utf8 *ansiReset = gTestColor ? "\x1b[0m" : ""; - for (uint8 rideType = 0; rideType < 91; rideType++) { if (!rideIsImplemented(rideType)) { continue; @@ -81,15 +135,19 @@ int main(int argc, char *argv[]) { testCount += tc.trackTypes.size(); } - printf("%s[==========]%s Running %d tests from %d test cases.\n", ansiGreen, ansiReset, testCount, testCaseCount); - printf("%s[----------]%s Global test environment set-up.\n", ansiGreen, ansiReset); + ColouredPrintF(CLIColour::GREEN, "[==========] "); + printf("Running %d tests from %d test cases.\n", testCount, testCaseCount); + + ColouredPrintF(CLIColour::GREEN, "[----------] "); + printf("Global test environment set-up.\n"); initHooks(); int successCount = 0; std::vector failures; for (auto &&tc : testCases) { const utf8string rideTypeName = RideNames[tc.rideType]; - printf("%s[----------]%s %lu tests from %s\n", ansiGreen, ansiReset, tc.trackTypes.size(), rideTypeName); + ColouredPrintF(CLIColour::GREEN, "[----------] "); + printf("%lu tests from %s\n", tc.trackTypes.size(), rideTypeName); for (auto &&trackType : tc.trackTypes) { utf8string trackTypeName; @@ -99,34 +157,44 @@ int main(int argc, char *argv[]) { trackTypeName = TrackNames[trackType]; } - printf("%s[ RUN ]%s %s.%s\n", ansiGreen, ansiReset, rideTypeName, trackTypeName); + ColouredPrintF(CLIColour::GREEN, "[ RUN ] "); + printf("%s.%s\n", rideTypeName, trackTypeName); bool success = testTrackPainting(tc.rideType, trackType); if (!success) { - printf("%s[ FAILED ]%s %s.%s (0 ms)\n", ansiRed, ansiReset, rideTypeName, trackTypeName); utf8string testCaseName = new utf8[64]; sprintf(testCaseName, "%s.%s", rideTypeName, trackTypeName); + + ColouredPrintF(CLIColour::RED, "[ FAILED ] "); + printf("%s (0 ms)\n", testCaseName); failures.push_back(testCaseName); } else { - printf("%s[ OK ]%s %s.%s (0 ms)\n", ansiGreen, ansiReset, rideTypeName, trackTypeName); + ColouredPrintF(CLIColour::GREEN, "[ OK ] "); + printf("%s.%s (0 ms)\n", rideTypeName, trackTypeName); successCount++; } } - printf("%s[----------]%s %lu tests from %s (0 ms total)\n", ansiGreen, ansiReset, tc.trackTypes.size(), - rideTypeName); + ColouredPrintF(CLIColour::GREEN, "[----------] "); + printf("%lu tests from %s (0 ms total)\n", tc.trackTypes.size(), rideTypeName); } printf("\n"); - printf("%s[----------]%s Global test environment tear-down\n", ansiGreen, ansiReset); - printf("%s[==========]%s %d tests from %d test cases ran. (0 ms total).\n", ansiGreen, ansiReset, testCount, - testCaseCount); - printf("%s[ PASSED ]%s %d tests.\n", ansiGreen, ansiReset, successCount); + ColouredPrintF(CLIColour::GREEN, "[----------] "); + printf("Global test environment tear-down\n"); + + ColouredPrintF(CLIColour::GREEN, "[==========] "); + printf("%d tests from %d test cases ran. (0 ms total).\n", testCount, testCaseCount); + + ColouredPrintF(CLIColour::GREEN, "[ PASSED ] "); + printf("%d tests.\n", successCount); if (failures.size() > 0) { - printf("%s[ FAILED ]%s %lu tests, listed below:\n", ansiRed, ansiReset, failures.size()); + ColouredPrintF(CLIColour::RED, "[ FAILED ] "); + printf("%lu tests, listed below:\n", failures.size()); for (auto &&failure : failures) { - printf("%s[ FAILED ]%s %s\n", ansiRed, ansiReset, failure); + ColouredPrintF(CLIColour::RED, "[ FAILED ] "); + printf("%s\n", failure); delete(failure); } @@ -139,5 +207,3 @@ int main(int argc, char *argv[]) { return 0; } - -#endif // USE_GTEST