Fixing memory leak
This commit is contained in:
@@ -64,31 +64,18 @@ boost::test_tools::predicate_result check_string(std::string test, std::string r
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_output_auto)
|
BOOST_AUTO_TEST_SUITE (test_output_auto)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(InitTest) {
|
BOOST_AUTO_TEST_CASE(OpenCloseTest) {
|
||||||
ENR_Handle p_handle = NULL;
|
|
||||||
|
|
||||||
int error = ENR_init(&p_handle);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
BOOST_CHECK(p_handle != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(OpenTest) {
|
|
||||||
std::string path = std::string(DATA_PATH);
|
std::string path = std::string(DATA_PATH);
|
||||||
|
|
||||||
ENR_Handle p_handle = NULL;
|
ENR_Handle p_handle = NULL;
|
||||||
ENR_init(&p_handle);
|
ENR_init(&p_handle);
|
||||||
|
|
||||||
int error = ENR_open(p_handle, path.c_str());
|
int error = ENR_open(p_handle, path.c_str());
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
ENR_close(&p_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(CloseTest) {
|
|
||||||
ENR_Handle p_handle = NULL;
|
|
||||||
int error = ENR_init(&p_handle);
|
|
||||||
|
|
||||||
error = ENR_close(&p_handle);
|
error = ENR_close(&p_handle);
|
||||||
BOOST_REQUIRE(error == -1);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(p_handle != NULL);
|
BOOST_CHECK(p_handle == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
@@ -106,7 +93,7 @@ struct Fixture{
|
|||||||
array_dim = 0;
|
array_dim = 0;
|
||||||
}
|
}
|
||||||
~Fixture() {
|
~Fixture() {
|
||||||
ENR_free((void**)&array);
|
free((void*)array);
|
||||||
error = ENR_close(&p_handle);
|
error = ENR_close(&p_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,15 +118,11 @@ BOOST_FIXTURE_TEST_CASE(test_getNetSize, Fixture)
|
|||||||
std::vector<int> test;
|
std::vector<int> test;
|
||||||
test.assign(i_array, i_array + array_dim);
|
test.assign(i_array, i_array + array_dim);
|
||||||
|
|
||||||
const int ref_dim = 5;
|
std::vector<int> ref = {11,2,13,1,0};
|
||||||
int ref_array[ref_dim] = {11,2,13,1,0};
|
|
||||||
|
|
||||||
std::vector<int> ref;
|
|
||||||
ref.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
||||||
|
|
||||||
ENR_free((void**)&i_array);
|
free((void*)i_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_getUnits, Fixture) {
|
BOOST_FIXTURE_TEST_CASE(test_getUnits, Fixture) {
|
||||||
@@ -152,7 +135,7 @@ BOOST_FIXTURE_TEST_CASE(test_getUnits, Fixture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_getElementName, Fixture) {
|
BOOST_FIXTURE_TEST_CASE(test_getElementName, Fixture) {
|
||||||
char* name = new char[MAXID];
|
char* name;
|
||||||
int length, index = 1;
|
int length, index = 1;
|
||||||
|
|
||||||
error = ENR_getElementName(p_handle, ENR_node, index, &name, &length);
|
error = ENR_getElementName(p_handle, ENR_node, index, &name, &length);
|
||||||
@@ -162,7 +145,7 @@ BOOST_FIXTURE_TEST_CASE(test_getElementName, Fixture) {
|
|||||||
std::string ref ("10");
|
std::string ref ("10");
|
||||||
BOOST_CHECK(check_string(test, ref));
|
BOOST_CHECK(check_string(test, ref));
|
||||||
|
|
||||||
delete(name);
|
free((void *)name);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) {
|
BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) {
|
||||||
@@ -170,8 +153,7 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) {
|
|||||||
error = ENR_getNodeAttribute(p_handle, 1, ENR_quality, &array, &array_dim);
|
error = ENR_getNodeAttribute(p_handle, 1, ENR_quality, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 11;
|
std::vector<float> ref_vec = { 1.0f,
|
||||||
float ref_array[ref_dim] = { 1.0f,
|
|
||||||
0.44407997f,
|
0.44407997f,
|
||||||
0.43766347f,
|
0.43766347f,
|
||||||
0.42827705f,
|
0.42827705f,
|
||||||
@@ -183,9 +165,6 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) {
|
|||||||
1.0f,
|
1.0f,
|
||||||
0.96745253f};
|
0.96745253f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -197,8 +176,7 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkAttribute, Fixture) {
|
|||||||
error = ENR_getLinkAttribute(p_handle, 1, ENR_flow, &array ,&array_dim);
|
error = ENR_getLinkAttribute(p_handle, 1, ENR_flow, &array ,&array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 13;
|
std::vector<float> ref_vec = { 1848.5812f,
|
||||||
float ref_array[ref_dim] = { 1848.5812f,
|
|
||||||
1220.4274f,
|
1220.4274f,
|
||||||
130.11162f,
|
130.11162f,
|
||||||
187.6893f,
|
187.6893f,
|
||||||
@@ -212,9 +190,6 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkAttribute, Fixture) {
|
|||||||
59.535515f,
|
59.535515f,
|
||||||
1848.5812f};
|
1848.5812f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -226,15 +201,11 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeResult, Fixture) {
|
|||||||
error = ENR_getNodeResult(p_handle, 1, 2, &array, &array_dim);
|
error = ENR_getNodeResult(p_handle, 1, 2, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 4;
|
std::vector<float> ref_vec = {0.041142918f,
|
||||||
float ref_array[ref_dim] = {0.041142918f,
|
|
||||||
150.0f,
|
150.0f,
|
||||||
987.98358f,
|
987.98358f,
|
||||||
120.45029f};
|
120.45029f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -246,8 +217,7 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkResult, Fixture) {
|
|||||||
error = ENR_getLinkResult(p_handle, 24, 13, &array, &array_dim);
|
error = ENR_getLinkResult(p_handle, 24, 13, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 8;
|
std::vector<float> ref_vec = {0.58586824f,
|
||||||
float ref_array[ref_dim] = {0.58586824f,
|
|
||||||
1892.2433f,
|
1892.2433f,
|
||||||
0.0f,
|
0.0f,
|
||||||
-200.71875f,
|
-200.71875f,
|
||||||
@@ -256,9 +226,6 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkResult, Fixture) {
|
|||||||
1.0f,
|
1.0f,
|
||||||
0.0f};
|
0.0f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -270,8 +237,7 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeSeries, Fixture){
|
|||||||
error = ENR_getNodeSeries(p_handle, 2, ENR_pressure, 0, 10, &array, &array_dim);
|
error = ENR_getNodeSeries(p_handle, 2, ENR_pressure, 0, 10, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 10;
|
std::vector<float> ref_vec = {119.25731f,
|
||||||
float ref_array[ref_dim] = {119.25731f,
|
|
||||||
120.45029f,
|
120.45029f,
|
||||||
121.19854f,
|
121.19854f,
|
||||||
122.00622f,
|
122.00622f,
|
||||||
@@ -282,9 +248,6 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeSeries, Fixture){
|
|||||||
123.40434f,
|
123.40434f,
|
||||||
123.81807f};
|
123.81807f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -296,8 +259,7 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkSeries, Fixture) {
|
|||||||
error = ENR_getLinkSeries(p_handle, 2, ENR_flow, 0, 10, &array, &array_dim);
|
error = ENR_getLinkSeries(p_handle, 2, ENR_flow, 0, 10, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 10;
|
std::vector<float> ref_vec = {1234.2072f,
|
||||||
float ref_array[ref_dim] = {1234.2072f,
|
|
||||||
1220.4274f,
|
1220.4274f,
|
||||||
1164.4f,
|
1164.4f,
|
||||||
1154.8175f,
|
1154.8175f,
|
||||||
@@ -308,9 +270,6 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkSeries, Fixture) {
|
|||||||
1087.556f,
|
1087.556f,
|
||||||
1082.5011f};
|
1082.5011f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -322,15 +281,11 @@ BOOST_FIXTURE_TEST_CASE(test_getNetReacts, Fixture) {
|
|||||||
error = ENR_getNetReacts(p_handle, &array, &array_dim);
|
error = ENR_getNetReacts(p_handle, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 4;
|
std::vector<float> ref_vec = {18806.59f,
|
||||||
float ref_array[ref_dim] = {18806.59f,
|
|
||||||
85424.438f,
|
85424.438f,
|
||||||
115174.05f,
|
115174.05f,
|
||||||
238972.66f};
|
238972.66f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
@@ -344,17 +299,13 @@ BOOST_FIXTURE_TEST_CASE(test_getEnergyUsage, Fixture) {
|
|||||||
error = ENR_getEnergyUsage(p_handle, 1, &linkIdx, &array, &array_dim);
|
error = ENR_getEnergyUsage(p_handle, 1, &linkIdx, &array, &array_dim);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
const int ref_dim = 6;
|
std::vector<float> ref_vec = {57.712959f,
|
||||||
float ref_array[ref_dim] = {57.712959f,
|
|
||||||
75.0f,
|
75.0f,
|
||||||
880.41583f,
|
880.41583f,
|
||||||
96.254318f,
|
96.254318f,
|
||||||
96.707115f,
|
96.707115f,
|
||||||
0.0f};
|
0.0f};
|
||||||
|
|
||||||
std::vector<float> ref_vec;
|
|
||||||
ref_vec.assign(ref_array, ref_array + ref_dim);
|
|
||||||
|
|
||||||
std::vector<float> test_vec;
|
std::vector<float> test_vec;
|
||||||
test_vec.assign(array, array + array_dim);
|
test_vec.assign(array, array + array_dim);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user