// // Created by trotfunky on 07/05/19. // #include #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) { pugi::xml_node node; 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,"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"); } TEST(drawFace,drawFace) { std::string xml = "\n" "\n" "\n" " \n" "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\t\n" "\t \n" "\t \n" "\t\n" "\t\n" "\t \n" "\t \n" "\t\n" " \n" ""; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string(xml.c_str()); ASSERT_NE(result,0); xmlParser::Group drawing = xmlParser::Group(doc.child("Drawing")); drawing.setX(1280/2.0); drawing.setY(-1024/2.0); std::cout << drawing << std::endl; sf::RenderWindow renderWindow(sf::VideoMode(1280,1024),"DA FACE"); sf::RectangleShape rectangleGhost = sf::RectangleShape(sf::Vector2f(660,1024)); rectangleGhost.setPosition(310,202); renderWindow.draw(rectangleGhost); sf::CircleShape circleGhost = sf::CircleShape(330,100); circleGhost.setPosition(310,202-330); renderWindow.draw(circleGhost); drawing.draw(renderWindow); renderWindow.display(); while (renderWindow.isOpen()) { sf::Event event; while (renderWindow.pollEvent(event)) { if (event.type == sf::Event::Closed) renderWindow.close(); if (event.type == sf::Event::KeyPressed) { renderWindow.close(); } } } } int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc,argv); return RUN_ALL_TESTS(); }