Fixes memory leak in EN_addnode() (#455)
* Fixing memory leak in EN_addnode() * Separating test_net_builder from test_toolkit Making test_net_builder a standalone test * Removing BOOST_TEST_MAIN * Work in progress
This commit is contained in:
@@ -9,7 +9,7 @@ EPANET {#epanet-readme}
|
||||
|
||||
|
||||
## For EPANET-related questions and discussion
|
||||
For community discussion, FAQ, and roadmapping of the project, go to the [Community Forum](http://community.wateranalytics.org/category/epanet).
|
||||
For community discussion, FAQ, and roadmapping of the project, go to the [Community Forum](http://community.wateranalytics.org/category/epanet).
|
||||
|
||||
## What is on this Repository?
|
||||
The EPANET Library is a pressurized pipe network hydraulic and water quality analysis toolkit written in C. If you are interested in using/extending EPANET for academic, personal, or commercial use, then you've come to the right place.
|
||||
|
||||
@@ -1794,6 +1794,7 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType)
|
||||
{
|
||||
nIdx = net->Nnodes + 1;
|
||||
node = &net->Node[nIdx];
|
||||
node->D = NULL;
|
||||
net->Ntanks++;
|
||||
|
||||
// resize tanks array
|
||||
@@ -1820,6 +1821,7 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType)
|
||||
tank->V1max = 10000;
|
||||
}
|
||||
net->Nnodes++;
|
||||
p->parser.MaxNodes = net->Nnodes;
|
||||
strncpy(node->ID, id, MAXID);
|
||||
|
||||
// set default values for new node
|
||||
|
||||
@@ -401,7 +401,7 @@ void freedata(Project *pr)
|
||||
// Free memory for node data
|
||||
if (pr->network.Node != NULL)
|
||||
{
|
||||
for (j = 0; j <= pr->parser.MaxNodes; j++)
|
||||
for (j = 1; j <= pr->parser.MaxNodes; j++)
|
||||
{
|
||||
// Free memory used for demand category list
|
||||
demand = pr->network.Node[j].D;
|
||||
|
||||
@@ -16,6 +16,14 @@ if(UNIX)
|
||||
endif(UNIX)
|
||||
|
||||
|
||||
add_executable(test_net_builder test_net_builder.cpp)
|
||||
target_link_libraries(test_net_builder ${Boost_LIBRARIES} epanet2)
|
||||
add_test(NAME test_net_builder
|
||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_net_builder
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
|
||||
|
||||
|
||||
set(toolkit_test_srcs
|
||||
test_toolkit.cpp
|
||||
test_project.cpp
|
||||
@@ -30,13 +38,10 @@ set(toolkit_test_srcs
|
||||
test_pattern.cpp
|
||||
test_curve.cpp
|
||||
test_control.cpp
|
||||
test_net_builder.cpp
|
||||
)
|
||||
|
||||
add_executable(test_toolkit ${toolkit_test_srcs})
|
||||
|
||||
target_link_libraries(test_toolkit ${Boost_LIBRARIES} epanet2)
|
||||
|
||||
add_test(NAME test_toolkit
|
||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_toolkit
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE net_builder
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
@@ -19,26 +22,14 @@
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include "test_toolkit.hpp"
|
||||
#include "epanet2_2.h"
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_net_builder)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_init_close)
|
||||
{
|
||||
EN_Project ph = NULL;
|
||||
EN_createproject(&ph);
|
||||
|
||||
int error = EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
#define DATA_PATH_TMP "./tmp.inp"
|
||||
#define DATA_PATH_RPT "./test.rpt"
|
||||
#define DATA_PATH_OUT "./test.out"
|
||||
|
||||
|
||||
struct FixtureInitClose {
|
||||
@@ -59,6 +50,7 @@ struct FixtureInitClose {
|
||||
};
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_net_builder)
|
||||
|
||||
|
||||
// BOOST_AUTO_TEST_CASE(net_builder_I)
|
||||
|
||||
@@ -54,6 +54,20 @@ BOOST_AUTO_TEST_CASE (test_open_close)
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_init_close)
|
||||
{
|
||||
EN_Project ph = NULL;
|
||||
EN_createproject(&ph);
|
||||
|
||||
int error = EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_save)
|
||||
{
|
||||
int error;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE toolkit
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -41,6 +41,24 @@ struct FixtureOpenClose{
|
||||
};
|
||||
|
||||
|
||||
struct FixtureInitClose {
|
||||
FixtureInitClose() {
|
||||
error = 0;
|
||||
ph = NULL;
|
||||
|
||||
EN_createproject(&ph);
|
||||
EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
|
||||
}
|
||||
|
||||
~FixtureInitClose() {
|
||||
EN_close(ph);
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
int error;
|
||||
EN_Project ph;
|
||||
};
|
||||
|
||||
|
||||
struct FixtureAfterStep{
|
||||
FixtureAfterStep() {
|
||||
error = 0;
|
||||
|
||||
@@ -7,7 +7,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
|
||||
add_executable(test_errormanager ./test_errormanager.cpp
|
||||
add_executable(test_errormanager ./test_errormanager.cpp
|
||||
../../src/util/errormanager.c)
|
||||
target_include_directories(test_errormanager PUBLIC ../../src/)
|
||||
target_link_libraries(test_errormanager ${Boost_LIBRARIES})
|
||||
|
||||
@@ -45,16 +45,16 @@ BOOST_AUTO_TEST_CASE (test_create_destroy)
|
||||
|
||||
struct Fixture{
|
||||
Fixture() {
|
||||
error_message = NULL;
|
||||
error_message = NULL;
|
||||
error_handle = create_error_manager(&mock_lookup);
|
||||
}
|
||||
~Fixture() {
|
||||
delete_error_manager(error_handle);
|
||||
free(error_message);
|
||||
}
|
||||
int error;
|
||||
error_handle_t *error_handle;
|
||||
char *error_message;
|
||||
}
|
||||
int error;
|
||||
error_handle_t *error_handle;
|
||||
char *error_message;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user