Test assert
Some checks failed
Build Dusk / run-tests (push) Successful in 2m6s
Build Dusk / build-linux (push) Successful in 1m56s
Build Dusk / build-psp (push) Failing after 1m48s

This commit is contained in:
2026-01-06 21:23:39 -06:00
parent 5e39097faa
commit 26a71a823a
4 changed files with 164 additions and 9 deletions

View File

@@ -3,6 +3,7 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_subdirectory(assert)
add_subdirectory(display)
# add_subdirectory(rpg)
add_subdirectory(item)

View File

@@ -0,0 +1,9 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
include(dusktest)
# Tests
dusktest(test_assert.c)

154
test/assert/test_assert.c Normal file
View File

@@ -0,0 +1,154 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "dusktest.h"
#include "assert/assert.h"
static void test_assertTrueImpl(void **state) {
(void)state;
// Should not assert when true false statement
assertTrueImpl(__FILE__, __LINE__, true, "This should not assert");
// Should assert when passing false statement
expect_assert_failure(assertTrueImpl(__FILE__, __LINE__, false, "asserts"));
}
static void test_assertFalseImpl(void **state) {
(void)state;
// Should not assert when passing false statement
assertFalseImpl(__FILE__, __LINE__, false, "This should not assert");
// Should assert when passing true statement
expect_assert_failure(assertFalseImpl(__FILE__, __LINE__, true, "asserts"));
}
static void test_assertUnreachableImpl(void **state) {
(void)state;
// Should always assert false
expect_assert_failure(assertUnreachableImpl(__FILE__, __LINE__, "asserts"));
}
static void test_assertNotNullImpl(void **state) {
(void)state;
int someValue = 42;
// Should not assert with a valid pointer
assertNotNullImpl(__FILE__, __LINE__, &someValue, "not assert");
// Should assert with a NULL pointer
expect_assert_failure(assertNotNullImpl(__FILE__, __LINE__, NULL, "asserts"));
}
static void test_assertDeprecatedImpl(void **state) {
(void)state;
// Always asserts when called
expect_assert_failure(assertDeprecatedImpl(__FILE__, __LINE__, "deprecated"));
}
static void test_assertTrue(void **state) {
(void)state;
// Should not assert when passing true statement
assertTrue(true, "This should not assert");
// Should assert when passing false statement
expect_assert_failure(assertTrue(false, "asserts"));
}
static void test_assertFalse(void **state) {
(void)state;
// Should not assert when passing true statement
assertFalse(false, "This should not assert");
// Should assert when passing false statement
expect_assert_failure(assertFalse(true, "asserts"));
}
static void test_assertUnreachable(void **state) {
(void)state;
// Should always assert false
expect_assert_failure(assertUnreachable("asserts"));
}
static void test_assertNotNull(void **state) {
(void)state;
int someValue = 42;
// Should not assert with a valid pointer
assertNotNull(&someValue, "not assert");
// Should assert with a NULL pointer
expect_assert_failure(assertNotNull(NULL, "asserts"));
}
static void test_assertNull(void **state) {
(void)state;
int someValue = 42;
// Should assert with a valid pointer
expect_assert_failure(assertNull(&someValue, "asserts"));
// Should not assert with a NULL pointer
assertNull(NULL, "not assert");
}
static void test_assertDeprecated(void **state) {
(void)state;
// Always asserts when called
expect_assert_failure(assertDeprecated("deprecated"));
}
static void test_assertStrLenMax(void **state) {
(void)state;
// Should not assert when string length is within limit
assertStrLenMax("test", 10, "This should not assert");
// Should assert when string length exceeds limit
expect_assert_failure(assertStrLenMax("exceeding", 5, "asserts"));
}
static void test_assertStrLenMin(void **state) {
(void)state;
// Should not assert when string length meets minimum
assertStrLenMin("sufficient", 5, "This should not assert");
// Should assert when string length is below minimum
expect_assert_failure(assertStrLenMin("tiny", 10, "asserts"));
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_assertTrueImpl),
cmocka_unit_test(test_assertFalseImpl),
cmocka_unit_test(test_assertUnreachableImpl),
cmocka_unit_test(test_assertNotNullImpl),
cmocka_unit_test(test_assertDeprecatedImpl),
cmocka_unit_test(test_assertTrue),
cmocka_unit_test(test_assertFalse),
cmocka_unit_test(test_assertUnreachable),
cmocka_unit_test(test_assertNotNull),
cmocka_unit_test(test_assertNull),
cmocka_unit_test(test_assertDeprecated),
cmocka_unit_test(test_assertStrLenMax),
cmocka_unit_test(test_assertStrLenMin),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}