Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Nov 15, 2023
1 parent 44fe98c commit 1c53c46
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
43 changes: 25 additions & 18 deletions tests/macros_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ BX_NO_INLINE void unusedFunction()
CHECK(false);
}

TEST(macros)
void testAssert()
{
BX_ASSERT(false, "Assert works!");
}

TEST_CASE("Macros", "")
{
uint32_t unused0;
BX_UNUSED(unused0);
Expand All @@ -39,38 +44,40 @@ TEST(macros)
uint32_t unused2;
BX_UNUSED(unused0, unused1, unused2, unusedFunction() );

CHECK_EQUAL(1, BX_VA_ARGS_COUNT(1) );
CHECK_EQUAL(2, BX_VA_ARGS_COUNT(1, 2) );
CHECK_EQUAL(3, BX_VA_ARGS_COUNT(1, 2, 3) );
CHECK_EQUAL(4, BX_VA_ARGS_COUNT(1, 2, 3, 4) );
CHECK_EQUAL(5, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
REQUIRE(1 == BX_VA_ARGS_COUNT(1) );
REQUIRE(2 == BX_VA_ARGS_COUNT(1, 2) );
REQUIRE(3 == BX_VA_ARGS_COUNT(1, 2, 3) );
REQUIRE(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) );
REQUIRE(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
REQUIRE(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );

CHECK_EQUAL(0, bx::strCmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
REQUIRE(0 == bx::strCmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );

{
struct PodStruct { int32_t x, y, z; };
CHECK_EQUAL(0, BX_OFFSETOF(PodStruct, x) );
CHECK_EQUAL(4, BX_OFFSETOF(PodStruct, y) );
CHECK_EQUAL(8, BX_OFFSETOF(PodStruct, z) );
REQUIRE(0 == BX_OFFSETOF(PodStruct, x) );
REQUIRE(4 == BX_OFFSETOF(PodStruct, y) );
REQUIRE(8 == BX_OFFSETOF(PodStruct, z) );
}

{
union PodUnion { int32_t x, y, z; };
CHECK_EQUAL(BX_OFFSETOF(PodUnion, x), BX_OFFSETOF(PodUnion, y) );
CHECK_EQUAL(BX_OFFSETOF(PodUnion, y), BX_OFFSETOF(PodUnion, z) );
REQUIRE(BX_OFFSETOF(PodUnion, x) == BX_OFFSETOF(PodUnion, y) );
REQUIRE(BX_OFFSETOF(PodUnion, y) == BX_OFFSETOF(PodUnion, z) );
}

{
struct NonPodStruct { NonPodStruct() { } int32_t x, y, z; };
CHECK_EQUAL(0, BX_OFFSETOF(NonPodStruct, x) );
CHECK_EQUAL(4, BX_OFFSETOF(NonPodStruct, y) );
CHECK_EQUAL(8, BX_OFFSETOF(NonPodStruct, z) );
REQUIRE(0 == BX_OFFSETOF(NonPodStruct, x) );
REQUIRE(4 == BX_OFFSETOF(NonPodStruct, y) );
REQUIRE(8 == BX_OFFSETOF(NonPodStruct, z) );
}

{
union NonPodUnion { NonPodUnion() { } int32_t x, y, z; };
CHECK_EQUAL(BX_OFFSETOF(NonPodUnion, x), BX_OFFSETOF(NonPodUnion, y) );
CHECK_EQUAL(BX_OFFSETOF(NonPodUnion, y), BX_OFFSETOF(NonPodUnion, z) );
REQUIRE(BX_OFFSETOF(NonPodUnion, x) == BX_OFFSETOF(NonPodUnion, y) );
REQUIRE(BX_OFFSETOF(NonPodUnion, y) == BX_OFFSETOF(NonPodUnion, z) );
}

REQUIRE_ASSERTS(testAssert() );
}
2 changes: 1 addition & 1 deletion tests/run_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool testAssertHandler(const bx::Location& _location, const char* _format, va_li
bx::printf("\n");

// Throwing exceptions is required for testing asserts being trigged.
// Use REQUIRE_THROWS to test asserts.
// Use REQUIRE_ASSERTS to test asserts.
throw std::exception();

return true;
Expand Down
7 changes: 6 additions & 1 deletion tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4312); // warning C4312 : 'reinterpret_cast' :
BX_PRAGMA_DIAGNOSTIC_POP();

#define TEST(_x) TEST_CASE(#_x, "")
#define CHECK_EQUAL(_x, _y) REQUIRE(_x == _y)

#if BX_CONFIG_DEBUG
# define REQUIRE_ASSERTS(_x) REQUIRE_THROWS(_x)
#else
# define REQUIRE_ASSERTS(_x) BX_UNUSED(_x)
#endif // BX_CONFIG_DEBUG

#include "dbg.h"

Expand Down

0 comments on commit 1c53c46

Please sign in to comment.