initial commit

This commit is contained in:
2010-04-05 23:38:59 +02:00
commit e7e0b39e82
150 changed files with 28636 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# - Try to find UnitTest++
#
#
SET (UNITTEST++_FOUND FALSE)
FIND_PATH (UNITTEST++_INCLUDE_DIR UnitTest++.h /usr/include/unittest++ /usr/local/include/unittest++ $ENV{UNITTESTXX_PATH}/src $ENV{UNITTESTXX_INCLUDE_PATH})
FIND_LIBRARY (UNITTEST++_LIBRARY NAMES UnitTest++ PATHS /usr/lib /usr/local/lib $ENV{UNITTESTXX_PATH} ENV{UNITTESTXX_LIBRARY_PATH})
IF (UNITTEST++_INCLUDE_DIR AND UNITTEST++_LIBRARY)
SET (UNITTEST++_FOUND TRUE)
ENDIF (UNITTEST++_INCLUDE_DIR AND UNITTEST++_LIBRARY)
IF (UNITTEST++_FOUND)
IF (NOT UnitTest++_FIND_QUIETLY)
MESSAGE(STATUS "Found UnitTest++: ${UNITTEST++_LIBRARY}")
ENDIF (NOT UnitTest++_FIND_QUIETLY)
ELSE (UNITTEST++_FOUND)
IF (UnitTest++_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find UnitTest++")
ENDIF (UnitTest++_FIND_REQUIRED)
ENDIF (UNITTEST++_FOUND)
MARK_AS_ADVANCED (
UNITTEST++_INCLUDE_DIR
UNITTEST++_LIBRARY
)
+51
View File
@@ -0,0 +1,51 @@
PROJECT (ENGINETESTS)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
# Needed for UnitTest++
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake )
SET ( TESTS_SRCS
main.cc
CommandsTests.cc
EntityTests.cc
EventsBaseTests.cc
PhysicsTests.cc
ControllerBaseTests.cc
)
FIND_PACKAGE (UnitTest++)
INCLUDE_DIRECTORIES ( ../ )
SET_TARGET_PROPERTIES ( ${PROJECT_EXECUTABLES} PROPERTIES
LINKER_LANGUAGE CXX
)
IF ( UNITTEST++_FOUND )
ADD_EXECUTABLE ( enginetests ${TESTS_SRCS} )
INCLUDE_DIRECTORIES ( ${UNITTEST++_INCLUDE_DIR} )
SET_TARGET_PROPERTIES ( enginetests PROPERTIES
LINKER_LANGUAGE CXX
OUTPUT_NAME runtests
)
TARGET_LINK_LIBRARIES ( enginetests
${UNITTEST++_LIBRARY}
Engine
)
OPTION (RUN_AUTOMATIC_TESTS "Perform automatic tests after compilation?" OFF)
IF (RUN_AUTOMATIC_TESTS)
ADD_CUSTOM_COMMAND (TARGET runtests
POST_BUILD
COMMAND ./runtests
COMMENT "Running automated tests..."
)
ENDIF (RUN_AUTOMATIC_TESTS)
ENDIF ( UNITTEST++_FOUND )
+138
View File
@@ -0,0 +1,138 @@
#include <UnitTest++.h>
#include "Logging.h"
#include "Commands.h"
#include "CommandsGlobal.h"
using namespace std;
using namespace Engine;
int global_int = -1;
string global_string = "";
vector<string> global_values;
struct CommandsFixture {
CommandsFixture () {
LoggingModule.Init (0, NULL);
LoggingModule.SetLogPrintLevel (LogLevelWarning);
CommandsModule.Init (0, NULL);
}
~CommandsFixture () {
CommandsModule.Destroy ();
LoggingModule.Destroy ();
}
Logging LoggingModule;
Commands CommandsModule;
};
bool test_cmd_set_global_int (vector<string> argv) {
global_int = 1;
return true;
};
bool test_cmd_set_global_string (vector<string> argv) {
if (argv.size() > 0) {
global_string = argv[0];
return true;
}
return false;
}
bool test_cmd_set_global_values (vector<string> argv) {
global_values = argv;
return true;
};
bool test_cmd_set_error (vector<string> argv) {
if (argv.size() > 0) {
CommandSetErrorString ("too many arguments passed to function!");
return false;
}
return true;
}
TEST_FIXTURE ( CommandsFixture, CommandSystemAddCommand ) {
AddCommand ("test", test_cmd_set_global_int);
CHECK_EQUAL (true, RunCommand ("test"));
}
TEST_FIXTURE ( CommandsFixture, CommandSystemRun ) {
global_int = -1;
AddCommand ("test", test_cmd_set_global_int);
CHECK_EQUAL (true, RunCommand ("test"));
CHECK_EQUAL (1, global_int);
}
TEST_FIXTURE ( CommandsFixture, CommandSystemArgv ) {
global_string = "oldstring";
AddCommand ("test_string", test_cmd_set_global_string);
CHECK_EQUAL (1, RunCommand ("test_string newstring"));
CHECK_EQUAL ("newstring", global_string);
}
TEST_FIXTURE ( CommandsFixture, CommandSystemArgValues ) {
global_values.clear();
AddCommand ("test_values", test_cmd_set_global_values);
CHECK_EQUAL (true, RunCommand ("test_values value1 value2 value3 "));
CHECK_EQUAL (static_cast<unsigned int> (3), global_values.size());
if (global_values.size() == 3) {
CHECK_EQUAL ("value1", global_values[0]);
CHECK_EQUAL ("value2", global_values[1]);
CHECK_EQUAL ("value3", global_values[2]);
}
global_values.clear ();
CHECK_EQUAL (true, RunCommand ("test_values"));
CHECK_EQUAL (static_cast<unsigned int> (0), global_values.size());
global_values.clear ();
CHECK_EQUAL (true, RunCommand ("test_values value1 \"value consisting of a string\""));
CHECK_EQUAL (static_cast<unsigned int> (2), global_values.size());
if (global_values.size () == 2) {
CHECK_EQUAL ("value consisting of a string", global_values[1]);
}
global_values.clear ();
CHECK_EQUAL (true, RunCommand ("test_values \"value consisting of a string\""));
CHECK_EQUAL (static_cast<unsigned int> (1), global_values.size());
if (global_values.size () == 1) {
CHECK_EQUAL ("value consisting of a string", global_values[0]);
}
}
TEST_FIXTURE ( CommandsFixture, CommandSystemQueue ) {
global_string = "oldstring";
global_int = -1;
AddCommand ("test_string", test_cmd_set_global_string);
AddCommand ("test_int", test_cmd_set_global_int);
QueueCommand ("test_string newstring");
QueueCommand ("test_int");
CommandQueueExecute ();
CHECK_EQUAL ("newstring", global_string);
CHECK_EQUAL (1, global_int);
}
TEST_FIXTURE ( CommandsFixture, CommandSystemError ) {
AddCommand ("set_error", test_cmd_set_error);
CHECK_EQUAL (false, RunCommand ("set_error error"));
CHECK_EQUAL ("too many arguments passed to function!", CommandGetErrorString ());
CHECK_EQUAL (true, RunCommand ("set_error"));
CHECK_EQUAL ("", CommandGetErrorString ());
}
+20
View File
@@ -0,0 +1,20 @@
#include <UnitTest++.h>
#include "ControllerBase.h"
#include "keytable.h"
using namespace std;
using namespace Engine;
TEST (test_convert_keystring) {
int key;
key = convert_keystring ("up");
CHECK_EQUAL (SDLK_UP, key);
key = convert_keystring ("escape");
CHECK_EQUAL (SDLK_ESCAPE, key);
key = convert_keystring ("blaaa");
CHECK_EQUAL (0, key);
}
+90
View File
@@ -0,0 +1,90 @@
#include <UnitTest++.h>
#include "Logging.h"
#include "EntityBase.h"
using namespace std;
using namespace Engine;
struct EntityFixture {
EntityFixture () {
LoggingModule.Init (0, NULL);
LoggingModule.SetLogPrintLevel (LogLevelWarning);
}
~EntityFixture () {
LoggingModule.Destroy ();
}
Logging LoggingModule;
};
TEST_FIXTURE ( EntityFixture, EntityPhysicStateGlobalizeTranslation ) {
EntityPhysicState phys_entity;
vector3d position (1, 0, -2);
vector3d orientation (0, 0.25 * M_PI, 0);
phys_entity.SetPosition (position);
phys_entity.SetOrientation (orientation);
vector3d origin (0, 0, 0);
phys_entity.Globalize (origin);
CHECK_EQUAL (origin[0], 1);
CHECK_EQUAL (origin[1], 0);
CHECK_EQUAL (origin[2], -2);
}
TEST_FIXTURE ( EntityFixture, EntityPhysicStateGlobalizeFull ) {
EntityPhysicState phys_entity;
vector3d position (3, 0, 1);
vector3d orientation (0, 45, 0);
phys_entity.SetPosition (position);
phys_entity.SetOrientation (orientation);
vector3d front (5, 0, 0);
phys_entity.Globalize (front);
CHECK_CLOSE (3 + cos (45 * M_PI / 180) * 5., front[0], 1.0e-5);
CHECK_CLOSE (0, front[1], 1.0e-5);
CHECK_CLOSE (1 - sin (45 * M_PI / 180) * 5., front[2], 1.0e-5);
}
TEST_FIXTURE ( EntityFixture, EntityPhysicStateLocalizeTranslation ) {
EntityPhysicState phys_entity;
vector3d position (1, 0, -2);
vector3d orientation (0, 45, 0);
phys_entity.SetPosition (position);
phys_entity.SetOrientation (orientation);
vector3d origin (1., 0, -2.);
phys_entity.Localize (origin);
CHECK_CLOSE (0, origin[0], 1.0e-5);
CHECK_CLOSE (0, origin[1], 1.0e-5);
CHECK_CLOSE (0, origin[2], 1.0e-5);
}
TEST_FIXTURE ( EntityFixture, EntityPhysicStateLocalizeFull ) {
EntityPhysicState phys_entity;
vector3d position (1, 0, -1);
vector3d orientation (0, 45, 0);
phys_entity.SetPosition (position);
phys_entity.SetOrientation (orientation);
vector3d origin (0, 0, 0);
phys_entity.Localize (origin);
CHECK_CLOSE (-sqrt (2), origin[0], 1.0e-5);
CHECK_CLOSE (0, origin[1], 1.0e-5);
CHECK_CLOSE (0, origin[2], 1.0e-5);
}
+130
View File
@@ -0,0 +1,130 @@
#include <UnitTest++.h>
#include "Logging.h"
#include "EventsBase.h"
using namespace std;
using namespace Engine;
int global_event_type = -1;
string global_event_string = "";
class TestEventListener : public EventListenerBase {
public:
TestEventListener() {
mName = "TestEventListener";
}
virtual bool HandleEvent (const EventBasePtr &event) const {
global_event_type = event->mEventType;
global_event_string = event->mEventData;
return true;
}
};
struct EventsFixture {
EventsFixture () {
LoggingModule.Init (0, NULL);
LoggingModule.SetLogPrintLevel (LogLevelWarning);
TestEventManager = new EventManager;
global_event_type = -1;
global_event_string = "";
}
~EventsFixture () {
delete TestEventManager;
TestEventManager = NULL;
LoggingModule.Destroy ();
}
Logging LoggingModule;
TestEventListener Listener;
EventManager *TestEventManager;
};
TEST_FIXTURE ( EventsFixture, TestEventListenerHandleEvent ) {
EventBasePtr event (new EventBase);
event->mEventType = 1;
event->mEventData = "test";
Listener.HandleEvent (event);
CHECK_EQUAL (1, global_event_type);
CHECK_EQUAL ("test", global_event_string);
}
TEST_FIXTURE ( EventsFixture, TestTestEventManagerZeroListeners ) {
CHECK_EQUAL (false, TestEventManager->HasEventTypeListener(123));
CHECK_EQUAL (0, TestEventManager->GetEventTypeListenerCount(123));
}
TEST_FIXTURE ( EventsFixture, TestTestEventManagerAddListener ) {
TestEventManager->RegisterListener (&Listener, 1);
CHECK_EQUAL (true, TestEventManager->HasEventTypeListener(1));
CHECK_EQUAL (false, TestEventManager->HasEventTypeListener(2));
TestEventManager->RegisterListener (&Listener, 1);
CHECK_EQUAL (2, TestEventManager->GetEventTypeListenerCount(1));
}
TEST_FIXTURE ( EventsFixture, TestTestEventManagerTriggerEvent ) {
TestEventManager->RegisterListener (&Listener, 1);
CHECK_EQUAL (true, TestEventManager->HasEventTypeListener(1));
EventBasePtr event (new EventBase);
event->mEventType = 1;
event->mEventData = "test";
CHECK_EQUAL (true, TestEventManager->TriggerEvent (event));
CHECK_EQUAL (1, global_event_type);
CHECK_EQUAL ("test", global_event_string);
event->mEventType = 0;
CHECK_EQUAL (false, TestEventManager->TriggerEvent (event));
}
TEST_FIXTURE ( EventsFixture, TestTestEventManagerQueueEvent ) {
TestEventManager->RegisterListener (&Listener, 1);
EventBasePtr event (new EventBase);
event->mEventType = 1;
event->mEventData = "test";
CHECK_EQUAL (true, TestEventManager->QueueEvent (event));
CHECK_EQUAL (1, TestEventManager->GetQueuedEventCount());
CHECK_EQUAL (true, TestEventManager->QueueEvent (event));
CHECK_EQUAL (2, TestEventManager->GetQueuedEventCount());
event->mEventType = 2;
CHECK_EQUAL (false, TestEventManager->QueueEvent (event));
}
TEST_FIXTURE ( EventsFixture, TestTestEventManagerProcess ) {
TestEventManager->RegisterListener (&Listener, 1);
EventBasePtr event (new EventBase);
event->mEventType = 1;
event->mEventData = "test";
CHECK_EQUAL (true, TestEventManager->QueueEvent (event));
CHECK_EQUAL (1, TestEventManager->GetQueuedEventCount());
CHECK_EQUAL (true, TestEventManager->QueueEvent (event));
CHECK_EQUAL (2, TestEventManager->GetQueuedEventCount());
TestEventManager->Process();
CHECK_EQUAL (1, global_event_type);
CHECK_EQUAL ("test", global_event_string);
CHECK_EQUAL (0, TestEventManager->GetQueuedEventCount());
}
+66
View File
@@ -0,0 +1,66 @@
#include <UnitTest++.h>
#include "Logging.h"
#include "PhysicsBase.h"
#include "ModelBase.h"
#include "EntityBase.h"
using namespace std;
using namespace Engine;
struct PhysicsFixture {
PhysicsFixture () {
LoggingModule.Init (0, NULL);
LoggingModule.SetLogPrintLevel (LogLevelMessage);
PhysicsModule.Init (0, NULL);
dummy_entity = CreateEntityPhysicState (EntityBaseTypeNone, 0);
particle_entity = CreateEntityPhysicState (EntityBaseTypeParticle, 1);
block_entity = CreateEntityPhysicState (EntityBaseTypeBlock, 2);
actor_entity = CreateEntityPhysicState (EntityBaseTypeActor, 3);
PhysicsModule.RegisterEntity (dummy_entity);
PhysicsModule.RegisterEntity (particle_entity);
PhysicsModule.RegisterEntity (block_entity);
PhysicsModule.RegisterEntity (actor_entity);
}
~PhysicsFixture () {
PhysicsModule.UnregisterEntity (0);
PhysicsModule.UnregisterEntity (1);
PhysicsModule.UnregisterEntity (2);
PhysicsModule.UnregisterEntity (3);
PhysicsModule.Destroy ();
LoggingModule.Destroy ();
}
Logging LoggingModule;
PhysicsBase PhysicsModule;
EntityPhysicState* dummy_entity;
EntityPhysicState* particle_entity;
EntityPhysicState* block_entity;
EntityPhysicState* actor_entity;
};
TEST_FIXTURE ( PhysicsFixture, PhysicsModuleActorActorCollision ) {
int result = -1;
EntityPhysicState* actor_2_entity = CreateEntityPhysicState (EntityBaseTypeActor, 4);
assert (actor_2_entity->mShape);
assert (actor_entity->mShape);
PhysicsModule.RegisterEntity (actor_2_entity);
actor_entity->mPosition = vector3d (0., 0., 0.);
actor_entity->mVelocity = vector3d (1., 0., 0.);
actor_2_entity->mPosition = vector3d (1.5, 0., 0.1);
actor_2_entity->mVelocity = vector3d (-1., 0., 0.);
result = PhysicsModule.Simulate (1000.);
CHECK_EQUAL (0, result);
PhysicsModule.UnregisterEntity (actor_2_entity->mId);
}
+8
View File
@@ -0,0 +1,8 @@
#include <UnitTest++.h>
using namespace std;
int main (int argc, char *argv[])
{
return UnitTest::RunAllTests ();
}