Adding unit tests.
This commit is contained in:
@ -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
|
||||
)
|
27
src/dawn/util/_test_.memory.cpp
Normal file
27
src/dawn/util/_test_.memory.cpp
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user