Merge pull request #420 from michaeltryby/dev

Cleaning up test build
This commit is contained in:
Michael Tryby
2019-03-15 19:18:50 -04:00
committed by GitHub
9 changed files with 233 additions and 163 deletions

View File

@@ -21,20 +21,19 @@ if(UNIX)
endif(UNIX)
#Prep ourselves for compiling boost
if(MSVC)
IF(MSVC)
set(Boost_DEBUG OFF)
set(Boost_DETAILED_FAILURE_MSG OFF)
set(Boost_USE_STATIC_LIBS ON)
endif(MSVC)
ENDIF(MSVC)
set(Boost_THREAD_FOUND OFF)
find_package(Boost COMPONENTS system thread filesystem)
find_package(Boost COMPONENTS unit_test_framework system thread filesystem)
include_directories (${Boost_INCLUDE_DIRS})
#I like to keep test files in a separate source directory called test
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test_*.cpp)
#Run through each source
foreach(testSrc ${TEST_SRCS})
#Extract the filename without an extension (NAME_WE)
@@ -43,6 +42,7 @@ foreach(testSrc ${TEST_SRCS})
#Add compile target
add_executable(${testName} ${testSrc})
#link to Boost libraries AND your targets and dependencies
IF(MSVC)
target_link_libraries(${testName} ${Boost_LIBRARIES} epanet2 epanet-output)

View File

@@ -1,5 +1,7 @@
//#define BOOST_TEST_DYN_LINK
#include <string>
#include <math.h>
@@ -55,13 +57,13 @@ boost::test_tools::predicate_result check_string(std::string test, std::string r
}
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_NET1 "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
struct FixtureOpenClose{
FixtureOpenClose() {
path_inp = std::string(DATA_PATH_INP);
path_inp = std::string(DATA_PATH_NET1);
path_rpt = std::string(DATA_PATH_RPT);
path_out = std::string(DATA_PATH_OUT);
@@ -81,3 +83,52 @@ struct FixtureOpenClose{
int error;
EN_Project ph;
};
struct FixtureAfterStep{
FixtureAfterStep() {
flag = 0;
tstop = 10800;
path_inp = std::string(DATA_PATH_NET1);
path_rpt = std::string(DATA_PATH_RPT);
path_out = std::string(DATA_PATH_OUT);
EN_createproject(&ph);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
error = EN_solveH(ph);
BOOST_REQUIRE(error == 0);
error = EN_openQ(ph);
BOOST_REQUIRE(error == 0);
error = EN_initQ(ph, flag);
BOOST_REQUIRE(error == 0);
do {
error = EN_runQ(ph, &t);
BOOST_REQUIRE(error == 0);
error = EN_stepQ(ph, &tstep);
BOOST_REQUIRE(error == 0);
} while (tstep > 0 && t < tstop);
}
~FixtureAfterStep() {
error = EN_closeQ(ph);
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
EN_deleteproject(&ph);
}
std::string path_inp;
std::string path_rpt;
std::string path_out;
int error, flag;
long t, tstep, tstop;
EN_Project ph;
};

View File

@@ -7,53 +7,26 @@ nodes and links from a project. Deletion can be conditional on
node or link appearing in any simple or rule-based controls.
*/
//#define NO_BOOST
#ifndef NO_BOOST
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#endif
#define BOOST_TEST_MODULE "rules"
#include <iostream>
#include <string>
#include "epanet2_2.h"
#include "shared_test.hpp"
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
#ifdef NO_BOOST
#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ )
#endif
using namespace std;
char R1[] = "RULE 1 \n IF NODE 2 LEVEL < 100 \n THEN LINK 9 STATUS = OPEN";
char R2[] = "RULE 2\nIF SYSTEM TIME = 4\nTHEN LINK 9 STATUS = CLOSED\nAND LINK 31 STATUS = CLOSED";
char R3[] = "RULE 3\nIF NODE 23 PRESSURE ABOVE 140\nAND NODE 2 LEVEL > 120\n"
"THEN LINK 113 STATUS = CLOSED\nELSE LINK 22 STATUS = CLOSED";
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setlinktype)
#else
int main(int argc, char *argv[])
#endif
BOOST_AUTO_TEST_SUITE (test_addrule)
BOOST_FIXTURE_TEST_CASE(test_add_get_rule, FixtureOpenClose)
{
int error = 0;
int ruleCount, nP, nTA, nEA;
int link113, node23, link22, pump9_before, pump9_after;
double priority;
EN_Project ph = NULL;
EN_createproject(&ph);
std::string path_inp = std::string(DATA_PATH_INP);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Add the 3 rules to the project
error = EN_addrule(ph, R1);
@@ -65,45 +38,39 @@ int main(int argc, char *argv[])
// Check that rules were added
error = EN_getcount(ph, EN_RULECOUNT, &ruleCount);
BOOST_REQUIRE(ruleCount == 3);
BOOST_CHECK(ruleCount == 3);
// Check the number of clauses in rule 3
error = EN_getrule(ph, 3, &nP, &nTA, &nEA, &priority);
BOOST_REQUIRE(nP == 2);
BOOST_REQUIRE(nTA == 1);
BOOST_REQUIRE(nTA == 1);
BOOST_CHECK(nP == 2);
BOOST_CHECK(nTA == 1);
BOOST_CHECK(nTA == 1);
// Try to delete link 113 conditionally which will fail
// because it's in rule 3
EN_getlinkindex(ph, "113", &link113);
EN_getlinkindex(ph, (char *)"113", &link113);
error = EN_deletelink(ph, link113, EN_CONDITIONAL);
BOOST_REQUIRE(error == 261);
// Delete node 23 unconditionally which will result in the
// deletion of rule 3 as well as links 22 and 113
EN_getnodeindex(ph, "23", &node23);
EN_getlinkindex(ph, "22", &link22);
EN_getlinkindex(ph, "9", &pump9_before);
EN_getnodeindex(ph, (char *)"23", &node23);
EN_getlinkindex(ph, (char *)"22", &link22);
EN_getlinkindex(ph, (char *)"9", &pump9_before);
error = EN_deletenode(ph, node23, EN_UNCONDITIONAL);
BOOST_REQUIRE(error == 0);
// Check that there are now only 2 rules
error = EN_getcount(ph, EN_RULECOUNT, &ruleCount);
BOOST_REQUIRE(ruleCount == 2);
BOOST_CHECK(ruleCount == 2);
// Check that link 22 no longer exists
error = EN_getlinkindex(ph, "22", &link22);
BOOST_REQUIRE(error > 0);
error = EN_getlinkindex(ph, (char *)"22", &link22);
BOOST_CHECK(error > 0);
// Check that the index of pump9 has been reduced by 2
error = EN_getlinkindex(ph, "9", &pump9_after);
BOOST_REQUIRE(pump9_before - pump9_after == 2);
// Close and delete project
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
error = EN_getlinkindex(ph, (char *)"9", &pump9_after);
BOOST_CHECK(pump9_before - pump9_after == 2);
}
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE_END()
#endif

View File

@@ -7,40 +7,22 @@ This is a test for the demand categories names get\set APIs
A demand category name is set, the network is saved, reopened and the new demand category name is checked.
*/
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_MODULE "demands"
#include <string>
#include "epanet2_2.h"
#include "shared_test.hpp"
// NOTE: Project Home needs to be updated to run unit test
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
using namespace std;
BOOST_AUTO_TEST_SUITE (test_demands)
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
BOOST_AUTO_TEST_CASE(test_categories_save)
{
if (ref.compare(test) == 0)
return true;
else
return false;
}
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_demand_categories)
{
string path_inp(DATA_PATH_INP);
string inp_save("net1_dem_cat.inp");
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
std::string path_inp(DATA_PATH_NET1);
std::string inp_save("net1_dem_cat.inp");
std::string path_rpt(DATA_PATH_RPT);
std::string path_out(DATA_PATH_OUT);
char node_id[] = "12";
char demand_category[] = "Demand category name";
char demname[80];
int error = 0;
int Nindex, ndem;
@@ -65,6 +47,22 @@ BOOST_AUTO_TEST_CASE(test_demand_categories)
BOOST_REQUIRE(error == 0);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demands/test_categories_save"))
{
std::string inp_save("net1_dem_cat.inp");
std::string path_rpt(DATA_PATH_RPT);
std::string path_out(DATA_PATH_OUT);
char node_id[] = "12";
char demand_category[] = "Demand category name";
char demname[80];
int error = 0;
int Nindex, ndem;
EN_Project ph = NULL;
BOOST_TEST_CHECKPOINT("Reopening saved input file");
error = EN_createproject(&ph);

View File

@@ -7,7 +7,6 @@
// US EPA - ORD/NRMRL
//
//#define BOOST_TEST_DYN_LINK
//#ifdef _WIN32
//#define _CRTDBG_MAP_ALLOC
@@ -20,7 +19,7 @@
#define BOOST_TEST_MODULE hydrqual
#include "test_shared.hpp"
#include "shared_test.hpp"
using namespace std;

View File

@@ -56,10 +56,10 @@ int main(int argc, char *argv[])
// Set network data using the new helper functions
EN_setcurvevalue(ph, 1, 1, 1500, 250);
EN_setjuncdata(ph, 1, 700, 500, "");
EN_setjuncdata(ph, 2, 710, 500, "");
EN_setjuncdata(ph, 1, 700, 500, (char *)"");
EN_setjuncdata(ph, 2, 710, 500, (char *)"");
EN_setnodevalue(ph, 3, EN_ELEVATION, 800);
EN_settankdata(ph, 4, 850, 120, 100, 150, 50.5, 0, "");
EN_settankdata(ph, 4, 850, 120, 100, 150, 50.5, 0, (char *)"");
EN_setlinkvalue(ph, 1, EN_PUMP_HCURVE, 1);
EN_setpipedata(ph, 2, 10560, 12, 100, 0);
EN_setpipedata(ph, 3, 5280, 14, 100, 0);

View File

@@ -10,69 +10,125 @@
#define BOOST_TEST_MODULE "node"
#include "test_shared.hpp"
#include "shared_test.hpp"
using namespace std;
using namespace boost;
BOOST_AUTO_TEST_SUITE (node_props_after_open)
BOOST_AUTO_TEST_SUITE (test_node)
BOOST_FIXTURE_TEST_CASE(test_node_getvalue, FixtureOpenClose)
BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureOpenClose)
{
const auto junc_props = {
int index;
const auto props = {
EN_ELEVATION,
EN_BASEDEMAND,
EN_PATTERN,
EN_EMITTER,
EN_INITQUAL,
//demand
//head
//pressure
//quality
};
const int num_props = 5;
const size_t num_props = 5;
std::vector<double> test (num_props);
double *value = test.data();
error = EN_getnodeindex(ph, (char *)"11", &index);
std::vector<double> ref = {710.0, 150.0, 1.0, 0.0, 0.5};
for (EN_NodeProperty p : junc_props) {
error = EN_getnodevalue(ph, 2, p, value++);
// Ranged for loop iterates over property set
for (EN_NodeProperty p : props) {
error = EN_getnodevalue(ph, index, p, value++);
BOOST_REQUIRE(error == 0);
}
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
const auto tank_props = {
EN_ELEVATION,
EN_INITQUAL,
EN_TANKLEVEL,
EN_INITVOLUME,
EN_MIXMODEL,
EN_MIXZONEVOL,
//demand
//head
//pressure
//quality
EN_TANKDIAM,
EN_MINVOLUME,
EN_MAXVOLUME,
EN_VOLCURVE,
EN_MINLEVEL,
EN_MAXLEVEL,
EN_MIXFRACTION,
EN_TANK_KBULK,
EN_TANKVOLUME
};
BOOST_CHECK(check_cdd_double(test, ref, 3));
}
BOOST_FIXTURE_TEST_CASE(test_tank_props, FixtureOpenClose)
{
int index;
const auto props = {
EN_ELEVATION,
EN_TANKLEVEL,
EN_MINLEVEL,
EN_MAXLEVEL,
EN_TANKDIAM,
EN_MINVOLUME
};
const size_t num_props = 6;
std::vector<double> test (num_props);
double *value = test.data();
error = EN_getnodeindex(ph, (char *)"2", &index);
std::vector<double> ref = {850.0, 120.0, 100.0, 150.0, 50.5, 200296.167};
// Ranged for loop iterates over property set
for (EN_NodeProperty p : props) {
error = EN_getnodevalue(ph, index, p, value++);
BOOST_REQUIRE(error == 0);
}
BOOST_CHECK(check_cdd_double(test, ref, 3));
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(node_props_after_step)
BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureAfterStep)
{
int index;
const auto props = {
EN_DEMAND,
EN_HEAD,
EN_PRESSURE,
EN_QUALITY
};
const size_t num_props = 4;
std::vector<double> test (num_props);
double *value = test.data();
error = EN_getnodeindex(ph, (char *)"11", &index);
std::vector<double> ref = {179.999, 991.574, 122.006, 0.857};
// Ranged for loop iterates over property set
for (EN_NodeProperty p : props) {
error = EN_getnodevalue(ph, index, p, value++);
BOOST_REQUIRE(error == 0);
}
BOOST_CHECK(check_cdd_double(test, ref, 3));
}
BOOST_FIXTURE_TEST_CASE(test_tank_props, FixtureAfterStep)
{
int index;
const auto props = {
EN_DEMAND,
EN_HEAD,
EN_PRESSURE,
EN_QUALITY
};
const size_t num_props = 4;
std::vector<double> test (num_props);
double *value = test.data();
error = EN_getnodeindex(ph, (char *)"2", &index);
std::vector<double> ref = {505.383, 978.138, 55.522, 0.911};
// Ranged for loop iterates over property set
for (EN_NodeProperty p : props) {
error = EN_getnodevalue(ph, index, p, value++);
BOOST_REQUIRE(error == 0);
}
BOOST_CHECK(check_cdd_double(test, ref, 3));
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -7,29 +7,28 @@
// US EPA - ORD/NRMRL
//
//#define BOOST_TEST_DYN_LINK
//#ifdef _WIN32
//#define _CRTDBG_MAP_ALLOC
//#include <stdlib.h>
//#include <crtdbg.h>
//#else
#include <stdlib.h>
//#include <stdlib.h>
//#endif
#define BOOST_TEST_MODULE "project"
#include "test_shared.hpp"
#include "shared_test.hpp"
using namespace std;
using namespace boost;
BOOST_AUTO_TEST_SUITE (test_proj)
BOOST_AUTO_TEST_SUITE (test_project)
BOOST_AUTO_TEST_CASE (test_proj_create_delete)
BOOST_AUTO_TEST_CASE (test_create_delete)
{
int error = 0;
EN_Project ph = NULL;
@@ -45,9 +44,9 @@ BOOST_AUTO_TEST_CASE (test_proj_create_delete)
BOOST_CHECK(ph == NULL);
}
BOOST_AUTO_TEST_CASE (test_proj_open_close)
BOOST_AUTO_TEST_CASE (test_open_close)
{
string path_inp(DATA_PATH_INP);
string path_inp(DATA_PATH_NET1);
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
@@ -63,11 +62,11 @@ BOOST_AUTO_TEST_CASE (test_proj_open_close)
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_CASE(test_proj_savefile)
BOOST_AUTO_TEST_CASE(test_save)
{
int error;
string path_inp(DATA_PATH_INP);
string path_inp(DATA_PATH_NET1);
string inp_save("test_reopen.inp");
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
@@ -89,7 +88,7 @@ BOOST_AUTO_TEST_CASE(test_proj_savefile)
EN_deleteproject(&ph_save);
}
BOOST_AUTO_TEST_CASE(test_proj_reopen, * unit_test::depends_on("test_proj/test_proj_savefile"))
BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_save"))
{
int error;
@@ -109,9 +108,9 @@ BOOST_AUTO_TEST_CASE(test_proj_reopen, * unit_test::depends_on("test_proj/test_p
EN_deleteproject(&ph_reopen);
}
BOOST_AUTO_TEST_CASE(test_proj_run)
BOOST_AUTO_TEST_CASE(test_run)
{
string path_inp(DATA_PATH_INP);
string path_inp(DATA_PATH_NET1);
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
@@ -131,7 +130,7 @@ BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(test_proj_fixture)
BOOST_FIXTURE_TEST_CASE(test_proj_title, FixtureOpenClose)
BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
{
// How is the API user supposed to know array size?
char c_test[3][80], c_ref[3][80];
@@ -152,7 +151,7 @@ BOOST_FIXTURE_TEST_CASE(test_proj_title, FixtureOpenClose)
// Need a test for EN_settitle
}
BOOST_FIXTURE_TEST_CASE(test_proj_getcount, FixtureOpenClose)
BOOST_FIXTURE_TEST_CASE(test_getcount, FixtureOpenClose)
{
int i, array[7];

View File

@@ -20,7 +20,7 @@
#define BOOST_TEST_MODULE hydqual
#include "test_shared.hpp"
#include "shared_test.hpp"
using namespace std;