From df4e62b550dccc3a71156eee627f6d14452bd832 Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Fri, 22 Mar 2019 15:34:34 -0400 Subject: [PATCH] Adding comment test --- tests/CMakeLists.txt | 4 +- tests/test_curve.cpp | 40 ++++++++++++++++ tests/test_demand.cpp | 2 +- tests/test_link.cpp | 31 +++++++++++- tests/test_node.cpp | 106 +++++++++++++++++++++++++++++++++++++++++ tests/test_pattern.cpp | 19 ++++++++ tests/test_toolkit.cpp | 2 + tests/test_toolkit.hpp | 12 +---- 8 files changed, 201 insertions(+), 15 deletions(-) create mode 100644 tests/test_curve.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7f3cd97..d16c376 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/test_curve.cpp b/tests/test_curve.cpp new file mode 100644 index 0000000..941b473 --- /dev/null +++ b/tests/test_curve.cpp @@ -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 + +#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() diff --git a/tests/test_demand.cpp b/tests/test_demand.cpp index 3a7d38f..2955079 100644 --- a/tests/test_demand.cpp +++ b/tests/test_demand.cpp @@ -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 diff --git a/tests/test_link.cpp b/tests/test_link.cpp index 0b9a25a..15f451e 100644 --- a/tests/test_link.cpp +++ b/tests/test_link.cpp @@ -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() diff --git a/tests/test_node.cpp b/tests/test_node.cpp index 68376fd..cc79c48 100644 --- a/tests/test_node.cpp +++ b/tests/test_node.cpp @@ -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() diff --git a/tests/test_pattern.cpp b/tests/test_pattern.cpp index a13cab6..674ea76 100644 --- a/tests/test_pattern.cpp +++ b/tests/test_pattern.cpp @@ -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() diff --git a/tests/test_toolkit.cpp b/tests/test_toolkit.cpp index 70718f1..f1cb75d 100644 --- a/tests/test_toolkit.cpp +++ b/tests/test_toolkit.cpp @@ -14,6 +14,8 @@ #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE toolkit +#include + #include #include "test_toolkit.hpp" diff --git a/tests/test_toolkit.hpp b/tests/test_toolkit.hpp index 1aa7400..03ac664 100644 --- a/tests/test_toolkit.hpp +++ b/tests/test_toolkit.hpp @@ -15,21 +15,11 @@ #define TEST_TOOLKIT_HPP -#ifdef _WIN32 -#define _CRTDBG_MAP_ALLOC -#include -#include -#else -#include -#endif - - -#include - #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"