Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Unit Tests
run: |
cd "${{github.workspace}}/My Projects/Torque3D/game"
./Torque3D runTests.tscript
./Torque3D_unittests

- name: Test Reporter
uses: phoenix-actions/test-reporting@v14
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-macos-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Unit Tests
run: |
cd "${{github.workspace}}/My Projects/Torque3D/game"
./Torque3D.app/Contents/MacOS/Torque3D runTests.tscript
./Torque3D_unittests

- name: Test Reporter
uses: phoenix-actions/test-reporting@v14
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-windows-msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Unit Tests
run: |
cd "${{github.workspace}}/My Projects/Torque3D/game"
./Torque3D.exe runTests.tscript
./Torque3D_unittests.exe

- name: Test Reporter
uses: phoenix-actions/test-reporting@v14
Expand Down
136 changes: 105 additions & 31 deletions Engine/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ forwardDef(TORQUE_BASIC_LIGHTING)
set(TORQUE_SDL ON) # we need sdl to do our platform interop
forwardDef(TORQUE_SDL)

if(TORQUE_TESTING)
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} TORQUE_TESTS_ENABLED)
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} "_VARIADIC_MAX=10")
endif()

# On Windows we disable CRT Security warnings - this comes from recommendations to use non-portable functions.
if (WIN32)
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} _CRT_SECURE_NO_WARNINGS WIN32)
Expand Down Expand Up @@ -253,11 +248,6 @@ if (UNIX AND NOT APPLE)
torqueAddSourceDirectories("platformX11")
endif (UNIX AND NOT APPLE)

if(TORQUE_TESTING)
torqueAddSourceDirectories("testing")
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} TORQUE_SHARED SDL_MAIN_HANDLED)
endif(TORQUE_TESTING)

# Add the collected files to our engine group
source_group(TREE "${CMAKE_SOURCE_DIR}/Engine/source" PREFIX "Engine" FILES ${TORQUE_SOURCE_FILES})
file(GLOB_RECURSE TORQUE_APP_GAME_SOURCES "${TORQUE_APP_ROOT_DIRECTORY}/source/*.cpp" "${TORQUE_APP_ROOT_DIRECTORY}/source/*.h")
Expand Down Expand Up @@ -389,10 +379,6 @@ if (APPLE)
"${TORQUE_APP_GAME_DIRECTORY}/${TORQUE_APP_NAME}.torsion"
"${TORQUE_APP_GAME_DIRECTORY}/Template.torsion.exports")

if(TORQUE_TESTING)
set(MACOSX_RESOURCES ${MACOSX_RESOURCES} "${TORQUE_APP_GAME_DIRECTORY}/runTests.${TORQUE_SCRIPT_EXTENSION}")
endif()

set(TORQUE_SOURCE_FILES ${TORQUE_SOURCE_FILES} ${TORQUE_PLATFORM_MAC_SOURCES} ${MACOSX_RESOURCES})

source_group("Resources" FILES ${MACOSX_RESOURCES})
Expand Down Expand Up @@ -426,7 +412,7 @@ if (NOT TORQUE_NET_CURL)
endif()

################# Executable Generation ###################
if (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
if (TORQUE_DYNAMIC_LIBRARY)
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} TORQUE_SHARED)

# Build the main engine library
Expand All @@ -438,10 +424,8 @@ if (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
set(TORQUE_SOURCE_FILES "main/main.cpp")
set(TORQUE_LINK_LIBRARIES TorqueEngine)
else()
if(NOT TORQUE_TESTING)
set(TORQUE_SOURCE_FILES "main/main.cpp" ${TORQUE_SOURCE_FILES})
endif()
endif (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
set(TORQUE_SOURCE_FILES "main/main.cpp" ${TORQUE_SOURCE_FILES})
endif (TORQUE_DYNAMIC_LIBRARY)

if (APPLE)
add_executable(${TORQUE_APP_NAME} MACOSX_BUNDLE
Expand Down Expand Up @@ -486,9 +470,9 @@ elseif (WIN32)

# NOTE: On Windows, /Zc:wchar_t- is necessary otherwise you get unicode errors
set_target_properties(${TORQUE_APP_NAME} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS}")
if (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
if (TORQUE_DYNAMIC_LIBRARY)
set_target_properties(TorqueEngine PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_COMMON_DEFAULT}")
endif (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
endif (TORQUE_DYNAMIC_LIBRARY)
else()
add_executable(${TORQUE_APP_NAME} ${TORQUE_SOURCE_FILES})

Expand Down Expand Up @@ -539,6 +523,13 @@ if(IS_ARM)
add_math_backend(neon MATH_SIMD_NEON)
endif()

foreach(MATH_BACKEND ${TORQUE_MATH_BACKENDS})
target_sources(${TORQUE_APP_NAME}
PRIVATE
$<TARGET_OBJECTS:${MATH_BACKEND}>
)
endforeach()

if(MSVC)
# Match projectGenerator naming for executables
set(OUTPUT_CONFIG DEBUG MINSIZEREL RELWITHDEBINFO)
Expand All @@ -547,10 +538,10 @@ if(MSVC)
list(GET OUTPUT_CONFIG ${INDEX} CONF)
list(GET OUTPUT_SUFFIX ${INDEX} SUFFIX)
set_property(TARGET ${TORQUE_APP_NAME} PROPERTY OUTPUT_NAME_${CONF} ${TORQUE_APP_NAME}_${SUFFIX})
if (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
if (TORQUE_DYNAMIC_LIBRARY)
set_property(TARGET TorqueEngine PROPERTY ${CONF}_POSTFIX "_${SUFFIX}")
set_property(TARGET TorqueEngine PROPERTY ${CONF}_OUTPUT_NAME ${TORQUE_APP_NAME})
endif (TORQUE_DYNAMIC_LIBRARY AND NOT TORQUE_TESTING)
endif (TORQUE_DYNAMIC_LIBRARY)
endforeach()
# Set Visual Studio startup project
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${TORQUE_APP_NAME})
Expand Down Expand Up @@ -591,14 +582,6 @@ if (TORQUE_TARGET_PROPERTIES)
endif (TORQUE_TARGET_PROPERTIES)
target_include_directories(${TORQUE_APP_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_BINARY_DIR}/temp" ${TORQUE_INCLUDE_DIRECTORIES})

if(TORQUE_TESTING)
if(WIN32)
target_link_options(${TORQUE_APP_NAME} PRIVATE "/SUBSYSTEM:CONSOLE")
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")
set_target_properties(gmock PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")
endif()
endif(TORQUE_TESTING)

append_defs()

# Process library binaries - these are coming from modules that are providing links to external, precompiled code that should be included
Expand Down Expand Up @@ -645,3 +628,94 @@ if (UNIX)
endif()
endforeach()
endif (UNIX)

if(TORQUE_TESTING)

enable_testing()

# Start with the same sources as the main application
set(TORQUE_TEST_SOURCES ${TORQUE_SOURCE_FILES})

# Add test sources
file(GLOB_RECURSE TORQUE_TEST_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/testing/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/testing/*.h"
)

list(APPEND TORQUE_TEST_SOURCES ${TORQUE_TEST_FILES})

list(FILTER TORQUE_TEST_SOURCES EXCLUDE REGEX "main/main\\.cpp$")
list(FILTER TORQUE_TEST_SOURCES EXCLUDE REGEX "gfx/D3D11/")
list(FILTER TORQUE_TEST_SOURCES EXCLUDE REGEX "gfx/gl/")

add_executable(${TORQUE_APP_NAME}_unittests
${TORQUE_TEST_SOURCES}
)

foreach(MATH_BACKEND ${TORQUE_MATH_BACKENDS})
target_sources(${TORQUE_APP_NAME}_unittests
PRIVATE
$<TARGET_OBJECTS:${MATH_BACKEND}>
)
endforeach()

target_include_directories(${TORQUE_APP_NAME}_unittests
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_BINARY_DIR}/temp"
${TORQUE_INCLUDE_DIRECTORIES}
)

target_compile_definitions(${TORQUE_APP_NAME}_unittests
PUBLIC
${TORQUE_COMPILE_DEFINITIONS}
TORQUE_SHARED
SDL_MAIN_HANDLED
)

target_link_libraries(${TORQUE_APP_NAME}_unittests
PRIVATE
${TORQUE_LINK_LIBRARIES}
${TORQUE_LINK_THIRDPARTY}
gtest
gmock
)

target_link_options(${TORQUE_APP_NAME}_unittests
PUBLIC
${TORQUE_LINK_OPTIONS}
)

if(APPLE)
target_link_libraries(${TORQUE_APP_NAME}_unittests
PRIVATE
${TORQUE_LINK_FRAMEWORKS}
)
endif()

if(WIN32)
target_link_libraries(${TORQUE_APP_NAME}_unittests
PRIVATE
${TORQUE_LINK_WINDOWS}
)
set_target_properties(${TORQUE_APP_NAME}_unittests
PROPERTIES COMPILE_FLAGS
"${TORQUE_CXX_FLAGS}"
)

target_link_options(${TORQUE_APP_NAME}_unittests PRIVATE "/SUBSYSTEM:CONSOLE")
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")
set_target_properties(gmock PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")
endif()

if(UNIX AND NOT APPLE)
target_link_libraries(${TORQUE_APP_NAME}_unittests
PRIVATE
${TORQUE_LINK_LINUX}
)
endif()

include(GoogleTest)
gtest_discover_tests(${TORQUE_APP_NAME}_unittests)

endif()
36 changes: 35 additions & 1 deletion Engine/source/core/frameAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ class FrameTemp
FrameTemp(const U32 numElements = 0)
{
mPosition = FrameAllocator::getWaterMark();
mData = (T*)FrameAllocator::alloc(sizeof(T) * numElements);
mData = reinterpret_cast<T*>(FrameAllocator::alloc(sizeof(T) * numElements));
mSize = numElements;

for (S32 i = 0; i < numElements; i++)
constructInPlace<T>(&mData[i]);
}

~FrameTemp()
Expand All @@ -303,6 +306,8 @@ class FrameTemp
}

// Operators
inline TORQUE_FORCEINLINE T* operator~() { return mData; }
inline TORQUE_FORCEINLINE const T* operator~() const { return mData; }

inline TORQUE_FORCEINLINE T& operator*() { return *mData; }
inline TORQUE_FORCEINLINE const T& operator*() const { return *mData; }
Expand All @@ -329,5 +334,34 @@ class FrameTemp
inline TORQUE_FORCEINLINE const U32 getObjectCount() const { return mSize; }
};

//-----------------------------------------------------------------------------
// FrameTemp specializations for types with no constructor/destructor
#define FRAME_TEMP_NC_SPEC(type) \
template<> \
inline FrameTemp<type>::FrameTemp( const U32 count ) \
{ \
AssertFatal( count > 0, "Allocating a FrameTemp with less than one instance" ); \
mPosition = FrameAllocator::getWaterMark(); \
mSize = count;\
mData = reinterpret_cast<type *>( FrameAllocator::alloc( sizeof( type ) * count ) ); \
} \
template<>\
inline FrameTemp<type>::~FrameTemp() \
{ \
FrameAllocator::setWaterMark( mPosition ); \
} \

FRAME_TEMP_NC_SPEC(char);
FRAME_TEMP_NC_SPEC(float);
FRAME_TEMP_NC_SPEC(double);
FRAME_TEMP_NC_SPEC(bool);
FRAME_TEMP_NC_SPEC(int);
FRAME_TEMP_NC_SPEC(short);

FRAME_TEMP_NC_SPEC(unsigned char);
FRAME_TEMP_NC_SPEC(unsigned int);
FRAME_TEMP_NC_SPEC(unsigned short);

#undef FRAME_TEMP_NC_SPEC

#endif // _H_FRAMEALLOCATOR_
4 changes: 0 additions & 4 deletions Engine/source/gfx/D3D11/gfxD3D11Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ DXGI_SWAP_CHAIN_DESC GFXD3D11Device::setupPresentParams(const GFXVideoMode &mode

void GFXD3D11Device::enumerateAdapters(Vector<GFXAdapter*> &adapterList)
{
#ifdef TORQUE_TESTS_ENABLED
return;
#endif

IDXGIAdapter1* EnumAdapter;
IDXGIFactory1* DXGIFactory;

Expand Down
4 changes: 0 additions & 4 deletions Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ void EnumerateVideoModes(Vector<GFXVideoMode>& outModes)

void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
{
#ifdef TORQUE_TESTS_ENABLED
return;
#endif

AssertFatal( SDL_WasInit(SDL_INIT_VIDEO), "");

PlatformGL::init(); // for hints about context creation
Expand Down
3 changes: 0 additions & 3 deletions Engine/source/testing/dataChunkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: MIT
//-----------------------------------------------------------------------------

#ifdef TORQUE_TESTS_ENABLED
#include "testing/unitTesting.h"
#include "core/dataChunker.h"

Expand Down Expand Up @@ -343,5 +342,3 @@ TEST(ThreeTieredChunkerTest,ThreeTieredChunker_Should_Function_Correctly)
EXPECT_TRUE(threeChunker.getT3Chunker().getFreeListHead().isEmpty());
}


#endif
2 changes: 0 additions & 2 deletions Engine/source/testing/frameAllocatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: MIT
//-----------------------------------------------------------------------------

#ifdef TORQUE_TESTS_ENABLED
#include "testing/unitTesting.h"
#include "core/frameAllocator.h"

Expand Down Expand Up @@ -192,4 +191,3 @@ TEST(FrameTempTest, FrameTempShould_Function_Correctly)
}


#endif
Loading
Loading