mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
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.
This commit is contained in:
parent
0ba22b7969
commit
564d48e95f
4 changed files with 58 additions and 45 deletions
2
.github/workflows/cmake.yml
vendored
2
.github/workflows/cmake.yml
vendored
|
|
@ -19,7 +19,7 @@ jobs:
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-latest, macos-latest ]
|
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
|
||||||
|
|
@ -30,35 +30,5 @@
|
||||||
|
|
||||||
namespace testing
|
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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
@ -26,8 +26,11 @@
|
||||||
#include "console/codeBlock.h"
|
#include "console/codeBlock.h"
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
#include "console/consoleInternal.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
|
class TorqueUnitTestListener : public ::testing::EmptyTestEventListener
|
||||||
|
|
@ -90,6 +93,40 @@ public:
|
||||||
TorqueUnitTestListener(bool verbose) : mVerbose(verbose) {}
|
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 TorqueScriptFixture : public testing::Test {};
|
||||||
|
|
||||||
class TorqueScriptTest : public TorqueScriptFixture {
|
class TorqueScriptTest : public TorqueScriptFixture {
|
||||||
|
|
@ -105,7 +142,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// uncomment to debug tests and use the test explorer.
|
// uncomment to debug tests and use the test explorer.
|
||||||
//#define TEST_EXPLORER
|
#define TEST_EXPLORER
|
||||||
#if !defined(TEST_EXPLORER)
|
#if !defined(TEST_EXPLORER)
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
@ -123,6 +160,17 @@ int main(int argc, char** argv)
|
||||||
Con::evaluate("GFXInit::createNullDevice();");
|
Con::evaluate("GFXInit::createNullDevice();");
|
||||||
Con::evaluate("if (!isObject(GuiDefaultProfile)) new GuiControlProfile(GuiDefaultProfile){}; if (!isObject(GuiTooltipProfile)) new GuiControlProfile(GuiTooltipProfile){};");
|
Con::evaluate("if (!isObject(GuiDefaultProfile)) new GuiControlProfile(GuiDefaultProfile){}; if (!isObject(GuiTooltipProfile)) new GuiControlProfile(GuiTooltipProfile){};");
|
||||||
testing::InitGoogleTest(&argc, argv);
|
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();
|
int res = RUN_ALL_TESTS();
|
||||||
|
|
||||||
StandardMainLoop::shutdown();
|
StandardMainLoop::shutdown();
|
||||||
|
|
@ -220,11 +268,6 @@ DefineEngineFunction(runAllUnitTests, int, (const char* testSpecs, const char* r
|
||||||
// Release the default listener.
|
// Release the default listener.
|
||||||
delete listeners.Release(listeners.default_result_printer());
|
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.
|
// Add the Torque unit test listener.
|
||||||
listeners.Append(new TorqueUnitTestListener(true));
|
listeners.Append(new TorqueUnitTestListener(true));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,29 +42,26 @@ protected:
|
||||||
|
|
||||||
// for tests in this class we probably only need the init_video an nothing else.
|
// 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);
|
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
|
void SetUp() override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformWindowManagerSDL* pwm;
|
|
||||||
|
|
||||||
void TearDown() override
|
void TearDown() override
|
||||||
{
|
{
|
||||||
delete pwm;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(PlatformWindowManagerSDLTest, Constructor)
|
TEST_F(PlatformWindowManagerSDLTest, Constructor)
|
||||||
{
|
{
|
||||||
|
PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
|
||||||
ASSERT_TRUE(pwm) << "no monitor to test against!";
|
ASSERT_TRUE(pwm) << "no monitor to test against!";
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
|
TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
|
||||||
{
|
{
|
||||||
|
PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
|
||||||
// Check out the primary desktop area...
|
// Check out the primary desktop area...
|
||||||
RectI primary = pwm->getPrimaryDesktopArea();
|
RectI primary = pwm->getPrimaryDesktopArea();
|
||||||
|
|
||||||
|
|
@ -74,6 +71,7 @@ TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
|
||||||
|
|
||||||
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
|
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
|
||||||
{
|
{
|
||||||
|
PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
|
||||||
// Now try to get info about all the monitors.
|
// Now try to get info about all the monitors.
|
||||||
Vector<RectI> monitorRects;
|
Vector<RectI> monitorRects;
|
||||||
pwm->getMonitorRegions(monitorRects);
|
pwm->getMonitorRegions(monitorRects);
|
||||||
|
|
@ -88,6 +86,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
|
||||||
|
|
||||||
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
|
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
|
||||||
{
|
{
|
||||||
|
PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
|
||||||
// Now try to get info about all the monitors.
|
// Now try to get info about all the monitors.
|
||||||
Vector<RectI> monitorRects;
|
Vector<RectI> monitorRects;
|
||||||
pwm->getMonitorRegions(monitorRects);
|
pwm->getMonitorRegions(monitorRects);
|
||||||
|
|
@ -98,6 +97,7 @@ TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
|
||||||
|
|
||||||
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
|
TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
|
||||||
{
|
{
|
||||||
|
PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
|
||||||
// Now try to get info about all the monitors.
|
// Now try to get info about all the monitors.
|
||||||
Vector<RectI> monitorRects;
|
Vector<RectI> monitorRects;
|
||||||
pwm->getMonitorRegions(monitorRects);
|
pwm->getMonitorRegions(monitorRects);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue