// // Created by trotfunky on 07/05/19. // #include #include "Circle.h" #include "xmlParser.h" #include "SFML/Graphics.hpp" #include "Group.h" TEST(xmlParserInits,initEmptyCircle) { xmlParser::Circle cercle = xmlParser::Circle(); EXPECT_EQ(cercle.getX(),0); EXPECT_EQ(cercle.getY(),1); EXPECT_EQ(cercle.getR(),2); EXPECT_EQ(cercle.label,"Test Circle"); EXPECT_EQ(cercle.getColor(),sf::Color::Yellow); } TEST(xmlParserInits,initEmptyCirclePugiXML) { xmlParser::Circle cercle = xmlParser::Circle(); pugi::xml_node node; EXPECT_EQ(cercle.getX(),0); EXPECT_EQ(cercle.getY(),1); EXPECT_EQ(cercle.getR(),2); EXPECT_EQ(cercle.label,"Test Circle"); EXPECT_EQ(cercle.getColor(),sf::Color::Yellow); } TEST(xmlParserInits,initEmptyGroup) { xmlParser::Group group = xmlParser::Group(); EXPECT_EQ(group.getX(),0); EXPECT_EQ(group.getY(),1); EXPECT_EQ(group.label,"Test Group"); } TEST(xmlParserInits,initEmptyGroupPugiXML) { pugi::xml_node node; xmlParser::Group group = xmlParser::Group(node); EXPECT_EQ(group.getX(),0); EXPECT_EQ(group.getY(),1); EXPECT_EQ(group.label,"Test Group"); } TEST(parseXML,parseXMLCircle) { std::string xml = "\n" ""; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string(xml.c_str()); ASSERT_NE(0,result); pugi::xml_node node = doc.child("Circle"); xmlParser::Circle cercle = xmlParser::Circle(node); EXPECT_EQ(cercle.getX(),0); EXPECT_EQ(cercle.getY(),1); EXPECT_EQ(cercle.getR(),2); EXPECT_EQ(cercle.label,"testCircle"); EXPECT_EQ(cercle.getColor(),sf::Color::Black); } TEST(parseXML,parseXMLGroup) { std::string xml = "\n" "\n" " \n" " \n" ""; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string(xml.c_str()); ASSERT_NE(0,result); pugi::xml_node node = doc.child("Group"); xmlParser::Group group = xmlParser::Group(node); EXPECT_EQ(group.getX(),0); EXPECT_EQ(group.getY(),1); EXPECT_EQ(group.label,"testGroup"); ASSERT_TRUE(group.getDrawingElement("testCircle1")); xmlParser::Circle* testCircle1 = dynamic_cast(group.getDrawingElement("testCircle1")); EXPECT_EQ(testCircle1->getX(),2); EXPECT_EQ(testCircle1->getY(),3); EXPECT_EQ(testCircle1->getR(),4); EXPECT_EQ(testCircle1->getColor(),sf::Color::Black); ASSERT_TRUE(group.getDrawingElement("testCircle2")); xmlParser::Circle* testCircle2 = dynamic_cast(group.getDrawingElement("testCircle2")); EXPECT_EQ(testCircle2->getX(),5); EXPECT_EQ(testCircle2->getY(),6); EXPECT_EQ(testCircle2->getR(),7); EXPECT_EQ(testCircle2->getColor(),sf::Color::Black); } TEST(parseXML,parseXMLNestGroup) { std::string xml = "\n" "\n" " \n" " \n" ""; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string(xml.c_str()); ASSERT_NE(0,result); pugi::xml_node node = doc.child("Group"); xmlParser::Group group = xmlParser::Group(node); ASSERT_TRUE(group.getDrawingElement("testGroup2")); xmlParser::Group* testGroup2 = dynamic_cast(group.getDrawingElement("testGroup2")); EXPECT_EQ(testGroup2->getX(),5); EXPECT_EQ(testGroup2->getY(),6); EXPECT_EQ(testGroup2->label,"testGroup2"); } int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc,argv); return RUN_ALL_TESTS(); }