278 lines
No EOL
9.1 KiB
C++
278 lines
No EOL
9.1 KiB
C++
//
|
|
// Created by trotfunky on 07/05/19.
|
|
//
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <iostream>
|
|
|
|
#include "imgui.h"
|
|
#include "imgui-SFML.h"
|
|
|
|
#include "Circle.h"
|
|
#include "xmlParser.h"
|
|
#include "SFML/Graphics.hpp"
|
|
#include "Group.h"
|
|
|
|
|
|
class ImGui_F : public ::testing::Test
|
|
{
|
|
protected:
|
|
|
|
sf::RenderWindow* window;
|
|
|
|
sf::Color bgColor;
|
|
|
|
sf::Clock deltaClock;
|
|
|
|
float color[3] = { 0.f, 0.f, 0.f };
|
|
|
|
// let's use char array as buffer, see next part
|
|
// for instructions on using std::string with ImGui
|
|
char windowTitle[255];
|
|
|
|
void SetUp() override
|
|
{
|
|
window = new sf::RenderWindow(sf::VideoMode(640, 480), "");
|
|
window->setVerticalSyncEnabled(true);
|
|
ImGui::SFML::Init(*window);
|
|
|
|
strcpy(windowTitle,"ImGui + SFML = <3");
|
|
|
|
window->setTitle(windowTitle);
|
|
window->resetGLStates(); // call it if you only draw ImGui. Otherwise not needed.
|
|
}
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(ImGui_F,ImGui_Example)
|
|
{
|
|
while (window->isOpen()) {
|
|
sf::Event event;
|
|
while (window->pollEvent(event)) {
|
|
ImGui::SFML::ProcessEvent(event);
|
|
|
|
if (event.type == sf::Event::Closed) {
|
|
window->close();
|
|
}
|
|
}
|
|
|
|
ImGui::SFML::Update(*window, deltaClock.restart());
|
|
|
|
ImGui::Begin("Sample window"); // begin window
|
|
|
|
// Background color edit
|
|
if (ImGui::ColorEdit3("Background color", color)) {
|
|
// this code gets called if color value changes, so
|
|
// the background color is upgraded automatically!
|
|
bgColor.r = static_cast<sf::Uint8>(color[0] * 255.f);
|
|
bgColor.g = static_cast<sf::Uint8>(color[1] * 255.f);
|
|
bgColor.b = static_cast<sf::Uint8>(color[2] * 255.f);
|
|
}
|
|
|
|
// Window title text edit
|
|
ImGui::InputText("Window title", windowTitle, 255);
|
|
|
|
if (ImGui::Button("Update window title")) {
|
|
// this code gets if user clicks on the button
|
|
// yes, you could have written if(ImGui::InputText(...))
|
|
// but I do this to show how buttons work :)
|
|
window->setTitle(windowTitle);
|
|
}
|
|
ImGui::End(); // end window
|
|
|
|
window->clear(bgColor); // fill background with color
|
|
ImGui::SFML::Render(*window);
|
|
window->display();
|
|
}
|
|
|
|
ImGui::SFML::Shutdown();
|
|
}
|
|
|
|
TEST_F(ImGui_F,ImGui_Perso)
|
|
{
|
|
// TODO : Copy examples to create new shapes 'n stuff
|
|
}
|
|
int main(int argc, char** argv)
|
|
{
|
|
::testing::InitGoogleTest(&argc,argv);
|
|
return RUN_ALL_TESTS();
|
|
} |