From 47fe3421585302f2101691a685ab99b0e1ad5cfc Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 1 May 2015 17:48:32 +0200 Subject: Change XMLNode* to XMLNode An XMLNode object is already simply a pointer, so no need to dynamically allocate XMLNodes. --- tests/test_XMLDocument.cpp | 52 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'tests/test_XMLDocument.cpp') diff --git a/tests/test_XMLDocument.cpp b/tests/test_XMLDocument.cpp index adabdd6..07abee3 100644 --- a/tests/test_XMLDocument.cpp +++ b/tests/test_XMLDocument.cpp @@ -38,12 +38,12 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_Constructor1 ) astra::XMLDocument *doc = astra::XMLDocument::createDocument("test"); BOOST_REQUIRE(doc); - astra::XMLNode *root = doc->getRootNode(); + astra::XMLNode root = doc->getRootNode(); BOOST_REQUIRE(root); - BOOST_CHECK(root->getName() == "test"); - BOOST_CHECK(root->getContent().empty()); + BOOST_CHECK(root.getName() == "test"); + BOOST_CHECK(root.getContent().empty()); } BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO ) @@ -53,12 +53,12 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO ) doc->saveToFile("test.xml"); astra::XMLDocument *doc2 = astra::XMLDocument::readFromFile("test.xml"); - astra::XMLNode *root = doc2->getRootNode(); + astra::XMLNode root = doc2->getRootNode(); BOOST_REQUIRE(root); - BOOST_CHECK(root->getName() == "test"); - BOOST_CHECK(root->getContent().empty()); + BOOST_CHECK(root.getName() == "test"); + BOOST_CHECK(root.getContent().empty()); } @@ -67,32 +67,28 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_CreateNodes ) astra::XMLDocument *doc = astra::XMLDocument::createDocument("test"); BOOST_REQUIRE(doc); - astra::XMLNode *root = doc->getRootNode(); + astra::XMLNode root = doc->getRootNode(); BOOST_REQUIRE(root); - astra::XMLNode *node = root->addChildNode("child"); + astra::XMLNode node = root.addChildNode("child"); BOOST_REQUIRE(node); - node->addAttribute("attr", "val"); + node.addAttribute("attr", "val"); doc->saveToFile("test2.xml"); - delete node; - delete root; delete doc; doc = astra::XMLDocument::readFromFile("test2.xml"); BOOST_REQUIRE(doc); root = doc->getRootNode(); BOOST_REQUIRE(node); - node = root->getSingleNode("child"); + node = root.getSingleNode("child"); BOOST_REQUIRE(node); - BOOST_CHECK(node->hasAttribute("attr")); - BOOST_CHECK(node->getAttribute("attr") == "val"); + BOOST_CHECK(node.hasAttribute("attr")); + BOOST_CHECK(node.getAttribute("attr") == "val"); - delete node; - delete root; delete doc; } @@ -101,16 +97,16 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_Options ) astra::XMLDocument *doc = astra::XMLDocument::createDocument("test"); BOOST_REQUIRE(doc); - astra::XMLNode *root = doc->getRootNode(); + astra::XMLNode root = doc->getRootNode(); BOOST_REQUIRE(root); - BOOST_CHECK(!root->hasOption("opt")); + BOOST_CHECK(!root.hasOption("opt")); - root->addOption("opt", "val"); + root.addOption("opt", "val"); - BOOST_CHECK(root->hasOption("opt")); + BOOST_CHECK(root.hasOption("opt")); - BOOST_CHECK(root->getOption("opt") == "val"); + BOOST_CHECK(root.getOption("opt") == "val"); } @@ -119,39 +115,35 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_List ) astra::XMLDocument *doc = astra::XMLDocument::createDocument("test"); BOOST_REQUIRE(doc); - astra::XMLNode *root = doc->getRootNode(); + astra::XMLNode root = doc->getRootNode(); BOOST_REQUIRE(root); - astra::XMLNode *node = root->addChildNode("child"); + astra::XMLNode node = root.addChildNode("child"); BOOST_REQUIRE(node); float fl[] = { 1.0, 3.5, 2.0, 4.75 }; - node->setContent(fl, sizeof(fl)/sizeof(fl[0])); + node.setContent(fl, sizeof(fl)/sizeof(fl[0])); doc->saveToFile("test3.xml"); - delete node; - delete root; delete doc; doc = astra::XMLDocument::readFromFile("test3.xml"); BOOST_REQUIRE(doc); root = doc->getRootNode(); BOOST_REQUIRE(root); - node = root->getSingleNode("child"); + node = root.getSingleNode("child"); BOOST_REQUIRE(node); - std::vector f = node->getContentNumericalArray(); + std::vector f = node.getContentNumericalArray(); BOOST_CHECK(f[0] == fl[0]); BOOST_CHECK(f[1] == fl[1]); BOOST_CHECK(f[2] == fl[2]); BOOST_CHECK(f[3] == fl[3]); - delete node; - delete root; delete doc; } -- cgit v1.2.3 From c6f6d6fbc3537cedefc0cef8e71819436a0a60c1 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 6 May 2015 10:27:22 +0200 Subject: Add extra XMLNode/XMLDocument/Config test --- tests/test_XMLDocument.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/test_XMLDocument.cpp') diff --git a/tests/test_XMLDocument.cpp b/tests/test_XMLDocument.cpp index 07abee3..18e880d 100644 --- a/tests/test_XMLDocument.cpp +++ b/tests/test_XMLDocument.cpp @@ -32,6 +32,7 @@ $Id$ #include #include "astra/XMLDocument.h" +#include "astra/Config.h" BOOST_AUTO_TEST_CASE( testXMLDocument_Constructor1 ) { @@ -148,3 +149,18 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_List ) } +BOOST_AUTO_TEST_CASE( testXMLDocument_Config ) +{ + astra::Config* cfg = new astra::Config(); + cfg->initialize("VolumeGeometry2D"); + + cfg->self.addChildNode("GridColCount", 1); + cfg->self.addChildNode("GridRowCount", 2); + + cfg->self.addOption("WindowMinX", 3); + cfg->self.addOption("WindowMaxX", 4); + cfg->self.addOption("WindowMinY", 5); + cfg->self.addOption("WindowMaxY", 6); + + delete cfg; +} -- cgit v1.2.3 From f4dcfd65f2695fd2163109e6577fb61c524c9d5f Mon Sep 17 00:00:00 2001 From: joergkappes Date: Sat, 28 Mar 2015 18:20:06 +0100 Subject: fix memleaks in test --- tests/test_XMLDocument.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_XMLDocument.cpp') diff --git a/tests/test_XMLDocument.cpp b/tests/test_XMLDocument.cpp index 18e880d..95429cb 100644 --- a/tests/test_XMLDocument.cpp +++ b/tests/test_XMLDocument.cpp @@ -45,6 +45,9 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_Constructor1 ) BOOST_CHECK(root.getName() == "test"); BOOST_CHECK(root.getContent().empty()); + + delete doc; + } BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO ) @@ -61,6 +64,9 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO ) BOOST_CHECK(root.getName() == "test"); BOOST_CHECK(root.getContent().empty()); + delete doc2; + delete doc; + } BOOST_AUTO_TEST_CASE( testXMLDocument_CreateNodes ) @@ -109,6 +115,8 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_Options ) BOOST_CHECK(root.getOption("opt") == "val"); + delete doc; + } BOOST_AUTO_TEST_CASE( testXMLDocument_List ) -- cgit v1.2.3