Added memory checks
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "dusktest.h"
|
||||
#include "util/string.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
static void test_stringIsWhitespace(void **state) {
|
||||
(void)state;
|
||||
@@ -20,6 +21,9 @@ static void test_stringIsWhitespace(void **state) {
|
||||
assert_false(stringIsWhitespace('1')); // '1' is not whitespace
|
||||
assert_false(stringIsWhitespace('_')); // '_' is not whitespace
|
||||
assert_false(stringIsWhitespace('-')); // '-' is not whitespace
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringCopy(void **state) {
|
||||
@@ -47,6 +51,9 @@ static void test_stringCopy(void **state) {
|
||||
|
||||
// Must have destSize large enough for source
|
||||
expect_assert_failure(stringCopy(dest, "this string is too long", 10));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringCompare(void **state) {
|
||||
@@ -69,6 +76,9 @@ static void test_stringCompare(void **state) {
|
||||
// Cannot compare NULL strings
|
||||
expect_assert_failure(stringCompare(NULL, "abc"));
|
||||
expect_assert_failure(stringCompare("abc", NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringCompareInsensitive(void **state) {
|
||||
@@ -84,6 +94,9 @@ static void test_stringCompareInsensitive(void **state) {
|
||||
// Cannot compare NULL strings
|
||||
expect_assert_failure(stringCompareInsensitive(NULL, "abc"));
|
||||
expect_assert_failure(stringCompareInsensitive("abc", NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringTrim(void **state) {
|
||||
@@ -127,6 +140,9 @@ static void test_stringTrim(void **state) {
|
||||
stringCopy(buf, "", sizeof(buf));
|
||||
stringTrim(buf);
|
||||
assert_string_equal(buf, "");
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringFindLastChar(void **state) {
|
||||
@@ -148,6 +164,9 @@ static void test_stringFindLastChar(void **state) {
|
||||
|
||||
// Cannot search NULL string
|
||||
expect_assert_failure(stringFindLastChar(NULL, 'a'));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringFormat(void **state) {
|
||||
@@ -204,6 +223,9 @@ static void test_stringFormat(void **state) {
|
||||
|
||||
// Must have destSize > 0 if dest is not NULL
|
||||
expect_assert_failure(stringFormat(buffer, 0, "Hello"));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringToI32(void **state) {
|
||||
@@ -330,6 +352,9 @@ static void test_stringToI32(void **state) {
|
||||
// Cannot have NULL output pointer
|
||||
stringCopy(buffer, "123", sizeof(buffer));
|
||||
expect_assert_failure(stringToI32(buffer, NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringToI64(void **state) {
|
||||
@@ -456,6 +481,9 @@ static void test_stringToI64(void **state) {
|
||||
// Cannot have NULL output pointer
|
||||
stringCopy(buffer, "123", sizeof(buffer));
|
||||
expect_assert_failure(stringToI64(buffer, NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringToI16(void **state) {
|
||||
@@ -574,6 +602,9 @@ static void test_stringToI16(void **state) {
|
||||
// Cannot have NULL output pointer
|
||||
stringCopy(buffer, "123", sizeof(buffer));
|
||||
expect_assert_failure(stringToI16(buffer, NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringToU16(void **state) {
|
||||
@@ -688,6 +719,9 @@ static void test_stringToU16(void **state) {
|
||||
// Cannot have NULL output pointer
|
||||
stringCopy(buffer, "123", sizeof(buffer));
|
||||
expect_assert_failure(stringToU16(buffer, NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringToF32(void **state) {
|
||||
@@ -819,6 +853,9 @@ static void test_stringToF32(void **state) {
|
||||
// Cannot have NULL output pointer
|
||||
stringCopy(buffer, "1.23", sizeof(buffer));
|
||||
expect_assert_failure(stringToF32(buffer, NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringEndsWith(void **state) {
|
||||
@@ -834,6 +871,9 @@ static void test_stringEndsWith(void **state) {
|
||||
// Cannot have NULL strings
|
||||
expect_assert_failure(stringEndsWith(NULL, "world"));
|
||||
expect_assert_failure(stringEndsWith("hello", NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_stringEndsWithCaseInsensitive(void **state) {
|
||||
@@ -848,6 +888,9 @@ static void test_stringEndsWithCaseInsensitive(void **state) {
|
||||
// Cannot have NULL strings
|
||||
expect_assert_failure(stringEndsWithCaseInsensitive(NULL, "WORLD"));
|
||||
expect_assert_failure(stringEndsWithCaseInsensitive("hello", NULL));
|
||||
|
||||
// Expect no leaks
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user