tsp_cpp/snippets/gTestXMLParser.cpp

53 lines
No EOL
1.2 KiB
C++

//
// Created by trotfunky on 07/05/19.
//
#include <gtest/gtest.h>
#include "Circle.h"
#include "xmlParser.h"
TEST(readXML,initEmptyCircle)
{
xmlParser::Circle cercle = xmlParser::Circle();
ASSERT_EQ(cercle.x,0);
ASSERT_EQ(cercle.y,1);
ASSERT_EQ(cercle.r,2);
ASSERT_EQ(cercle.label,"Test circle");
}
TEST(readXML,initEmptyCirclePugiXML)
{
xmlParser::Circle cercle = xmlParser::Circle();
pugi::xml_node node;
ASSERT_EQ(cercle.x,0);
ASSERT_EQ(cercle.y,1);
ASSERT_EQ(cercle.r,2);
ASSERT_EQ(cercle.label,"Test circle");
}
TEST(readXML,parseXMLCircle)
{
std::string xml = "<?xml version = \"1.0\"?>\n"
"<Circle label=\"testCircle\" x=\"0\" y=\"1\" r=\"2\" color=\"Black\"/>";
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_string(xml.c_str());
EXPECT_NE(0,result);
pugi::xml_node node = doc.child("Circle");
xmlParser::Circle cercle = xmlParser::Circle(node);
ASSERT_EQ(cercle.x,0);
ASSERT_EQ(cercle.y,1);
ASSERT_EQ(cercle.r,2);
ASSERT_EQ(cercle.label,"testCircle");
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}