198 lines
No EOL
6.9 KiB
C++
198 lines
No EOL
6.9 KiB
C++
//
|
|
// Created by trotfunky on 07/05/19.
|
|
//
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <iostream>
|
|
|
|
#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 = "<?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());
|
|
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 = "<?xml version = \"1.0\"?>\n"
|
|
"<Group label=\"testGroup\" x=\"0\" y=\"1\">\n"
|
|
" <Circle label=\"testCircle1\" x=\"2\" y=\"3\" r=\"4\" color=\"Black\"/>\n"
|
|
" <Circle label=\"testCircle2\" x=\"5\" y=\"6\" r=\"7\" color=\"Black\"/>\n"
|
|
"</Group>";
|
|
|
|
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<xmlParser::Circle*>(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<xmlParser::Circle*>(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 = "<?xml version = \"1.0\"?>\n"
|
|
"<Group label=\"testGroup1\" x=\"0\" y=\"1\">\n"
|
|
" <Circle label=\"testCircle\" x=\"2\" y=\"3\" r=\"4\" color=\"Black\"/>\n"
|
|
" <Group label=\"testGroup2\" x=\"5\" y=\"6\"/>\n"
|
|
"</Group>";
|
|
|
|
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<xmlParser::Group*>(group.getDrawingElement("testGroup2"));
|
|
EXPECT_EQ(testGroup2->getX(),5);
|
|
EXPECT_EQ(testGroup2->getY(),6);
|
|
EXPECT_EQ(testGroup2->label,"testGroup2");
|
|
}
|
|
|
|
TEST(drawFace,drawFace)
|
|
{
|
|
std::string xml = "<?xml version=\"1.0\"?>\n"
|
|
"<!-- Dans cette version de format, les coordonnees (x,y) sont exprimees dans un -->\n"
|
|
"<!-- repere dont le centre est au centre de l'ecran, les valeurs positives de x -->\n"
|
|
"<!-- etant vers la droite, les valeurs positives de y etant vers le haut. --> \n"
|
|
"<Drawing>\n"
|
|
" <!-- Le noeud suivant cree un cercle dont le centre est en (0,0), -->\n"
|
|
" <!-- de rayon 200, de couleur noir, qui a pour etiquette -->\n"
|
|
" <!-- \"contourVisage\" -->\n"
|
|
" <Circle label=\"contourVisage\" x=\"0\" y=\"0\" r=\"200\" color=\"Black\"/>\n"
|
|
" <Circle label=\"nez\" x=\"0\" y=\"0\" r=\"20\" color=\"Red\"/>\n"
|
|
" <!-- Le noeud suivant cree un groupe \"oreilles\" positionne en (0,210) -->\n"
|
|
" <Group label=\"oreilles\" x=\"0\" y=\"210\">\n"
|
|
"\t<Group label=\"oreille\" x=\"-210\" y=\"0\">\n"
|
|
"\t <Circle label=\"c1\" x=\"0\" y=\"0\" r=\"100\" color=\"Black\"/>\n"
|
|
"\t <Circle label=\"c2\" x=\"0\" y=\"0\" r=\"70\" color=\"Magenta\"/>\n"
|
|
"\t</Group>\n"
|
|
"\t<Group label=\"oreille2\" x=\"210\" y=\"0\">\n"
|
|
"\t <Circle label=\"c1\" x=\"0\" y=\"0\" r=\"100\" color=\"Black\"/>\n"
|
|
"\t <Circle label=\"c2\" x=\"0\" y=\"0\" r=\"70\" color=\"Magenta\"/>\n"
|
|
"\t</Group>\n"
|
|
" </Group>\n"
|
|
"</Drawing>";
|
|
|
|
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();
|
|
} |