mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-16 19:00:56 +00:00
Removed all local type definitions for GCC.
This commit is contained in:
parent
6cc59a97cc
commit
bedde94a9f
5 changed files with 194 additions and 168 deletions
|
|
@ -25,22 +25,78 @@
|
|||
#include "core/util/journal/journaledSignal.h"
|
||||
#include "core/util/safeDelete.h"
|
||||
|
||||
TEST(Journal, BasicAPI)
|
||||
FIXTURE(Journal)
|
||||
{
|
||||
public:
|
||||
// Used for basic API test.
|
||||
struct receiver
|
||||
{
|
||||
U32 lastTriggerValue;
|
||||
void triggerReceiver(U16 msg)
|
||||
U16 lastTriggerValue;
|
||||
void trigger(U16 msg)
|
||||
{
|
||||
lastTriggerValue = msg;
|
||||
}
|
||||
} rec;
|
||||
};
|
||||
|
||||
// Used for non-basic test.
|
||||
typedef JournaledSignal<void(U32, U16)> EventA;
|
||||
typedef JournaledSignal<void(U8, S8)> EventB;
|
||||
typedef JournaledSignal<void(U32, S32)> EventC;
|
||||
|
||||
// Root, non-dynamic signal receiver.
|
||||
struct multiReceiver {
|
||||
U32 recvA, recvB, recvC;
|
||||
|
||||
EventA *dynamicA;
|
||||
EventB *dynamicB;
|
||||
EventC *dynamicC;
|
||||
|
||||
void receiverRoot(U8 msg)
|
||||
{
|
||||
if(msg==1)
|
||||
{
|
||||
dynamicA = new EventA();
|
||||
dynamicA->notify(this, &multiReceiver::receiverA);
|
||||
}
|
||||
|
||||
if(msg==2)
|
||||
{
|
||||
dynamicB = new EventB();
|
||||
dynamicB->notify(this, &multiReceiver::receiverB);
|
||||
}
|
||||
|
||||
if(msg==3)
|
||||
{
|
||||
dynamicC = new EventC();
|
||||
dynamicC->notify(this, &multiReceiver::receiverC);
|
||||
}
|
||||
}
|
||||
|
||||
void receiverA(U32, U16 d)
|
||||
{
|
||||
recvA += d;
|
||||
}
|
||||
|
||||
void receiverB(U8, S8 d)
|
||||
{
|
||||
recvB += d;
|
||||
}
|
||||
|
||||
void receiverC(U32, S32 d)
|
||||
{
|
||||
recvC += d;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TEST_FIX(Journal, BasicAPI)
|
||||
{
|
||||
receiver rec;
|
||||
rec.lastTriggerValue = 0;
|
||||
|
||||
// Set up a journaled signal to test with.
|
||||
JournaledSignal<void(U16)> testEvent;
|
||||
testEvent.notify(&rec, &receiver::triggerReceiver);
|
||||
testEvent.notify(&rec, &receiver::trigger);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
|
|
@ -71,63 +127,16 @@ TEST(Journal, BasicAPI)
|
|||
<< "Should encounter last journaled value (18).";
|
||||
}
|
||||
|
||||
TEST(Journal, DynamicSignals)
|
||||
TEST_FIX(Journal, DynamicSignals)
|
||||
{
|
||||
typedef JournaledSignal<void(U32, U16)> EventA;
|
||||
typedef JournaledSignal<void(U8, S8)> EventB;
|
||||
typedef JournaledSignal<void(U32, S32)> EventC;
|
||||
|
||||
// Root, non-dynamic signal receiver.
|
||||
struct receiver {
|
||||
U32 recvA, recvB, recvC;
|
||||
|
||||
EventA *dynamicA;
|
||||
EventB *dynamicB;
|
||||
EventC *dynamicC;
|
||||
|
||||
void receiverRoot(U8 msg)
|
||||
{
|
||||
if(msg==1)
|
||||
{
|
||||
dynamicA = new EventA();
|
||||
dynamicA->notify(this, &receiver::receiverA);
|
||||
}
|
||||
|
||||
if(msg==2)
|
||||
{
|
||||
dynamicB = new EventB();
|
||||
dynamicB->notify(this, &receiver::receiverB);
|
||||
}
|
||||
|
||||
if(msg==3)
|
||||
{
|
||||
dynamicC = new EventC();
|
||||
dynamicC->notify(this, &receiver::receiverC);
|
||||
}
|
||||
}
|
||||
|
||||
void receiverA(U32, U16 d)
|
||||
{
|
||||
recvA += d;
|
||||
}
|
||||
|
||||
void receiverB(U8, S8 d)
|
||||
{
|
||||
recvB += d;
|
||||
}
|
||||
|
||||
void receiverC(U32, S32 d)
|
||||
{
|
||||
recvC += d;
|
||||
}
|
||||
} rec;
|
||||
multiReceiver rec;
|
||||
|
||||
// Reset our state values.
|
||||
rec.recvA = rec.recvB = rec.recvC = 0;
|
||||
|
||||
// Set up a signal to start with.
|
||||
JournaledSignal<void(U8)> testEvent;
|
||||
testEvent.notify(&rec, &receiver::receiverRoot);
|
||||
testEvent.notify(&rec, &multiReceiver::receiverRoot);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
|
|
@ -177,4 +186,4 @@ TEST(Journal, DynamicSignals)
|
|||
EXPECT_EQ(rec.recvC, 2) << "recvC wasn't 2 - something broken in journal?";
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,22 +25,40 @@
|
|||
#include "core/util/tVector.h"
|
||||
|
||||
// Define some test data used below.
|
||||
static const S32 ints[] = {0, 10, 2, 3, 14, 4, 12, 6, 16, 7, 8, 1, 11, 5, 13, 9, 15};
|
||||
static const U32 length = sizeof(ints) / sizeof(S32);
|
||||
static S32 QSORT_CALLBACK sortInts(const S32* a, const S32* b)
|
||||
FIXTURE(Vector)
|
||||
{
|
||||
S32 av = *a;
|
||||
S32 bv = *b;
|
||||
|
||||
if (av < bv)
|
||||
return -1;
|
||||
else if (av > bv)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
public:
|
||||
struct Dtor
|
||||
{
|
||||
bool* ptr;
|
||||
Dtor() {} // Needed for vector increment.
|
||||
Dtor(bool* ptr): ptr(ptr) {}
|
||||
~Dtor()
|
||||
{
|
||||
*ptr = true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Vector, Allocation)
|
||||
static const S32 ints[];
|
||||
static const U32 length;
|
||||
static S32 QSORT_CALLBACK sortInts(const S32* a, const S32* b)
|
||||
{
|
||||
S32 av = *a;
|
||||
S32 bv = *b;
|
||||
|
||||
if (av < bv)
|
||||
return -1;
|
||||
else if (av > bv)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
const S32 VectorFixture::ints[] = {0, 10, 2, 3, 14, 4, 12, 6, 16, 7, 8, 1, 11, 5, 13, 9, 15};
|
||||
const U32 VectorFixture::length = sizeof(VectorFixture::ints) / sizeof(S32);
|
||||
|
||||
TEST_FIX(Vector, Allocation)
|
||||
{
|
||||
Vector<S32> *vector = new Vector<S32>;
|
||||
for (S32 i = 0; i < 1000; i++)
|
||||
|
|
@ -57,19 +75,8 @@ TEST(Vector, Allocation)
|
|||
delete vector;
|
||||
}
|
||||
|
||||
TEST(Vector, Deallocation)
|
||||
TEST_FIX(Vector, Deallocation)
|
||||
{
|
||||
struct Dtor
|
||||
{
|
||||
bool* ptr;
|
||||
Dtor() {} // Needed for vector increment.
|
||||
Dtor(bool* ptr): ptr(ptr) {}
|
||||
~Dtor()
|
||||
{
|
||||
*ptr = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool dtorVals[10];
|
||||
Vector<Dtor> v;
|
||||
|
||||
|
|
@ -101,7 +108,7 @@ TEST(Vector, Deallocation)
|
|||
<< "Element " << i << "'s destructor was not called";
|
||||
}
|
||||
|
||||
TEST(Vector, Sorting)
|
||||
TEST_FIX(Vector, Sorting)
|
||||
{
|
||||
Vector<S32> v;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@
|
|||
#include "console/console.h"
|
||||
#include "core/util/tVector.h"
|
||||
|
||||
TEST(ThreadPool, BasicAPI)
|
||||
FIXTURE(ThreadPool)
|
||||
{
|
||||
public:
|
||||
// Represents a single unit of work. In this test we just set an element in
|
||||
// a result vector.
|
||||
struct TestItem : public ThreadPool::WorkItem
|
||||
|
|
@ -43,7 +44,10 @@ TEST(ThreadPool, BasicAPI)
|
|||
mResults[mIndex] = mIndex;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TEST_FIX(ThreadPool, BasicAPI)
|
||||
{
|
||||
// Construct the vector of results from the work items.
|
||||
const U32 numItems = 100;
|
||||
Vector<U32> results(__FILE__, __LINE__);
|
||||
|
|
|
|||
|
|
@ -28,57 +28,10 @@
|
|||
#include "core/util/tVector.h"
|
||||
#include "console/console.h"
|
||||
|
||||
// Test deque without concurrency.
|
||||
TEST(ThreadSafeDeque, PopFront)
|
||||
FIXTURE(ThreadSafeDeque)
|
||||
{
|
||||
ThreadSafeDeque<char> deque;
|
||||
String str = "teststring";
|
||||
|
||||
for(U32 i = 0; i < str.length(); i++)
|
||||
deque.pushBack(str[i]);
|
||||
|
||||
EXPECT_FALSE(deque.isEmpty());
|
||||
|
||||
char ch;
|
||||
for(U32 i = 0; i < str.length(); i++)
|
||||
{
|
||||
EXPECT_TRUE(deque.tryPopFront(ch));
|
||||
EXPECT_EQ(str[i], ch);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(deque.isEmpty());
|
||||
}
|
||||
|
||||
TEST(ThreadSafeDeque, PopBack)
|
||||
{
|
||||
ThreadSafeDeque<char> deque;
|
||||
String str = "teststring";
|
||||
|
||||
const char* p1 = str.c_str() + 4;
|
||||
const char* p2 = p1 + 1;
|
||||
while(*p2)
|
||||
{
|
||||
deque.pushFront(*p1);
|
||||
deque.pushBack(*p2);
|
||||
--p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
char ch;
|
||||
for(S32 i = str.length()-1; i >= 0; i--)
|
||||
{
|
||||
EXPECT_TRUE(deque.tryPopBack(ch));
|
||||
EXPECT_EQ(str[i], ch);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(deque.isEmpty());
|
||||
}
|
||||
|
||||
// Test deque in a concurrent setting.
|
||||
TEST(ThreadSafeDeque, Concurrent1)
|
||||
{
|
||||
const U32 NumValues = 100;
|
||||
|
||||
public:
|
||||
// Used by the concurrent test.
|
||||
struct Value : public ThreadSafeRefCount<Value>
|
||||
{
|
||||
U32 mIndex;
|
||||
|
|
@ -121,9 +74,6 @@ TEST(ThreadSafeDeque, Concurrent1)
|
|||
}
|
||||
};
|
||||
|
||||
Deque mDeque;
|
||||
Vector<U32> mValues;
|
||||
|
||||
struct ProducerThread : public Thread
|
||||
{
|
||||
Vector<U32>& mValues;
|
||||
|
|
@ -163,6 +113,61 @@ TEST(ThreadSafeDeque, Concurrent1)
|
|||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Test deque without concurrency.
|
||||
TEST_FIX(ThreadSafeDeque, PopFront)
|
||||
{
|
||||
ThreadSafeDeque<char> deque;
|
||||
String str = "teststring";
|
||||
|
||||
for(U32 i = 0; i < str.length(); i++)
|
||||
deque.pushBack(str[i]);
|
||||
|
||||
EXPECT_FALSE(deque.isEmpty());
|
||||
|
||||
char ch;
|
||||
for(U32 i = 0; i < str.length(); i++)
|
||||
{
|
||||
EXPECT_TRUE(deque.tryPopFront(ch));
|
||||
EXPECT_EQ(str[i], ch);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(deque.isEmpty());
|
||||
}
|
||||
|
||||
TEST_FIX(ThreadSafeDeque, PopBack)
|
||||
{
|
||||
ThreadSafeDeque<char> deque;
|
||||
String str = "teststring";
|
||||
|
||||
const char* p1 = str.c_str() + 4;
|
||||
const char* p2 = p1 + 1;
|
||||
while(*p2)
|
||||
{
|
||||
deque.pushFront(*p1);
|
||||
deque.pushBack(*p2);
|
||||
--p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
char ch;
|
||||
for(S32 i = str.length()-1; i >= 0; i--)
|
||||
{
|
||||
EXPECT_TRUE(deque.tryPopBack(ch));
|
||||
EXPECT_EQ(str[i], ch);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(deque.isEmpty());
|
||||
}
|
||||
|
||||
// Test deque in a concurrent setting.
|
||||
TEST_FIX(ThreadSafeDeque, Concurrent1)
|
||||
{
|
||||
const U32 NumValues = 100;
|
||||
|
||||
Deque mDeque;
|
||||
Vector<U32> mValues;
|
||||
|
||||
mValues.setSize(NumValues);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,42 +27,23 @@
|
|||
#include "core/util/tVector.h"
|
||||
#include "console/console.h"
|
||||
|
||||
TEST(ThreadSafeRefCount, Serial)
|
||||
FIXTURE(ThreadSafeRefCount)
|
||||
{
|
||||
struct TestObject : public ThreadSafeRefCount<TestObject>
|
||||
public:
|
||||
struct TestObjectDtor : public ThreadSafeRefCount<TestObjectDtor>
|
||||
{
|
||||
bool &flag;
|
||||
TestObject(bool &f) : flag(f)
|
||||
TestObjectDtor(bool &f) : flag(f)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
~TestObject()
|
||||
~TestObjectDtor()
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
};
|
||||
typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||
typedef ThreadSafeRef<TestObjectDtor> TestObjectDtorRef;
|
||||
|
||||
bool deleted = false;
|
||||
TestObjectRef ref1 = new TestObject(deleted);
|
||||
ASSERT_FALSE(deleted);
|
||||
EXPECT_FALSE(ref1->isShared());
|
||||
EXPECT_TRUE(ref1 != NULL);
|
||||
|
||||
TestObjectRef ref2 = ref1;
|
||||
EXPECT_TRUE(ref1->isShared());
|
||||
EXPECT_TRUE(ref2->isShared());
|
||||
EXPECT_EQ(ref1, ref2);
|
||||
|
||||
ref1 = NULL;
|
||||
EXPECT_FALSE(ref2->isShared());
|
||||
|
||||
ref2 = NULL;
|
||||
ASSERT_TRUE(deleted);
|
||||
}
|
||||
|
||||
TEST(ThreadSafeRefCount, Concurrent)
|
||||
{
|
||||
enum
|
||||
{
|
||||
NUM_ADD_REFS_PER_THREAD = 10,
|
||||
|
|
@ -72,7 +53,6 @@ TEST(ThreadSafeRefCount, Concurrent)
|
|||
|
||||
class TestObject : public ThreadSafeRefCount<TestObject> {};
|
||||
typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||
TestObjectRef mRef;
|
||||
|
||||
class TestThread : public Thread
|
||||
{
|
||||
|
|
@ -104,7 +84,31 @@ TEST(ThreadSafeRefCount, Concurrent)
|
|||
}
|
||||
};
|
||||
|
||||
mRef = new TestObject;
|
||||
};
|
||||
|
||||
TEST_FIX(ThreadSafeRefCount, Serial)
|
||||
{
|
||||
bool deleted = false;
|
||||
TestObjectDtorRef ref1 = new TestObjectDtor(deleted);
|
||||
ASSERT_FALSE(deleted);
|
||||
EXPECT_FALSE(ref1->isShared());
|
||||
EXPECT_TRUE(ref1 != NULL);
|
||||
|
||||
TestObjectDtorRef ref2 = ref1;
|
||||
EXPECT_TRUE(ref1->isShared());
|
||||
EXPECT_TRUE(ref2->isShared());
|
||||
EXPECT_EQ(ref1, ref2);
|
||||
|
||||
ref1 = NULL;
|
||||
EXPECT_FALSE(ref2->isShared());
|
||||
|
||||
ref2 = NULL;
|
||||
ASSERT_TRUE(deleted);
|
||||
}
|
||||
|
||||
TEST_FIX(ThreadSafeRefCount, Concurrent)
|
||||
{
|
||||
TestObjectRef mRef = new TestObject;
|
||||
EXPECT_EQ(2, mRef->getRefCount()); // increments of 2
|
||||
|
||||
Vector<TestThread*> threads;
|
||||
|
|
@ -141,11 +145,8 @@ TEST(ThreadSafeRefCount, Concurrent)
|
|||
mRef = NULL;
|
||||
}
|
||||
|
||||
TEST(ThreadSafeRefCount, Tagging)
|
||||
TEST_FIX(ThreadSafeRefCount, Tagging)
|
||||
{
|
||||
struct TestObject : public ThreadSafeRefCount<TestObject> {};
|
||||
typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||
|
||||
TestObjectRef ref;
|
||||
EXPECT_FALSE(ref.isTagged());
|
||||
EXPECT_FALSE(bool(ref));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue