Skip to content

Commit bbeeba6

Browse files
committed
moved remaining tests
FrameTemp had its template initializers removed, and also its ~ operator, return these if we need to.
1 parent ed4b6c3 commit bbeeba6

6 files changed

Lines changed: 57 additions & 16 deletions

File tree

Engine/source/core/frameAllocator.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ class FrameTemp
291291
FrameTemp(const U32 numElements = 0)
292292
{
293293
mPosition = FrameAllocator::getWaterMark();
294-
mData = (T*)FrameAllocator::alloc(sizeof(T) * numElements);
294+
mData = reinterpret_cast<T*>(FrameAllocator::alloc(sizeof(T) * numElements));
295295
mSize = numElements;
296+
297+
for (S32 i = 0; i < numElements; i++)
298+
constructInPlace<T>(&mData[i]);
296299
}
297300

298301
~FrameTemp()
@@ -303,6 +306,8 @@ class FrameTemp
303306
}
304307

305308
// Operators
309+
inline TORQUE_FORCEINLINE T* operator~() { return mData; }
310+
inline TORQUE_FORCEINLINE const T* operator~() const { return mData; }
306311

307312
inline TORQUE_FORCEINLINE T& operator*() { return *mData; }
308313
inline TORQUE_FORCEINLINE const T& operator*() const { return *mData; }
@@ -329,5 +334,34 @@ class FrameTemp
329334
inline TORQUE_FORCEINLINE const U32 getObjectCount() const { return mSize; }
330335
};
331336

337+
//-----------------------------------------------------------------------------
338+
// FrameTemp specializations for types with no constructor/destructor
339+
#define FRAME_TEMP_NC_SPEC(type) \
340+
template<> \
341+
inline FrameTemp<type>::FrameTemp( const U32 count ) \
342+
{ \
343+
AssertFatal( count > 0, "Allocating a FrameTemp with less than one instance" ); \
344+
mPosition = FrameAllocator::getWaterMark(); \
345+
mSize = count;\
346+
mData = reinterpret_cast<type *>( FrameAllocator::alloc( sizeof( type ) * count ) ); \
347+
} \
348+
template<>\
349+
inline FrameTemp<type>::~FrameTemp() \
350+
{ \
351+
FrameAllocator::setWaterMark( mPosition ); \
352+
} \
353+
354+
FRAME_TEMP_NC_SPEC(char);
355+
FRAME_TEMP_NC_SPEC(float);
356+
FRAME_TEMP_NC_SPEC(double);
357+
FRAME_TEMP_NC_SPEC(bool);
358+
FRAME_TEMP_NC_SPEC(int);
359+
FRAME_TEMP_NC_SPEC(short);
360+
361+
FRAME_TEMP_NC_SPEC(unsigned char);
362+
FRAME_TEMP_NC_SPEC(unsigned int);
363+
FRAME_TEMP_NC_SPEC(unsigned short);
364+
365+
#undef FRAME_TEMP_NC_SPEC
332366

333367
#endif // _H_FRAMEALLOCATOR_
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// IN THE SOFTWARE.
2121
//-----------------------------------------------------------------------------
2222

23-
#ifdef TORQUE_TESTS_ENABLED
2423
#include "testing/unitTesting.h"
2524
#include "core/util/path.h"
2625

@@ -36,5 +35,3 @@ TEST(MakeRelativePath, MakeRelativePath)
3635
EXPECT_EQ(Torque::Path::MakeRelativePath("levels/den/file.png", "art/interiors/burg/"), "../../../levels/den/file.png");
3736
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/dts/burg/"), "../../interiors/burg/file.png");
3837
};
39-
40-
#endif
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,28 @@ TEST(String, Order)
218218
}
219219
}
220220

221-
/// TODO
222221
TEST(String, Find)
223222
{
223+
String str("foobarbarfoo");
224+
225+
// Character searches.
226+
EXPECT_EQ(str.find('f'), 0);
227+
EXPECT_EQ(str.find('o'), 1);
228+
EXPECT_EQ(str.find('b'), 3);
229+
EXPECT_EQ(str.find('r'), 5);
230+
231+
// Substring searches.
232+
EXPECT_EQ(str.find("foo"), 0);
233+
EXPECT_EQ(str.find("bar"), 3);
234+
EXPECT_EQ(str.find("barfoo"), 6);
235+
236+
// Not found.
237+
EXPECT_EQ(str.find("baz"), String::NPos);
238+
EXPECT_EQ(str.find('x'), String::NPos);
239+
240+
// Empty string.
241+
EXPECT_EQ(String("").find("foo"), String::NPos);
242+
EXPECT_EQ(String("").find('f'), String::NPos);
224243
}
225244

226245
TEST(String, Insert)

Engine/source/core/util/test/swizzleTest.cpp renamed to Engine/source/testing/swizzleTest.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// IN THE SOFTWARE.
2121
//-----------------------------------------------------------------------------
2222

23-
#ifdef TORQUE_TESTS_ENABLED
2423
#include "platform/platform.h"
2524
#include "testing/unitTesting.h"
2625
#include "core/util/swizzle.h"
@@ -106,7 +105,7 @@ TEST(Swizzle, Swizzle)
106105
EXPECT_TRUE( same )
107106
<< "Test object failed to be competent";
108107

109-
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
108+
bgraObjSwizzle.InPlace( objTest.address(), sizeof(TestStruct) * (sizeof(objIdx) / sizeof(U32)));
110109
same = true;
111110

112111
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
@@ -115,7 +114,7 @@ TEST(Swizzle, Swizzle)
115114
EXPECT_TRUE( same )
116115
<< "Object RGBA->BGRA test failed.";
117116

118-
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
117+
bgraObjSwizzle.InPlace( objTest.address(), sizeof(TestStruct) * (sizeof(objIdx) / sizeof(U32)));
119118
same = true;
120119

121120
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
@@ -125,5 +124,3 @@ TEST(Swizzle, Swizzle)
125124
<< "Object RGBA->BGRA reverse test failed.";
126125
}
127126
};
128-
129-
#endif

Engine/source/core/util/test/tFixedSizeDequeTest.cpp renamed to Engine/source/testing/tFixedSizeDequeTest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// IN THE SOFTWARE.
2121
//-----------------------------------------------------------------------------
2222

23-
#ifdef TORQUE_TESTS_ENABLED
2423
#include "testing/unitTesting.h"
2524
#include "core/util/tFixedSizeDeque.h"
2625

@@ -45,5 +44,3 @@ TEST(FixedSizeDeque, FixedSizeDeque)
4544
EXPECT_EQ( deque.popFront(), 2 );
4645
EXPECT_TRUE( deque.isEmpty() );
4746
};
48-
49-
#endif

Engine/source/core/util/test/tVectorTest.cpp renamed to Engine/source/testing/tVectorTest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// IN THE SOFTWARE.
2121
//-----------------------------------------------------------------------------
2222

23-
#ifdef TORQUE_TESTS_ENABLED
2423
#include "testing/unitTesting.h"
2524
#include "core/util/tVector.h"
2625

@@ -121,5 +120,3 @@ TEST_FIX(Vector, Sorting)
121120
EXPECT_TRUE(v[i] <= v[i + 1])
122121
<< "Element " << i << " was not in sorted order";
123122
}
124-
125-
#endif

0 commit comments

Comments
 (0)