Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggiunto test #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 128 additions & 12 deletions tests/testCarTrailer.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "car_trailer.h"
#include "catch2/catch2.hpp"



#include <fstream>
#include <streambuf>
#include <sstream>
#include <string>
#include <iostream>

TEST_CASE("init should succeed with non zero value", "[oselin_init]") {

Parameters p;
p.svgwidth =0;
p.svgwidth = 0;
p.svgheight = 0;

REQUIRE(oselin_init(p) == NULL);
Expand All @@ -22,6 +24,7 @@ TEST_CASE("init should succeed with non zero value", "[oselin_init]") {


TEST_CASE("oselin init copy should not return null value", "[oselin_init_acopyof]") {

REQUIRE(oselin_init_acopyof(NULL) == NULL);

Parameters p;
Expand All @@ -39,7 +42,7 @@ TEST_CASE("oselin init copy should not return null value", "[oselin_init_acopyof


TEST_CASE("tosvg should return 1 if some errors occur", "[oselin_to_svg]") {

REQUIRE(oselin_to_svg(NULL)==1);

Parameters p;
Expand All @@ -58,7 +61,7 @@ TEST_CASE("tosvg should return 1 if some errors occur", "[oselin_to_svg]") {
}

TEST_CASE("trigonometry should return 1 if something bad happens", "[oselin_trigonometry]") {

Parameters p;
p.svgwidth = 800;
p.svgheight = 600;
Expand All @@ -71,10 +74,13 @@ TEST_CASE("trigonometry should return 1 if something bad happens", "[oselin_trig
OselinDevice *dev = oselin_init(p);

REQUIRE(oselin_trigonometry(NULL)==1);
REQUIRE(oselin_trigonometry(dev)==0);

delete dev;
}

TEST_CASE("parsing should return empty string if nothing is fed into it", "[oselin_parsing]") {

Parameters p;
p.svgwidth = 800;
p.svgheight = 600;
Expand All @@ -84,20 +90,130 @@ TEST_CASE("parsing should return empty string if nothing is fed into it", "[osel
p.ncars = 2;
p.nfloors = 2;

OselinDevice *dev = oselin_init(p);
oselin_parsing(dev,"");
REQUIRE(dev->svg =="");
//OselinDevice *dev = oselin_init(p);
OselinDevice * dev;
dev = oselin_parsing("");
REQUIRE(dev->svg == "");

delete dev;

}


TEST_CASE("", "[oselin_set]") {

//OselinDevice *oselin_set(OselinDevice *, int, float);
}


TEST_CASE("The function should return NULL fi something bad happens", "[oselin_init_acopyof]") {

REQUIRE(oselin_init_acopyof(NULL)==NULL);
}


TEST_CASE("Creating and saving a brand new device. Checking if parsing works." "[oselin_parsing]"){

Parameters p;
p.svgwidth = 800;
p.svgheight = 600;
p.length = 100;
p.height = 50;
p.radius = 16;
p.ncars = 2;
p.nfloors = 2;

OselinDevice *dev = oselin_init(p);

oselin_trigonometry(dev);
oselin_to_svg(dev, true, true);
std::string filename = "testparsing.svg";
std::ofstream MyFile(filename);
MyFile << (dev->svg + "\n</svg>");
MyFile.close();
//---------------------------------------------
std::ifstream file(filename);
std::stringstream buffer;
buffer << file.rdbuf();
std::string s = buffer.str();
OselinDevice *dev2 = oselin_parsing(s);
REQUIRE(dev->param.svgwidth == dev2->param.svgwidth );
REQUIRE(dev->param.svgheight == dev2->param.svgheight);
REQUIRE(dev->param.radius == dev2->param.radius );
REQUIRE(dev->param.length == dev2->param.length );
REQUIRE(dev->param.height == dev2->param.height );
REQUIRE(dev->param.ncars == dev2->param.ncars );
REQUIRE(dev->param.nfloors == dev2->param.nfloors );
REQUIRE(dev->param.margin == dev2->param.margin );



delete dev; delete dev2;
}

TEST_CASE("oselin_init_acopyof dovrebbe ritornare una copia del device", "[machine]") {

OselinDevice* dev = new OselinDevice;

Parameters p;
p.svgwidth = 800;
p.svgheight = 600;
p.length = 100;
p.height = 50;
p.radius = 18;
p.ncars = 2;
p.nfloors = 2;
(*dev) = (*oselin_init(p));
if (dev != NULL){
oselin_trigonometry(dev,false);
}

dev->offset = 30 + dev->downfloor.width + DOWNOFFSET;
REQUIRE (oselin_to_svg(dev) == oselin_to_svg(oselin_init_acopyof(dev)));

delete dev;



}

TEST_CASE("oselin_init_acopyof dovrebbe ritornare una copia del device in caso di dev = NULL", "[machine]") {

OselinDevice* dev = NULL;

REQUIRE (NULL == oselin_init_acopyof(dev));



}
TEST_CASE("oselin_init_acopyof dovrebbe ritornare una copia del device", "[machine]") {

OselinDevice* dev = new OselinDevice;

Parameters p;
p.svgwidth = 800;
p.svgheight = 600;
p.length = 100;
p.height = 50;
p.radius = 18;
p.ncars = 2;
p.nfloors = 2;
(*dev) = (*oselin_init(p));
if (dev != NULL){
oselin_trigonometry(dev,false);
}

dev->offset = 30 + dev->downfloor.width + DOWNOFFSET;
REQUIRE (oselin_to_svg(dev) == oselin_to_svg(oselin_init_acopyof(dev)));

delete dev;

}

TEST_CASE("oselin_init_acopyof dovrebbe ritornare una copia del device in caso di dev = NULL", "[machine]") {

OselinDevice* dev = NULL;

REQUIRE (NULL == oselin_init_acopyof(dev));

}