Added memory checks
Some checks failed
Build Dusk / run-tests (push) Successful in 2m6s
Build Dusk / build-linux (push) Successful in 2m6s
Build Dusk / build-psp (push) Failing after 1m47s

This commit is contained in:
2026-01-06 11:02:26 -06:00
parent af5bf987c8
commit 0df7845f2c
19 changed files with 640 additions and 13 deletions

View File

@@ -104,9 +104,10 @@ static void test_inventorySet(void **state) {
assert_int_equal(inventory.storage[0].quantity, 1);
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
assert_int_equal(inventory.storage[1].quantity, 5);
assert_int_equal(inventory.storage[2].item, ITEM_ID_NULL);
// Setting early item to 0 should shift others down
inventorySet(&inventory, ITEM_ID_POTION, 0);
inventorySet(&inventory, ITEM_ID_POTION, 0);// Item 0 removed
assert_int_equal(inventory.storage[0].item, ITEM_ID_POTATO);
assert_int_equal(inventory.storage[0].quantity, 5);
assert_int_equal(inventory.storage[1].item, ITEM_ID_NULL);
@@ -325,6 +326,40 @@ static void test_inventoryItemFull(void **state) {
inventory.storageSize = 2;
}
static void test_inventorySortById(void **state) {
(void)state;
inventorystack_t storage[5];
inventory_t inventory;
inventoryInit(&inventory, storage, 5);
// Add items out of order
inventorySet(&inventory, ITEM_ID_POTATO, 3);
inventorySet(&inventory, ITEM_ID_APPLE, 5);
inventorySet(&inventory, ITEM_ID_POTION, 2);
// Sort by ID
inventorySortById(&inventory);
// Check order
assert_int_equal(inventory.storage[0].item, ITEM_ID_POTION);
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
assert_int_equal(inventory.storage[2].item, ITEM_ID_APPLE);
// Should fail when given NULL inventory pointer
expect_assert_failure(inventorySortById(NULL));
// Should fail when given NULL storage pointer
inventory.storage = NULL;
expect_assert_failure(inventorySortById(&inventory));
inventory.storage = storage;
// Should fail when given zero storage size
inventory.storageSize = 0;
expect_assert_failure(inventorySortById(&inventory));
inventory.storageSize = 5;
}
int main(int argc, char** argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_inventoryInit),
@@ -335,6 +370,7 @@ int main(int argc, char** argv) {
cmocka_unit_test(test_inventoryGetCount),
cmocka_unit_test(test_inventoryIsFull),
cmocka_unit_test(test_inventoryItemFull),
cmocka_unit_test(test_inventorySortById)
};
return cmocka_run_group_tests(tests, NULL, NULL);