diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 19f4c35ed..8946c8180 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -19,7 +19,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ ubuntu-latest, macos-latest ] + os: [ ubuntu-latest, macos-latest, windows-latest ] steps: - uses: actions/checkout@v3 diff --git a/Engine/source/testing/memoryTester.h b/Engine/source/testing/memoryTester.h index 72d19e8d8..566a11e70 100644 --- a/Engine/source/testing/memoryTester.h +++ b/Engine/source/testing/memoryTester.h @@ -30,35 +30,5 @@ namespace testing { - class MemoryLeakDetector : public EmptyTestEventListener - { - public: - virtual void OnTestStart(const TestInfo&) - { -#if defined(TORQUE_OS_WIN) - _CrtMemCheckpoint(&memState_); -#endif - } - - virtual void OnTestEnd(const TestInfo& test_info) - { - if(test_info.result()->Passed()) - { -#if defined(TORQUE_OS_WIN) - _CrtMemState stateNow, stateDiff; - _CrtMemCheckpoint(&stateNow); - int diffResult = _CrtMemDifference(&stateDiff, &memState_, &stateNow); - if (diffResult) - { - FAIL() << "Memory leak of " << stateDiff.lSizes[1] << " byte(s) detected."; - } -#endif - } - } - - private: -#if defined(TORQUE_OS_WIN) - _CrtMemState memState_; -#endif - }; -} \ No newline at end of file + +} diff --git a/Engine/source/testing/unitTesting.cpp b/Engine/source/testing/unitTesting.cpp index 14029bdba..f99efbaca 100644 --- a/Engine/source/testing/unitTesting.cpp +++ b/Engine/source/testing/unitTesting.cpp @@ -26,8 +26,11 @@ #include "console/codeBlock.h" #include "console/engineAPI.h" #include "console/consoleInternal.h" -#include "memoryTester.h" +#if defined(TORQUE_OS_WIN) +#define _CRTDBG_MAP_ALLOC +#include +#endif //----------------------------------------------------------------------------- class TorqueUnitTestListener : public ::testing::EmptyTestEventListener @@ -90,6 +93,40 @@ public: TorqueUnitTestListener(bool verbose) : mVerbose(verbose) {} }; +class MemoryLeakDetector : public ::testing::EmptyTestEventListener +{ +public: + virtual void OnTestStart(const ::testing::TestInfo& testInfo) + { +#if defined(TORQUE_OS_WIN) + _CrtMemCheckpoint(&memState_); +#endif + } + + virtual void OnTestEnd(const ::testing::TestInfo& testInfo) + { + if (testInfo.result()->Passed()) + { +#if defined(TORQUE_OS_WIN) + _CrtMemState stateNow, stateDiff; + _CrtMemCheckpoint(&stateNow); + int diffResult = _CrtMemDifference(&stateDiff, &memState_, &stateNow); + if (diffResult) + { + FAIL() << "Memory leak of " << stateDiff.lSizes[1] << " byte(s) detected."; + } +#endif + } + } + +private: +#if defined(TORQUE_OS_WIN) + _CrtMemState memState_; +#endif +public: + MemoryLeakDetector() {} +}; + class TorqueScriptFixture : public testing::Test {}; class TorqueScriptTest : public TorqueScriptFixture { @@ -105,7 +142,7 @@ private: }; // uncomment to debug tests and use the test explorer. -//#define TEST_EXPLORER +#define TEST_EXPLORER #if !defined(TEST_EXPLORER) int main(int argc, char** argv) { @@ -123,6 +160,17 @@ int main(int argc, char** argv) Con::evaluate("GFXInit::createNullDevice();"); Con::evaluate("if (!isObject(GuiDefaultProfile)) new GuiControlProfile(GuiDefaultProfile){}; if (!isObject(GuiTooltipProfile)) new GuiControlProfile(GuiTooltipProfile){};"); testing::InitGoogleTest(&argc, argv); + + // Fetch the unit test instance. + testing::UnitTest& unitTest = *testing::UnitTest::GetInstance(); + // Fetch the unit test event listeners. + testing::TestEventListeners& listeners = unitTest.listeners(); + + listeners.Append(new MemoryLeakDetector()); + + // Add the Torque unit test listener. + listeners.Append(new TorqueUnitTestListener(true)); + int res = RUN_ALL_TESTS(); StandardMainLoop::shutdown(); @@ -220,11 +268,6 @@ DefineEngineFunction(runAllUnitTests, int, (const char* testSpecs, const char* r // Release the default listener. delete listeners.Release(listeners.default_result_printer()); - if (Con::getBoolVariable("$Testing::CheckMemoryLeaks", false)) { - // Add the memory leak tester. - listeners.Append(new testing::MemoryLeakDetector); - } - // Add the Torque unit test listener. listeners.Append(new TorqueUnitTestListener(true)); diff --git a/Engine/source/testing/windowManagerTest.cpp b/Engine/source/testing/windowManagerTest.cpp index 408ce4acb..aa0eb731d 100644 --- a/Engine/source/testing/windowManagerTest.cpp +++ b/Engine/source/testing/windowManagerTest.cpp @@ -42,29 +42,26 @@ protected: // for tests in this class we probably only need the init_video an nothing else. SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE); - - pwm = static_cast(CreatePlatformWindowManager()); } void SetUp() override { } - PlatformWindowManagerSDL* pwm; - void TearDown() override { - delete pwm; } }; TEST_F(PlatformWindowManagerSDLTest, Constructor) { + PlatformWindowManagerSDL* pwm = static_cast(CreatePlatformWindowManager()); ASSERT_TRUE(pwm) << "no monitor to test against!"; } TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest) { + PlatformWindowManagerSDL* pwm = static_cast(CreatePlatformWindowManager()); // Check out the primary desktop area... RectI primary = pwm->getPrimaryDesktopArea(); @@ -74,6 +71,7 @@ TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest) TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid) { + PlatformWindowManagerSDL* pwm = static_cast(CreatePlatformWindowManager()); // Now try to get info about all the monitors. Vector monitorRects; pwm->getMonitorRegions(monitorRects); @@ -88,6 +86,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid) TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne) { + PlatformWindowManagerSDL* pwm = static_cast(CreatePlatformWindowManager()); // Now try to get info about all the monitors. Vector monitorRects; pwm->getMonitorRegions(monitorRects); @@ -98,6 +97,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne) TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow) { + PlatformWindowManagerSDL* pwm = static_cast(CreatePlatformWindowManager()); // Now try to get info about all the monitors. Vector monitorRects; pwm->getMonitorRegions(monitorRects);