mirror of
https://github.com/bkthomps/Containers.git
synced 2025-11-16 12:34:47 +00:00
Bug bash (#105)
Valgrind previously did not fail the test suite when there were memory leaks or invalid accesses. Due to this, a few bugs slipped in. These bugs have been fixed, and now every container has more test cases. Furthermore, the test suite has been updated to fail if Valgrind reports any errors.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <limits.h>
|
||||
#include <memory.h>
|
||||
#include "test.h"
|
||||
#include "../src/include/multiset.h"
|
||||
@@ -553,6 +554,57 @@ static void test_put_out_of_memory(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
struct big_object {
|
||||
int n;
|
||||
double d;
|
||||
signed char c[8];
|
||||
};
|
||||
|
||||
static int compare_big_object(const void *const one, const void *const two)
|
||||
{
|
||||
const struct big_object *const a = one;
|
||||
const struct big_object *const b = two;
|
||||
return a->n - b->n;
|
||||
}
|
||||
|
||||
static void test_big_object(void)
|
||||
{
|
||||
int i;
|
||||
multiset me = multiset_init(sizeof(struct big_object), compare_big_object);
|
||||
assert(me);
|
||||
for (i = 0; i < 16; i++) {
|
||||
int j;
|
||||
struct big_object b;
|
||||
b.n = INT_MIN + i;
|
||||
b.d = i + 0.5;
|
||||
for (j = 0; j < 8; j++) {
|
||||
b.c[j] = (signed char) (SCHAR_MIN + i + j);
|
||||
}
|
||||
assert(multiset_put(me, &b) == 0);
|
||||
b.n = -1;
|
||||
b.d = -1;
|
||||
for (j = 0; j < 8; j++) {
|
||||
b.c[j] = -1;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 16; i++) {
|
||||
int j;
|
||||
struct big_object b;
|
||||
b.n = INT_MIN + i;
|
||||
b.d = i + 0.5;
|
||||
for (j = 0; j < 8; j++) {
|
||||
b.c[j] = (signed char) (SCHAR_MIN + i + j);
|
||||
}
|
||||
assert(multiset_contains(me, &b) == 1);
|
||||
assert(b.n == INT_MIN + i);
|
||||
assert(b.d == i + 0.5);
|
||||
for (j = 0; j < 8; j++) {
|
||||
assert(b.c[j] == SCHAR_MIN + i + j);
|
||||
}
|
||||
}
|
||||
assert(!multiset_destroy(me));
|
||||
}
|
||||
|
||||
void test_multiset(void)
|
||||
{
|
||||
test_invalid_init();
|
||||
@@ -568,4 +620,5 @@ void test_multiset(void)
|
||||
test_init_out_of_memory();
|
||||
test_put_out_of_memory();
|
||||
#endif
|
||||
test_big_object();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user