Adding comment test
This commit is contained in:
@@ -28,7 +28,7 @@ set(toolkit_test_srcs
|
||||
test_link.cpp
|
||||
# test_pump.cpp
|
||||
test_pattern.cpp
|
||||
# test_curve.cpp
|
||||
test_curve.cpp
|
||||
test_control.cpp
|
||||
test_net_builder.cpp)
|
||||
|
||||
@@ -61,4 +61,4 @@ add_test(NAME test_errormanager
|
||||
|
||||
add_test(NAME test_output
|
||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_output
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/outfile/data)
|
||||
|
||||
40
tests/test_curve.cpp
Normal file
40
tests/test_curve.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Module: test_curve.cpp
|
||||
Description: Tests EPANET toolkit api functions
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
Last Updated: 03/21/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "test_toolkit.hpp"
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (curve)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Set curve comments
|
||||
error = EN_getcurveindex(ph, (char *)"1", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_CURVE, index, (char *)"Curve 1");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Check curve comments
|
||||
error = EN_getcurveindex(ph, (char *)"1", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_CURVE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Curve 1"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Module: test_analysis.cpp
|
||||
Module: test_demand.cpp
|
||||
Description: Tests EPANET toolkit api functions
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
|
||||
@@ -133,12 +133,41 @@ BOOST_AUTO_TEST_CASE(test_link_setid_reopen, * boost::unit_test::depends_on("tes
|
||||
// Check that 3rd link has its new name
|
||||
error = EN_getlinkindex(ph, (char *)"Link3", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_REQUIRE(index == 3);
|
||||
BOOST_CHECK(index == 3);
|
||||
|
||||
error = EN_close(ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_link_comments, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Set link comments
|
||||
error = EN_getlinkindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_LINK, index, (char *)"P11");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_getlinkindex(ph, (char *)"9", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_LINK, index, (char *)"Pump9");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Check link comments
|
||||
error = EN_getlinkindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_LINK, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"P11"));
|
||||
|
||||
error = EN_getlinkindex(ph, (char *)"9", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_LINK, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Pump9"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -192,3 +192,109 @@ BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_sa
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(node_comments)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_node_comments, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Add comments to selected objects
|
||||
error = EN_getnodeindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"J11");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_getnodeindex(ph, (char *)"23", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"Junc23");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Check comments
|
||||
error = EN_getnodeindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"J11"));
|
||||
|
||||
error = EN_getnodeindex(ph, (char *)"23", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Junc23"));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_replace_comment, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Replace short comment with longer one and vice versa
|
||||
error = EN_getnodeindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"Junction11");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Junction11"));
|
||||
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"J11");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"J11"));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_save_comment, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
|
||||
// Add comments to selected objects
|
||||
error = EN_getnodeindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"J11");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_getnodeindex(ph, (char *)"23", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_NODE, index, (char *)"Junc23");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_saveinpfile(ph, DATA_PATH_TMP);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_reopen_comment, * boost::unit_test::depends_on("node_comments/test_save_comment"))
|
||||
{
|
||||
int error, index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Create & load a project
|
||||
EN_Project ph = NULL;
|
||||
EN_createproject(&ph);
|
||||
|
||||
error = EN_open(ph, DATA_PATH_TMP, DATA_PATH_RPT, "");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Check that comments were saved & read correctly
|
||||
// Check comments
|
||||
error = EN_getnodeindex(ph, (char *)"11", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"J11"));
|
||||
|
||||
error = EN_getnodeindex(ph, (char *)"23", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_NODE, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Junc23"));
|
||||
|
||||
// Close project
|
||||
EN_close(ph);
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -131,4 +131,23 @@ BOOST_AUTO_TEST_CASE(add_set_pattern)
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_pattern_comments, FixtureOpenClose)
|
||||
{
|
||||
int index;
|
||||
char comment[EN_MAXMSG + 1];
|
||||
|
||||
// Set pattern comment
|
||||
error = EN_getpatternindex(ph, (char *)"1", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcomment(ph, EN_TIMEPAT, index, (char *)"Time Pattern 1");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Check pattern comment
|
||||
error = EN_getpatternindex(ph, (char *)"1", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getcomment(ph, EN_TIMEPAT, index, comment);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(comment, (char *)"Time Pattern 1"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE toolkit
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include "test_toolkit.hpp"
|
||||
|
||||
@@ -15,21 +15,11 @@
|
||||
#define TEST_TOOLKIT_HPP
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "epanet2_2.h"
|
||||
|
||||
|
||||
#define DATA_PATH_NET1 "./net1.inp"
|
||||
#define DATA_PATH_TMP "./tmp.inp"
|
||||
#define DATA_PATH_RPT "./test.rpt"
|
||||
#define DATA_PATH_OUT "./test.out"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user