From 2d56b4d860e7b98869e4a508b58593e0fae79a15 Mon Sep 17 00:00:00 2001 From: Amorilia <amorilia@users.sourceforge.net> Date: Sat, 2 Jul 2011 08:37:31 +0100 Subject: [PATCH] Added test for writing incomplete trees (fails at the moment). --- CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 13 +++++++++++++ test/write_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 test/CMakeLists.txt create mode 100644 test/write_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d882377f..bea78b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -428,3 +428,7 @@ TriStripper/policy.cpp set_target_properties(niflib PROPERTIES DEFINE_SYMBOL BUILDING_NIFLIB_DLL) + +# build the tests, this needs boost +enable_testing() +add_subdirectory(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..6184264e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,13 @@ +# find boost; we use this for the testing framework +if(MINGW) + set(Boost_COMPILER -gcc45) +endif(MINGW) +find_package(Boost 1.45.0 REQUIRED COMPONENTS unit_test_framework) +include_directories(${Boost_INCLUDE_DIRS}) + +foreach(TEST + write_test) + add_executable(${TEST} ${TEST}.cpp) + target_link_libraries(${TEST} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} niflib) + add_test(niflib::${TEST} ${TEST}) +endforeach() diff --git a/test/write_test.cpp b/test/write_test.cpp new file mode 100644 index 00000000..f88984d9 --- /dev/null +++ b/test/write_test.cpp @@ -0,0 +1,37 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> + +#include <sstream> // stringstream + +#include "niflib.h" +#include "obj/NiNode.h" +#include "obj/NiKeyframeController.h" + +using namespace Niflib; +using namespace std; + +BOOST_AUTO_TEST_SUITE(write_test_suite) + +BOOST_AUTO_TEST_CASE(write_incomplete_tree_test) +{ + stringstream ss; + + // create a simple nif tree with back reference + NiNodeRef node = new NiNode; + NiKeyframeControllerRef ctrl = new NiKeyframeController; + node->AddController(ctrl); + BOOST_REQUIRE_EQUAL(ctrl->GetTarget(), node); + // controller target is the node, but isn't in the tree + // check that WriteNifTree does not throw + BOOST_CHECK_NO_THROW(WriteNifTree(ss, ctrl)); + // check that written target is NULL + ss.seekg(0); + NiObjectRef root; + BOOST_CHECK_NO_THROW(root = ReadNifTree(ss)); + NiKeyframeControllerRef ctrl2 = DynamicCast<NiKeyframeController>(root); + BOOST_REQUIRE(ctrl2 != NULL); + BOOST_CHECK(ctrl2->GetTarget() == NULL); +} + +BOOST_AUTO_TEST_SUITE_END() -- GitLab