Initial structure

This commit is contained in:
2015-09-04 10:02:06 +02:00
commit 98e363eda6
457 changed files with 127943 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
project(tests)
find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework)
include_directories(
${CMAKE_SOURCE_DIR}/include/dd
${Boost_INCLUDE_DIRS}
)
set(SOURCE_FILES
main.cpp
FileWatcherTest.cpp
ComponentCopyTest.cpp
)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
add_executable(tests ${SOURCE_FILES})
target_link_libraries(tests
daydream
${Boost_LIBRARIES}
)
+29
View File
@@ -0,0 +1,29 @@
#include <boost/test/unit_test.hpp>
#include "Core/Component.h"
using namespace dd;
struct TestComponent : public Component
{
int Int = 5;
float Float = 1.33333f;
double Double = 1.33333;
std::string String = "Hello World";
};
BOOST_AUTO_TEST_CASE(component_copy)
{
auto componentFactory = new Factory<Component>();
componentFactory->Register<TestComponent>();
auto component1 = static_cast<TestComponent*>(componentFactory->Create<TestComponent>());
auto component2 = static_cast<TestComponent*>(componentFactory->Copy<TestComponent>(component1));
BOOST_CHECK(component1->Int == component2->Int);
BOOST_CHECK_CLOSE(component1->Float, component2->Float, 0.00001f);
BOOST_CHECK_CLOSE(component1->Double, component2->Double, 0.00001f);
BOOST_CHECK(component1->String == component2->String);
delete component2;
delete component1;
delete componentFactory;
}
+69
View File
@@ -0,0 +1,69 @@
#include <chrono>
#include <thread>
#include <fstream>
#include <cstdio>
#include <boost/test/unit_test.hpp>
#include "Core/Util/FileWatcher.h"
using namespace dd;
const std::string testFileName = "FileWatcherTestFile";
BOOST_AUTO_TEST_CASE(file_watcher)
{
auto fw = new FileWatcher("");
bool f_created = false;
bool f_size_changed = false;
bool f_timestamp_changed = false;
bool f_deleted = false;
// Make sure the test file doesn't exist
remove(testFileName.c_str());
// Set up the file watcher to watch for changes
fw->AddWatch(testFileName,
[&f_created, &f_size_changed, &f_timestamp_changed, &f_deleted]
(std::string path, FileWatcher::FileEventFlags flags)
{
if (flags & FileWatcher::FileEventFlags::Created)
f_created = true;
if (flags & FileWatcher::FileEventFlags::SizeChanged)
f_size_changed = true;
if (flags & FileWatcher::FileEventFlags::TimestampChanged)
f_timestamp_changed = true;
if (flags & FileWatcher::FileEventFlags::Deleted)
f_deleted = true;
});
// Create the file
FILE* testFile = fopen(testFileName.c_str(), "w");
fw->Check();
// Write to the file
fputs("test", testFile);
fclose(testFile);
fw->Check();
// Change file timestamp
std::time_t time;
std::localtime(&time);
time -= 1;
boost::filesystem::last_write_time(testFileName, time);
fw->Check();
// Delete the file;
remove(testFileName.c_str());
fw->Check();
BOOST_CHECK(f_created);
BOOST_CHECK(f_size_changed);
BOOST_CHECK(f_timestamp_changed);
BOOST_CHECK(f_deleted);
delete fw;
}
+2
View File
@@ -0,0 +1,2 @@
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>