diff --git a/libxmlmm-test/CDataTest.cpp b/libxmlmm-test/CDataTest.cpp index b5f13cf..3f52311 100644 --- a/libxmlmm-test/CDataTest.cpp +++ b/libxmlmm-test/CDataTest.cpp @@ -21,7 +21,7 @@ #include #include -#include "rtest.h" +#include #include #include @@ -29,57 +29,51 @@ // NOTE: Nodes can not live w/o their Document. -SUITE(CDataTest) +TEST(CDataTest, cdata_get_content) { -//------------------------------------------------------------------------------ - TEST(cdata_get_content) - { - xml::Document doc; + xml::Document doc; - std::string xml = - "\n" - "\n"; + std::string xml = + "\n" + "\n"; - doc.read_from_string(xml); + doc.read_from_string(xml); - xml::Element* element = doc.get_root_element(); - CHECK(element != NULL); + xml::Element* element = doc.get_root_element(); + EXPECT_TRUE(element != NULL); - std::vector children = element->get_children(); - CHECK_EQUAL(1, children.size()); - xml::CData* c_data = dynamic_cast(children.at(0)); - CHECK(c_data != NULL); - CHECK_EQUAL("This is a test.", c_data->get_content()); - } + std::vector children = element->get_children(); + EXPECT_EQ(1, children.size()); + xml::CData* c_data = dynamic_cast(children.at(0)); + EXPECT_TRUE(c_data != NULL); + EXPECT_EQ("This is a test.", c_data->get_content()); +} -//------------------------------------------------------------------------------ - TEST(cdata_element_get_text) - { - xml::Document doc; +TEST(CDataTest, data_element_get_text) +{ + xml::Document doc; - std::string xml = - "\n" - "\n"; + std::string xml = + "\n" + "\n"; - doc.read_from_string(xml); + doc.read_from_string(xml); - xml::Element* element = doc.get_root_element(); - CHECK(element != NULL); + xml::Element* element = doc.get_root_element(); + EXPECT_TRUE(element != NULL); - CHECK_EQUAL("This is a test.", element->get_text()); - } + EXPECT_EQ("This is a test.", element->get_text()); +} -//------------------------------------------------------------------------------ - TEST(cdata_behaves_like_text_in_xpath) - { - xml::Document doc; +TEST(CDataTest, cdata_behaves_like_text_in_xpath) +{ + xml::Document doc; - std::string xml = - "\n" - "\n"; + std::string xml = + "\n" + "\n"; - doc.read_from_string(xml); - std::string text = doc.query_string("/test/text()"); - CHECK_EQUAL("This is a test.", text); - } + doc.read_from_string(xml); + std::string text = doc.query_string("/test/text()"); + EXPECT_EQ("This is a test.", text); } \ No newline at end of file diff --git a/libxmlmm-test/DocumentTest.cpp b/libxmlmm-test/DocumentTest.cpp index 04b385e..e61ea48 100644 --- a/libxmlmm-test/DocumentTest.cpp +++ b/libxmlmm-test/DocumentTest.cpp @@ -21,247 +21,230 @@ #include #include -#include "rtest.h" +#include #include #include -SUITE(DocumentTest) +TEST(DocumentTest, initial_document_has_no_root_element) { -//------------------------------------------------------------------------------ - TEST(initial_document_has_no_root_element) - { - xml::Document doc; - CHECK(! doc.has_root_element()); - } - -//------------------------------------------------------------------------------ - TEST(create_root_element) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - CHECK(root != NULL); - CHECK_EQUAL("test", root->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(get_root_node_throws_on_no_root_element) - { - xml::Document doc; - CHECK_THROW(doc.get_root_element(), xml::NoRootElement); - } - -//------------------------------------------------------------------------------ - TEST(constness) - { - const std::string xml = - "\n" \ - "\n"; - const xml::Document doc(xml); - CHECK(doc.has_root_element()); - CHECK(doc.get_root_element() != NULL); - CHECK_EQUAL(xml, doc.write_to_string()); - } - -//------------------------------------------------------------------------------ - TEST(write_to_string) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - - std::string xml = - "\n" \ - "\n"; - CHECK_EQUAL(xml, doc.write_to_string()); - } - -//------------------------------------------------------------------------------ - TEST(read_from_string) - { - xml::Document doc; - - std::string xml = - "\n" - "\n"; - - doc.read_from_string(xml); - - xml::Element* root = doc.get_root_element(); - CHECK(root != NULL); - CHECK_EQUAL("test", root->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(build_html) - { - xml::Document doc; - xml::Element* html = doc.create_root_element("html"); - - xml::Element* head = html->add_element("head"); - xml::Element* title = head->add_element("title"); - title->set_text("This is a test HTML."); - xml::Element* style_link = head->add_element("link"); - style_link->set_attribute("rel", "stylesheet"); - style_link->set_attribute("type", "text/css"); - style_link->set_attribute("href", "style.css"); - - xml::Element* body = html->add_element("body"); - xml::Element* h1 = body->add_element("h1"); - h1->set_text("This is a test HTML"); - xml::Element* p1 = body->add_element("p"); - p1->add_text("This is a test for "); - xml::Element* em1 = p1->add_element("em"); - em1->set_text("libxmlmm"); - p1->add_text(". It aimes to see if a HTML document can be created with the interface."); - - std::stringstream buff; - buff << doc; - - std::string ref = - "\n" - "This is a test HTML." - "" - "

This is a test HTML

This is a test for libxmlmm." - " It aimes to see if a HTML document can be created with the interface.

\n"; - CHECK_EQUAL(ref, buff.str()); - } - -//------------------------------------------------------------------------------ - TEST(read_from_stream) - { - std::stringstream xmat( - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n"); - - const std::string xml(xmat.str()); - const xml::Document check(xml); - - xml::Document doc; - doc.read_from_stream(xmat); - // We assume our earlier testing of write_to_string is valid - CHECK_EQUAL(doc.write_to_string(), check.write_to_string()); - } - -//------------------------------------------------------------------------------ - TEST(xpath_string_query) - { - std::stringstream xmsg( - "\n" - "\n" - " Mack\n" - " Joe\n" - " Sally\n" - " Mike\n" - " Hello everybody!\n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmsg); - - std::string body = doc.query_string("/message/body"); - CHECK_EQUAL("Hello everybody!", body); - std::string body_text = doc.query_string("/message/body/text()"); - CHECK_EQUAL("Hello everybody!", body_text); - double to_count = doc.query_number("count(/message/to)"); - CHECK_CLOSE(3.0, to_count, 1e-4); - - std::string message_version_string = doc.query_string("/message/@version"); - CHECK_EQUAL("1.2", message_version_string); - double message_version_number = doc.query_number("/message/@version"); - CHECK_CLOSE(1.2, message_version_number, 1e-4); - } - -//------------------------------------------------------------------------------ - TEST(xpath_get_elements) - { - std::stringstream xmsg( - "\n" - "\n" - " Mack\n" - " Joe\n" - " Sally\n" - " Mike\n" - " Hello everybody!\n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmsg); - - std::vector to_nodes = doc.find_nodes("/message/to"); - CHECK_EQUAL(3, to_nodes.size()); - - std::vector to_elements = doc.find_elements("/message/to"); - CHECK_EQUAL(3, to_elements.size()); - - CHECK_EQUAL("Joe", to_elements[0]->get_text()); - CHECK_EQUAL("Sally", to_elements[1]->get_text()); - CHECK_EQUAL("Mike", to_elements[2]->get_text()); - } - -//------------------------------------------------------------------------------ - TEST(xpath_get_element) - { - std::stringstream xmsg( - "\n" - "\n" - " Mack\n" - " Joe\n" - " Sally\n" - " Mike\n" - " Hello everybody!\n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmsg); - - xml::Node* from_node = doc.find_node("/message/from"); - CHECK(from_node != NULL); - - xml::Element* from_element = doc.find_element("/message/from"); - CHECK(from_element != NULL); - - CHECK_EQUAL("Mack", from_element->get_text()); - } - -//------------------------------------------------------------------------------ - TEST(writes_latin1) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - - std::stringstream buff; - // NOTE: This implicitly tests write_to_string too. - doc.write_to_stream(buff, "ISO-8859-1"); - - std::string ref = - "\n" - "\n"; - CHECK_EQUAL(ref, buff.str()); - } - -//------------------------------------------------------------------------------ - TEST(writes_latin1_to_file) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - - std::stringstream buff; - // NOTE: This implicitly tests write_to_string too. - doc.write_to_stream(buff, "ISO-8859-1"); - - std::string ref = - "\n" - "\n"; - CHECK_EQUAL(ref, buff.str()); - } + xml::Document doc; + EXPECT_TRUE(! doc.has_root_element()); } +TEST(DocumentTest, create_root_element) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + EXPECT_TRUE(root != NULL); + EXPECT_EQ("test", root->get_name()); +} + +TEST(DocumentTest, get_root_node_throws_on_no_root_element) +{ + xml::Document doc; + EXPECT_THROW(doc.get_root_element(), xml::NoRootElement); +} + +TEST(DocumentTest, constness) +{ + const std::string xml = + "\n" \ + "\n"; + const xml::Document doc(xml); + EXPECT_TRUE(doc.has_root_element()); + EXPECT_TRUE(doc.get_root_element() != NULL); + EXPECT_EQ(xml, doc.write_to_string()); +} + +TEST(DocumentTest, write_to_string) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + + std::string xml = + "\n" \ + "\n"; + EXPECT_EQ(xml, doc.write_to_string()); +} + +TEST(DocumentTest, read_from_string) +{ + xml::Document doc; + + std::string xml = + "\n" + "\n"; + + doc.read_from_string(xml); + + xml::Element* root = doc.get_root_element(); + EXPECT_TRUE(root != NULL); + EXPECT_EQ("test", root->get_name()); +} + +TEST(DocumentTest, build_html) +{ + xml::Document doc; + xml::Element* html = doc.create_root_element("html"); + + xml::Element* head = html->add_element("head"); + xml::Element* title = head->add_element("title"); + title->set_text("This is a test HTML."); + xml::Element* style_link = head->add_element("link"); + style_link->set_attribute("rel", "stylesheet"); + style_link->set_attribute("type", "text/css"); + style_link->set_attribute("href", "style.css"); + + xml::Element* body = html->add_element("body"); + xml::Element* h1 = body->add_element("h1"); + h1->set_text("This is a test HTML"); + xml::Element* p1 = body->add_element("p"); + p1->add_text("This is a test for "); + xml::Element* em1 = p1->add_element("em"); + em1->set_text("libxmlmm"); + p1->add_text(". It aimes to see if a HTML document can be created with the interface."); + + std::stringstream buff; + buff << doc; + + std::string ref = + "\n" + "This is a test HTML." + "" + "

This is a test HTML

This is a test for libxmlmm." + " It aimes to see if a HTML document can be created with the interface.

\n"; + EXPECT_EQ(ref, buff.str()); +} + +TEST(DocumentTest, read_from_stream) +{ + std::stringstream xmat( + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"); + + const std::string xml(xmat.str()); + const xml::Document check(xml); + + xml::Document doc; + doc.read_from_stream(xmat); + // We assume our earlier testing of write_to_string is valid + EXPECT_EQ(doc.write_to_string(), check.write_to_string()); +} + +TEST(DocumentTest, xpath_string_query) +{ + std::stringstream xmsg( + "\n" + "\n" + " Mack\n" + " Joe\n" + " Sally\n" + " Mike\n" + " Hello everybody!\n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmsg); + + std::string body = doc.query_string("/message/body"); + EXPECT_EQ("Hello everybody!", body); + std::string body_text = doc.query_string("/message/body/text()"); + EXPECT_EQ("Hello everybody!", body_text); + double to_count = doc.query_number("count(/message/to)"); + EXPECT_FLOAT_EQ(3.0, to_count, 1e-4); + + std::string message_version_string = doc.query_string("/message/@version"); + EXPECT_EQ("1.2", message_version_string); + double message_version_number = doc.query_number("/message/@version"); + EXPECT_FLOAT_EQ(1.2, message_version_number); +} +TEST(DocumentTest, xpath_get_elements) +{ + std::stringstream xmsg( + "\n" + "\n" + " Mack\n" + " Joe\n" + " Sally\n" + " Mike\n" + " Hello everybody!\n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmsg); + + std::vector to_nodes = doc.find_nodes("/message/to"); + EXPECT_EQ(3, to_nodes.size()); + + std::vector to_elements = doc.find_elements("/message/to"); + EXPECT_EQ(3, to_elements.size()); + + EXPECT_EQ("Joe", to_elements[0]->get_text()); + EXPECT_EQ("Sally", to_elements[1]->get_text()); + EXPECT_EQ("Mike", to_elements[2]->get_text()); +} + +TEST(DocumentTest, xpath_get_element) +{ + std::stringstream xmsg( + "\n" + "\n" + " Mack\n" + " Joe\n" + " Sally\n" + " Mike\n" + " Hello everybody!\n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmsg); + + xml::Node* from_node = doc.find_node("/message/from"); + EXPECT_TRUE(from_node != NULL); + + xml::Element* from_element = doc.find_element("/message/from"); + EXPECT_TRUE(from_element != NULL); + + EXPECT_EQ("Mack", from_element->get_text()); +} + + +TEST(DocumentTest, writes_latin1) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + + std::stringstream buff; + // NOTE: This implicitly tests write_to_string too. + doc.write_to_stream(buff, "ISO-8859-1"); + + std::string ref = + "\n" + "\n"; + EXPECT_EQ(ref, buff.str()); +} + +TEST(DocumentTest, writes_latin1_to_file) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + + std::stringstream buff; + // NOTE: This implicitly tests write_to_string too. + doc.write_to_stream(buff, "ISO-8859-1"); + + std::string ref = + "\n" + "\n"; + EXPECT_EQ(ref, buff.str()); +} diff --git a/libxmlmm-test/ElementTest.cpp b/libxmlmm-test/ElementTest.cpp index cb7218a..2070960 100644 --- a/libxmlmm-test/ElementTest.cpp +++ b/libxmlmm-test/ElementTest.cpp @@ -21,7 +21,7 @@ #include #include -#include "rtest.h" +#include #include #include @@ -30,165 +30,149 @@ // NOTE: Elements can not live w/o their Document. -SUITE(ElementTest) +TEST(ElementTest, get_name) { -//------------------------------------------------------------------------------ - TEST(get_name) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - CHECK_EQUAL("test", root->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(set_name) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->set_name("root"); - CHECK_EQUAL("root", root->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(set_text) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->set_text("This is a test"); - CHECK_EQUAL("This is a test", root->get_text()); - } - -//------------------------------------------------------------------------------ - TEST(add_text) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->add_text("This is"); - root->add_text(" a test"); - CHECK_EQUAL("This is a test", root->get_text()); - } - -//------------------------------------------------------------------------------ - TEST(get_set_attribute) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->set_attribute("key", "value"); - CHECK(root->has_attribute("key")); - CHECK_EQUAL("value", root->get_attribute("key")); - } - -//------------------------------------------------------------------------------ - TEST(remove_attribute) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->set_attribute("key", "value"); - root->remove_attribute("key"); - - CHECK(! root->has_attribute("key")); - } - -//------------------------------------------------------------------------------ - TEST(add_element) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - xml::Element* element1 = root->add_element("element1"); - CHECK(element1 != NULL); - CHECK_EQUAL("element1", element1->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(get_parent) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - xml::Element* element1 = root->add_element("element1"); - CHECK_EQUAL(root, element1->get_parent()); - } - -//------------------------------------------------------------------------------ - TEST(browse_children) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - xml::Element* element1 = root->add_element("element1"); - xml::Element* element2 = root->add_element("element2"); - xml::Element* element3 = root->add_element("element3"); - - std::vector children = root->get_children(); - CHECK_EQUAL(3, children.size()); - CHECK_EQUAL(element1, children[0]); - CHECK_EQUAL(element2, children[1]); - CHECK_EQUAL(element3, children[2]); - } - -//------------------------------------------------------------------------------ - TEST(simple_xpath_querry) - { - std::stringstream xmat( - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmat); - - xml::Element* xroot = doc.get_root_element(); - CHECK(xroot != NULL); - - xml::Element* xambient = xroot->find_element("./ambient"); - CHECK(xambient != NULL); - CHECK_EQUAL("ambient", xambient->get_name()); - } - -//------------------------------------------------------------------------------ - TEST(get_attribute_with_type) - { - std::stringstream xmsg( - "\n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmsg); - - xml::Element* xroot = doc.get_root_element(); - CHECK(xroot != NULL); - - CHECK_CLOSE(1.2f, xroot->get_attribute("version"), 1e-4f); - CHECK_EQUAL(1, xroot->get_attribute("id")); - CHECK_EQUAL("1.2", xroot->get_attribute("version")); - } - -//------------------------------------------------------------------------------ - TEST(get_attribute_with_invalid_type) - { - std::stringstream xmsg( - "\n" - "\n"); - - xml::Document doc; - doc.read_from_stream(xmsg); - - xml::Element* xroot = doc.get_root_element(); - CHECK(xroot != NULL); - - CHECK_THROW(xroot->get_attribute("version"), xml::Exception); - } - -//------------------------------------------------------------------------------ - TEST(set_attribute_with_type) - { - xml::Document doc; - xml::Element* root = doc.create_root_element("test"); - root->set_attribute("key", 8); - CHECK(root->has_attribute("key")); - CHECK_EQUAL("8", root->get_attribute("key")); - } + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + EXPECT_EQ("test", root->get_name()); +} + +TEST(ElementTest, set_name) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->set_name("root"); + EXPECT_EQ("root", root->get_name()); +} + +TEST(ElementTest, set_text) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->set_text("This is a test"); + EXPECT_EQ("This is a test", root->get_text()); +} + +TEST(ElementTest, add_text) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->add_text("This is"); + root->add_text(" a test"); + EXPECT_EQ("This is a test", root->get_text()); +} + +TEST(ElementTest, get_set_attribute) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->set_attribute("key", "value"); + EXPECT_TRUE(root->has_attribute("key")); + EXPECT_EQ("value", root->get_attribute("key")); +} + +TEST(ElementTest, remove_attribute) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->set_attribute("key", "value"); + root->remove_attribute("key"); + + EXPECT_TRUE(! root->has_attribute("key")); +} + +TEST(ElementTest, add_element) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + xml::Element* element1 = root->add_element("element1"); + EXPECT_TRUE(element1 != NULL); + EXPECT_EQ("element1", element1->get_name()); +} + +TEST(ElementTest, get_parent) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + xml::Element* element1 = root->add_element("element1"); + EXPECT_EQ(root, element1->get_parent()); +} + +TEST(ElementTest, rowse_children) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + xml::Element* element1 = root->add_element("element1"); + xml::Element* element2 = root->add_element("element2"); + xml::Element* element3 = root->add_element("element3"); + + std::vector children = root->get_children(); + EXPECT_EQ(3, children.size()); + EXPECT_EQ(element1, children[0]); + EXPECT_EQ(element2, children[1]); + EXPECT_EQ(element3, children[2]); +} + +TEST(ElementTest, simple_xpath_querry) +{ + std::stringstream xmat( + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmat); + + xml::Element* xroot = doc.get_root_element(); + EXPECT_TRUE(xroot != NULL); + + xml::Element* xambient = xroot->find_element("./ambient"); + EXPECT_TRUE(xambient != NULL); + EXPECT_EQ("ambient", xambient->get_name()); +} + +TEST(ElementTest, get_attribute_with_type) +{ + std::stringstream xmsg( + "\n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmsg); + + xml::Element* xroot = doc.get_root_element(); + EXPECT_TRUE(xroot != NULL); + + EXPECT_FLOAT_EQ(1.2f, xroot->get_attribute("version")); + EXPECT_EQ(1, xroot->get_attribute("id")); + EXPECT_EQ("1.2", xroot->get_attribute("version")); +} + +TEST(ElementTest, get_attribute_with_invalid_type) +{ + std::stringstream xmsg( + "\n" + "\n"); + + xml::Document doc; + doc.read_from_stream(xmsg); + + xml::Element* xroot = doc.get_root_element(); + EXPECT_TRUE(xroot != NULL); + + EXPECT_THROW(xroot->get_attribute("version"), xml::Exception); +} + +TEST(ElementTest, set_attribute_with_type) +{ + xml::Document doc; + xml::Element* root = doc.create_root_element("test"); + root->set_attribute("key", 8); + EXPECT_TRUE(root->has_attribute("key")); + EXPECT_EQ("8", root->get_attribute("key")); } diff --git a/libxmlmm-test/libxmlmm-test.vcxproj b/libxmlmm-test/libxmlmm-test.vcxproj index 325360c..0f748a2 100644 --- a/libxmlmm-test/libxmlmm-test.vcxproj +++ b/libxmlmm-test/libxmlmm-test.vcxproj @@ -101,8 +101,11 @@ Console - true + DebugFull + + echo 1 > $(TargetPath).is_google_test + @@ -119,8 +122,11 @@ Console true true - true + DebugFull + + echo 1 > $(TargetPath).is_google_test + @@ -133,8 +139,11 @@ Console - true + DebugFull + + echo 1 > $(TargetPath).is_google_test + @@ -151,18 +160,17 @@ Console true true - true + DebugFull + + echo 1 > $(TargetPath).is_google_test + - - - - - + diff --git a/libxmlmm-test/libxmlmm-test.vcxproj.filters b/libxmlmm-test/libxmlmm-test.vcxproj.filters index 6ed2661..d5db95c 100644 --- a/libxmlmm-test/libxmlmm-test.vcxproj.filters +++ b/libxmlmm-test/libxmlmm-test.vcxproj.filters @@ -24,16 +24,8 @@ Source Files - + Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/libxmlmm-test/test.cpp b/libxmlmm-test/main.cpp similarity index 89% rename from libxmlmm-test/test.cpp rename to libxmlmm-test/main.cpp index d7d1399..c6d5adf 100644 --- a/libxmlmm-test/test.cpp +++ b/libxmlmm-test/main.cpp @@ -19,10 +19,11 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#include "rtest.h" +#include -int main() +int main(int argc, char* argv[]) { - return rtest::run(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/libxmlmm-test/rtest.cpp b/libxmlmm-test/rtest.cpp deleted file mode 100644 index cee718b..0000000 --- a/libxmlmm-test/rtest.cpp +++ /dev/null @@ -1,66 +0,0 @@ - -#include "rtest.h" - -#include -#include - -namespace rtest -{ - std::vector& get_tests() - { - static std::vector tests; - return tests; - } - - int run() - { - std::vector& tests = get_tests(); - - unsigned int failed = 0; - for (unsigned int i = 0; i < tests.size(); i++) - { - try - { - tests[i]->run(); - } - catch (impl::Failure& failure) - { - std::cerr << failure.file << "(" << failure.line << "): error: " << failure.msg << std::endl; - failed++; - } - catch (std::exception& ex) - { - std::cerr << tests[i]->file << "(" << tests[i]->line << "): error: " << ex.what() << std::endl; - failed++; - } - catch (...) - { - std::cerr << tests[i]->file << "(" << tests[i]->line << "): error: Test " << tests[i]->name << " crashed." << std::endl; - failed++; - } - } - - unsigned int succeded = tests.size() - failed; - std::cerr << succeded << " of " << tests.size() << " tests succeded." << std::endl; - - return failed == 0 ? 0 : -1; - } - - namespace impl - { - Failure::Failure(const char* f, unsigned int l, const std::string& m) - { - file = f; - line = l; - msg = m; - } - - Test::Test(const char* n, const char* f, unsigned int l) - { - name = n; - file = f; - line = l; - get_tests().push_back(this); - } - } -} diff --git a/libxmlmm-test/rtest.h b/libxmlmm-test/rtest.h deleted file mode 100644 index fbaa5c8..0000000 --- a/libxmlmm-test/rtest.h +++ /dev/null @@ -1,105 +0,0 @@ - -#ifndef _RTEST_H_ -#define _RTEST_H_ - -#include -#include -#include - -namespace rtest -{ - int run(); - - namespace impl - { - struct Failure - { - const char* file; - unsigned int line; - std::string msg; - - Failure(const char* file, unsigned int line, const std::string& msg); - }; - - struct Test - { - const char* name; - const char* file; - unsigned int line; - - Test(const char* name, const char* file, unsigned int line); - - virtual void run() = 0; - }; - } -} - -#define SUITE(NAME) namespace NAME ## _suite - -#define TEST(NAME) \ - struct Test_ ## NAME : public ::rtest::impl::Test \ - { \ - Test_ ## NAME() \ - : Test(#NAME, __FILE__, __LINE__) {} \ - \ - void run(); \ - \ - } test_ ## NAME; \ - \ - void Test_ ## NAME ::run() - -#define TEST_FIXTURE(FIXTURE, NAME) \ - struct Helper_ ## NAME : public FIXTURE \ - { \ - void run(); \ - }; \ - \ - struct Test_ ## NAME : public ::rtest::impl::Test \ - { \ - Test_ ## NAME() \ - : Test(#NAME, __FILE__, __LINE__) {} \ - \ - void run() \ - { \ - Helper_ ## NAME fixture; \ - fixture.run(); \ - } \ - } test_ ## NAME; \ - \ - void Helper_ ## NAME ::run() - -#define CHECK(COND) \ - if (!(COND)) \ - { \ - throw ::rtest::impl::Failure(__FILE__, __LINE__, #COND " failed."); \ - } - -#define CHECK_EQUAL(A, B) \ - if (! (A == B)) \ - { \ - std::stringstream buff; \ - buff << "Expected " << A << " but got " << B << "."; \ - throw ::rtest::impl::Failure(__FILE__, __LINE__, buff.str()); \ - } - -#define CHECK_CLOSE(A, B, EPS) \ - if (std::abs(A - B) >= EPS) \ - { \ - std::stringstream buff; \ - buff << "Expected " << A << " +- " << EPS << " but got " << B << "."; \ - throw ::rtest::impl::Failure(__FILE__, __LINE__, buff.str()); \ - } - -#define CHECK_THROW(EXPR, OBJ) \ - try \ - { \ - EXPR; \ - throw ::rtest::impl::Failure(__FILE__, __LINE__, "'" #EXPR "' did not throw '" #OBJ "'."); \ - } \ - catch (OBJ) \ - { \ - /* OK */ \ - } - - -#endif diff --git a/libxmlmm/Attribute.cpp b/libxmlmm/Attribute.cpp index 3acc109..d21427b 100644 --- a/libxmlmm/Attribute.cpp +++ b/libxmlmm/Attribute.cpp @@ -24,11 +24,11 @@ namespace xml { -//------------------------------------------------------------------------------ + Attribute::Attribute(xmlNode* const cobj) : Node(cobj) {} -//------------------------------------------------------------------------------ + std::string Attribute::get_value() const { const char *const ptr = reinterpret_cast(xmlGetProp(cobj->parent, cobj->name)); @@ -39,7 +39,7 @@ namespace xml return ""; } -//------------------------------------------------------------------------------ + void Attribute::set_value(const std::string& value) { xmlSetProp(cobj->parent, cobj->name, reinterpret_cast(value.c_str())); diff --git a/libxmlmm/CData.cpp b/libxmlmm/CData.cpp index ff13f08..cecc566 100644 --- a/libxmlmm/CData.cpp +++ b/libxmlmm/CData.cpp @@ -23,7 +23,7 @@ namespace xml { -//------------------------------------------------------------------------------ + CData::CData(xmlNode* const cobj) : Content(cobj) {} diff --git a/libxmlmm/Comment.cpp b/libxmlmm/Comment.cpp index 408f960..7bbf5a2 100644 --- a/libxmlmm/Comment.cpp +++ b/libxmlmm/Comment.cpp @@ -23,7 +23,7 @@ namespace xml { -//------------------------------------------------------------------------------ + Comment::Comment(xmlNode* const cobj) : Content(cobj) {} diff --git a/libxmlmm/Content.cpp b/libxmlmm/Content.cpp index 6e82e9e..39f1858 100644 --- a/libxmlmm/Content.cpp +++ b/libxmlmm/Content.cpp @@ -24,11 +24,11 @@ namespace xml { -//------------------------------------------------------------------------------ + Content::Content(xmlNode* cobj) : Node(cobj) {} -//------------------------------------------------------------------------------ + std::string Content::get_value() const { if (cobj->content != NULL) @@ -38,19 +38,19 @@ namespace xml return std::string(); } -//------------------------------------------------------------------------------ + std::string Content::get_content() const { return this->get_value(); } -//------------------------------------------------------------------------------ + void Content::set_content(const std::string& value) { xmlNodeSetContent(cobj, reinterpret_cast(value.c_str())); } -//------------------------------------------------------------------------------ + bool Content::is_blank() const { return xmlIsBlankNode(const_cast(cobj)); diff --git a/libxmlmm/Document.cpp b/libxmlmm/Document.cpp index 7780a2b..d30e991 100644 --- a/libxmlmm/Document.cpp +++ b/libxmlmm/Document.cpp @@ -29,14 +29,14 @@ namespace xml { -//------------------------------------------------------------------------------ + Document::Document() : cobj(xmlNewDoc(BAD_CAST "1.0")) { cobj->_private = this; } -//------------------------------------------------------------------------------ + Document::Document(const std::string &xml) : cobj(xmlNewDoc(BAD_CAST "1.0")) { @@ -44,19 +44,19 @@ namespace xml this->read_from_string(xml); } -//------------------------------------------------------------------------------ + Document::~Document() { xmlFreeDoc(cobj); } -//------------------------------------------------------------------------------ + bool Document::has_root_element() const { return xmlDocGetRootElement(cobj) != NULL; } -//------------------------------------------------------------------------------ + Element* Document::get_root_element() { xmlNode* root = xmlDocGetRootElement(cobj); @@ -67,13 +67,13 @@ namespace xml return reinterpret_cast(root->_private); } -//------------------------------------------------------------------------------ + const Element* Document::get_root_element() const { return const_cast(this)->get_root_element(); } -//------------------------------------------------------------------------------ + Element* Document::create_root_element(const std::string& name) { if (has_root_element()) @@ -92,7 +92,7 @@ namespace xml return reinterpret_cast(root->_private); } -//------------------------------------------------------------------------------ + std::string Document::write_to_string() const { xmlChar* buffer = 0; @@ -110,7 +110,7 @@ namespace xml return xml; } -//------------------------------------------------------------------------------ + std::string Document::write_to_string(const std::string& encoding) const { xmlChar* buffer = 0; @@ -128,19 +128,19 @@ namespace xml return xml; } -//------------------------------------------------------------------------------ + void Document::write_to_stream(std::ostream& os) const { os << write_to_string(); } -//------------------------------------------------------------------------------ + void Document::write_to_stream(std::ostream& os, const std::string& encoding) const { os << write_to_string(encoding); } -//------------------------------------------------------------------------------ + void Document::write_to_file(const std::string& file) const { int result = xmlSaveFormatFile(file.c_str(), cobj, 1); @@ -150,7 +150,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + void Document::write_to_file(const std::string& file, const std::string& encoding) const { int result = xmlSaveFormatFileEnc(file.c_str(), cobj, encoding.c_str(), 1); @@ -160,7 +160,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + void Document::read_from_string(const std::string& xml) { xmlDoc* tmp_cobj = xmlReadDoc(reinterpret_cast(xml.c_str()), NULL, NULL, 0); @@ -172,13 +172,13 @@ namespace xml cobj = tmp_cobj; } -//------------------------------------------------------------------------------ + void Document::read_from_stream(std::istream& is) { read_from_string(read_until_eof(is)); } -//------------------------------------------------------------------------------ + void Document::read_from_file(const std::string& file) { xmlDoc* tmp_cobj = xmlReadFile(file.c_str(), NULL, 0); @@ -190,7 +190,7 @@ namespace xml cobj = tmp_cobj; } -//------------------------------------------------------------------------------ + Node* Document::find_node(const std::string& xpath) { try @@ -203,7 +203,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + const Node* Document::find_node(const std::string& xpath) const { try @@ -216,7 +216,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::vector Document::find_nodes(const std::string& xpath) { try @@ -229,7 +229,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::vector Document::find_nodes(const std::string& xpath) const { try @@ -242,7 +242,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + Element* Document::find_element(const std::string& xpath) { try @@ -255,7 +255,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + const Element* Document::find_element(const std::string& xpath) const { try @@ -268,7 +268,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::vector Document::find_elements(const std::string& xpath) { try @@ -281,7 +281,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::vector Document::find_elements(const std::string& xpath) const { try @@ -294,7 +294,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::string Document::query_string(const std::string& xpath) const { try @@ -307,7 +307,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + double Document::query_number(const std::string& xpath) const { try @@ -320,7 +320,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + LIBXMLMM_EXPORT std::ostream& operator << (std::ostream& os, const Document& doc) { @@ -328,7 +328,7 @@ namespace xml return os; } -//------------------------------------------------------------------------------ + LIBXMLMM_EXPORT std::istream& operator >> (std::istream& is, Document& doc) { diff --git a/libxmlmm/Element.cpp b/libxmlmm/Element.cpp index ea41596..baec98f 100644 --- a/libxmlmm/Element.cpp +++ b/libxmlmm/Element.cpp @@ -29,11 +29,11 @@ namespace xml { -//------------------------------------------------------------------------------ + Element::Element(xmlNode* const cobj) : Node(cobj) {} -//------------------------------------------------------------------------------ + std::string Element::get_name() const { assert(cobj != NULL); @@ -44,19 +44,19 @@ namespace xml return std::string(); } -//------------------------------------------------------------------------------ + void Element::set_name(const std::string& value) { xmlNodeSetName(cobj, reinterpret_cast(value.c_str())); } -//------------------------------------------------------------------------------ + bool Element::has_attribute(const std::string& key) const { return xmlGetProp(cobj, reinterpret_cast(key.c_str())) != NULL; } -//------------------------------------------------------------------------------ + std::string Element::get_attribute(const std::string& key) const { const xmlChar* const value = xmlGetProp(cobj, reinterpret_cast(key.c_str())); @@ -67,19 +67,19 @@ namespace xml return reinterpret_cast(value); } -//------------------------------------------------------------------------------ + void Element::set_attribute(const std::string& key, const std::string& value) { xmlSetProp(cobj, reinterpret_cast(key.c_str()), reinterpret_cast(value.c_str())); } -//------------------------------------------------------------------------------ + void Element::remove_attribute(const std::string& key) { xmlUnsetProp(cobj, reinterpret_cast(key.c_str())); } -//------------------------------------------------------------------------------ + std::string Element::get_value() const { const Content* const content = get_text_node(); @@ -90,13 +90,13 @@ namespace xml return std::string(); } -//------------------------------------------------------------------------------ + std::string Element::get_text() const { return this->get_value(); } -//------------------------------------------------------------------------------ + Content* Element::get_text_node() const { for(xmlNode* child = cobj->children; child; child = child->next) @@ -113,7 +113,7 @@ namespace xml return NULL; } -//------------------------------------------------------------------------------ + void Element::set_text(const std::string& text) { Content* node = get_text_node(); @@ -127,14 +127,14 @@ namespace xml } } -//------------------------------------------------------------------------------ + void Element::add_text(const std::string& text) { xmlNode* node = xmlNewText(reinterpret_cast(text.c_str())); xmlAddChild(cobj, node); } -//------------------------------------------------------------------------------ + Element* Element::add_element(const std::string& name) { xmlNode* node = xmlNewNode(NULL, reinterpret_cast(name.c_str())); @@ -142,7 +142,7 @@ namespace xml return reinterpret_cast(node->_private); } -//------------------------------------------------------------------------------ + std::vector Element::get_children() { std::vector children; @@ -155,7 +155,7 @@ namespace xml return children; } -//------------------------------------------------------------------------------ + std::vector Element::get_children() const { std::vector children; @@ -168,25 +168,25 @@ namespace xml return children; } -//------------------------------------------------------------------------------ + Element* Element::find_element(const std::string& xpath) { return this->find(xpath); } -//------------------------------------------------------------------------------ + const Element* Element::find_element(const std::string& xpath) const { return this->find(xpath); } -//------------------------------------------------------------------------------ + std::vector Element::find_elements(const std::string& xpath) { return this->find_all(xpath); } -//------------------------------------------------------------------------------ + std::vector Element::find_elements(const std::string& xpath) const { return this->find_all(xpath); diff --git a/libxmlmm/LibXmlSentry.cpp b/libxmlmm/LibXmlSentry.cpp index 25d1b08..a8e8bf6 100644 --- a/libxmlmm/LibXmlSentry.cpp +++ b/libxmlmm/LibXmlSentry.cpp @@ -33,7 +33,7 @@ namespace xml { unsigned int LibXmlSentry::use_count = 0; -//------------------------------------------------------------------------------ + LibXmlSentry::LibXmlSentry() { if (use_count == 0) @@ -47,7 +47,7 @@ namespace xml use_count++; } -//------------------------------------------------------------------------------ + LibXmlSentry::~LibXmlSentry() { use_count--; diff --git a/libxmlmm/Node.cpp b/libxmlmm/Node.cpp index 339d688..cc8442c 100644 --- a/libxmlmm/Node.cpp +++ b/libxmlmm/Node.cpp @@ -30,20 +30,20 @@ namespace xml { -//------------------------------------------------------------------------------ + Node::Node(xmlNode* const co) : cobj(co) { assert(cobj != NULL); } -//------------------------------------------------------------------------------ + Node::~Node() { assert(cobj != NULL); } -//------------------------------------------------------------------------------ + std::string Node::get_path() const { xmlChar* path = xmlGetNodePath(cobj); @@ -57,7 +57,7 @@ namespace xml return value; } -//------------------------------------------------------------------------------ + Element* Node::get_parent() { if (cobj->parent != NULL) @@ -73,37 +73,37 @@ namespace xml } } -//------------------------------------------------------------------------------ + const Element* Node::get_parent() const { return const_cast(this)->get_parent(); } -//------------------------------------------------------------------------------ + Node* Node::find_node(const std::string& xpath) { return this->find(xpath); } -//------------------------------------------------------------------------------ + const Node* Node::find_node(const std::string& xpath) const { return this->find(xpath); } -//------------------------------------------------------------------------------ + std::vector Node::find_nodes(const std::string& xpath) { return this->find_all(xpath); } -//------------------------------------------------------------------------------ + std::vector Node::find_nodes(const std::string& xpath) const { return this->find_all(xpath); } -//------------------------------------------------------------------------------ + std::string Node::query_string(const std::string& xpath) const { FindNodeset search(cobj, xpath); @@ -140,7 +140,7 @@ namespace xml return value; } -//------------------------------------------------------------------------------ + double Node::query_number(const std::string& xpath) const { FindNodeset search(cobj, xpath); @@ -169,7 +169,7 @@ namespace xml } -//------------------------------------------------------------------------------ + Node::FindNodeset::FindNodeset(xmlNode *const cobj, const std::string &xpath, const xmlXPathObjectType type) { ctxt = xmlXPathNewContext(cobj->doc); @@ -190,7 +190,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + Node::FindNodeset::~FindNodeset() { xmlXPathFreeObject(result); diff --git a/libxmlmm/ProcessingInstruction.cpp b/libxmlmm/ProcessingInstruction.cpp index 820f991..855f7ec 100644 --- a/libxmlmm/ProcessingInstruction.cpp +++ b/libxmlmm/ProcessingInstruction.cpp @@ -23,7 +23,7 @@ namespace xml { -//------------------------------------------------------------------------------ + ProcessingInstruction::ProcessingInstruction(xmlNode* const cobj) : Content(cobj) {} diff --git a/libxmlmm/Text.cpp b/libxmlmm/Text.cpp index b3a83e5..54bf8fe 100644 --- a/libxmlmm/Text.cpp +++ b/libxmlmm/Text.cpp @@ -23,7 +23,7 @@ namespace xml { -//------------------------------------------------------------------------------ + Text::Text(xmlNode* const cobj) : Content(cobj) {} diff --git a/libxmlmm/utils.cpp b/libxmlmm/utils.cpp index f12135e..24c9db4 100644 --- a/libxmlmm/utils.cpp +++ b/libxmlmm/utils.cpp @@ -36,7 +36,7 @@ namespace xml { -//------------------------------------------------------------------------------ + std::string get_last_error() { const xmlError* const error = xmlGetLastError(); @@ -50,7 +50,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + void wrap_node(xmlNode* const cobj) { switch (cobj->type) @@ -97,7 +97,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + void free_wrapper(xmlNode* const cobj) { switch (cobj->type) @@ -126,7 +126,7 @@ namespace xml } } -//------------------------------------------------------------------------------ + std::string read_until_eof(std::istream& is) { std::string result;