Ver código fonte

fix for windows

Windows segfault was only appearing after changes to windowManagerTest, either that or because linux was failing first it wasn't giving windows a chance to fail. see if this works.
marauder2k7 2 anos atrás
pai
commit
564d48e95f

+ 1 - 1
.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

+ 2 - 32
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
-   };
-}
+   
+}

+ 50 - 7
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 <crtdbg.h>
+#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));
 

+ 5 - 5
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<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
    }
 
    void SetUp() override
    {
    }
 
-   PlatformWindowManagerSDL* pwm;
-
    void TearDown() override
    {
-      delete pwm;
    }
 };
 
 TEST_F(PlatformWindowManagerSDLTest, Constructor)
 {
+   PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
    ASSERT_TRUE(pwm) << "no monitor to test against!";
 }
 
 TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
 {
+   PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(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<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
    // Now try to get info about all the monitors.
    Vector<RectI> monitorRects;
    pwm->getMonitorRegions(monitorRects);
@@ -88,6 +86,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
 
 TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
 {
+   PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
    // Now try to get info about all the monitors.
    Vector<RectI> monitorRects;
    pwm->getMonitorRegions(monitorRects);
@@ -98,6 +97,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
 
 TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
 {
+   PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
    // Now try to get info about all the monitors.
    Vector<RectI> monitorRects;
    pwm->getMonitorRegions(monitorRects);