mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
define TORQUE_TESTS_ENABLED
This commit is contained in:
parent
d6a4c63c27
commit
2ef93acac6
|
|
@ -212,7 +212,7 @@ endif (UNIX AND NOT APPLE)
|
|||
|
||||
if(TORQUE_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)
|
||||
|
||||
# Add the collected files to our engine group
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@
|
|||
#include "console/engineAPI.h"
|
||||
#include "math/mathUtils.h"
|
||||
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#endif
|
||||
//#ifdef TORQUE_TESTS_ENABLED
|
||||
//#include "testing/unitTesting.h"
|
||||
//#endif
|
||||
|
||||
//====================================================================
|
||||
//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"),
|
||||
"Adds two rotations together.\n"
|
||||
"@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
|
||||
// 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:
|
||||
//#ifdef TORQUE_TESTS_ENABLED
|
||||
//#include "testing/unitTesting.h"
|
||||
//#include "platform/platformNet.h"
|
||||
//#include "core/util/journal/process.h"
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//struct TcpHandle
|
||||
//{
|
||||
// NetSocket mSocket;
|
||||
// S32 mDataReceived;
|
||||
//
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#include "platform/platformNet.h"
|
||||
#include "core/util/journal/process.h"
|
||||
|
||||
struct TcpHandle
|
||||
{
|
||||
NetSocket mSocket;
|
||||
S32 mDataReceived;
|
||||
|
||||
void notify(NetSocket sock, U32 state)
|
||||
{
|
||||
// Only consider our own socket.
|
||||
if(mSocket != sock)
|
||||
return;
|
||||
|
||||
// Ok - what's the state? We do some dumb responses to given states
|
||||
// in order to fulfill the request.
|
||||
if(state == Net::Connected)
|
||||
{
|
||||
U8 reqBuffer[] = {
|
||||
"GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||
};
|
||||
|
||||
Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||
|
||||
ASSERT_EQ(Net::NoError, e)
|
||||
<< "Got an error sending our HTTP request!";
|
||||
}
|
||||
else
|
||||
{
|
||||
Process::requestShutdown();
|
||||
mSocket = NetSocket::INVALID;
|
||||
ASSERT_EQ(Net::Disconnected, state)
|
||||
<< "Ended with a network error!";
|
||||
}
|
||||
}
|
||||
|
||||
void receive(NetSocket sock, RawData incomingData)
|
||||
{
|
||||
// Only consider our own socket.
|
||||
if(mSocket != sock)
|
||||
return;
|
||||
|
||||
mDataReceived += incomingData.size;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Net, TCPRequest)
|
||||
{
|
||||
TcpHandle handler;
|
||||
|
||||
handler.mSocket = NetSocket::INVALID;
|
||||
handler.mDataReceived = 0;
|
||||
|
||||
// Hook into the signals.
|
||||
Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
|
||||
Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
|
||||
|
||||
// Open a TCP connection to torque3d.org
|
||||
handler.mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||
const U32 limit = Platform::getRealMilliseconds() + (5*1000);
|
||||
while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
|
||||
|
||||
// Unhook from the signals.
|
||||
Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
|
||||
Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
|
||||
|
||||
EXPECT_GT(handler.mDataReceived, 0)
|
||||
<< "Didn't get any data back!";
|
||||
}
|
||||
|
||||
struct JournalHandle
|
||||
{
|
||||
NetSocket mSocket;
|
||||
S32 mDataReceived;
|
||||
|
||||
void notify(NetSocket sock, U32 state)
|
||||
{
|
||||
// Only consider our own socket.
|
||||
if(mSocket != sock)
|
||||
return;
|
||||
|
||||
// Ok - what's the state? We do some dumb responses to given states
|
||||
// in order to fulfill the request.
|
||||
if(state == Net::Connected)
|
||||
{
|
||||
U8 reqBuffer[] = {
|
||||
"GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||
};
|
||||
|
||||
Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||
|
||||
ASSERT_EQ(Net::NoError, e)
|
||||
<< "Got an error sending our HTTP request!";
|
||||
}
|
||||
else
|
||||
{
|
||||
Process::requestShutdown();
|
||||
mSocket = NetSocket::INVALID;
|
||||
ASSERT_EQ(Net::Disconnected, state)
|
||||
<< "Ended with a network error!";
|
||||
}
|
||||
}
|
||||
|
||||
void receive(NetSocket sock, RawData incomingData)
|
||||
{
|
||||
// Only consider our own socket.
|
||||
if(mSocket != sock)
|
||||
return;
|
||||
mDataReceived += incomingData.size;
|
||||
}
|
||||
|
||||
void makeRequest()
|
||||
{
|
||||
mSocket = NetSocket::INVALID;
|
||||
mDataReceived = 0;
|
||||
|
||||
// Hook into the signals.
|
||||
Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
|
||||
Net::smConnectionReceive->notify(this, &JournalHandle::receive);
|
||||
|
||||
// Open a TCP connection to torque3d.org
|
||||
mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||
|
||||
// Let the callbacks enable things to process.
|
||||
while(Process::processEvents()) {}
|
||||
|
||||
// Unhook from the signals.
|
||||
Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
|
||||
Net::smConnectionReceive->remove(this, &JournalHandle::receive);
|
||||
|
||||
EXPECT_GT(mDataReceived, 0)
|
||||
<< "Didn't get any data back!";
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
// void notify(NetSocket sock, U32 state)
|
||||
// {
|
||||
// // Only consider our own socket.
|
||||
// if(mSocket != sock)
|
||||
// return;
|
||||
//
|
||||
// // Ok - what's the state? We do some dumb responses to given states
|
||||
// // in order to fulfill the request.
|
||||
// if(state == Net::Connected)
|
||||
// {
|
||||
// U8 reqBuffer[] = {
|
||||
// "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||
// };
|
||||
//
|
||||
// Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||
//
|
||||
// ASSERT_EQ(Net::NoError, e)
|
||||
// << "Got an error sending our HTTP request!";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Process::requestShutdown();
|
||||
// mSocket = NetSocket::INVALID;
|
||||
// ASSERT_EQ(Net::Disconnected, state)
|
||||
// << "Ended with a network error!";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void receive(NetSocket sock, RawData incomingData)
|
||||
// {
|
||||
// // Only consider our own socket.
|
||||
// if(mSocket != sock)
|
||||
// return;
|
||||
//
|
||||
// mDataReceived += incomingData.size;
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//TEST(Net, TCPRequest)
|
||||
//{
|
||||
// TcpHandle handler;
|
||||
//
|
||||
// handler.mSocket = NetSocket::INVALID;
|
||||
// handler.mDataReceived = 0;
|
||||
//
|
||||
// // Hook into the signals.
|
||||
// Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
|
||||
// Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
|
||||
//
|
||||
// // Open a TCP connection to torque3d.org
|
||||
// handler.mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||
// const U32 limit = Platform::getRealMilliseconds() + (5*1000);
|
||||
// while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
|
||||
//
|
||||
// // Unhook from the signals.
|
||||
// Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
|
||||
// Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
|
||||
//
|
||||
// EXPECT_GT(handler.mDataReceived, 0)
|
||||
// << "Didn't get any data back!";
|
||||
//}
|
||||
//
|
||||
//struct JournalHandle
|
||||
//{
|
||||
// NetSocket mSocket;
|
||||
// S32 mDataReceived;
|
||||
//
|
||||
// void notify(NetSocket sock, U32 state)
|
||||
// {
|
||||
// // Only consider our own socket.
|
||||
// if(mSocket != sock)
|
||||
// return;
|
||||
//
|
||||
// // Ok - what's the state? We do some dumb responses to given states
|
||||
// // in order to fulfill the request.
|
||||
// if(state == Net::Connected)
|
||||
// {
|
||||
// U8 reqBuffer[] = {
|
||||
// "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
||||
// };
|
||||
//
|
||||
// Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
||||
//
|
||||
// ASSERT_EQ(Net::NoError, e)
|
||||
// << "Got an error sending our HTTP request!";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Process::requestShutdown();
|
||||
// mSocket = NetSocket::INVALID;
|
||||
// ASSERT_EQ(Net::Disconnected, state)
|
||||
// << "Ended with a network error!";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void receive(NetSocket sock, RawData incomingData)
|
||||
// {
|
||||
// // Only consider our own socket.
|
||||
// if(mSocket != sock)
|
||||
// return;
|
||||
// mDataReceived += incomingData.size;
|
||||
// }
|
||||
//
|
||||
// void makeRequest()
|
||||
// {
|
||||
// mSocket = NetSocket::INVALID;
|
||||
// mDataReceived = 0;
|
||||
//
|
||||
// // Hook into the signals.
|
||||
// Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
|
||||
// Net::smConnectionReceive->notify(this, &JournalHandle::receive);
|
||||
//
|
||||
// // Open a TCP connection to torque3d.org
|
||||
// mSocket = Net::openConnectTo("108.61.193.195:80");
|
||||
//
|
||||
// // Let the callbacks enable things to process.
|
||||
// while(Process::processEvents()) {}
|
||||
//
|
||||
// // Unhook from the signals.
|
||||
// Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
|
||||
// Net::smConnectionReceive->remove(this, &JournalHandle::receive);
|
||||
//
|
||||
// EXPECT_GT(mDataReceived, 0)
|
||||
// << "Didn't get any data back!";
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//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
|
||||
// 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:
|
||||
//#ifdef TORQUE_TESTS_ENABLED
|
||||
//#include "testing/unitTesting.h"
|
||||
//#include "platform/threads/threadSafeRefCount.h"
|
||||
//#include "platform/threads/thread.h"
|
||||
//#include "core/util/tVector.h"
|
||||
//#include "console/console.h"
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//FIXTURE(ThreadSafeRefCount)
|
||||
//{
|
||||
//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
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#include "platform/threads/threadSafeRefCount.h"
|
||||
#include "platform/threads/thread.h"
|
||||
#include "core/util/tVector.h"
|
||||
#include "console/console.h"
|
||||
|
||||
FIXTURE(ThreadSafeRefCount)
|
||||
{
|
||||
public:
|
||||
struct TestObjectDtor : public ThreadSafeRefCount<TestObjectDtor>
|
||||
{
|
||||
bool &flag;
|
||||
TestObjectDtor(bool &f) : flag(f)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
~TestObjectDtor()
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
};
|
||||
typedef ThreadSafeRef<TestObjectDtor> TestObjectDtorRef;
|
||||
|
||||
enum
|
||||
{
|
||||
NUM_ADD_REFS_PER_THREAD = 10,
|
||||
NUM_EXTRA_REFS_PER_THREAD = 10,
|
||||
NUM_THREADS = 10
|
||||
};
|
||||
|
||||
class TestObject : public ThreadSafeRefCount<TestObject> {};
|
||||
typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||
|
||||
class TestThread : public Thread
|
||||
{
|
||||
public:
|
||||
TestObjectRef mRef;
|
||||
Vector<TestObjectRef> mExtraRefs;
|
||||
|
||||
TestThread(TestObjectRef ref) : mRef(ref) {}
|
||||
|
||||
void run(void* arg)
|
||||
{
|
||||
if (!arg)
|
||||
{
|
||||
// Create references.
|
||||
for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||
mRef->addRef();
|
||||
|
||||
mExtraRefs.setSize(NUM_EXTRA_REFS_PER_THREAD);
|
||||
for (U32 i = 0; i < NUM_EXTRA_REFS_PER_THREAD; i++)
|
||||
mExtraRefs[i] = mRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clear references.
|
||||
mExtraRefs.clear();
|
||||
for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||
mRef->release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
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;
|
||||
threads.setSize(NUM_THREADS);
|
||||
|
||||
// Create threads.
|
||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
threads[i] = new TestThread(mRef);
|
||||
|
||||
// Run phase 1: create references.
|
||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
threads[i]->start(NULL);
|
||||
|
||||
// Wait for completion.
|
||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
threads[i]->join();
|
||||
|
||||
EXPECT_EQ(2 + ((1 + NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2),
|
||||
mRef->getRefCount());
|
||||
|
||||
// Run phase 2: release references.
|
||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
threads[i]->start((void*) 1);
|
||||
|
||||
// Wait for completion.
|
||||
for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
{
|
||||
threads[i]->join();
|
||||
delete threads[i];
|
||||
}
|
||||
|
||||
EXPECT_EQ(2, mRef->getRefCount()); // increments of two
|
||||
|
||||
mRef = NULL;
|
||||
}
|
||||
|
||||
TEST_FIX(ThreadSafeRefCount, Tagging)
|
||||
{
|
||||
TestObjectRef ref;
|
||||
EXPECT_FALSE(ref.isTagged());
|
||||
EXPECT_FALSE(bool(ref));
|
||||
EXPECT_FALSE(bool(ref.ptr()));
|
||||
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL));
|
||||
EXPECT_FALSE(ref.isTagged());
|
||||
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||
EXPECT_TRUE(ref.isTagged());
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||
EXPECT_TRUE(ref.isTagged());
|
||||
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||
EXPECT_FALSE(ref.isTagged());
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||
EXPECT_FALSE(ref.isTagged());
|
||||
|
||||
EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||
EXPECT_TRUE(ref.isTagged());
|
||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||
EXPECT_TRUE(ref.isTagged());
|
||||
EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfSet));
|
||||
|
||||
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
|
||||
// enum
|
||||
// {
|
||||
// NUM_ADD_REFS_PER_THREAD = 10,
|
||||
// NUM_EXTRA_REFS_PER_THREAD = 10,
|
||||
// NUM_THREADS = 10
|
||||
// };
|
||||
//
|
||||
// class TestObject : public ThreadSafeRefCount<TestObject> {};
|
||||
// typedef ThreadSafeRef<TestObject> TestObjectRef;
|
||||
//
|
||||
// class TestThread : public Thread
|
||||
// {
|
||||
// public:
|
||||
// TestObjectRef mRef;
|
||||
// Vector<TestObjectRef> mExtraRefs;
|
||||
//
|
||||
// TestThread(TestObjectRef ref) : mRef(ref) {}
|
||||
//
|
||||
// void run(void* arg)
|
||||
// {
|
||||
// if (!arg)
|
||||
// {
|
||||
// // Create references.
|
||||
// for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||
// mRef->addRef();
|
||||
//
|
||||
// mExtraRefs.setSize(NUM_EXTRA_REFS_PER_THREAD);
|
||||
// for (U32 i = 0; i < NUM_EXTRA_REFS_PER_THREAD; i++)
|
||||
// mExtraRefs[i] = mRef;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Clear references.
|
||||
// mExtraRefs.clear();
|
||||
// for (U32 i = 0; i < NUM_ADD_REFS_PER_THREAD; i++)
|
||||
// mRef->release();
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
//};
|
||||
//
|
||||
//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;
|
||||
// threads.setSize(NUM_THREADS);
|
||||
//
|
||||
// // Create threads.
|
||||
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
// threads[i] = new TestThread(mRef);
|
||||
//
|
||||
// // Run phase 1: create references.
|
||||
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
// threads[i]->start(NULL);
|
||||
//
|
||||
// // Wait for completion.
|
||||
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
// threads[i]->join();
|
||||
//
|
||||
// EXPECT_EQ(2 + ((1 + NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2),
|
||||
// mRef->getRefCount());
|
||||
//
|
||||
// // Run phase 2: release references.
|
||||
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
// threads[i]->start((void*) 1);
|
||||
//
|
||||
// // Wait for completion.
|
||||
// for (U32 i = 0; i < NUM_THREADS; i++)
|
||||
// {
|
||||
// threads[i]->join();
|
||||
// delete threads[i];
|
||||
// }
|
||||
//
|
||||
// EXPECT_EQ(2, mRef->getRefCount()); // increments of two
|
||||
//
|
||||
// mRef = NULL;
|
||||
//}
|
||||
//
|
||||
//TEST_FIX(ThreadSafeRefCount, Tagging)
|
||||
//{
|
||||
// TestObjectRef ref;
|
||||
// EXPECT_FALSE(ref.isTagged());
|
||||
// EXPECT_FALSE(bool(ref));
|
||||
// EXPECT_FALSE(bool(ref.ptr()));
|
||||
//
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL));
|
||||
// EXPECT_FALSE(ref.isTagged());
|
||||
//
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||
// EXPECT_TRUE(ref.isTagged());
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Set));
|
||||
// EXPECT_TRUE(ref.isTagged());
|
||||
//
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||
// EXPECT_FALSE(ref.isTagged());
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_Unset));
|
||||
// EXPECT_FALSE(ref.isTagged());
|
||||
//
|
||||
// EXPECT_TRUE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||
// EXPECT_TRUE(ref.isTagged());
|
||||
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_SetOrFail));
|
||||
// EXPECT_TRUE(ref.isTagged());
|
||||
// EXPECT_FALSE(ref.trySetFromTo(ref, NULL, TestObjectRef::TAG_FailIfSet));
|
||||
//
|
||||
// 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…
Reference in a new issue