Adding unit tests.

This commit is contained in:
2023-11-01 23:52:36 -05:00
parent c4032b4a84
commit f573ff8366
14 changed files with 158 additions and 17 deletions

View File

@ -10,3 +10,14 @@ target_sources(${DAWN_TARGET_NAME}
UsageLock.cpp
Xml.cpp
)
# Tests
target_sources(dawntests
PRIVATE
memory.cpp
UsageLock.cpp
Xml.cpp
_test_.memory.cpp
)

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include <catch2/catch_test_macros.hpp>
#include "util/memory.hpp"
#include "assert/assert.hpp"
TEST_CASE("memorycallMalloc", "[memory]") {
SECTION("memory isn't null") {
void *p = memoryCallMalloc(10);
REQUIRE(p != nullptr);
REQUIRE(p != NULL);
memoryCallFree(p);
}
SECTION("memory is writeable") {
void *p = memoryCallMalloc(10);
for(int i = 0; i < 10; i++) {
((char*)p)[i] = 'a';
}
REQUIRE(((char*)p)[0] == 'a');
REQUIRE(((char*)p)[9] == 'a');
memoryCallFree(p);
}
}