From ffc001bb97cd729177e523378ef3f6fa9363eed0 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 30 May 2026 16:08:24 +0100 Subject: [PATCH] moved remaining tests FrameTemp had its template initializers removed, and also its ~ operator, return these if we need to. --- Engine/source/core/frameAllocator.h | 36 ++++++++++++++++++- .../{core/util/test => testing}/pathTest.cpp | 3 -- .../{core/util/test => testing}/strTest.cpp | 21 ++++++++++- .../util/test => testing}/swizzleTest.cpp | 7 ++-- .../test => testing}/tFixedSizeDequeTest.cpp | 3 -- .../util/test => testing}/tVectorTest.cpp | 3 -- 6 files changed, 57 insertions(+), 16 deletions(-) rename Engine/source/{core/util/test => testing}/pathTest.cpp (98%) rename Engine/source/{core/util/test => testing}/strTest.cpp (95%) rename Engine/source/{core/util/test => testing}/swizzleTest.cpp (94%) rename Engine/source/{core/util/test => testing}/tFixedSizeDequeTest.cpp (98%) rename Engine/source/{core/util/test => testing}/tVectorTest.cpp (99%) diff --git a/Engine/source/core/frameAllocator.h b/Engine/source/core/frameAllocator.h index 7d09f2b86..632debfc3 100644 --- a/Engine/source/core/frameAllocator.h +++ b/Engine/source/core/frameAllocator.h @@ -291,8 +291,11 @@ public: FrameTemp(const U32 numElements = 0) { mPosition = FrameAllocator::getWaterMark(); - mData = (T*)FrameAllocator::alloc(sizeof(T) * numElements); + mData = reinterpret_cast(FrameAllocator::alloc(sizeof(T) * numElements)); mSize = numElements; + + for (S32 i = 0; i < numElements; i++) + constructInPlace(&mData[i]); } ~FrameTemp() @@ -303,6 +306,8 @@ public: } // 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; } @@ -329,5 +334,34 @@ public: 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::FrameTemp( const U32 count ) \ + { \ + AssertFatal( count > 0, "Allocating a FrameTemp with less than one instance" ); \ + mPosition = FrameAllocator::getWaterMark(); \ + mSize = count;\ + mData = reinterpret_cast( FrameAllocator::alloc( sizeof( type ) * count ) ); \ + } \ + template<>\ + inline FrameTemp::~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_ diff --git a/Engine/source/core/util/test/pathTest.cpp b/Engine/source/testing/pathTest.cpp similarity index 98% rename from Engine/source/core/util/test/pathTest.cpp rename to Engine/source/testing/pathTest.cpp index 67009da6a..3dc111140 100644 --- a/Engine/source/core/util/test/pathTest.cpp +++ b/Engine/source/testing/pathTest.cpp @@ -20,7 +20,6 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#ifdef TORQUE_TESTS_ENABLED #include "testing/unitTesting.h" #include "core/util/path.h" @@ -36,5 +35,3 @@ TEST(MakeRelativePath, MakeRelativePath) EXPECT_EQ(Torque::Path::MakeRelativePath("levels/den/file.png", "art/interiors/burg/"), "../../../levels/den/file.png"); EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/dts/burg/"), "../../interiors/burg/file.png"); }; - -#endif \ No newline at end of file diff --git a/Engine/source/core/util/test/strTest.cpp b/Engine/source/testing/strTest.cpp similarity index 95% rename from Engine/source/core/util/test/strTest.cpp rename to Engine/source/testing/strTest.cpp index b78422924..94ebdfe30 100644 --- a/Engine/source/core/util/test/strTest.cpp +++ b/Engine/source/testing/strTest.cpp @@ -218,9 +218,28 @@ TEST(String, Order) } } -/// TODO TEST(String, Find) { + String str("foobarbarfoo"); + + // Character searches. + EXPECT_EQ(str.find('f'), 0); + EXPECT_EQ(str.find('o'), 1); + EXPECT_EQ(str.find('b'), 3); + EXPECT_EQ(str.find('r'), 5); + + // Substring searches. + EXPECT_EQ(str.find("foo"), 0); + EXPECT_EQ(str.find("bar"), 3); + EXPECT_EQ(str.find("barfoo"), 6); + + // Not found. + EXPECT_EQ(str.find("baz"), String::NPos); + EXPECT_EQ(str.find('x'), String::NPos); + + // Empty string. + EXPECT_EQ(String("").find("foo"), String::NPos); + EXPECT_EQ(String("").find('f'), String::NPos); } TEST(String, Insert) diff --git a/Engine/source/core/util/test/swizzleTest.cpp b/Engine/source/testing/swizzleTest.cpp similarity index 94% rename from Engine/source/core/util/test/swizzleTest.cpp rename to Engine/source/testing/swizzleTest.cpp index 942150022..da0fcf0dd 100644 --- a/Engine/source/core/util/test/swizzleTest.cpp +++ b/Engine/source/testing/swizzleTest.cpp @@ -20,7 +20,6 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#ifdef TORQUE_TESTS_ENABLED #include "platform/platform.h" #include "testing/unitTesting.h" #include "core/util/swizzle.h" @@ -106,7 +105,7 @@ TEST(Swizzle, Swizzle) EXPECT_TRUE( same ) << "Test object failed to be competent"; - bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) ); + bgraObjSwizzle.InPlace( objTest.address(), sizeof(TestStruct) * (sizeof(objIdx) / sizeof(U32))); same = true; for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ ) @@ -115,7 +114,7 @@ TEST(Swizzle, Swizzle) EXPECT_TRUE( same ) << "Object RGBA->BGRA test failed."; - bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) ); + bgraObjSwizzle.InPlace( objTest.address(), sizeof(TestStruct) * (sizeof(objIdx) / sizeof(U32))); same = true; for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ ) @@ -125,5 +124,3 @@ TEST(Swizzle, Swizzle) << "Object RGBA->BGRA reverse test failed."; } }; - -#endif \ No newline at end of file diff --git a/Engine/source/core/util/test/tFixedSizeDequeTest.cpp b/Engine/source/testing/tFixedSizeDequeTest.cpp similarity index 98% rename from Engine/source/core/util/test/tFixedSizeDequeTest.cpp rename to Engine/source/testing/tFixedSizeDequeTest.cpp index 1fcc94e20..3db19037a 100644 --- a/Engine/source/core/util/test/tFixedSizeDequeTest.cpp +++ b/Engine/source/testing/tFixedSizeDequeTest.cpp @@ -20,7 +20,6 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#ifdef TORQUE_TESTS_ENABLED #include "testing/unitTesting.h" #include "core/util/tFixedSizeDeque.h" @@ -45,5 +44,3 @@ TEST(FixedSizeDeque, FixedSizeDeque) EXPECT_EQ( deque.popFront(), 2 ); EXPECT_TRUE( deque.isEmpty() ); }; - -#endif \ No newline at end of file diff --git a/Engine/source/core/util/test/tVectorTest.cpp b/Engine/source/testing/tVectorTest.cpp similarity index 99% rename from Engine/source/core/util/test/tVectorTest.cpp rename to Engine/source/testing/tVectorTest.cpp index 3a3aeec13..3b5a362d0 100644 --- a/Engine/source/core/util/test/tVectorTest.cpp +++ b/Engine/source/testing/tVectorTest.cpp @@ -20,7 +20,6 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#ifdef TORQUE_TESTS_ENABLED #include "testing/unitTesting.h" #include "core/util/tVector.h" @@ -121,5 +120,3 @@ TEST_FIX(Vector, Sorting) EXPECT_TRUE(v[i] <= v[i + 1]) << "Element " << i << " was not in sorted order"; } - -#endif \ No newline at end of file