Skip to content
Snippets Groups Projects
Commit 2d56b4d8 authored by Amorilia's avatar Amorilia
Browse files

Added test for writing incomplete trees (fails at the moment).

parent 2d89aa38
No related branches found
No related tags found
No related merge requests found
......@@ -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)
# 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()
#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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment