test: add memcheck and fix memleaks in test
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #13 PR #13
This commit is contained in:
parent
219812f20e
commit
150cca40af
@ -38,7 +38,7 @@ name: tag
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Build release
|
- name: Build release
|
||||||
image: registry.riba-interactive.de/alpine-build:3
|
image: registry.riba-interactive.de/alpine-build:4
|
||||||
commands:
|
commands:
|
||||||
- cmake -S. -Bcmake-build-ci -DCMAKE_BUILD_TYPE=Release
|
- cmake -S. -Bcmake-build-ci -DCMAKE_BUILD_TYPE=Release
|
||||||
- cd cmake-build-ci
|
- cd cmake-build-ci
|
||||||
@ -58,7 +58,7 @@ name: Build and Test
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Build and run tests
|
- name: Build and run tests
|
||||||
image: registry.riba-interactive.de/alpine-build:3
|
image: registry.riba-interactive.de/alpine-build:4
|
||||||
commands:
|
commands:
|
||||||
- cmake -S. -Bcmake-build-ci -DCMAKE_BUILD_TYPE=Debug -DENABLE_TEST_COVERAGE=on
|
- cmake -S. -Bcmake-build-ci -DCMAKE_BUILD_TYPE=Debug -DENABLE_TEST_COVERAGE=on
|
||||||
- cd cmake-build-ci
|
- cd cmake-build-ci
|
||||||
|
|||||||
@ -35,7 +35,7 @@ if ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING)
|
|||||||
|
|
||||||
setup_target_for_coverage_lcov(
|
setup_target_for_coverage_lcov(
|
||||||
NAME coverage
|
NAME coverage
|
||||||
EXECUTABLE ${CMAKE_CTEST_COMMAND}
|
EXECUTABLE ${CMAKE_CTEST_COMMAND} -T memcheck
|
||||||
EXCLUDE "tests/*"
|
EXCLUDE "tests/*"
|
||||||
LCOV_ARGS --rc lcov_branch_coverage=1
|
LCOV_ARGS --rc lcov_branch_coverage=1
|
||||||
GENHTML_ARGS --rc genhtml_branch_coverage=1
|
GENHTML_ARGS --rc genhtml_branch_coverage=1
|
||||||
|
|||||||
@ -8,4 +8,5 @@ RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/a
|
|||||||
flex \
|
flex \
|
||||||
git \
|
git \
|
||||||
ncurses-dev\
|
ncurses-dev\
|
||||||
lcov@testing
|
lcov@testing \
|
||||||
|
valgrind
|
||||||
@ -109,12 +109,18 @@ spec("hashtable") {
|
|||||||
|
|
||||||
it("should not work with the str having NULL as string") {
|
it("should not work with the str having NULL as string") {
|
||||||
str key = STR_NULL_INIT;
|
str key = STR_NULL_INIT;
|
||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 0);
|
value *value = value_new(1337);
|
||||||
|
check(value_hashtable_insert(hashtable, key, value) == 0);
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return 0 with NULL as this param") {
|
it("should return 0 with NULL as this param") {
|
||||||
str key = STR_STATIC_INIT("leet");
|
str key = STR_STATIC_INIT("leet");
|
||||||
check(value_hashtable_insert(NULL, key, value_new(1)) == 0, "return should be 0");
|
value *value = value_new(1);
|
||||||
|
check(value_hashtable_insert(NULL, key, value) == 0, "return should be 0");
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should not allow double entry") {
|
it("should not allow double entry") {
|
||||||
@ -124,7 +130,10 @@ spec("hashtable") {
|
|||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
||||||
check(value_hashtable_has(hashtable, key) == 1, "hashtable should have the key");
|
check(value_hashtable_has(hashtable, key) == 1, "hashtable should have the key");
|
||||||
|
|
||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 0);
|
value *value = value_new(1337);
|
||||||
|
check(value_hashtable_insert(hashtable, key, value) == 0, "return should be 0");
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +176,6 @@ spec("hashtable") {
|
|||||||
check(value_hashtable_markStolenCheck(hashtable, key, (value_hashtable_value_check_fn) value_check_counter, &counter) == 1);
|
check(value_hashtable_markStolenCheck(hashtable, key, (value_hashtable_value_check_fn) value_check_counter, &counter) == 1);
|
||||||
check(value_hashtable_isStolenCheck(hashtable, key, (value_hashtable_value_check_fn) value_check_counter, &counter) == 1);
|
check(value_hashtable_isStolenCheck(hashtable, key, (value_hashtable_value_check_fn) value_check_counter, &counter) == 1);
|
||||||
value_destroy(&resultValue);
|
value_destroy(&resultValue);
|
||||||
check(resultValue == NULL, "resultValue should be NULL");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,12 +214,15 @@ spec("hashtable") {
|
|||||||
describe("value_hashtable_markStolen()") {
|
describe("value_hashtable_markStolen()") {
|
||||||
it("should mark the value for the given key as stolen") {
|
it("should mark the value for the given key as stolen") {
|
||||||
str key = STR_STATIC_INIT("leet");
|
str key = STR_STATIC_INIT("leet");
|
||||||
|
value *value = NULL;
|
||||||
check(value_hashtable_has(hashtable, key) == 0,"hashtable should not have the key already");
|
check(value_hashtable_has(hashtable, key) == 0,"hashtable should not have the key already");
|
||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
||||||
check(value_hashtable_has(hashtable, key) == 1, "hashtable should have the key");
|
check(value_hashtable_has(hashtable, key) == 1, "hashtable should have the key");
|
||||||
|
value = value_hashtable_lookup(hashtable, key);
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
check(value_hashtable_markStolen(hashtable, key) == 1, "hashtable should mark the value for the key as stolen");
|
check(value_hashtable_markStolen(hashtable, key) == 1, "hashtable should mark the value for the key as stolen");
|
||||||
check(value_hashtable_isStolen(hashtable, key) == 1, "hashtable should have the value for the key marked as stolen");
|
check(value_hashtable_isStolen(hashtable, key) == 1, "hashtable should have the value for the key marked as stolen");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return 0 the given key that is not existing") {
|
it("should return 0 the given key that is not existing") {
|
||||||
@ -224,8 +235,12 @@ spec("hashtable") {
|
|||||||
|
|
||||||
it("should work with the empty str") {
|
it("should work with the empty str") {
|
||||||
str key = STR_STATIC_INIT("");
|
str key = STR_STATIC_INIT("");
|
||||||
|
value *value = NULL;
|
||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
||||||
|
value = value_hashtable_lookup(hashtable, key);
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
check(value_hashtable_markStolen(hashtable, key) == 1, "return should be 1");
|
check(value_hashtable_markStolen(hashtable, key) == 1, "return should be 1");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should not work with the str having NULL as string") {
|
it("should not work with the str having NULL as string") {
|
||||||
@ -303,6 +318,7 @@ spec("hashtable") {
|
|||||||
str otherKey2 = STR_STATIC_INIT("otherKey2");
|
str otherKey2 = STR_STATIC_INIT("otherKey2");
|
||||||
str otherKey3 = STR_STATIC_INIT("otherKey3");
|
str otherKey3 = STR_STATIC_INIT("otherKey3");
|
||||||
str otherKey4 = STR_STATIC_INIT("otherKey4");
|
str otherKey4 = STR_STATIC_INIT("otherKey4");
|
||||||
|
value *value = NULL;
|
||||||
|
|
||||||
check(value_hashtable_has(hashtable, key) == 0,"hashtable should not have the key already");
|
check(value_hashtable_has(hashtable, key) == 0,"hashtable should not have the key already");
|
||||||
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, key, value_new(1337)) == 1);
|
||||||
@ -313,8 +329,11 @@ spec("hashtable") {
|
|||||||
check(value_hashtable_insert(hashtable, otherKey3, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, otherKey3, value_new(1337)) == 1);
|
||||||
check(value_hashtable_insert(hashtable, otherKey4, value_new(1337)) == 1);
|
check(value_hashtable_insert(hashtable, otherKey4, value_new(1337)) == 1);
|
||||||
|
|
||||||
|
value = value_hashtable_lookup(hashtable, key);
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
check(value_hashtable_markStolen(hashtable, key) == 1, "hashtable should mark the value for the key as stolen");
|
check(value_hashtable_markStolen(hashtable, key) == 1, "hashtable should mark the value for the key as stolen");
|
||||||
check(value_hashtable_isStolen(hashtable, key) == 1, "hashtable should have the value for the key marked as stolen");
|
check(value_hashtable_isStolen(hashtable, key) == 1, "hashtable should have the value for the key marked as stolen");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,10 @@ spec("list") {
|
|||||||
for_it_end();
|
for_it_end();
|
||||||
|
|
||||||
it("should return 0 with NULL as this param") {
|
it("should return 0 with NULL as this param") {
|
||||||
check(value_list_push(NULL, value_new(1)) == 0, "return should not be 0");
|
value *value = value_new(1);
|
||||||
|
check(value_list_push(NULL, value) == 0, "return should not be 0");
|
||||||
|
check(value != NULL, "value should not be NULL");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return 0 with NULL as valueElement param") {
|
it("should return 0 with NULL as valueElement param") {
|
||||||
@ -130,7 +133,9 @@ spec("list") {
|
|||||||
for_it_end();
|
for_it_end();
|
||||||
|
|
||||||
it("should return 0 with NULL as this param") {
|
it("should return 0 with NULL as this param") {
|
||||||
check(value_list_unshift(NULL, value_new(1)) == 0, "return should not be 0");
|
value *value = value_new(1);
|
||||||
|
check(value_list_unshift(NULL, value) == 0, "return should not be 0");
|
||||||
|
value_destroy(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return 0 with NULL as valueElement param") {
|
it("should return 0 with NULL as valueElement param") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user