Removed all local type definitions for GCC.

This commit is contained in:
Daniel Buckmaster 2014-09-29 14:31:07 +10:00
parent 6cc59a97cc
commit bedde94a9f
5 changed files with 194 additions and 168 deletions

View file

@ -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__);

View file

@ -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);

View file

@ -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));