-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4865bf6
commit 25dc725
Showing
9 changed files
with
162 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
find_package(Catch2 REQUIRED) | ||
|
||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") | ||
|
||
add_executable(test_cpp_doom ${sources}) | ||
target_link_libraries(test_cpp_doom Catch2::Catch2 lib_common_cpp_doom) | ||
target_compile_definitions(test_cpp_doom PUBLIC CATCH_CONFIG_CONSOLE_WIDTH=300) | ||
target_include_directories(test_cpp_doom PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||
|
||
add_test(NAME test_cpp_doom COMMAND test_cpp_doom) | ||
add_subdirectory(cpp_doom) | ||
add_subdirectory(dehacked) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") | ||
|
||
add_executable(test_cpp_doom ${sources}) | ||
target_link_libraries(test_cpp_doom Catch2::Catch2 lib_common_cpp_doom) | ||
target_compile_definitions(test_cpp_doom PUBLIC CATCH_CONFIG_CONSOLE_WIDTH=300) | ||
target_include_directories(test_cpp_doom PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||
|
||
add_test(NAME test_cpp_doom COMMAND test_cpp_doom) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "z_zone.hpp" | ||
|
||
TEST_CASE("Z_Init", "[z_native]") { | ||
Z_Init(); | ||
// REQUIRE(Z_ZoneSize() == 0x2000000); | ||
} | ||
|
||
#if 0 | ||
|
||
TEST_CASE("Z_Malloc(PU_STATIC)", "[z_native]") { | ||
void * ptr = Z_Malloc(10, PU_STATIC, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL)", "[z_native]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVSPEC)", "[z_native]") { | ||
void * ptr = Z_Malloc(10, PU_LEVSPEC, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL) and Z_Free", "[z_native]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
Z_Free(ptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL) and Z_Free and Z_Malloc(PU_LEVEL)", "[z_native]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
Z_Free(ptr); | ||
void * ptr2 = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr2 != nullptr); | ||
REQUIRE(ptr == ptr2); | ||
} | ||
|
||
#else | ||
|
||
struct memblock_t { | ||
int id; // = ZONEID | ||
int tag; | ||
int size; | ||
void ** user; | ||
memblock_t * prev; | ||
memblock_t * next; | ||
}; | ||
|
||
long * where; | ||
long what; | ||
|
||
TEST_CASE("Z_ZOverwrite header", "[z_native]") { | ||
|
||
void * guard = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(guard != nullptr); | ||
|
||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
|
||
void * guard2 = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(guard2 != nullptr); | ||
|
||
// Corrupt header | ||
where = nullptr; | ||
what = 0x42424242; | ||
|
||
auto * byte_ptr = reinterpret_cast<uint8_t *>(ptr); | ||
auto * header = reinterpret_cast<memblock_t *>(byte_ptr - sizeof(memblock_t)); | ||
REQUIRE(header->tag == PU_LEVEL); | ||
long * what_ptr = &what; | ||
long ** where_ptr = &where; | ||
|
||
auto distance = reinterpret_cast<uint8_t*>(&(header->next)) - reinterpret_cast<uint8_t*>(header); | ||
if constexpr (sizeof(void *) == 8) | ||
REQUIRE(distance == 32); | ||
else | ||
REQUIRE(distance == 20); | ||
|
||
uint8_t * byte_where_ptr = reinterpret_cast<uint8_t*>(where_ptr); | ||
uint8_t * adjusted_byte_where_ptr = byte_where_ptr - distance; | ||
|
||
header->prev = reinterpret_cast<memblock_t *>(adjusted_byte_where_ptr); | ||
header->next = reinterpret_cast<memblock_t *>(what_ptr); | ||
// Corruption done | ||
|
||
// Verify state | ||
REQUIRE(where == nullptr); | ||
|
||
Z_Free(ptr); | ||
|
||
// Check if successful | ||
REQUIRE(where != nullptr); | ||
REQUIRE(*where == 0x42424242); | ||
} | ||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") | ||
|
||
add_executable(test_dehacked ${sources}) | ||
target_link_libraries(test_dehacked Catch2::Catch2 lib_common_dehacked) | ||
target_compile_definitions(test_dehacked PUBLIC CATCH_CONFIG_CONSOLE_WIDTH=300) | ||
target_include_directories(test_dehacked PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||
|
||
add_test(NAME test_dehacked COMMAND test_dehacked) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "z_zone.hpp" | ||
|
||
TEST_CASE("Z_Init", "[z_zone]") { | ||
Z_Init(); | ||
REQUIRE(Z_ZoneSize() == 0x2000000); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_STATIC)", "[z_zone]") { | ||
void * ptr = Z_Malloc(10, PU_STATIC, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL)", "[z_zone]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVSPEC)", "[z_zone]") { | ||
void * ptr = Z_Malloc(10, PU_LEVSPEC, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL) and Z_Free", "[z_zone]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
Z_Free(ptr); | ||
} | ||
|
||
TEST_CASE("Z_Malloc(PU_LEVEL) and Z_Free and Z_Malloc(PU_LEVEL)", "[z_zone]") { | ||
void * ptr = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr != nullptr); | ||
Z_Free(ptr); | ||
void * ptr2 = Z_Malloc(10, PU_LEVEL, nullptr); | ||
REQUIRE(ptr2 != nullptr); | ||
REQUIRE(ptr == ptr2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch2/catch.hpp> |