trotFunky
71ce85cec4
New classes : - DrawingElement (Base class for every other element) - Group : Groups DrawingElements together Modified Circle to work with DrawingElement Corrected a *maybe* failed vector copy in Polynomial.tpp
135 lines
No EOL
4.1 KiB
C++
135 lines
No EOL
4.1 KiB
C++
//
|
|
// Created by trotfunky on 07/05/19.
|
|
//
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#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 = "<?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");
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
::testing::InitGoogleTest(&argc,argv);
|
|
return RUN_ALL_TESTS();
|
|
} |