Adding tests for gettitle and saveinpfile

This commit is contained in:
Michael Tryby
2019-02-28 08:11:59 -05:00
parent ab536d1927
commit c7d533c6e4
4 changed files with 69 additions and 17 deletions

View File

@@ -247,9 +247,9 @@ int DLLEXPORT EN_gettitle(EN_Project p, char *line1, char *line2, char *line3)
*/
{
if (!p->Openflag) return 102;
strcpy(line1, p->Title[0]);
strcpy(line2, p->Title[1]);
strcpy(line3, p->Title[2]);
strncpy(line1, p->Title[0], TITLELEN);
strncpy(line2, p->Title[1], TITLELEN);
strncpy(line3, p->Title[2], TITLELEN);
return 0;
}
@@ -265,7 +265,7 @@ int DLLEXPORT EN_settitle(EN_Project p, char *line1, char *line2, char *line3)
strncpy(p->Title[0], line1, TITLELEN);
strncpy(p->Title[1], line2, TITLELEN);
strncpy(p->Title[2], line3, TITLELEN);
return 123;
return 0;
}
int DLLEXPORT EN_getcount(EN_Project p, int object, int *count)

View File

@@ -272,7 +272,7 @@ int newline(Project *pr, int sect, char *line)
{
n = (int)strlen(line);
if (line[n - 1] == 10)
line[n - 1] = ' ';
line[n - 1] = '\0';
strncpy(pr->Title[parser->Ntitle], line, TITLELEN);
parser->Ntitle++;
}

View File

@@ -27,7 +27,7 @@ if(MSVC)
set(Boost_USE_STATIC_LIBS ON)
endif(MSVC)
set(Boost_THREAD_FOUND OFF)
find_package(Boost COMPONENTS thread)
find_package(Boost COMPONENTS thread filesystem)
include_directories (${Boost_INCLUDE_DIRS})

View File

@@ -19,6 +19,8 @@
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <string>
#include "epanet2_2.h"
@@ -29,11 +31,20 @@
#define DATA_PATH_OUT "./test.out"
using namespace std;
using namespace boost;
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
{
if (ref.compare(test) == 0)
return true;
else
return false;
}
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE (test_alloc_free)
BOOST_AUTO_TEST_CASE (test_create_delete)
{
int error = 0;
EN_Project ph = NULL;
@@ -69,6 +80,8 @@ BOOST_AUTO_TEST_CASE (test_open_close)
BOOST_AUTO_TEST_CASE(test_save_reopen)
{
int error;
string path_inp(DATA_PATH_INP);
string inp_save("test_reopen.inp");
string path_rpt(DATA_PATH_RPT);
@@ -78,23 +91,27 @@ BOOST_AUTO_TEST_CASE(test_save_reopen)
EN_Project ph_reopen;
EN_createproject(&ph_save);
error = EN_open(ph_save, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
BOOST_REQUIRE(error == 0);
EN_open(ph_save, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
EN_saveinpfile(ph_save, inp_save.c_str());
EN_close(ph_save);
error = EN_saveinpfile(ph_save, inp_save.c_str());
BOOST_REQUIRE(error == 0);
error = EN_close(ph_save);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph_save);
BOOST_TEST_CHECKPOINT("Saved input file");
EN_createproject(&ph_reopen);
error = EN_open(ph_reopen, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
BOOST_REQUIRE(error == 0);
EN_open(ph_reopen, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
EN_close(ph_reopen);
error = EN_close(ph_reopen);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph_reopen);
}
BOOST_AUTO_TEST_CASE(test_epanet)
BOOST_AUTO_TEST_CASE(test_runproject)
{
string path_inp(DATA_PATH_INP);
string path_rpt(DATA_PATH_RPT);
@@ -136,8 +153,43 @@ struct Fixture{
EN_Project ph;
};
BOOST_AUTO_TEST_SUITE(test_epanet_fixture)
BOOST_FIXTURE_TEST_CASE(test_proj_save, Fixture)
{
string inp_save("test_projsave.inp");
error = EN_saveinpfile(ph, inp_save.c_str());
BOOST_REQUIRE(error == 0);
BOOST_CHECK(filesystem::exists(inp_save) == true);
}
BOOST_FIXTURE_TEST_CASE(test_proj_title, Fixture)
{
char c_test[3][80], c_ref[3][80];
strncpy(c_ref[0], " EPANET Example Network 1", 26);
strncpy(c_ref[1], "A simple example of modeling chlorine decay. Both bulk and", 59);
strncpy(c_ref[2], "wall reactions are included. ", 30);
error = EN_gettitle(ph, c_test[0], c_test[1], c_test[2]);
BOOST_REQUIRE(error == 0);
for (int i = 0; i < 3; i++) {
string test (c_test[i]);
string ref (c_ref[i]);
BOOST_CHECK(check_string(test, ref));
}
// Need a test for EN_settitle
}
BOOST_FIXTURE_TEST_CASE(test_epanet, Fixture)
{
error = EN_solveH(ph);