mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
define TORQUE_TESTS_ENABLED
This commit is contained in:
parent
d6a4c63c27
commit
2ef93acac6
4 changed files with 381 additions and 389 deletions
|
|
@ -212,7 +212,7 @@ endif (UNIX AND NOT APPLE)
|
||||||
|
|
||||||
if(TORQUE_TESTING)
|
if(TORQUE_TESTING)
|
||||||
torqueAddSourceDirectories("testing")
|
torqueAddSourceDirectories("testing")
|
||||||
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} TORQUE_SHARED SDL_MAIN_HANDLED)
|
set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} TORQUE_SHARED SDL_MAIN_HANDLED TORQUE_TESTS_ENABLED)
|
||||||
endif(TORQUE_TESTING)
|
endif(TORQUE_TESTING)
|
||||||
|
|
||||||
# Add the collected files to our engine group
|
# Add the collected files to our engine group
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
#include "math/mathUtils.h"
|
#include "math/mathUtils.h"
|
||||||
|
|
||||||
#ifdef TORQUE_TESTS_ENABLED
|
//#ifdef TORQUE_TESTS_ENABLED
|
||||||
#include "testing/unitTesting.h"
|
//#include "testing/unitTesting.h"
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
//Eulers setup
|
//Eulers setup
|
||||||
|
|
@ -317,14 +317,6 @@ void RotationF::normalize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Testing
|
|
||||||
#ifdef TORQUE_TESTS_ENABLED
|
|
||||||
TEST(Maths, RotationF_Calculations)
|
|
||||||
{
|
|
||||||
//TODO: implement unit test
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DefineEngineFunction(AddRotation, RotationF, (RotationF a, RotationF b, const char* returnType), ("Euler"),
|
DefineEngineFunction(AddRotation, RotationF, (RotationF a, RotationF b, const char* returnType), ("Euler"),
|
||||||
"Adds two rotations together.\n"
|
"Adds two rotations together.\n"
|
||||||
"@param a Rotation one."
|
"@param a Rotation one."
|
||||||
|
|
|
||||||
|
|
@ -1,178 +1,178 @@
|
||||||
//-----------------------------------------------------------------------------
|
////-----------------------------------------------------------------------------
|
||||||
// Copyright (c) 2014 GarageGames, LLC
|
//// Copyright (c) 2014 GarageGames, LLC
|
||||||
|
////
|
||||||
|
//// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
//// of this software and associated documentation files (the "Software"), to
|
||||||
|
//// deal in the Software without restriction, including without limitation the
|
||||||
|
//// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
//// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
//// furnished to do so, subject to the following conditions:
|
||||||
|
////
|
||||||
|
//// The above copyright notice and this permission notice shall be included in
|
||||||
|
//// all copies or substantial portions of the Software.
|
||||||
|
////
|
||||||
|
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
//// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
//// IN THE SOFTWARE.
|
||||||
|
////-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
//#ifdef TORQUE_TESTS_ENABLED
|
||||||
// of this software and associated documentation files (the "Software"), to
|
//#include "testing/unitTesting.h"
|
||||||
// deal in the Software without restriction, including without limitation the
|
//#include "platform/platformNet.h"
|
||||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
//#include "core/util/journal/process.h"
|
||||||
// sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in
|
//struct TcpHandle
|
||||||
// all copies or substantial portions of the Software.
|
//{
|
||||||
|
// NetSocket mSocket;
|
||||||
|
// S32 mDataReceived;
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// void notify(NetSocket sock, U32 state)
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// {
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// // Only consider our own socket.
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// if(mSocket != sock)
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// return;
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
//
|
||||||
// IN THE SOFTWARE.
|
// // Ok - what's the state? We do some dumb responses to given states
|
||||||
//-----------------------------------------------------------------------------
|
// // in order to fulfill the request.
|
||||||
|
// if(state == Net::Connected)
|
||||||
#ifdef TORQUE_TESTS_ENABLED
|
// {
|
||||||
#include "testing/unitTesting.h"
|
// U8 reqBuffer[] = {
|
||||||
#include "platform/platformNet.h"
|
// "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||||
#include "core/util/journal/process.h"
|
// };
|
||||||
|
//
|
||||||
struct TcpHandle
|
// Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||||
{
|
//
|
||||||
NetSocket mSocket;
|
// ASSERT_EQ(Net::NoError, e)
|
||||||
S32 mDataReceived;
|
// << "Got an error sending our HTTP request!";
|
||||||
|
// }
|
||||||
void notify(NetSocket sock, U32 state)
|
// else
|
||||||
{
|
// {
|
||||||
// Only consider our own socket.
|
// Process::requestShutdown();
|
||||||
if(mSocket != sock)
|
// mSocket = NetSocket::INVALID;
|
||||||
return;
|
// ASSERT_EQ(Net::Disconnected, state)
|
||||||
|
// << "Ended with a network error!";
|
||||||
// Ok - what's the state? We do some dumb responses to given states
|
// }
|
||||||
// in order to fulfill the request.
|
// }
|
||||||
if(state == Net::Connected)
|
//
|
||||||
{
|
// void receive(NetSocket sock, RawData incomingData)
|
||||||
U8 reqBuffer[] = {
|
// {
|
||||||
"GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
// // Only consider our own socket.
|
||||||
};
|
// if(mSocket != sock)
|
||||||
|
// return;
|
||||||
Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
//
|
||||||
|
// mDataReceived += incomingData.size;
|
||||||
ASSERT_EQ(Net::NoError, e)
|
// }
|
||||||
<< "Got an error sending our HTTP request!";
|
//};
|
||||||
}
|
//
|
||||||
else
|
//TEST(Net, TCPRequest)
|
||||||
{
|
//{
|
||||||
Process::requestShutdown();
|
// TcpHandle handler;
|
||||||
mSocket = NetSocket::INVALID;
|
//
|
||||||
ASSERT_EQ(Net::Disconnected, state)
|
// handler.mSocket = NetSocket::INVALID;
|
||||||
<< "Ended with a network error!";
|
// handler.mDataReceived = 0;
|
||||||
}
|
//
|
||||||
}
|
// // Hook into the signals.
|
||||||
|
// Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
|
||||||
void receive(NetSocket sock, RawData incomingData)
|
// Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
|
||||||
{
|
//
|
||||||
// Only consider our own socket.
|
// // Open a TCP connection to torque3d.org
|
||||||
if(mSocket != sock)
|
// handler.mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||||
return;
|
// const U32 limit = Platform::getRealMilliseconds() + (5*1000);
|
||||||
|
// while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
|
||||||
mDataReceived += incomingData.size;
|
//
|
||||||
}
|
// // Unhook from the signals.
|
||||||
};
|
// Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
|
||||||
|
// Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
|
||||||
TEST(Net, TCPRequest)
|
//
|
||||||
{
|
// EXPECT_GT(handler.mDataReceived, 0)
|
||||||
TcpHandle handler;
|
// << "Didn't get any data back!";
|
||||||
|
//}
|
||||||
handler.mSocket = NetSocket::INVALID;
|
//
|
||||||
handler.mDataReceived = 0;
|
//struct JournalHandle
|
||||||
|
//{
|
||||||
// Hook into the signals.
|
// NetSocket mSocket;
|
||||||
Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
|
// S32 mDataReceived;
|
||||||
Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
|
//
|
||||||
|
// void notify(NetSocket sock, U32 state)
|
||||||
// Open a TCP connection to torque3d.org
|
// {
|
||||||
handler.mSocket = Net::openConnectTo("108.61.193.195:80");
|
// // Only consider our own socket.
|
||||||
const U32 limit = Platform::getRealMilliseconds() + (5*1000);
|
// if(mSocket != sock)
|
||||||
while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
|
// return;
|
||||||
|
//
|
||||||
// Unhook from the signals.
|
// // Ok - what's the state? We do some dumb responses to given states
|
||||||
Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
|
// // in order to fulfill the request.
|
||||||
Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
|
// if(state == Net::Connected)
|
||||||
|
// {
|
||||||
EXPECT_GT(handler.mDataReceived, 0)
|
// U8 reqBuffer[] = {
|
||||||
<< "Didn't get any data back!";
|
// "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||||
}
|
// };
|
||||||
|
//
|
||||||
struct JournalHandle
|
// Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||||
{
|
//
|
||||||
NetSocket mSocket;
|
// ASSERT_EQ(Net::NoError, e)
|
||||||
S32 mDataReceived;
|
// << "Got an error sending our HTTP request!";
|
||||||
|
// }
|
||||||
void notify(NetSocket sock, U32 state)
|
// else
|
||||||
{
|
// {
|
||||||
// Only consider our own socket.
|
// Process::requestShutdown();
|
||||||
if(mSocket != sock)
|
// mSocket = NetSocket::INVALID;
|
||||||
return;
|
// ASSERT_EQ(Net::Disconnected, state)
|
||||||
|
// << "Ended with a network error!";
|
||||||
// Ok - what's the state? We do some dumb responses to given states
|
// }
|
||||||
// in order to fulfill the request.
|
// }
|
||||||
if(state == Net::Connected)
|
//
|
||||||
{
|
// void receive(NetSocket sock, RawData incomingData)
|
||||||
U8 reqBuffer[] = {
|
// {
|
||||||
"GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
// // Only consider our own socket.
|
||||||
};
|
// if(mSocket != sock)
|
||||||
|
// return;
|
||||||
Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
// mDataReceived += incomingData.size;
|
||||||
|
// }
|
||||||
ASSERT_EQ(Net::NoError, e)
|
//
|
||||||
<< "Got an error sending our HTTP request!";
|
// void makeRequest()
|
||||||
}
|
// {
|
||||||
else
|
// mSocket = NetSocket::INVALID;
|
||||||
{
|
// mDataReceived = 0;
|
||||||
Process::requestShutdown();
|
//
|
||||||
mSocket = NetSocket::INVALID;
|
// // Hook into the signals.
|
||||||
ASSERT_EQ(Net::Disconnected, state)
|
// Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
|
||||||
<< "Ended with a network error!";
|
// Net::smConnectionReceive->notify(this, &JournalHandle::receive);
|
||||||
}
|
//
|
||||||
}
|
// // Open a TCP connection to torque3d.org
|
||||||
|
// mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||||
void receive(NetSocket sock, RawData incomingData)
|
//
|
||||||
{
|
// // Let the callbacks enable things to process.
|
||||||
// Only consider our own socket.
|
// while(Process::processEvents()) {}
|
||||||
if(mSocket != sock)
|
//
|
||||||
return;
|
// // Unhook from the signals.
|
||||||
mDataReceived += incomingData.size;
|
// Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
|
||||||
}
|
// Net::smConnectionReceive->remove(this, &JournalHandle::receive);
|
||||||
|
//
|
||||||
void makeRequest()
|
// EXPECT_GT(mDataReceived, 0)
|
||||||
{
|
// << "Didn't get any data back!";
|
||||||
mSocket = NetSocket::INVALID;
|
// }
|
||||||
mDataReceived = 0;
|
//};
|
||||||
|
//
|
||||||
// Hook into the signals.
|
//TEST(Net, JournalTCPRequest)
|
||||||
Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
|
//{
|
||||||
Net::smConnectionReceive->notify(this, &JournalHandle::receive);
|
// JournalHandle handler;
|
||||||
|
//
|
||||||
// Open a TCP connection to torque3d.org
|
// Journal::Record("journalTCP.jrn");
|
||||||
mSocket = Net::openConnectTo("108.61.193.195:80");
|
// ASSERT_TRUE(Journal::IsRecording());
|
||||||
|
// handler.makeRequest();
|
||||||
// Let the callbacks enable things to process.
|
// S32 bytesRead = handler.mDataReceived;
|
||||||
while(Process::processEvents()) {}
|
// Journal::Stop();
|
||||||
|
//
|
||||||
// Unhook from the signals.
|
// Journal::Play("journalTCP.jrn");
|
||||||
Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
|
// handler.makeRequest();
|
||||||
Net::smConnectionReceive->remove(this, &JournalHandle::receive);
|
// Journal::Stop();
|
||||||
|
//
|
||||||
EXPECT_GT(mDataReceived, 0)
|
// EXPECT_EQ(bytesRead, handler.mDataReceived)
|
||||||
<< "Didn't get any data back!";
|
// << "Didn't get same data back from journal playback.";
|
||||||
}
|
//}
|
||||||
};
|
//
|
||||||
|
//#endif
|
||||||
TEST(Net, JournalTCPRequest)
|
|
||||||
{
|
|
||||||
JournalHandle handler;
|
|
||||||
|
|
||||||
Journal::Record("journalTCP.jrn");
|
|
||||||
ASSERT_TRUE(Journal::IsRecording());
|
|
||||||
handler.makeRequest();
|
|
||||||
S32 bytesRead = handler.mDataReceived;
|
|
||||||
Journal::Stop();
|
|
||||||
|
|
||||||
Journal::Play("journalTCP.jrn");
|
|
||||||
handler.makeRequest();
|
|
||||||
Journal::Stop();
|
|
||||||
|
|
||||||
EXPECT_EQ(bytesRead, handler.mDataReceived)
|
|
||||||
<< "Didn't get same data back from journal playback.";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -1,205 +1,205 @@
|
||||||
//-----------------------------------------------------------------------------
|
////-----------------------------------------------------------------------------
|
||||||
// Copyright (c) 2014 GarageGames, LLC
|
//// Copyright (c) 2014 GarageGames, LLC
|
||||||
|
////
|
||||||
|
//// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
//// of this software and associated documentation files (the "Software"), to
|
||||||
|
//// deal in the Software without restriction, including without limitation the
|
||||||
|
//// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
//// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
//// furnished to do so, subject to the following conditions:
|
||||||
|
////
|
||||||
|
//// The above copyright notice and this permission notice shall be included in
|
||||||
|
//// all copies or substantial portions of the Software.
|
||||||
|
////
|
||||||
|
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
//// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
//// IN THE SOFTWARE.
|
||||||
|
////-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
//#ifdef TORQUE_TESTS_ENABLED
|
||||||
// of this software and associated documentation files (the "Software"), to
|
//#include "testing/unitTesting.h"
|
||||||
// deal in the Software without restriction, including without limitation the
|
//#include "platform/threads/threadSafeRefCount.h"
|
||||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
//#include "platform/threads/thread.h"
|
||||||
// sell copies of the Software, and to permit persons to whom the Software is
|
//#include "core/util/tVector.h"
|
||||||
// furnished to do so, subject to the following conditions:
|
//#include "console/console.h"
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in
|
//FIXTURE(ThreadSafeRefCount)
|
||||||
// all copies or substantial portions of the Software.
|
//{
|
||||||
|
//public:
|
||||||
|
// struct TestObjectDtor : public ThreadSafeRefCount<TestObjectDtor>
|
||||||
|
// {
|
||||||
|
// bool &flag;
|
||||||
|
// TestObjectDtor(bool &f) : flag(f)
|
||||||
|
// {
|
||||||
|
// flag = false;
|
||||||
|
// }
|
||||||
|
// ~TestObjectDtor()
|
||||||
|
// {
|
||||||
|
// flag = true;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// typedef ThreadSafeRef<TestObjectDtor> TestObjectDtorRef;
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// enum
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// {
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// NUM_ADD_REFS_PER_THREAD = 10,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// NUM_EXTRA_REFS_PER_THREAD = 10,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// NUM_THREADS = 10
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
// };
|
||||||
// IN THE SOFTWARE.
|
//
|
||||||
//-----------------------------------------------------------------------------
|
// class TestObject : public ThreadSafeRefCount<TestObject> {};
|
||||||
|
// typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||||
#ifdef TORQUE_TESTS_ENABLED
|
//
|
||||||
#include "testing/unitTesting.h"
|
// class TestThread : public Thread
|
||||||
#include "platform/threads/threadSafeRefCount.h"
|
// {
|
||||||
#include "platform/threads/thread.h"
|
// public:
|
||||||
#include "core/util/tVector.h"
|
// TestObjectRef mRef;
|
||||||
#include "console/console.h"
|
// Vector<TestObjectRef> mExtraRefs;
|
||||||
|
//
|
||||||
FIXTURE(ThreadSafeRefCount)
|
// TestThread(TestObjectRef ref) : mRef(ref) {}
|
||||||
{
|
//
|
||||||
public:
|
// void run(void* arg)
|
||||||
struct TestObjectDtor : public ThreadSafeRefCount<TestObjectDtor>
|
// {
|
||||||
{
|
// if (!arg)
|
||||||
bool &flag;
|
// {
|
||||||
TestObjectDtor(bool &f) : flag(f)
|
// // Create references.
|
||||||
{
|
// for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||||
flag = false;
|
// mRef->addRef();
|
||||||
}
|
//
|
||||||
~TestObjectDtor()
|
// mExtraRefs.setSize(NUM_EXTRA_REFS_PER_THREAD);
|
||||||
{
|
// for (U32 i = 0; i < NUM_EXTRA_REFS_PER_THREAD; i++)
|
||||||
flag = true;
|
// mExtraRefs[i] = mRef;
|
||||||
}
|
// }
|
||||||
};
|
// else
|
||||||
typedef ThreadSafeRef<TestObjectDtor> TestObjectDtorRef;
|
// {
|
||||||
|
// // Clear references.
|
||||||
enum
|
// mExtraRefs.clear();
|
||||||
{
|
// for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||||
NUM_ADD_REFS_PER_THREAD = 10,
|
// mRef->release();
|
||||||
NUM_EXTRA_REFS_PER_THREAD = 10,
|
// }
|
||||||
NUM_THREADS = 10
|
// }
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
class TestObject : public ThreadSafeRefCount<TestObject> {};
|
//};
|
||||||
typedef ThreadSafeRef<TestObject> TestObjectRef;
|
//
|
||||||
|
//TEST_FIX(ThreadSafeRefCount, Serial)
|
||||||
class TestThread : public Thread
|
//{
|
||||||
{
|
// bool deleted = false;
|
||||||
public:
|
// TestObjectDtorRef ref1 = new TestObjectDtor(deleted);
|
||||||
TestObjectRef mRef;
|
// ASSERT_FALSE(deleted);
|
||||||
Vector<TestObjectRef> mExtraRefs;
|
// EXPECT_FALSE(ref1->isShared());
|
||||||
|
// EXPECT_TRUE(ref1 != NULL);
|
||||||
TestThread(TestObjectRef ref) : mRef(ref) {}
|
//
|
||||||
|
// TestObjectDtorRef ref2 = ref1;
|
||||||
void run(void* arg)
|
// EXPECT_TRUE(ref1->isShared());
|
||||||
{
|
// EXPECT_TRUE(ref2->isShared());
|
||||||
if (!arg)
|
// EXPECT_EQ(ref1, ref2);
|
||||||
{
|
//
|
||||||
// Create references.
|
// ref1 = NULL;
|
||||||
for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
// EXPECT_FALSE(ref2->isShared());
|
||||||
mRef->addRef();
|
//
|
||||||
|
// ref2 = NULL;
|
||||||
mExtraRefs.setSize(NUM_EXTRA_REFS_PER_THREAD);
|
// ASSERT_TRUE(deleted);
|
||||||
for (U32 i = 0; i < NUM_EXTRA_REFS_PER_THREAD; i++)
|
//}
|
||||||
mExtraRefs[i] = mRef;
|
//
|
||||||
}
|
//TEST_FIX(ThreadSafeRefCount, Concurrent)
|
||||||
else
|
//{
|
||||||
{
|
// TestObjectRef mRef = new TestObject;
|
||||||
// Clear references.
|
// EXPECT_EQ(2, mRef->getRefCount()); // increments of 2
|
||||||
mExtraRefs.clear();
|
//
|
||||||
for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
// Vector<TestThread*> threads;
|
||||||
mRef->release();
|
// threads.setSize(NUM_THREADS);
|
||||||
}
|
//
|
||||||
}
|
// // Create threads.
|
||||||
};
|
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||||
|
// threads[i] = new TestThread(mRef);
|
||||||
};
|
//
|
||||||
|
// // Run phase 1: create references.
|
||||||
TEST_FIX(ThreadSafeRefCount, Serial)
|
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||||
{
|
// threads[i]->start(NULL);
|
||||||
bool deleted = false;
|
//
|
||||||
TestObjectDtorRef ref1 = new TestObjectDtor(deleted);
|
// // Wait for completion.
|
||||||
ASSERT_FALSE(deleted);
|
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||||
EXPECT_FALSE(ref1->isShared());
|
// threads[i]->join();
|
||||||
EXPECT_TRUE(ref1 != NULL);
|
//
|
||||||
|
// EXPECT_EQ(2 + ((1 + NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2),
|
||||||
TestObjectDtorRef ref2 = ref1;
|
// mRef->getRefCount());
|
||||||
EXPECT_TRUE(ref1->isShared());
|
//
|
||||||
EXPECT_TRUE(ref2->isShared());
|
// // Run phase 2: release references.
|
||||||
EXPECT_EQ(ref1, ref2);
|
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||||
|
// threads[i]->start((void*) 1);
|
||||||
ref1 = NULL;
|
//
|
||||||
EXPECT_FALSE(ref2->isShared());
|
// // Wait for completion.
|
||||||
|
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||||
ref2 = NULL;
|
// {
|
||||||
ASSERT_TRUE(deleted);
|
// threads[i]->join();
|
||||||
}
|
// delete threads[i];
|
||||||
|
// }
|
||||||
TEST_FIX(ThreadSafeRefCount, Concurrent)
|
//
|
||||||
{
|
// EXPECT_EQ(2, mRef->getRefCount()); // increments of two
|
||||||
TestObjectRef mRef = new TestObject;
|
//
|
||||||
EXPECT_EQ(2, mRef->getRefCount()); // increments of 2
|
// mRef = NULL;
|
||||||
|
//}
|
||||||
Vector<TestThread*> threads;
|
//
|
||||||
threads.setSize(NUM_THREADS);
|
//TEST_FIX(ThreadSafeRefCount, Tagging)
|
||||||
|
//{
|
||||||
// Create threads.
|
// TestObjectRef ref;
|
||||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
threads[i] = new TestThread(mRef);
|
// EXPECT_FALSE(bool(ref));
|
||||||
|
// EXPECT_FALSE(bool(ref.ptr()));
|
||||||
// Run phase 1: create references.
|
//
|
||||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL));
|
||||||
threads[i]->start(NULL);
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
|
//
|
||||||
// Wait for completion.
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
threads[i]->join();
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||||
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
EXPECT_EQ(2 + ((1 + NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2),
|
//
|
||||||
mRef->getRefCount());
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||||
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
// Run phase 2: release references.
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
threads[i]->start((void*) 1);
|
//
|
||||||
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||||
// Wait for completion.
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||||
{
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
threads[i]->join();
|
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfSet));
|
||||||
delete threads[i];
|
//
|
||||||
}
|
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_UnsetOrFail));
|
||||||
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
EXPECT_EQ(2, mRef->getRefCount()); // increments of two
|
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_UnsetOrFail));
|
||||||
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
mRef = NULL;
|
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfUnset));
|
||||||
}
|
//
|
||||||
|
// TestObjectRef objectA = new TestObject;
|
||||||
TEST_FIX(ThreadSafeRefCount, Tagging)
|
// TestObjectRef objectB = new TestObject;
|
||||||
{
|
//
|
||||||
TestObjectRef ref;
|
// EXPECT_FALSE(objectA->isShared());
|
||||||
EXPECT_FALSE(ref.isTagged());
|
// EXPECT_FALSE(objectB->isShared());
|
||||||
EXPECT_FALSE(bool(ref));
|
//
|
||||||
EXPECT_FALSE(bool(ref.ptr()));
|
// ref = objectA;
|
||||||
|
// EXPECT_FALSE(ref.isTagged());
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL));
|
// EXPECT_TRUE(ref == objectA);
|
||||||
EXPECT_FALSE(ref.isTagged());
|
// EXPECT_TRUE(ref == objectA.ptr());
|
||||||
|
// EXPECT_TRUE(objectA->isShared());
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
//
|
||||||
EXPECT_TRUE(ref.isTagged());
|
// EXPECT_TRUE(ref.trySetFromTo(objectA, objectB, TestObjectRef::TAG_Set));
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
EXPECT_TRUE(ref.isTagged());
|
// EXPECT_EQ(ref, objectB);
|
||||||
|
// EXPECT_EQ(ref, objectB.ptr());
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
// EXPECT_TRUE(objectB->isShared());
|
||||||
EXPECT_FALSE(ref.isTagged());
|
// EXPECT_FALSE(objectA->isShared());
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
//
|
||||||
EXPECT_FALSE(ref.isTagged());
|
// EXPECT_TRUE(ref.trySetFromTo(ref, objectA));
|
||||||
|
// EXPECT_TRUE(ref.isTagged());
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
// EXPECT_EQ(ref, objectA);
|
||||||
EXPECT_TRUE(ref.isTagged());
|
// EXPECT_EQ(ref, objectA.ptr());
|
||||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
//}
|
||||||
EXPECT_TRUE(ref.isTagged());
|
//
|
||||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfSet));
|
//#endif
|
||||||
|
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_UnsetOrFail));
|
|
||||||
EXPECT_FALSE(ref.isTagged());
|
|
||||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_UnsetOrFail));
|
|
||||||
EXPECT_FALSE(ref.isTagged());
|
|
||||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfUnset));
|
|
||||||
|
|
||||||
TestObjectRef objectA = new TestObject;
|
|
||||||
TestObjectRef objectB = new TestObject;
|
|
||||||
|
|
||||||
EXPECT_FALSE(objectA->isShared());
|
|
||||||
EXPECT_FALSE(objectB->isShared());
|
|
||||||
|
|
||||||
ref = objectA;
|
|
||||||
EXPECT_FALSE(ref.isTagged());
|
|
||||||
EXPECT_TRUE(ref == objectA);
|
|
||||||
EXPECT_TRUE(ref == objectA.ptr());
|
|
||||||
EXPECT_TRUE(objectA->isShared());
|
|
||||||
|
|
||||||
EXPECT_TRUE(ref.trySetFromTo(objectA, objectB, TestObjectRef::TAG_Set));
|
|
||||||
EXPECT_TRUE(ref.isTagged());
|
|
||||||
EXPECT_EQ(ref, objectB);
|
|
||||||
EXPECT_EQ(ref, objectB.ptr());
|
|
||||||
EXPECT_TRUE(objectB->isShared());
|
|
||||||
EXPECT_FALSE(objectA->isShared());
|
|
||||||
|
|
||||||
EXPECT_TRUE(ref.trySetFromTo(ref, objectA));
|
|
||||||
EXPECT_TRUE(ref.isTagged());
|
|
||||||
EXPECT_EQ(ref, objectA);
|
|
||||||
EXPECT_EQ(ref, objectA.ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue