Merge pull request #445 from michaeltryby/dev-unittesting

Fix leaky test code
This commit is contained in:
Michael Tryby
2019-04-03 16:58:12 -04:00
committed by GitHub
28 changed files with 459 additions and 357 deletions

View File

@@ -11,12 +11,16 @@
******************************************************************************
*/
#include <stdio.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>

View File

@@ -10,8 +10,10 @@
Last Updated: 03/17/2019
******************************************************************************
*/
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif

View File

@@ -11,8 +11,13 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <string.h>
#include "epanet_py.h"

View File

@@ -11,8 +11,10 @@
******************************************************************************
*/
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif

View File

@@ -11,13 +11,16 @@
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -11,13 +11,16 @@
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -12,13 +12,16 @@
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -10,8 +10,15 @@ License: see LICENSE
Last Updated: 11/27/2018
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include "types.h"
#include "funcs.h"

View File

@@ -11,13 +11,16 @@ Last Updated: 04/03/2019
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -11,18 +11,23 @@ Last Updated: 04/03/2019
******************************************************************************
*/
#include <stdio.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"
#include "funcs.h"
#include "hash.h"
#include "text.h"
#include <math.h>
// Default values
#define MAXITER 200 // Default max. # hydraulic iterations

View File

@@ -11,12 +11,16 @@ Last Updated: 04/03/2019
******************************************************************************
*/
#include <stdio.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -11,12 +11,16 @@ Last Updated: 03/17/2019
******************************************************************************
*/
#include <stdio.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -14,10 +14,14 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include "mempool.h"
/*

View File

@@ -11,13 +11,16 @@ Last Updated: 11/27/2018
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "types.h"

View File

@@ -11,7 +11,13 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>

View File

@@ -11,13 +11,16 @@ Last Updated: 11/27/2018
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "mempool.h"

View File

@@ -11,6 +11,13 @@ Last Updated: 11/27/2018
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <math.h>
#include "types.h"

View File

@@ -11,13 +11,17 @@ Last Updated: 11/27/2018
******************************************************************************
*/
#include <stdio.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <math.h>
#include "mempool.h"
#include "types.h"

View File

@@ -11,13 +11,15 @@
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#define snprintf _snprintf

View File

@@ -11,13 +11,15 @@
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "funcs.h"

View File

@@ -18,13 +18,16 @@
linsolve() -- called from netsolve() in HYDRAUL.C
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>

View File

@@ -30,7 +30,8 @@ set(toolkit_test_srcs
test_pattern.cpp
test_curve.cpp
test_control.cpp
test_net_builder.cpp)
test_net_builder.cpp
)
add_executable(test_toolkit ${toolkit_test_srcs})

View File

@@ -22,9 +22,10 @@ BOOST_AUTO_TEST_SUITE (test_analysis)
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
{
int i;
double array[12];
std::vector<double> test;
std::vector<double> test(12);
double *array = test.data();
std::vector<double> ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0};
error = EN_solveH(ph);
@@ -35,23 +36,24 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
for (i=EN_TRIALS; i<=EN_DEMANDCHARGE; i++) {
error = EN_getoption(ph, i, &array[i]);
error = EN_getoption(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 12);
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_getoption(ph, 18, &array[0]);
double temp;
error = EN_getoption(ph, 18, &temp);
BOOST_CHECK(error == 251);
}
BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
{
int i;
long array[16];
std::vector<long> test;
std::vector<long> test(16);
long *array = test.data();
std::vector<long> ref = {86400, 3600, 300, 7200, 0, 3600, 0, 360, 0, 25, 0, 86400, 86400, 0, 3600, 0};
error = EN_solveH(ph);
@@ -62,14 +64,15 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
for (i=EN_DURATION; i<=EN_NEXTEVENTTANK; i++) {
error = EN_gettimeparam(ph, i, &array[i]);
error = EN_gettimeparam(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 16);
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_gettimeparam(ph, 18, &array[0]);
long temp;
error = EN_gettimeparam(ph, 18, &temp);
BOOST_CHECK(error == 251);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -61,8 +61,8 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
BOOST_REQUIRE(n2 == n1);
for (i = 0; i < n1; i++)
{
BOOST_REQUIRE(X1[i] == X2[i]);
BOOST_REQUIRE(Y1[i] == Y2[i]);
BOOST_CHECK(X1[i] == X2[i]);
BOOST_CHECK(Y1[i] == Y2[i]);
}
}

View File

@@ -11,6 +11,14 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <boost/test/unit_test.hpp>
#include "test_toolkit.hpp"
@@ -35,6 +43,9 @@ BOOST_AUTO_TEST_CASE(test_init_close)
struct FixtureInitClose {
FixtureInitClose() {
error = 0;
ph = NULL;
EN_createproject(&ph);
EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
}

View File

@@ -11,6 +11,8 @@
******************************************************************************
*/
#include <string.h>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
@@ -109,19 +111,20 @@ BOOST_AUTO_TEST_SUITE(test_proj_fixture)
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];
char c_test[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);
// ref is an automatic variable and therefore doesn't need to be deleted
std::string ref[3] = {
" EPANET Example Network 1",
"A simple example of modeling chlorine decay. Both bulk and",
"wall reactions are included. "};
error = EN_gettitle(ph, c_test[0], c_test[1], c_test[2]);
BOOST_REQUIRE(error == 0);
for (int i = 0; i < 3; i++) {
std::string test (c_test[i]);
std::string ref (c_ref[i]);
BOOST_CHECK(check_string(test, ref));
BOOST_CHECK(check_string(test, ref[i]));
}
// Need a test for EN_settitle
@@ -129,17 +132,18 @@ BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
BOOST_FIXTURE_TEST_CASE(test_getcount, FixtureOpenClose)
{
int i, array[7];
int i;
std::vector<int> test(7);
int *array = test.data();
std::vector<int> test;
std::vector<int> ref = { 11, 2, 13, 1, 1, 2, 0 };
for (i=EN_NODECOUNT; i<=EN_RULECOUNT; i++) {
error = EN_getcount(ph, i, &array[i]);
error = EN_getcount(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 7);
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_getcount(ph, 7, &i);

View File

@@ -21,9 +21,10 @@ BOOST_AUTO_TEST_SUITE (test_report)
BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
{
int i;
double array[5];
std::vector<double> test;
std::vector<double> test(5);
double *array = test.data();
std::vector<double> ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08,
0.0089173150106518495, 0.99999998187144024};
@@ -35,15 +36,13 @@ BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) {
error = EN_getstatistic(ph, i, &array[i]);
error = EN_getstatistic(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 5);
// BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
BOOST_CHECK(check_cdd_double(test, ref, 3));
error = EN_getstatistic(ph, 8, &array[0]);
double temp;
error = EN_getstatistic(ph, 8, &temp);
BOOST_CHECK(error == 251);
}

View File

@@ -14,7 +14,6 @@
#ifndef TEST_TOOLKIT_HPP
#define TEST_TOOLKIT_HPP
#include "epanet2_2.h"
@@ -25,6 +24,9 @@
struct FixtureOpenClose{
FixtureOpenClose() {
error = 0;
ph = NULL;
EN_createproject(&ph);
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
}
@@ -41,6 +43,9 @@ struct FixtureOpenClose{
struct FixtureAfterStep{
FixtureAfterStep() {
error = 0;
ph = NULL;
flag = 0;
tstop = 10800;