Start building some unit tests using Catch test library
- Current version of Catch is included in the repo at test/catch.hpp
This commit is contained in:
12
test/catch.cpp
Normal file
12
test/catch.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
// After this are some globals that are referenced from common code but not defined, and not used in the test cases
|
||||
#include "graphtool.hpp"
|
||||
sf::Texture fields_gworld, anim_gworld, boom_gworld, dlogpics_gworld, items_gworld, missiles_gworld, monst_gworld[NUM_MONST_SHEETS];
|
||||
sf::Texture pc_gworld, roads_gworld, small_ter_gworld, status_gworld, talkfaces_gworld, terrain_gworld[NUM_TER_SHEETS];
|
||||
sf::Texture tiny_obj_gworld, vehicle_gworld;
|
||||
sf::RenderWindow mainPtr;
|
||||
fs::path scenario_temp_dir_name = "test_scenario";
|
||||
cCustomGraphics spec_scen_g;
|
9416
test/catch.hpp
Normal file
9416
test/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
1
test/files/scenario/bad_root.xml
Normal file
1
test/files/scenario/bad_root.xml
Normal file
@@ -0,0 +1 @@
|
||||
<foo></foo>
|
1
test/files/scenario/bad_root_attr.xml
Normal file
1
test/files/scenario/bad_root_attr.xml
Normal file
@@ -0,0 +1 @@
|
||||
<scenario vers="2.0.0"></scenario>
|
1
test/files/scenario/missing_toplevel.xml
Normal file
1
test/files/scenario/missing_toplevel.xml
Normal file
@@ -0,0 +1 @@
|
||||
<scenario boes="2.0.0"></scenario>
|
1
test/files/scenario/no_version.xml
Normal file
1
test/files/scenario/no_version.xml
Normal file
@@ -0,0 +1 @@
|
||||
<scenario></scenario>
|
41
test/scen_read.cpp
Normal file
41
test/scen_read.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "ticpp.h"
|
||||
#include "dialog.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "scenario.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ticpp;
|
||||
|
||||
extern Document xmlDocFromStream(istream& stream, string name);
|
||||
extern void readScenarioFromXml(Document&& data, cScenario& scenario);
|
||||
|
||||
TEST_CASE("Loading a new-format scenario record") {
|
||||
ifstream fin;
|
||||
cScenario scen;
|
||||
Document doc;
|
||||
fin.exceptions(ios::badbit);
|
||||
|
||||
SECTION("When the version attribute is missing") {
|
||||
fin.open("files/scenario/bad_root.xml");
|
||||
doc = xmlDocFromStream(fin, "bad_root.xml");
|
||||
REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xBadNode);
|
||||
}
|
||||
SECTION("When the version attribute is missing") {
|
||||
fin.open("files/scenario/no_version.xml");
|
||||
doc = xmlDocFromStream(fin, "no_version.xml");
|
||||
REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xMissingAttr);
|
||||
}
|
||||
SECTION("When the root tag has a bad attribute") {
|
||||
fin.open("files/scenario/bad_root_attr.xml");
|
||||
doc = xmlDocFromStream(fin, "bad_root_attr.xml");
|
||||
REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xBadAttr);
|
||||
}
|
||||
SECTION("When an essential toplevel element is missing") {
|
||||
fin.open("files/scenario/missing_toplevel.xml");
|
||||
doc = xmlDocFromStream(fin, "missing_toplevel.xml");
|
||||
REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xMissingElem);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user