summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bx/tests')
-rw-r--r--3rdparty/bx/tests/allocator_test.cpp78
-rw-r--r--3rdparty/bx/tests/atomic_test.cpp4
-rw-r--r--3rdparty/bx/tests/crt_test.cpp27
-rw-r--r--3rdparty/bx/tests/dbg.h4
-rw-r--r--3rdparty/bx/tests/easing_test.cpp6
-rw-r--r--3rdparty/bx/tests/filepath_test.cpp9
-rw-r--r--3rdparty/bx/tests/handle_bench.cpp4
-rw-r--r--3rdparty/bx/tests/handle_test.cpp4
-rw-r--r--3rdparty/bx/tests/hash_test.cpp111
-rw-r--r--3rdparty/bx/tests/macros_test.cpp45
-rw-r--r--3rdparty/bx/tests/main_test.cpp8
-rw-r--r--3rdparty/bx/tests/math_bench.cpp32
-rw-r--r--3rdparty/bx/tests/math_test.cpp225
-rw-r--r--3rdparty/bx/tests/nlalloc_test.cpp195
-rw-r--r--3rdparty/bx/tests/os_test.cpp18
-rw-r--r--3rdparty/bx/tests/queue_test.cpp4
-rw-r--r--3rdparty/bx/tests/readerwriter_test.cpp31
-rw-r--r--3rdparty/bx/tests/ringbuffer_test.cpp4
-rw-r--r--3rdparty/bx/tests/rng_test.cpp4
-rw-r--r--3rdparty/bx/tests/run_test.cpp17
-rw-r--r--3rdparty/bx/tests/settings_test.cpp12
-rw-r--r--3rdparty/bx/tests/simd_bench.cpp4
-rw-r--r--3rdparty/bx/tests/simd_test.cpp28
-rw-r--r--3rdparty/bx/tests/sort_test.cpp148
-rw-r--r--3rdparty/bx/tests/string_test.cpp119
-rw-r--r--3rdparty/bx/tests/test.h12
-rw-r--r--3rdparty/bx/tests/thread_test.cpp12
-rw-r--r--3rdparty/bx/tests/tokenizecmd_test.cpp4
-rw-r--r--3rdparty/bx/tests/typetraits_test.cpp688
-rw-r--r--3rdparty/bx/tests/uint32_test.cpp87
-rw-r--r--3rdparty/bx/tests/url_test.cpp4
-rw-r--r--3rdparty/bx/tests/vsnprintf_test.cpp151
32 files changed, 1713 insertions, 386 deletions
diff --git a/3rdparty/bx/tests/allocator_test.cpp b/3rdparty/bx/tests/allocator_test.cpp
new file mode 100644
index 00000000000..635d01a3175
--- /dev/null
+++ b/3rdparty/bx/tests/allocator_test.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
+ */
+
+#include "test.h"
+
+#include <bx/allocator.h>
+
+struct MockNonFreeingAllocator : public bx::AllocatorI
+{
+ MockNonFreeingAllocator()
+ : m_sbrk(1)
+ {
+ }
+
+ ~MockNonFreeingAllocator() override
+ {
+ }
+
+ void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) override
+ {
+ BX_ASSERT(_ptr == NULL, "MockNonFreeingAllocator can't realloc or free.");
+ BX_ASSERT(m_sbrk + _size < BX_COUNTOF(m_storage), "");
+ BX_UNUSED(_ptr, _file, _line);
+
+ const uint32_t sbrk = bx::alignUp(m_sbrk, bx::max(_align, 1) );
+ m_sbrk = sbrk + _size;
+
+ return &m_storage[sbrk];
+ }
+
+ uint32_t m_sbrk;
+ BX_ALIGN_DECL(256, uint8_t) m_storage[0x10000];
+};
+
+bool testAlignment(size_t _expected, void* _ptr)
+{
+ bool aligned = bx::isAligned(_ptr, _expected);
+// BX_TRACE("%p, %d", _ptr, _expected);
+ BX_WARN(aligned, "%p not aligned to %d bytes.", _ptr, _expected);
+ return aligned;
+}
+
+TEST_CASE("Allocator", "")
+{
+ MockNonFreeingAllocator mnfa;
+
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(2, bx::alloc (&mnfa, 1, 2 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(4, bx::alloc (&mnfa, 1, 4 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(8, bx::alloc (&mnfa, 1, 8 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(16, bx::alloc (&mnfa, 1, 16 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(32, bx::alloc (&mnfa, 1, 32 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(64, bx::alloc (&mnfa, 1, 64 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(128, bx::alloc (&mnfa, 1, 128) ) );
+
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(2, bx::alignedAlloc(&mnfa, 1, 2 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(4, bx::alignedAlloc(&mnfa, 1, 4 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(8, bx::alignedAlloc(&mnfa, 1, 8 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(16, bx::alignedAlloc(&mnfa, 1, 16 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(32, bx::alignedAlloc(&mnfa, 1, 32 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(64, bx::alignedAlloc(&mnfa, 1, 64 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(128, bx::alignedAlloc(&mnfa, 1, 128) ) );
+}
diff --git a/3rdparty/bx/tests/atomic_test.cpp b/3rdparty/bx/tests/atomic_test.cpp
index 04a623686e7..a4278f3138f 100644
--- a/3rdparty/bx/tests/atomic_test.cpp
+++ b/3rdparty/bx/tests/atomic_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/crt_test.cpp b/3rdparty/bx/tests/crt_test.cpp
index bda079036ee..68476a12cfa 100644
--- a/3rdparty/bx/tests/crt_test.cpp
+++ b/3rdparty/bx/tests/crt_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -23,14 +23,14 @@ TEST_CASE("memSet", "")
TEST_CASE("memMove", "")
{
- const char* orignal = "xxxxabvgd";
+ const char* original = "xxxxabvgd";
char str[] = { 'x', 'x', 'x', 'x', 'a', 'b', 'v', 'g', 'd' };
bx::memMove(&str[4], &str[4], 0);
- REQUIRE(0 == bx::memCmp(str, orignal, 9) );
+ REQUIRE(0 == bx::memCmp(str, original, 9) );
bx::memMove(&str[4], &str[4], 5);
- REQUIRE(0 == bx::memCmp(str, orignal, 9) );
+ REQUIRE(0 == bx::memCmp(str, original, 9) );
bx::memMove(str, &str[4], 5);
REQUIRE(0 == bx::memCmp(str, "abvgd", 5) );
@@ -39,5 +39,20 @@ TEST_CASE("memMove", "")
REQUIRE(str[4] == 'a' );
bx::memSet(str, 'x', 4);
- REQUIRE(0 == bx::memCmp(str, orignal, 9) );
+ REQUIRE(0 == bx::memCmp(str, original, 9) );
+}
+
+TEST_CASE("scatter/gather", "")
+{
+ const char* str = "a\0b\0v\0g\0d";
+
+ char tmp0[64];
+ bx::gather(tmp0, str, 2, 1, 5);
+ REQUIRE(0 == bx::memCmp(tmp0, "abvgd", 5) );
+
+ char tmp1[64];
+ bx::scatter(tmp1, 2, tmp0, 1, 5);
+ bx::memSet(&tmp1[1], 2, 0, 1, 5);
+ REQUIRE(0 == bx::memCmp(tmp1, str, 5) );
+
}
diff --git a/3rdparty/bx/tests/dbg.h b/3rdparty/bx/tests/dbg.h
index 243dc234afc..9aee6bb77a4 100644
--- a/3rdparty/bx/tests/dbg.h
+++ b/3rdparty/bx/tests/dbg.h
@@ -1,6 +1,6 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2011-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#ifndef DBG_H_HEADER_GUARD
diff --git a/3rdparty/bx/tests/easing_test.cpp b/3rdparty/bx/tests/easing_test.cpp
index 06944547f4a..44f6f7f987e 100644
--- a/3rdparty/bx/tests/easing_test.cpp
+++ b/3rdparty/bx/tests/easing_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -42,7 +42,7 @@ TEST_CASE("easing", "")
if (vv >= ys
&& vv < ye)
{
- bx::write(writer, "*");
+ bx::write(writer, &err, "*");
break;
}
}
diff --git a/3rdparty/bx/tests/filepath_test.cpp b/3rdparty/bx/tests/filepath_test.cpp
index 2662adeddf1..7484c48eab8 100644
--- a/3rdparty/bx/tests/filepath_test.cpp
+++ b/3rdparty/bx/tests/filepath_test.cpp
@@ -1,10 +1,10 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
-#include <bx/filepath.h>
+#include <bx/file.h>
struct FilePathTest
{
@@ -96,9 +96,8 @@ TEST_CASE("FilePath", "")
const FilePathTest& test = s_filePathTest[ii];
fp.set(test.filePath);
- const bx::StringView result = fp.get();
- REQUIRE(0 == bx::strCmp(test.expected, result) );
+ REQUIRE(0 == bx::strCmp(test.expected, fp) );
}
for (uint32_t ii = 0; ii < BX_COUNTOF(s_filePathSplit); ++ii)
diff --git a/3rdparty/bx/tests/handle_bench.cpp b/3rdparty/bx/tests/handle_bench.cpp
index 4effb59758e..f6f1b203fc5 100644
--- a/3rdparty/bx/tests/handle_bench.cpp
+++ b/3rdparty/bx/tests/handle_bench.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include <bx/timer.h>
diff --git a/3rdparty/bx/tests/handle_test.cpp b/3rdparty/bx/tests/handle_test.cpp
index eb89b1f67a9..0d91e51883d 100644
--- a/3rdparty/bx/tests/handle_test.cpp
+++ b/3rdparty/bx/tests/handle_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/hash_test.cpp b/3rdparty/bx/tests/hash_test.cpp
index 1ec6702080e..cc827aee0fc 100644
--- a/3rdparty/bx/tests/hash_test.cpp
+++ b/3rdparty/bx/tests/hash_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -29,19 +29,22 @@ void makeCrcTable(uint32_t _poly)
struct HashTest
{
- uint32_t crc32;
+ uint32_t crc32[bx::HashCrc32::Count];
uint32_t adler32;
+ uint32_t murmur2a;
const char* input;
};
const HashTest s_hashTest[] =
{
- { 0, 1, "" },
- { 0xe8b7be43, 0x00620062, "a" },
- { 0x9e83486d, 0x012600c4, "ab" },
- { 0xc340daab, 0x06060205, "abvgd" },
- { 0x07642fe2, 0x020a00d6, "1389" },
- { 0x26d75737, 0x04530139, "555333" },
+ // Crc32 | Adler32 | Murmur2A | Input
+ // Ieee Castagnoli Koopman | | |
+ { { 0, 0, 0 }, 1, 0, "" },
+ { { 0xe8b7be43, 0xc1d04330, 0x0da2aa8a }, 0x00620062, 0x0803888b, "a" },
+ { { 0x9e83486d, 0xe2a22936, 0x31ec935a }, 0x012600c4, 0x618515af, "ab" },
+ { { 0xc340daab, 0x49e1b6e3, 0x945a1e78 }, 0x06060205, 0x94e3dc4d, "abvgd" },
+ { { 0x07642fe2, 0x45a04162, 0x3d4bf72d }, 0x020a00d6, 0xe602fc07, "1389" },
+ { { 0x26d75737, 0xb73d7b80, 0xd524eb40 }, 0x04530139, 0x58d37863, "555333" },
};
TEST_CASE("HashCrc32", "")
@@ -58,10 +61,13 @@ TEST_CASE("HashCrc32", "")
{
const HashTest& test = s_hashTest[ii];
- bx::HashCrc32 hash;
- hash.begin();
- hash.add(test.input, bx::strLen(test.input) );
- REQUIRE(test.crc32 == hash.end() );
+ for (uint32_t jj = 0; jj < bx::HashCrc32::Count; ++jj)
+ {
+ bx::HashCrc32 hash;
+ hash.begin(bx::HashCrc32::Enum(jj) );
+ hash.add(test.input, bx::strLen(test.input) );
+ REQUIRE(test.crc32[jj] == hash.end() );
+ }
}
}
@@ -77,3 +83,82 @@ TEST_CASE("HashAdler32", "")
REQUIRE(test.adler32 == hash.end() );
}
}
+
+/*-----------------------------------------------------------------------------
+// MurmurHash2A, by Austin Appleby
+//
+// This is a variant of MurmurHash2 modified to use the Merkle-Damgard
+// construction. Bulk speed should be identical to Murmur2, small-key speed
+// will be 10%-20% slower due to the added overhead at the end of the hash.
+//
+// This variant fixes a minor issue where null keys were more likely to
+// collide with each other than expected, and also makes the function
+// more amenable to incremental implementations.
+*/
+
+#define mmix(h,k) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; }
+
+uint32_t MurmurHash2A(const void * key, int len, uint32_t seed = 0)
+{
+ const uint32_t m = 0x5bd1e995;
+ const int r = 24;
+ uint32_t l = len;
+
+ const unsigned char * data = (const unsigned char *)key;
+
+ uint32_t h = seed;
+
+ while(len >= 4)
+ {
+ uint32_t k = *(uint32_t*)data;
+
+ mmix(h,k);
+
+ data += 4;
+ len -= 4;
+ }
+
+ uint32_t t = 0;
+
+ switch(len)
+ {
+ case 3: t ^= data[2] << 16; BX_FALLTHROUGH;
+ case 2: t ^= data[1] << 8; BX_FALLTHROUGH;
+ case 1: t ^= data[0];
+ };
+
+ mmix(h,t);
+ mmix(h,l);
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
+
+TEST_CASE("HashMurmur2A", "")
+{
+ uint32_t seed = 0;
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_hashTest); ++ii)
+ {
+ const HashTest& test = s_hashTest[ii];
+
+ bx::HashMurmur2A hash;
+ hash.begin(seed);
+ hash.add(test.input, bx::strLen(test.input) );
+ REQUIRE(test.murmur2a == hash.end() );
+
+ REQUIRE(test.murmur2a == MurmurHash2A(test.input, bx::strLen(test.input), seed) );
+ }
+}
+
+TEST_CASE("HashMurmur2A-Separate-Add", "")
+{
+ bx::HashMurmur2A hash;
+ hash.begin();
+ hash.add("0123456789");
+ hash.add("abvgd012345");
+ REQUIRE(MurmurHash2A("0123456789abvgd012345", 21) == hash.end() );
+}
diff --git a/3rdparty/bx/tests/macros_test.cpp b/3rdparty/bx/tests/macros_test.cpp
index e0d5ffae8b4..75081b95d70 100644
--- a/3rdparty/bx/tests/macros_test.cpp
+++ b/3rdparty/bx/tests/macros_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -13,7 +13,6 @@ BX_STATIC_ASSERT(false
|| BX_CRT_LIBCXX
|| BX_CRT_MINGW
|| BX_CRT_MSVC
- || BX_CRT_MUSL
|| BX_CRT_NEWLIB
);
@@ -24,20 +23,6 @@ BX_STATIC_ASSERT(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) );
BX_STATIC_ASSERT(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
BX_STATIC_ASSERT(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
-BX_STATIC_ASSERT( 0 == BX_ALIGN_16( 0) );
-BX_STATIC_ASSERT( 16 == BX_ALIGN_16( 1) );
-BX_STATIC_ASSERT( 16 == BX_ALIGN_16( 15) );
-BX_STATIC_ASSERT( 16 == BX_ALIGN_16( 16) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_16(255) );
-
-BX_STATIC_ASSERT( 0 == BX_ALIGN_256( 0) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_256( 1) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_256( 15) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_256(255) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_256(256) );
-BX_STATIC_ASSERT(256 == BX_ALIGN_256(256) );
-BX_STATIC_ASSERT(512 == BX_ALIGN_256(511) );
-
BX_NO_INLINE void unusedFunction()
{
CHECK(false);
@@ -62,4 +47,30 @@ TEST(macros)
CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
CHECK_EQUAL(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) );
+ }
+
+ {
+ 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) );
+ }
+
+ {
+ 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) );
+ }
+
+ {
+ 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) );
+ }
}
diff --git a/3rdparty/bx/tests/main_test.cpp b/3rdparty/bx/tests/main_test.cpp
index b9e9074a8ea..93ee589e601 100644
--- a/3rdparty/bx/tests/main_test.cpp
+++ b/3rdparty/bx/tests/main_test.cpp
@@ -1,17 +1,17 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
-static const char* s_argv[] = { "bx.test" };
-
int runAllTests(int _argc, const char* _argv[]);
#if BX_PLATFORM_ANDROID
# include <android/native_activity.h>
+static const char* s_argv[] = { "bx.test" };
+
void ANativeActivity_onCreate(ANativeActivity*, void*, size_t)
{
exit(runAllTests(BX_COUNTOF(s_argv), s_argv) );
diff --git a/3rdparty/bx/tests/math_bench.cpp b/3rdparty/bx/tests/math_bench.cpp
index 50a8b3d2301..488369cad4e 100644
--- a/3rdparty/bx/tests/math_bench.cpp
+++ b/3rdparty/bx/tests/math_bench.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include <bx/math.h>
@@ -60,6 +60,10 @@ void math_bench()
mathTest<bx::sin >("bx::sin");
bx::write(writer, &err, "\n");
+ mathTest< ::sinhf>(" ::sinhf");
+ mathTest<bx::sinh >("bx::sinh");
+
+ bx::write(writer, &err, "\n");
mathTest< ::asinf>(" ::asinf");
mathTest<bx::asin >("bx::asin");
@@ -68,6 +72,10 @@ void math_bench()
mathTest<bx::cos >("bx::cos");
bx::write(writer, &err, "\n");
+ mathTest< ::coshf>(" ::coshf");
+ mathTest<bx::cosh >("bx::cosh");
+
+ bx::write(writer, &err, "\n");
mathTest< ::acosf>(" ::acosf");
mathTest<bx::acos >("bx::acos");
@@ -76,6 +84,26 @@ void math_bench()
mathTest<bx::tan >("bx::tan");
bx::write(writer, &err, "\n");
+ mathTest< ::tanhf>(" ::tanhf");
+ mathTest<bx::tanh >("bx::tanh");
+
+ bx::write(writer, &err, "\n");
mathTest< ::atanf>(" ::atanf");
mathTest<bx::atan >("bx::atan");
+
+ bx::write(writer, &err, "\n");
+ mathTest< ::expf>(" ::expf");
+ mathTest<bx::exp >("bx::exp");
+
+ bx::write(writer, &err, "\n");
+ mathTest< ::exp2f>(" ::exp2f");
+ mathTest<bx::exp2 >("bx::exp2");
+
+ bx::write(writer, &err, "\n");
+ mathTest< ::logf >(" ::logf");
+ mathTest<bx::log >("bx::log");
+
+ bx::write(writer, &err, "\n");
+ mathTest< ::log2f>(" ::log2f");
+ mathTest<bx::log2 >("bx::log2");
}
diff --git a/3rdparty/bx/tests/math_test.cpp b/3rdparty/bx/tests/math_test.cpp
index 2eeac286282..511655940df 100644
--- a/3rdparty/bx/tests/math_test.cpp
+++ b/3rdparty/bx/tests/math_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -8,6 +8,8 @@
#include <bx/file.h>
#include <math.h>
+#include <stdint.h> // intXX_t
+#include <limits.h> // UCHAR_*
#if !BX_COMPILER_MSVC || BX_COMPILER_MSVC >= 1800
TEST_CASE("isFinite, isInfinite, isNan", "")
@@ -31,11 +33,39 @@ TEST_CASE("log2", "")
{
log2_test(0.0f);
log2_test(256.0f);
+
+ REQUIRE(0.0f == bx::log2(1.0f) );
+ REQUIRE(0 == bx::log2(1) );
+
+ REQUIRE(1.0f == bx::log2(2.0f) );
+ REQUIRE(1 == bx::log2(2) );
+
+ REQUIRE(2.0f == bx::log2(4.0f) );
+ REQUIRE(2 == bx::log2(4) );
+
+ REQUIRE(3.0f == bx::log2(8.0f) );
+ REQUIRE(3 == bx::log2(8) );
+
+ REQUIRE(4.0f == bx::log2(16.0f) );
+ REQUIRE(4 == bx::log2(16) );
+
+ REQUIRE(5.0f == bx::log2(32.0f) );
+ REQUIRE(5 == bx::log2(32) );
+
+ REQUIRE(6.0f == bx::log2(64.0f) );
+ REQUIRE(6 == bx::log2(64) );
+
+ REQUIRE(7.0f == bx::log2(128.0f) );
+ REQUIRE(7 == bx::log2(128) );
+
+ REQUIRE(8.0f == bx::log2(256.0f) );
+ REQUIRE(8 == bx::log2(256) );
}
TEST_CASE("libm", "")
{
bx::WriterI* writer = bx::getNullOut();
+ bx::Error err;
REQUIRE(1389.0f == bx::abs(-1389.0f) );
REQUIRE(1389.0f == bx::abs( 1389.0f) );
@@ -43,7 +73,6 @@ TEST_CASE("libm", "")
REQUIRE( 0.0f == bx::abs( 0.0f) );
REQUIRE(389.0f == bx::mod(1389.0f, 1000.0f) );
- REQUIRE(bx::isNan(bx::mod(0.0f, 0.0f) ) );
REQUIRE( 13.0f == bx::floor( 13.89f) );
REQUIRE(-14.0f == bx::floor(-13.89f) );
@@ -52,17 +81,15 @@ TEST_CASE("libm", "")
REQUIRE( 13.0f == bx::trunc( 13.89f) );
REQUIRE(-13.0f == bx::trunc(-13.89f) );
- REQUIRE(bx::equal( 0.89f, bx::fract( 13.89f), 0.000001f) );
- REQUIRE(bx::equal(-0.89f, bx::fract(-13.89f), 0.000001f) );
-
- bx::Error err;
+ REQUIRE(bx::isEqual( 0.89f, bx::fract( 13.89f), 0.000001f) );
+ REQUIRE(bx::isEqual(-0.89f, bx::fract(-13.89f), 0.000001f) );
for (int32_t yy = -10; yy < 10; ++yy)
{
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "ldexp(%f, %d) == %f (expected: %f)\n", xx, yy, bx::ldexp(xx, yy), ::ldexpf(xx, yy) );
- REQUIRE(bx::equal(bx::ldexp(xx, yy), ::ldexpf(xx, yy), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::ldexp(xx, yy), ::ldexpf(xx, yy), 0.00001f) );
}
}
@@ -70,85 +97,116 @@ TEST_CASE("libm", "")
{
bx::write(writer, &err, "exp(%f) == %f (expected: %f)\n", xx, bx::exp(xx), ::expf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::exp(xx), ::expf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::exp(xx), ::expf(xx), 0.00001f) );
}
for (float xx = 0.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "rsqrt(%f) == %f (expected: %f)\n", xx, bx::rsqrt(xx), 1.0f/::sqrtf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::rsqrt(xx), 1.0f/::sqrtf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::rsqrt(xx), 1.0f/::sqrtf(xx), 0.00001f) );
+ }
+
+ for (float xx = 0.0f; xx < 1000000.0f; xx += 1000.f)
+ {
+ bx::write(writer, &err, "sqrt(%f) == %f (expected: %f)\n", xx, bx::sqrt(xx), ::sqrtf(xx) );
+ REQUIRE(err.isOk() );
+ REQUIRE(bx::isEqual(bx::sqrt(xx), ::sqrtf(xx), 0.00001f) );
}
for (float xx = 0.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "sqrt(%f) == %f (expected: %f)\n", xx, bx::sqrt(xx), ::sqrtf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::sqrt(xx), ::sqrtf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::sqrt(xx), ::sqrtf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "pow(1.389f, %f) == %f (expected: %f)\n", xx, bx::pow(1.389f, xx), ::powf(1.389f, xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::pow(1.389f, xx), ::powf(1.389f, xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::pow(1.389f, xx), ::powf(1.389f, xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.001f)
{
bx::write(writer, &err, "asin(%f) == %f (expected: %f)\n", xx, bx::asin(xx), ::asinf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::asin(xx), ::asinf(xx), 0.0001f) );
+ REQUIRE(bx::isEqual(bx::asin(xx), ::asinf(xx), 0.0001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "sin(%f) == %f (expected: %f)\n", xx, bx::sin(xx), ::sinf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::sin(xx), ::sinf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::sin(xx), ::sinf(xx), 0.00001f) );
+ }
+
+ for (float xx = -bx::kPi2; xx < bx::kPi2; xx += 0.0001f)
+ {
+ bx::write(writer, &err, "sin(%f) == %f (expected: %f)\n", xx, bx::sin(xx), ::sinf(xx) );
+ REQUIRE(err.isOk() );
+ REQUIRE(bx::isEqual(bx::sin(xx), ::sinf(xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.1f)
{
bx::write(writer, &err, "sinh(%f) == %f (expected: %f)\n", xx, bx::sinh(xx), ::sinhf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::sinh(xx), ::sinhf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::sinh(xx), ::sinhf(xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.001f)
{
bx::write(writer, &err, "acos(%f) == %f (expected: %f\n)", xx, bx::acos(xx), ::acosf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::acos(xx), ::acosf(xx), 0.0001f) );
+ REQUIRE(bx::isEqual(bx::acos(xx), ::acosf(xx), 0.0001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "cos(%f) == %f (expected: %f)\n", xx, bx::cos(xx), ::cosf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::cos(xx), ::cosf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::cos(xx), ::cosf(xx), 0.00001f) );
+ }
+
+ for (float xx = -bx::kPi2; xx < bx::kPi2; xx += 0.0001f)
+ {
+ bx::write(writer, &err, "cos(%f) == %f (expected: %f)\n", xx, bx::cos(xx), ::cosf(xx) );
+ REQUIRE(err.isOk() );
+ REQUIRE(bx::isEqual(bx::cos(xx), ::cosf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "tan(%f) == %f (expected: %f)\n", xx, bx::tan(xx), ::tanf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::tan(xx), ::tanf(xx), 0.001f) );
+ REQUIRE(bx::isEqual(bx::tan(xx), ::tanf(xx), 0.001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.1f)
{
bx::write(writer, &err, "tanh(%f) == %f (expected: %f\n", xx, bx::tanh(xx), ::tanhf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::tanh(xx), ::tanhf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::tanh(xx), ::tanhf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "atan(%f) == %f (expected: %f)\n", xx, bx::atan(xx), ::atanf(xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::atan(xx), ::atanf(xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::atan(xx), ::atanf(xx), 0.00001f) );
}
+}
+
+TEST_CASE("atan2", "")
+{
+ bx::WriterI* writer = bx::getNullOut();
+ bx::Error err;
+
+ REQUIRE(bx::isEqual(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::atan2(0.0f, 1.0f), ::atan2f(0.0f, 1.0f), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::atan2(0.0f, -1.0f), ::atan2f(0.0f, -1.0f), 0.00001f) );
for (float yy = -100.0f; yy < 100.0f; yy += 0.1f)
{
@@ -156,11 +214,16 @@ TEST_CASE("libm", "")
{
bx::write(writer, &err, "atan2(%f, %f) == %f (expected: %f)\n", yy, xx, bx::atan2(yy, xx), ::atan2f(yy, xx) );
REQUIRE(err.isOk() );
- REQUIRE(bx::equal(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) );
+ REQUIRE(bx::isEqual(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) );
}
}
+}
- REQUIRE(bx::equal(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) );
+TEST_CASE("sign", "")
+{
+ REQUIRE(-1 == bx::sign(-0.1389f) );
+ REQUIRE( 0 == bx::sign( 0.0000f) );
+ REQUIRE( 1 == bx::sign( 0.1389f) );
}
TEST_CASE("ToBits", "")
@@ -169,9 +232,16 @@ TEST_CASE("ToBits", "")
REQUIRE(UINT64_C(0x123456789abcdef0) == bx::doubleToBits(bx::bitsToDouble(UINT32_C(0x123456789abcdef0) ) ) );
}
+TEST_CASE("lerp", "")
+{
+ REQUIRE(1389.0f == bx::lerp(1389.0f, 1453.0f, 0.0f) );
+ REQUIRE(1453.0f == bx::lerp(1389.0f, 1453.0f, 1.0f) );
+ REQUIRE(0.5f == bx::lerp(0.0f, 1.0f, 0.5f) );
+}
+
void mtxCheck(const float* _a, const float* _b)
{
- if (!bx::equal(_a, _b, 16, 0.01f) )
+ if (!bx::isEqual(_a, _b, 16, 0.01f) )
{
DBG("\n"
"A:\n"
@@ -194,7 +264,7 @@ void mtxCheck(const float* _a, const float* _b)
, _b[12], _b[13], _b[14], _b[15]
);
- CHECK(false);
+ REQUIRE(false);
}
}
@@ -203,8 +273,14 @@ TEST_CASE("quaternion", "")
float mtxQ[16];
float mtx[16];
- float quat[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
- bx::mtxQuat(mtxQ, quat);
+ bx::Quaternion quat = bx::init::Identity;
+ bx::Quaternion q2 = bx::init::None;
+
+ bx::Vec3 axis = bx::init::None;
+ bx::Vec3 euler = bx::init::None;
+ float angle;
+
+ bx::mtxFromQuaternion(mtxQ, quat);
bx::mtxIdentity(mtx);
mtxCheck(mtxQ, mtx);
@@ -212,28 +288,87 @@ TEST_CASE("quaternion", "")
float ay = bx::kPi/13.0f;
float az = bx::kPi/7.0f;
- bx::quatRotateX(quat, ax);
- bx::mtxQuat(mtxQ, quat);
- bx::mtxRotateX(mtx, ax);
- mtxCheck(mtxQ, mtx);
+ { // x
+ quat = bx::rotateX(ax);
+ bx::mtxFromQuaternion(mtxQ, quat);
+ bx::mtxRotateX(mtx, ax);
+ mtxCheck(mtxQ, mtx);
- float euler[3];
- bx::quatToEuler(euler, quat);
- CHECK(bx::equal(euler[0], ax, 0.001f) );
+ bx::toAxisAngle(axis, angle, quat);
+ REQUIRE(bx::isEqual(axis, bx::Vec3{1.0f, 0.0f, 0.0f}, 0.01f) );
+ REQUIRE(bx::isEqual(angle, ax, 0.01f) );
- bx::quatRotateY(quat, ay);
- bx::mtxQuat(mtxQ, quat);
- bx::mtxRotateY(mtx, ay);
- mtxCheck(mtxQ, mtx);
+ euler = bx::toEuler(quat);
+ REQUIRE(bx::isEqual(euler.x, ax, 0.001f) );
+ q2 = bx::fromEuler(euler);
+ REQUIRE(bx::isEqual(quat, q2, 0.001f) );
+ }
- bx::quatToEuler(euler, quat);
- CHECK(bx::equal(euler[1], ay, 0.001f) );
+ { // y
+ quat = bx::rotateY(ay);
+ bx::mtxFromQuaternion(mtxQ, quat);
+ bx::mtxRotateY(mtx, ay);
+ mtxCheck(mtxQ, mtx);
- bx::quatRotateZ(quat, az);
- bx::mtxQuat(mtxQ, quat);
- bx::mtxRotateZ(mtx, az);
- mtxCheck(mtxQ, mtx);
+ bx::toAxisAngle(axis, angle, quat);
+ REQUIRE(bx::isEqual(axis, bx::Vec3{0.0f, 1.0f, 0.0f}, 0.01f) );
+ REQUIRE(bx::isEqual(angle, ay, 0.01f) );
+ euler = bx::toEuler(quat);
+ REQUIRE(bx::isEqual(euler.y, ay, 0.001f) );
+ q2 = bx::fromEuler(euler);
+ REQUIRE(bx::isEqual(quat, q2, 0.001f) );
+
+ }
+
+ { // z
+ quat = bx::rotateZ(az);
+ bx::mtxFromQuaternion(mtxQ, quat);
+ bx::mtxRotateZ(mtx, az);
+ mtxCheck(mtxQ, mtx);
+
+ bx::toAxisAngle(axis, angle, quat);
+ REQUIRE(bx::isEqual(axis, bx::Vec3{0.0f, 0.0f, 1.0f}, 0.01f) );
+ REQUIRE(bx::isEqual(angle, az, 0.01f) );
+
+ euler = bx::toEuler(quat);
+ REQUIRE(bx::isEqual(euler.z, az, 0.001f) );
+ q2 = bx::fromEuler(euler);
+ REQUIRE(bx::isEqual(quat, q2, 0.001f) );
+ }
+}
+
+TEST_CASE("limits", "")
+{
+ STATIC_REQUIRE(bx::LimitsT<int8_t>::min == INT8_MIN);
+ STATIC_REQUIRE(bx::LimitsT<int8_t>::max == INT8_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<signed char>::min == CHAR_MIN);
+ STATIC_REQUIRE(bx::LimitsT<signed char>::max == CHAR_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<unsigned char>::min == 0);
+ STATIC_REQUIRE(bx::LimitsT<unsigned char>::max == UCHAR_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<int16_t>::min == INT16_MIN);
+ STATIC_REQUIRE(bx::LimitsT<int16_t>::max == INT16_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<uint16_t>::min == 0);
+ STATIC_REQUIRE(bx::LimitsT<uint16_t>::max == UINT16_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<int32_t>::min == INT32_MIN);
+ STATIC_REQUIRE(bx::LimitsT<int32_t>::max == INT32_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<uint32_t>::min == 0);
+ STATIC_REQUIRE(bx::LimitsT<uint32_t>::max == UINT32_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<int64_t>::min == INT64_MIN);
+ STATIC_REQUIRE(bx::LimitsT<int64_t>::max == INT64_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<uint64_t>::min == 0);
+ STATIC_REQUIRE(bx::LimitsT<uint64_t>::max == UINT64_MAX);
+
+ STATIC_REQUIRE(bx::LimitsT<float>::min == std::numeric_limits<float>::lowest() );
+ STATIC_REQUIRE(bx::LimitsT<float>::max == std::numeric_limits<float>::max() );
- bx::quatToEuler(euler, quat);
- CHECK(bx::equal(euler[2], az, 0.001f) );
+ STATIC_REQUIRE(bx::LimitsT<double>::min == std::numeric_limits<double>::lowest() );
+ STATIC_REQUIRE(bx::LimitsT<double>::max == std::numeric_limits<double>::max() );
}
diff --git a/3rdparty/bx/tests/nlalloc_test.cpp b/3rdparty/bx/tests/nlalloc_test.cpp
deleted file mode 100644
index 91b0354926f..00000000000
--- a/3rdparty/bx/tests/nlalloc_test.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
- */
-
-#include "test.h"
-#include <bx/sort.h>
-#include <bx/allocator.h>
-
-bx::DefaultAllocator g_allocator0;
-
-struct TinyStlAllocator
-{
- static void* static_allocate(size_t _bytes)
- {
- return BX_ALLOC(&g_allocator0, _bytes);
- }
-
- static void static_deallocate(void* _ptr, size_t /*_bytes*/)
- {
- if (NULL != _ptr)
- {
- BX_FREE(&g_allocator0, _ptr);
- }
- }
-};
-
-#define TINYSTL_ALLOCATOR ::TinyStlAllocator
-#include <tinystl/vector.h>
-
-namespace stl = tinystl;
-
-namespace bx
-{
- struct Blk
- {
- static const uint64_t kInvalid = UINT64_MAX;
-
- Blk()
- : ptr(kInvalid)
- , size(0)
- {
- }
-
- Blk(uint64_t _ptr, uint32_t _size)
- : ptr(_ptr)
- , size(_size)
- {
- }
-
- uint64_t ptr;
- uint32_t size;
- };
-
- inline bool operator<(const Blk& _lhs, const Blk& _rhs)
- {
- return _lhs.ptr < _rhs.ptr;
- }
-
- inline bool isValid(const Blk& _blk)
- {
- return Blk::kInvalid != _blk.ptr;
- }
-
- // First-fit non-local allocator.
- class NonLocalAllocator
- {
- public:
- NonLocalAllocator()
- {
- reset();
- }
-
- ~NonLocalAllocator()
- {
- }
-
- void reset()
- {
- m_free.clear();
- m_used = 0;
- }
-
- void add(const Blk& _blk)
- {
- m_free.push_back(_blk);
- }
-
- Blk remove()
- {
- BX_CHECK(0 == m_used, "");
-
- if (0 < m_free.size() )
- {
- Blk freeBlock = m_free.back();
- m_free.pop_back();
- return freeBlock;
- }
-
- return Blk{};
- }
-
- Blk alloc(uint32_t _size)
- {
- _size = max(_size, 16u);
-
- for (FreeList::iterator it = m_free.begin(), itEnd = m_free.end(); it != itEnd; ++it)
- {
- if (it->size >= _size)
- {
- uint64_t ptr = it->ptr;
-
- if (it->size != _size)
- {
- it->size -= _size;
- it->ptr += _size;
- }
- else
- {
- m_free.erase(it);
- }
-
- m_used += _size;
- return Blk{ ptr, _size };
- }
- }
-
- // there is no block large enough.
- return Blk{};
- }
-
- void free(const Blk& _blk)
- {
- m_used -= _blk.size;
- m_free.push_back(_blk);
- compact();
- }
-
- bool compact()
- {
- bx::quickSort(
- m_free.begin()
- , uint32_t(m_free.end() - m_free.begin() )
- , sizeof(Blk)
- , [](const void* _a, const void* _b) -> int32_t {
- const Blk& lhs = *(const Blk*)(_a);
- const Blk& rhs = *(const Blk*)(_b);
- return lhs < rhs ? -1 : 1;
- });
-
- for (FreeList::iterator it = m_free.begin(), next = it, itEnd = m_free.end(); next != itEnd;)
- {
- if ( (it->ptr + it->size) == next->ptr)
- {
- it->size += next->size;
- next = m_free.erase(next);
- }
- else
- {
- it = next;
- ++next;
- }
- }
-
- return 0 == m_used;
- }
-
- uint32_t getUsed() const
- {
- return m_used;
- }
-
- private:
- typedef stl::vector<Blk> FreeList;
- FreeList m_free;
- uint32_t m_used;
- };
-} // namespace bx
-
-TEST_CASE("nlalloc")
-{
- bx::NonLocalAllocator nla;
-
- bx::Blk blk;
-
- blk = nla.alloc(100);
- REQUIRE(!isValid(blk) );
- nla.add(bx::Blk{0x1000, 100});
-
- blk = nla.alloc(100);
- REQUIRE(isValid(blk) );
-
- nla.free(blk);
- REQUIRE(0 == nla.getUsed() );
-}
diff --git a/3rdparty/bx/tests/os_test.cpp b/3rdparty/bx/tests/os_test.cpp
index bf51c725e05..6f1151558c3 100644
--- a/3rdparty/bx/tests/os_test.cpp
+++ b/3rdparty/bx/tests/os_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -14,15 +14,19 @@ TEST_CASE("getProcessMemoryUsed", "")
// DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() );
}
+#if BX_CONFIG_SUPPORTS_THREADING
+
TEST_CASE("semaphore_timeout", "")
{
bx::Semaphore sem;
- int64_t start = bx::getHPCounter();
- bool ok = sem.wait(900);
- int64_t elapsed = bx::getHPCounter() - start;
+ int64_t start = bx::getHPCounter();
+ bool ok = sem.wait(900);
+ int64_t elapsed = bx::getHPCounter() - start;
int64_t frequency = bx::getHPFrequency();
- double ms = double(elapsed) / double(frequency) * 1000;
- printf("%f\n", ms);
+ double ms = double(elapsed) / double(frequency) * 1000;
+ bx::printf("%f\n", ms);
REQUIRE(!ok);
}
+
+#endif // BX_CONFIG_SUPPORTS_THREADING
diff --git a/3rdparty/bx/tests/queue_test.cpp b/3rdparty/bx/tests/queue_test.cpp
index 4a4d5c9a325..253b52667f0 100644
--- a/3rdparty/bx/tests/queue_test.cpp
+++ b/3rdparty/bx/tests/queue_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/readerwriter_test.cpp b/3rdparty/bx/tests/readerwriter_test.cpp
new file mode 100644
index 00000000000..96e77a0a098
--- /dev/null
+++ b/3rdparty/bx/tests/readerwriter_test.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
+ */
+
+#include "test.h"
+#include <bx/readerwriter.h>
+
+TEST_CASE("writeLE", "")
+{
+ bx::SizerWriter writer;
+
+ bx::Error err;
+
+ int32_t total = bx::writeLE(&writer, 1.0f, &err);
+
+ REQUIRE(err.isOk() );
+ REQUIRE(total == 4);
+}
+
+TEST_CASE("writeBE", "")
+{
+ bx::SizerWriter writer;
+
+ bx::Error err;
+
+ int32_t total = bx::writeBE(&writer, 1.0f, &err);
+
+ REQUIRE(err.isOk() );
+ REQUIRE(total == 4);
+}
diff --git a/3rdparty/bx/tests/ringbuffer_test.cpp b/3rdparty/bx/tests/ringbuffer_test.cpp
index d0d2a426572..11629fc6c14 100644
--- a/3rdparty/bx/tests/ringbuffer_test.cpp
+++ b/3rdparty/bx/tests/ringbuffer_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/rng_test.cpp b/3rdparty/bx/tests/rng_test.cpp
index b5161f7167e..a06b7747f17 100644
--- a/3rdparty/bx/tests/rng_test.cpp
+++ b/3rdparty/bx/tests/rng_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/run_test.cpp b/3rdparty/bx/tests/run_test.cpp
index 090c1186c0c..b2b43d8fede 100644
--- a/3rdparty/bx/tests/run_test.cpp
+++ b/3rdparty/bx/tests/run_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#define CATCH_CONFIG_RUNNER
@@ -15,6 +15,17 @@ int runAllTests(int _argc, const char* _argv[])
", CRT: " BX_CRT_NAME
", Date: " __DATE__
", Time: " __TIME__
+ ", C++: " BX_CPP_NAME
);
- return Catch::Session().run(_argc, _argv);
+
+ using namespace Catch;
+
+ Session session;
+
+ ConfigData config;
+ config.defaultColourMode = BX_PLATFORM_EMSCRIPTEN ? ColourMode::None : ColourMode::PlatformDefault;
+
+ session.useConfigData(config);
+
+ return session.run(_argc, _argv);
}
diff --git a/3rdparty/bx/tests/settings_test.cpp b/3rdparty/bx/tests/settings_test.cpp
index 584397ad143..46fa3ad6c9a 100644
--- a/3rdparty/bx/tests/settings_test.cpp
+++ b/3rdparty/bx/tests/settings_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -21,9 +21,9 @@ TEST_CASE("Settings", "")
settings.set("test/foo/bar/abvgd", "1389");
bx::FileWriter writer;
- if (bx::open(&writer, filePath) )
+ if (bx::open(&writer, filePath, false, bx::ErrorIgnore{}) )
{
- bx::write(&writer, settings);
+ bx::write(&writer, settings, bx::ErrorIgnore{});
bx::close(&writer);
}
@@ -37,9 +37,9 @@ TEST_CASE("Settings", "")
settings.clear();
bx::FileReader reader;
- if (bx::open(&reader, filePath) )
+ if (bx::open(&reader, filePath, bx::ErrorIgnore{}) )
{
- bx::read(&reader, settings);
+ bx::read(&reader, settings, bx::ErrorIgnore{});
bx::close(&reader);
}
diff --git a/3rdparty/bx/tests/simd_bench.cpp b/3rdparty/bx/tests/simd_bench.cpp
index 66e26297aaf..668a8df6120 100644
--- a/3rdparty/bx/tests/simd_bench.cpp
+++ b/3rdparty/bx/tests/simd_bench.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include <bx/allocator.h>
diff --git a/3rdparty/bx/tests/simd_test.cpp b/3rdparty/bx/tests/simd_test.cpp
index 3a211ca1054..65cbfb7bd3c 100644
--- a/3rdparty/bx/tests/simd_test.cpp
+++ b/3rdparty/bx/tests/simd_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -162,10 +162,10 @@ void simd_check_float(
, _0, _1, _2, _3
);
- CHECK(bx::equal(c.f[0], _0, 0.0001f) );
- CHECK(bx::equal(c.f[1], _1, 0.0001f) );
- CHECK(bx::equal(c.f[2], _2, 0.0001f) );
- CHECK(bx::equal(c.f[3], _3, 0.0001f) );
+ CHECK(bx::isEqual(c.f[0], _0, 0.0001f) );
+ CHECK(bx::isEqual(c.f[1], _1, 0.0001f) );
+ CHECK(bx::isEqual(c.f[2], _2, 0.0001f) );
+ CHECK(bx::isEqual(c.f[3], _3, 0.0001f) );
}
void simd_check_float(
@@ -189,14 +189,14 @@ void simd_check_float(
, _0, _1, _2, _3, _4, _5, _6, _7
);
- CHECK(bx::equal(c.f[0], _0, 0.0001f) );
- CHECK(bx::equal(c.f[1], _1, 0.0001f) );
- CHECK(bx::equal(c.f[2], _2, 0.0001f) );
- CHECK(bx::equal(c.f[3], _3, 0.0001f) );
- CHECK(bx::equal(c.f[4], _4, 0.0001f) );
- CHECK(bx::equal(c.f[5], _5, 0.0001f) );
- CHECK(bx::equal(c.f[6], _6, 0.0001f) );
- CHECK(bx::equal(c.f[7], _7, 0.0001f) );
+ CHECK(bx::isEqual(c.f[0], _0, 0.0001f) );
+ CHECK(bx::isEqual(c.f[1], _1, 0.0001f) );
+ CHECK(bx::isEqual(c.f[2], _2, 0.0001f) );
+ CHECK(bx::isEqual(c.f[3], _3, 0.0001f) );
+ CHECK(bx::isEqual(c.f[4], _4, 0.0001f) );
+ CHECK(bx::isEqual(c.f[5], _5, 0.0001f) );
+ CHECK(bx::isEqual(c.f[6], _6, 0.0001f) );
+ CHECK(bx::isEqual(c.f[7], _7, 0.0001f) );
}
void simd_check_string(const char* _str, bx::simd128_t _a)
diff --git a/3rdparty/bx/tests/sort_test.cpp b/3rdparty/bx/tests/sort_test.cpp
index e2a5a25449d..4abb76db334 100644
--- a/3rdparty/bx/tests/sort_test.cpp
+++ b/3rdparty/bx/tests/sort_test.cpp
@@ -1,14 +1,15 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
+#include <bx/bx.h>
#include <bx/sort.h>
#include <bx/string.h>
#include <bx/rng.h>
-TEST_CASE("quickSort", "")
+TEST_CASE("sort-quickSort", "")
{
const char* str[] =
{
@@ -18,19 +19,43 @@ TEST_CASE("quickSort", "")
"jagoda",
};
- bx::quickSort(str, BX_COUNTOF(str), sizeof(void*)
- , [](const void* _lhs, const void* _rhs)
- {
- const char* lhs = *(const char**)_lhs;
- const char* rhs = *(const char**)_rhs;
- return bx::strCmp(lhs, rhs);
- });
+ REQUIRE(!bx::isSorted(str, BX_COUNTOF(str) ) );
+
+ bx::quickSort(str, BX_COUNTOF(str) );
REQUIRE(0 == bx::strCmp(str[0], "jabuka") );
REQUIRE(0 == bx::strCmp(str[1], "jagoda") );
REQUIRE(0 == bx::strCmp(str[2], "kruska") );
REQUIRE(0 == bx::strCmp(str[3], "malina") );
+ REQUIRE(bx::isSorted(str, BX_COUNTOF(str) ) );
+
+ auto bsearchStrCmpFn = [](const void* _lhs, const void* _rhs)
+ {
+ const char* lhs = (const char*)_lhs;
+ const char* rhs = *(const char**)_rhs;
+ return bx::strCmp(lhs, rhs);
+ };
+
+ REQUIRE(~4 == bx::binarySearch("sljiva", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 0 == bx::binarySearch("jabuka", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 1 == bx::binarySearch("jagoda", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 2 == bx::binarySearch("kruska", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 3 == bx::binarySearch("malina", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE(~3 == bx::binarySearch("kupina", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+
+ REQUIRE( 0 == bx::lowerBound("jabuka", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 1 == bx::upperBound("jabuka", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+
+ REQUIRE( 1 == bx::lowerBound("jagoda", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 2 == bx::upperBound("jagoda", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+
+ REQUIRE( 2 == bx::lowerBound("kruska", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 3 == bx::upperBound("kruska", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+
+ REQUIRE( 3 == bx::lowerBound("malina", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+ REQUIRE( 4 == bx::upperBound("malina", str, BX_COUNTOF(str), sizeof(str[0]), bsearchStrCmpFn) );
+
int8_t byte[128];
bx::RngMwc rng;
for (uint32_t ii = 0; ii < BX_COUNTOF(byte); ++ii)
@@ -38,16 +63,105 @@ TEST_CASE("quickSort", "")
byte[ii] = rng.gen()&0xff;
}
- bx::quickSort(byte, BX_COUNTOF(byte), 1
- , [](const void* _lhs, const void* _rhs)
- {
- int8_t lhs = *(const int8_t*)_lhs;
- int8_t rhs = *(const int8_t*)_rhs;
- return lhs - rhs;
- });
+ REQUIRE(!bx::isSorted(byte, BX_COUNTOF(byte) ) );
+
+ bx::quickSort(byte, BX_COUNTOF(byte) );
for (uint32_t ii = 1; ii < BX_COUNTOF(byte); ++ii)
{
REQUIRE(byte[ii-1] <= byte[ii]);
}
+
+ REQUIRE(bx::isSorted(byte, BX_COUNTOF(byte) ) );
+}
+
+TEST_CASE("sort-unique", "")
+{
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | 14
+ int32_t test[] = { 100, 101, 101, 101, 103, 104, 105, 105, 105, 106, 106, 107, 108, 109 };
+ REQUIRE(bx::isSorted(test, BX_COUNTOF(test) ) );
+
+ REQUIRE(0 == bx::unique(test, 0) );
+ REQUIRE(1 == bx::unique(test, 1) );
+
+ REQUIRE(2 == bx::unique(test, 4) );
+ bx::quickSort(test, BX_COUNTOF(test) );
+
+ REQUIRE(3 == bx::unique(test, 5) );
+ bx::quickSort(test, BX_COUNTOF(test) );
+
+ uint32_t last = bx::unique(test, BX_COUNTOF(test) );
+ REQUIRE(9 == last);
+
+ REQUIRE(9 == bx::unique(test, last) );
+}
+
+TEST_CASE("sort-lower/upperBound int32_t", "")
+{
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | 14
+ const int32_t test[] = { 100, 101, 101, 101, 103, 104, 105, 105, 105, 106, 106, 107, 108, 109 };
+ REQUIRE(bx::isSorted(test, BX_COUNTOF(test) ) );
+
+ const uint32_t resultLowerBound[] = { 0, 1, 4, 4, 5, 6, 9, 11, 12, 13 };
+ const uint32_t resultUpperBound[] = { 1, 4, 4, 5, 6, 9, 11, 12, 13, 14 };
+
+ STATIC_REQUIRE(10 == BX_COUNTOF(resultLowerBound) );
+ STATIC_REQUIRE(10 == BX_COUNTOF(resultUpperBound) );
+
+ for (int32_t key = test[0], keyMax = test[BX_COUNTOF(test)-1], ii = 0; key <= keyMax; ++key, ++ii)
+ {
+ REQUIRE(resultLowerBound[ii] == bx::lowerBound(key, test, BX_COUNTOF(test) ) );
+ REQUIRE(resultUpperBound[ii] == bx::upperBound(key, test, BX_COUNTOF(test) ) );
+ }
+}
+
+template<typename Ty>
+int32_t compareAscendingTest(const Ty& _lhs, const Ty& _rhs)
+{
+ return bx::compareAscending<Ty>(&_lhs, &_rhs);
+}
+
+template<typename Ty>
+int32_t compareDescendingTest(const Ty& _lhs, const Ty& _rhs)
+{
+ return bx::compareDescending<Ty>(&_lhs, &_rhs);
+}
+
+template<typename Ty>
+void compareTest(const Ty& _min, const Ty& _max)
+{
+ REQUIRE(_min < _max);
+
+ REQUIRE(-1 == compareAscendingTest<Ty>(bx::min<Ty>(), bx::max<Ty>() ) );
+ REQUIRE(-1 == compareAscendingTest<Ty>(Ty(0), bx::max<Ty>() ) );
+ REQUIRE( 0 == compareAscendingTest<Ty>(bx::min<Ty>(), bx::min<Ty>() ) );
+ REQUIRE( 0 == compareAscendingTest<Ty>(bx::max<Ty>(), bx::max<Ty>() ) );
+ REQUIRE( 1 == compareAscendingTest<Ty>(bx::max<Ty>(), Ty(0) ) );
+ REQUIRE( 1 == compareAscendingTest<Ty>(bx::max<Ty>(), bx::min<Ty>() ) );
+
+ REQUIRE(-1 == compareAscendingTest<Ty>(_min, _max) );
+ REQUIRE( 0 == compareAscendingTest<Ty>(_min, _min) );
+ REQUIRE( 0 == compareAscendingTest<Ty>(_max, _max) );
+ REQUIRE( 1 == compareAscendingTest<Ty>(_max, _min) );
+
+ REQUIRE( 1 == compareDescendingTest<Ty>(_min, _max) );
+ REQUIRE( 0 == compareDescendingTest<Ty>(_min, _min) );
+ REQUIRE( 0 == compareDescendingTest<Ty>(_max, _max) );
+ REQUIRE(-1 == compareDescendingTest<Ty>(_max, _min) );
+}
+
+TEST_CASE("sort-ComparisonFn", "")
+{
+ compareTest< int8_t>( -13, 89);
+ compareTest<int16_t>(-1389, 1389);
+ compareTest<int32_t>(-1389, 1389);
+ compareTest<int64_t>(-1389, 1389);
+
+ compareTest< uint8_t>( 13, 89);
+ compareTest<uint16_t>( 13, 1389);
+ compareTest<uint32_t>( 13, 1389);
+ compareTest<uint64_t>( 13, 1389);
+
+ compareTest< float>(-13.89f, 1389.0f);
+ compareTest<double>(-13.89f, 1389.0f);
}
diff --git a/3rdparty/bx/tests/string_test.cpp b/3rdparty/bx/tests/string_test.cpp
index b7c4ed8ab52..cbcb50e8b5a 100644
--- a/3rdparty/bx/tests/string_test.cpp
+++ b/3rdparty/bx/tests/string_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -16,7 +16,7 @@ TEST_CASE("stringPrintfTy", "")
{
std::string test;
bx::stringPrintf(test, "printf into std::string.");
- REQUIRE(0 == bx::strCmp(bx::StringView(test), "printf into std::string.") );
+ REQUIRE(0 == bx::strCmp(bx::StringView(test.data(), int32_t(test.length() ) ), "printf into std::string.") );
}
TEST_CASE("prettify", "")
@@ -91,6 +91,10 @@ TEST_CASE("strCat", "")
TEST_CASE("strCmp", "")
{
+ REQUIRE(0 < bx::strCmp("abvgd", "abv") );
+ REQUIRE(0 < bx::strCmp("abvgd", "") );
+ REQUIRE(0 > bx::strCmp("", "abvgd") );
+ REQUIRE(0 != bx::strCmp(".tar.gz", ".") );
REQUIRE(0 != bx::strCmp("meh", "meh/") );
}
@@ -184,6 +188,7 @@ TEST_CASE("strRFind", "")
REQUIRE(bx::strRFind(bx::StringView(test, 0), 's').isEmpty() );
REQUIRE(bx::strRFind(bx::StringView(test, 1), 's').isEmpty() );
REQUIRE(&test[2] == bx::strRFind(test, 's').getPtr() );
+ REQUIRE(&test[3] == bx::strRFind(test, 't').getPtr() );
}
TEST_CASE("strFindI", "")
@@ -221,6 +226,18 @@ TEST_CASE("strFind", "")
REQUIRE(bx::strFind("vgd", 'a').isEmpty() );
}
+
+ {
+ bx::StringView test = bx::strFind("a", "a");
+ REQUIRE(test.getLength() == 1);
+ REQUIRE(*test.getPtr() == 'a');
+ }
+
+ {
+ bx::StringView test = bx::strFind("a", bx::StringView("a ", 1) );
+ REQUIRE(test.getLength() == 1);
+ REQUIRE(*test.getPtr() == 'a');
+ }
}
TEST_CASE("strSkip", "")
@@ -316,6 +333,7 @@ TEST_CASE("toString double", "")
REQUIRE(testToString(-270.000000, "-270.0") );
REQUIRE(testToString(2.225073858507201e-308, "2.225073858507201e-308") );
REQUIRE(testToString(-79.39773355813419, "-79.39773355813419") );
+ REQUIRE(testToString(-1.234567e-9, "-1.234567e-9") );
}
template<typename Ty>
@@ -457,12 +475,26 @@ TEST_CASE("StringView", "")
TEST_CASE("Trim", "")
{
+ REQUIRE(bx::strLTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("aba", "a"), "ba") );
+
+ REQUIRE(bx::strRTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("aba", "a"), "ab") );
+
+ REQUIRE(bx::strTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strTrim("aba", "a"), "b") );
+
REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "ab"), "vgd") );
- REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "abvgd") );
+
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd", "vagbd"), "abvgd") );
+
REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vgd"), "abvgd") );
REQUIRE(0 == bx::strCmp(bx::strLTrim("/555333/podmac/", "/"), "555333/podmac/") );
- REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "abvgd") );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd", "vagbd"), "abvgd") );
+
REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "abv"), "abvgd") );
REQUIRE(0 == bx::strCmp(bx::strRTrim("/555333/podmac/", "/"), "/555333/podmac") );
@@ -477,6 +509,37 @@ TEST_CASE("Trim", "")
REQUIRE(0 == bx::strCmp(bx::strTrim(uri.getPath(), "/"), "555333/podmac") );
}
+TEST_CASE("TrimSpace", "")
+{
+ REQUIRE(bx::strLTrimSpace("").isEmpty() );
+ REQUIRE(bx::strRTrimSpace("").isEmpty() );
+ REQUIRE(bx::strTrimSpace( "").isEmpty() );
+
+ REQUIRE(bx::strLTrimSpace("\n").isEmpty() );
+ REQUIRE(bx::strRTrimSpace("\n").isEmpty() );
+ REQUIRE(bx::strTrimSpace( "\n").isEmpty() );
+
+ const bx::StringView t0("1389");
+ const bx::StringView t1(" 1389");
+ const bx::StringView t2("1389 ");
+ const bx::StringView t3(" 1389 ");
+
+ REQUIRE(0 == bx::strCmp(bx::strLTrimSpace(t0), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strLTrimSpace(t1), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strLTrimSpace(t2), t2) );
+ REQUIRE(0 == bx::strCmp(bx::strLTrimSpace(t3), "1389 ") );
+
+ REQUIRE(0 == bx::strCmp(bx::strRTrimSpace(t0), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strRTrimSpace(t1), t1) );
+ REQUIRE(0 == bx::strCmp(bx::strRTrimSpace(t2), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strRTrimSpace(t3), " 1389") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrimSpace(t0), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSpace(t1), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSpace(t2), t0) );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSpace(t3), t0) );
+}
+
TEST_CASE("strWord", "")
{
REQUIRE(bx::strWord(" abvgd-1389.0").isEmpty() );
@@ -491,3 +554,49 @@ TEST_CASE("strFindBlock", "")
bx::StringView result = bx::strFindBlock(test1, '{', '}');
REQUIRE(19 == result.getLength() );
}
+
+TEST_CASE("prefix", "")
+{
+ REQUIRE( bx::hasPrefix("abvgd-1389.0", "abv") );
+ REQUIRE(!bx::hasPrefix("abvgd-1389.0", "bvg") );
+ REQUIRE( bx::hasPrefix("abvgd-1389.0", "") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd-1389.0", "abv"), "gd-1389.0") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd-1389.0", "xyz"), "abvgd-1389.0") );
+}
+
+TEST_CASE("suffix", "")
+{
+ REQUIRE( bx::hasSuffix("abvgd-1389.0", "389.0") );
+ REQUIRE(!bx::hasSuffix("abvgd-1389.0", "1389") );
+ REQUIRE( bx::hasSuffix("abvgd-1389.0", "") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd-1389.0", "389.0"), "abvgd-1") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd-1389.0", "xyz"), "abvgd-1389.0") );
+}
+
+TEST_CASE("0terminated", "")
+{
+ const bx::StringView t0("1389");
+ REQUIRE(t0.is0Terminated() );
+ const bx::StringView t1(strTrimPrefix(t0, "13") );
+ REQUIRE(!t1.is0Terminated() );
+ const bx::StringView t2(strTrimSuffix(t0, "89") );
+ REQUIRE(!t2.is0Terminated() );
+
+ bx::DefaultAllocator crt;
+ g_allocator = &crt;
+
+ typedef bx::StringT<&g_allocator> String;
+
+ String st;
+ REQUIRE(st.is0Terminated() );
+
+ st = strTrimPrefix(t0, "13");
+ REQUIRE(2 == st.getLength() );
+ REQUIRE(st.is0Terminated() );
+
+ st = strTrimSuffix(t0, "89");
+ REQUIRE(2 == st.getLength() );
+ REQUIRE(st.is0Terminated() );
+}
diff --git a/3rdparty/bx/tests/test.h b/3rdparty/bx/tests/test.h
index 43da95a56d2..7157174de59 100644
--- a/3rdparty/bx/tests/test.h
+++ b/3rdparty/bx/tests/test.h
@@ -1,16 +1,16 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
-#ifndef __TEST_H__
-#define __TEST_H__
+#ifndef BX_TEST_H_HEADER_GUARD
+#define BX_TEST_H_HEADER_GUARD
#include <bx/bx.h>
BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4312); // warning C4312 : 'reinterpret_cast' : conversion from 'int' to 'const char *' of greater size
-#include <catch/catch.hpp>
+#include <catch/catch_amalgamated.hpp>
BX_PRAGMA_DIAGNOSTIC_POP();
#define TEST(_x) TEST_CASE(#_x, "")
@@ -18,4 +18,4 @@ BX_PRAGMA_DIAGNOSTIC_POP();
#include "dbg.h"
-#endif // __TEST_H__
+#endif // BX_TEST_H_HEADER_GUARD
diff --git a/3rdparty/bx/tests/thread_test.cpp b/3rdparty/bx/tests/thread_test.cpp
index 80db9b5b969..b517eac069f 100644
--- a/3rdparty/bx/tests/thread_test.cpp
+++ b/3rdparty/bx/tests/thread_test.cpp
@@ -1,11 +1,13 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
#include <bx/thread.h>
+#if BX_CONFIG_SUPPORTS_THREADING
+
bx::DefaultAllocator s_allocator;
bx::MpScUnboundedBlockingQueue<void> s_mpsc(&s_allocator);
@@ -42,7 +44,9 @@ TEST_CASE("Thread", "")
REQUIRE(!th.isRunning() );
- th.init(threadExit0);
+ bool init = th.init(threadExit0, NULL, 0, NULL);
+ REQUIRE(init);
+
REQUIRE(th.isRunning() );
th.push(NULL);
th.shutdown();
@@ -67,3 +71,5 @@ TEST_CASE("MpScUnboundedBlockingQueue", "")
REQUIRE(result == 0x1389);
}
+
+#endif // BX_CONFIG_SUPPORTS_THREADING
diff --git a/3rdparty/bx/tests/tokenizecmd_test.cpp b/3rdparty/bx/tests/tokenizecmd_test.cpp
index e0910fef087..6490a750f7c 100644
--- a/3rdparty/bx/tests/tokenizecmd_test.cpp
+++ b/3rdparty/bx/tests/tokenizecmd_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2012-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2012-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/typetraits_test.cpp b/3rdparty/bx/tests/typetraits_test.cpp
new file mode 100644
index 00000000000..aef3e084731
--- /dev/null
+++ b/3rdparty/bx/tests/typetraits_test.cpp
@@ -0,0 +1,688 @@
+/*
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
+ */
+
+#include "test.h"
+#include <bx/typetraits.h>
+
+struct TestClass { };
+struct TestClassFinal final { };
+struct TestClassMember { int32_t x; };
+struct TestClassMemberPrivate { int32_t x; private: int32_t y; };
+struct TestClassStaticOnly { static int32_t x; };
+struct TestClassCtor { TestClassCtor (const TestClassCtor&) {} };
+struct TestClassDefaultCtor { TestClassDefaultCtor (const TestClassDefaultCtor&) = default; };
+struct TestClassDefaultDtor { ~TestClassDefaultDtor () = default; };
+struct TestClassVirtualDtor { virtual ~TestClassVirtualDtor () = default; };
+struct TestClassAbstractBase { virtual ~TestClassAbstractBase() = 0; };
+struct TestClassPolymorphic { virtual int32_t x() { return 1389; } };
+struct TestClassDerivedA /* */
+ : TestClass { };
+struct TestClassDerivedB /* */
+ : TestClassDerivedA { };
+struct TestClassDerivedX /* */
+ : TestClassVirtualDtor { };
+union TestUnionEmpty { };
+union TestUnion { int32_t x; float y; };
+enum TestEnumEmpty { };
+enum TestEnum { Enum };
+
+TEST_CASE("type-traits isReference", "")
+{
+ STATIC_REQUIRE(!bx::isReference<TestClass >() );
+ STATIC_REQUIRE( bx::isReference<TestClass& >() );
+ STATIC_REQUIRE( bx::isReference<TestClass&& >() );
+ STATIC_REQUIRE(!bx::isReference<long >() );
+ STATIC_REQUIRE( bx::isReference<long& >() );
+ STATIC_REQUIRE( bx::isReference<long&& >() );
+ STATIC_REQUIRE(!bx::isReference<double* >() );
+ STATIC_REQUIRE( bx::isReference<double*& >() );
+ STATIC_REQUIRE( bx::isReference<double*&& >() );;
+}
+
+TEST_CASE("type-traits isLvalueReference", "")
+{
+ STATIC_REQUIRE(!bx::isLvalueReference<TestClass >() );
+ STATIC_REQUIRE( bx::isLvalueReference<TestClass& >() );
+ STATIC_REQUIRE(!bx::isLvalueReference<TestClass&& >() );
+ STATIC_REQUIRE(!bx::isLvalueReference<long >() );
+ STATIC_REQUIRE( bx::isLvalueReference<long& >() );
+ STATIC_REQUIRE(!bx::isLvalueReference<long&& >() );
+ STATIC_REQUIRE(!bx::isLvalueReference<double* >() );
+ STATIC_REQUIRE( bx::isLvalueReference<double*& >() );
+ STATIC_REQUIRE(!bx::isLvalueReference<double*&& >() );;
+}
+
+TEST_CASE("type-traits isRvalueReference", "")
+{
+ STATIC_REQUIRE(!bx::isRvalueReference<TestClass >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<TestClass& >() );
+ STATIC_REQUIRE( bx::isRvalueReference<TestClass&& >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<long >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<long& >() );
+ STATIC_REQUIRE( bx::isRvalueReference<long&& >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<double* >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<double*& >() );
+ STATIC_REQUIRE( bx::isRvalueReference<double*&& >() );;
+}
+
+TEST_CASE("type-traits isPointer", "")
+{
+ STATIC_REQUIRE(!bx::isPointer<TestClass >() );
+ STATIC_REQUIRE(!bx::isPointer<TestClass& >() );
+ STATIC_REQUIRE( bx::isPointer<TestClass* >() );
+ STATIC_REQUIRE( bx::isPointer<TestClass const * volatile >() );
+ STATIC_REQUIRE(!bx::isPointer<int32_t >() );
+ STATIC_REQUIRE( bx::isPointer<int32_t* >() );
+ STATIC_REQUIRE(!bx::isPointer<int32_t[1389] >() );
+}
+
+TEST_CASE("type-traits AddLvalueReferenceT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass >, TestClass& >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass& >, TestClass& >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass&&>, TestClass& >() );
+
+ STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass> >() );
+ STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass&> >() );
+ STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass&&> >() );
+}
+
+TEST_CASE("type-traits AddRvalueReferenceT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass >, TestClass&& >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass& >, TestClass& >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass&&>, TestClass&& >() );
+
+ STATIC_REQUIRE( bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass> >() );
+ STATIC_REQUIRE(!bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass&> >() );
+ STATIC_REQUIRE( bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass&&> >() );
+}
+
+TEST_CASE("type-traits RemoveReferenceT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass& >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass&&>, TestClass >() );
+
+ STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass> >() );
+ STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass&> >() );
+ STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass&&> >() );
+}
+
+TEST_CASE("type-traits AddPointerT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass >, TestClass* >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass* >, TestClass** >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass& >, TestClass* >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass**>, TestClass*** >() );
+
+ STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass> >() );
+ STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass*> >() );
+ STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass&> >() );
+ STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass**> >() );
+}
+
+TEST_CASE("type-traits RemovePointerT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass* >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass**>, TestClass* >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<bx::RemovePointerType<TestClass**>>, TestClass >() );
+
+ STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<TestClass> >() );
+ STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<TestClass*> >() );
+ STATIC_REQUIRE( bx::isPointer<bx::RemovePointerType<TestClass**> >() );
+ STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<bx::RemovePointerType<TestClass**>> >() );
+}
+
+TEST_CASE("type-traits AddConstT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType< TestClass >, const TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType<const TestClass >, const TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType< volatile TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType<const volatile TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType<const volatile TestClass*>, const volatile TestClass* const >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddConstType<TestClass* const volatile>, TestClass* const volatile >() );
+}
+
+TEST_CASE("type-traits RemoveConstT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::RemoveConstType< TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<const TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveConstType< volatile TestClass >, volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<const volatile TestClass >, volatile TestClass >() );
+ STATIC_REQUIRE(!bx::isSame<bx::RemoveConstType<const volatile TestClass*>, volatile TestClass*>() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<TestClass* const volatile>, TestClass* volatile>() );
+}
+
+TEST_CASE("type-traits AddVolatileT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType< TestClass >, volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType< volatile TestClass >, volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const volatile TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const volatile TestClass*>, const volatile TestClass* volatile >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<TestClass* const volatile>, TestClass* const volatile >() );
+}
+
+TEST_CASE("type-traits RemoveVolatileT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType< TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<const TestClass >, const TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType< volatile TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<const volatile TestClass >, const TestClass >() );
+ STATIC_REQUIRE(!bx::isSame<bx::RemoveVolatileType<const volatile TestClass*>, const TestClass* >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<TestClass* const volatile>, TestClass* const >() );
+}
+
+TEST_CASE("type-traits AddCvT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType< TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType<const TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType< volatile TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType<const volatile TestClass >, const volatile TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType<const volatile TestClass*>, const volatile TestClass* const volatile >() );
+ STATIC_REQUIRE( bx::isSame<bx::AddCvType<TestClass* const volatile>, TestClass* const volatile >() );
+}
+
+TEST_CASE("type-traits RemoveCvT", "")
+{
+ STATIC_REQUIRE( bx::isSame<bx::RemoveCvType< TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<const TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveCvType< volatile TestClass >, TestClass >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<const volatile TestClass >, TestClass >() );
+ STATIC_REQUIRE(!bx::isSame<bx::RemoveCvType<const volatile TestClass*>, TestClass* >() );
+ STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<TestClass* const volatile>, TestClass* >() );
+}
+
+TEST_CASE("type-traits isTriviallyCopyable", "")
+{
+ STATIC_REQUIRE( bx::isTriviallyCopyable<int32_t >() );
+ STATIC_REQUIRE( bx::isTriviallyCopyable<TestClass >() );
+ STATIC_REQUIRE(!bx::isTriviallyCopyable<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isTriviallyCopyable<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isTriviallyCopyable<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isTriviallyCopyable<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isTriviallyConstructible", "")
+{
+ STATIC_REQUIRE( bx::isTriviallyConstructible<int32_t >() );
+ STATIC_REQUIRE( bx::isTriviallyConstructible<TestClass >() );
+ STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isTriviallyConstructible<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isTriviallyDestructible", "")
+{
+ STATIC_REQUIRE( bx::isTriviallyDestructible<int32_t >() );
+ STATIC_REQUIRE( bx::isTriviallyDestructible<TestClass >() );
+ STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isTriviallyDestructible<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isSigned", "")
+{
+ STATIC_REQUIRE(!bx::isSigned<bool >() );
+ STATIC_REQUIRE( bx::isSigned<char >() );
+ STATIC_REQUIRE( bx::isSigned<signed char >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned char >() );
+ STATIC_REQUIRE( bx::isSigned<short >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned short >() );
+ STATIC_REQUIRE( bx::isSigned<int >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned int >() );
+ STATIC_REQUIRE( bx::isSigned<long >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned long >() );
+ STATIC_REQUIRE( bx::isSigned<long long >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned long long >() );
+ STATIC_REQUIRE( bx::isSigned<long long int >() );
+ STATIC_REQUIRE(!bx::isSigned<unsigned long long int >() );
+
+ STATIC_REQUIRE( bx::isSigned<int8_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uint8_t >() );
+ STATIC_REQUIRE( bx::isSigned<int16_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uint16_t >() );
+ STATIC_REQUIRE( bx::isSigned<int32_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uint32_t >() );
+ STATIC_REQUIRE( bx::isSigned<int64_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uint64_t >() );
+ STATIC_REQUIRE( bx::isSigned<intmax_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uintmax_t >() );
+ STATIC_REQUIRE(!bx::isSigned<uintptr_t >() );
+ STATIC_REQUIRE( bx::isSigned<ptrdiff_t >() );
+ STATIC_REQUIRE(!bx::isSigned<size_t >() );
+
+ STATIC_REQUIRE( bx::isSigned<float >() );
+ STATIC_REQUIRE( bx::isSigned<double >() );
+ STATIC_REQUIRE( bx::isSigned<long double >() );
+}
+
+TEST_CASE("type-traits isUnsigned", "")
+{
+ STATIC_REQUIRE( bx::isUnsigned<bool >() );
+ STATIC_REQUIRE(!bx::isUnsigned<char >() );
+ STATIC_REQUIRE(!bx::isUnsigned<signed char >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned char >() );
+ STATIC_REQUIRE(!bx::isUnsigned<short >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned short >() );
+ STATIC_REQUIRE(!bx::isUnsigned<int >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned int >() );
+ STATIC_REQUIRE(!bx::isUnsigned<long >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned long >() );
+ STATIC_REQUIRE(!bx::isUnsigned<long long >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned long long >() );
+ STATIC_REQUIRE(!bx::isUnsigned<long long int >() );
+ STATIC_REQUIRE( bx::isUnsigned<unsigned long long int >() );
+
+ STATIC_REQUIRE(!bx::isUnsigned<int8_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uint8_t >() );
+ STATIC_REQUIRE(!bx::isUnsigned<int16_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uint16_t >() );
+ STATIC_REQUIRE(!bx::isUnsigned<int32_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uint32_t >() );
+ STATIC_REQUIRE(!bx::isUnsigned<int64_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uint64_t >() );
+ STATIC_REQUIRE(!bx::isUnsigned<intmax_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uintmax_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<uintptr_t >() );
+ STATIC_REQUIRE(!bx::isUnsigned<ptrdiff_t >() );
+ STATIC_REQUIRE( bx::isUnsigned<size_t >() );
+
+ STATIC_REQUIRE(!bx::isUnsigned<float >() );
+ STATIC_REQUIRE(!bx::isUnsigned<double >() );
+ STATIC_REQUIRE(!bx::isUnsigned<long double >() );
+}
+
+TEST_CASE("type-traits isInteger", "")
+{
+ STATIC_REQUIRE( bx::isInteger<bool >() );
+ STATIC_REQUIRE( bx::isInteger<char >() );
+ STATIC_REQUIRE( bx::isInteger<signed char >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned char >() );
+ STATIC_REQUIRE( bx::isInteger<short >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned short >() );
+ STATIC_REQUIRE( bx::isInteger<int >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned int >() );
+ STATIC_REQUIRE( bx::isInteger<long >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned long >() );
+ STATIC_REQUIRE( bx::isInteger<long long >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned long long >() );
+ STATIC_REQUIRE( bx::isInteger<long long int >() );
+ STATIC_REQUIRE( bx::isInteger<unsigned long long int >() );
+
+ STATIC_REQUIRE( bx::isInteger<int8_t >() );
+ STATIC_REQUIRE( bx::isInteger<uint8_t >() );
+ STATIC_REQUIRE( bx::isInteger<int16_t >() );
+ STATIC_REQUIRE( bx::isInteger<uint16_t >() );
+ STATIC_REQUIRE( bx::isInteger<int32_t >() );
+ STATIC_REQUIRE( bx::isInteger<uint32_t >() );
+ STATIC_REQUIRE( bx::isInteger<int64_t >() );
+ STATIC_REQUIRE( bx::isInteger<uint64_t >() );
+ STATIC_REQUIRE( bx::isInteger<intmax_t >() );
+ STATIC_REQUIRE( bx::isInteger<uintmax_t >() );
+ STATIC_REQUIRE( bx::isInteger<uintptr_t >() );
+ STATIC_REQUIRE( bx::isInteger<ptrdiff_t >() );
+ STATIC_REQUIRE( bx::isInteger<size_t >() );
+
+ STATIC_REQUIRE(!bx::isInteger<float >() );
+ STATIC_REQUIRE(!bx::isInteger<double >() );
+ STATIC_REQUIRE(!bx::isInteger<long double >() );
+
+ STATIC_REQUIRE(!bx::isInteger<TestClass >() );
+ STATIC_REQUIRE(!bx::isInteger<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isInteger<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isInteger<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isInteger<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isFloatingPoint", "")
+{
+ STATIC_REQUIRE(!bx::isFloatingPoint<bool >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<char >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<signed char >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned char >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<short >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned short >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<int >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned int >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<long >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<long long >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long long >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<long long int >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long long int >() );
+
+ STATIC_REQUIRE(!bx::isFloatingPoint<int8_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uint8_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<int16_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uint16_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<int32_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uint32_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<int64_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uint64_t >() );
+
+ STATIC_REQUIRE(!bx::isFloatingPoint<intmax_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uintmax_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<uintptr_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<ptrdiff_t >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<size_t >() );
+
+ STATIC_REQUIRE( bx::isFloatingPoint<float >() );
+ STATIC_REQUIRE( bx::isFloatingPoint<double >() );
+ STATIC_REQUIRE( bx::isFloatingPoint<long double >() );
+
+ STATIC_REQUIRE(!bx::isFloatingPoint<TestClass >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isFloatingPoint<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isArithmetic", "")
+{
+ STATIC_REQUIRE( bx::isArithmetic<bool >() );
+ STATIC_REQUIRE( bx::isArithmetic<char >() );
+ STATIC_REQUIRE( bx::isArithmetic<signed char >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned char >() );
+ STATIC_REQUIRE( bx::isArithmetic<short >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned short >() );
+ STATIC_REQUIRE( bx::isArithmetic<int >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned int >() );
+ STATIC_REQUIRE( bx::isArithmetic<long >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned long >() );
+ STATIC_REQUIRE( bx::isArithmetic<long long >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned long long >() );
+ STATIC_REQUIRE( bx::isArithmetic<long long int >() );
+ STATIC_REQUIRE( bx::isArithmetic<unsigned long long int >() );
+
+ STATIC_REQUIRE( bx::isArithmetic<int8_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uint8_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<int16_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uint16_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<int32_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uint32_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<int64_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uint64_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<intmax_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uintmax_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<uintptr_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<ptrdiff_t >() );
+ STATIC_REQUIRE( bx::isArithmetic<size_t >() );
+
+ STATIC_REQUIRE( bx::isArithmetic<float >() );
+ STATIC_REQUIRE( bx::isArithmetic<double >() );
+ STATIC_REQUIRE( bx::isArithmetic<long double >() );
+
+ STATIC_REQUIRE(!bx::isArithmetic<TestClass >() );
+ STATIC_REQUIRE(!bx::isArithmetic<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isArithmetic<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isArithmetic<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isArithmetic<TestClassVirtualDtor >() );
+}
+
+TEST_CASE("type-traits isBoundedArray", "")
+{
+ STATIC_REQUIRE(!bx::isBoundedArray<TestClass >() );
+ STATIC_REQUIRE(!bx::isBoundedArray<TestClass[] >() );
+ STATIC_REQUIRE( bx::isBoundedArray<TestClass[1389] >() );
+ STATIC_REQUIRE(!bx::isBoundedArray<float >() );
+ STATIC_REQUIRE(!bx::isBoundedArray<int >() );
+ STATIC_REQUIRE(!bx::isBoundedArray<int[] >() );
+ STATIC_REQUIRE( bx::isBoundedArray<int[1389] >() );
+}
+
+TEST_CASE("type-traits isUnboundedArray", "")
+{
+ STATIC_REQUIRE(!bx::isUnboundedArray<TestClass >() );
+ STATIC_REQUIRE( bx::isUnboundedArray<TestClass[] >() );
+ STATIC_REQUIRE(!bx::isUnboundedArray<TestClass[1389] >() );
+ STATIC_REQUIRE(!bx::isUnboundedArray<float >() );
+ STATIC_REQUIRE(!bx::isUnboundedArray<int32_t >() );
+ STATIC_REQUIRE( bx::isUnboundedArray<int32_t[] >() );
+ STATIC_REQUIRE(!bx::isUnboundedArray<int32_t[1389] >() );
+}
+
+TEST_CASE("type-traits isArray", "")
+{
+ STATIC_REQUIRE(!bx::isArray<TestClass >() );
+ STATIC_REQUIRE( bx::isArray<TestClass[] >() );
+ STATIC_REQUIRE( bx::isArray<TestClass[1389] >() );
+ STATIC_REQUIRE(!bx::isArray<float >() );
+ STATIC_REQUIRE(!bx::isArray<int32_t >() );
+ STATIC_REQUIRE( bx::isArray<int32_t[] >() );
+ STATIC_REQUIRE( bx::isArray<int32_t[1389] >() );
+ STATIC_REQUIRE( bx::isArray<TestUnion[] >() );
+}
+
+TEST_CASE("type-traits isEnum", "")
+{
+ STATIC_REQUIRE(!bx::isEnum<TestClass >() );
+ STATIC_REQUIRE(!bx::isEnum<TestUnion >() );
+ STATIC_REQUIRE(!bx::isEnum<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isEnum<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isEnum<int32_t[] >() );
+ STATIC_REQUIRE( bx::isEnum<TestEnumEmpty >() );
+ STATIC_REQUIRE( bx::isEnum<TestEnum >() );
+}
+
+TEST_CASE("type-traits isUnion", "")
+{
+ STATIC_REQUIRE(!bx::isUnion<TestClass >() );
+ STATIC_REQUIRE( bx::isUnion<TestUnion >() );
+ STATIC_REQUIRE( bx::isUnion<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isUnion<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isUnion<int32_t[] >() );
+ STATIC_REQUIRE(!bx::isUnion<TestEnumEmpty >() );
+ STATIC_REQUIRE(!bx::isUnion<TestEnum >() );
+}
+
+TEST_CASE("type-traits isClass", "")
+{
+ STATIC_REQUIRE( bx::isClass<TestClass >() );
+ STATIC_REQUIRE( bx::isClass<TestClassFinal >() );
+ STATIC_REQUIRE( bx::isClass<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isClass<TestClassMember >() );
+ STATIC_REQUIRE( bx::isClass<TestClassMemberPrivate >() );
+ STATIC_REQUIRE( bx::isClass<TestClassStaticOnly >() );
+ STATIC_REQUIRE( bx::isClass<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isClass<TestClassDefaultDtor >() );
+ STATIC_REQUIRE( bx::isClass<TestClassVirtualDtor >() );
+ STATIC_REQUIRE( bx::isClass<TestClassAbstractBase >() );
+ STATIC_REQUIRE( bx::isClass<TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isClass<TestClassDerivedB >() );
+ STATIC_REQUIRE(!bx::isClass<TestUnion >() );
+ STATIC_REQUIRE(!bx::isClass<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isClass<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isFinal", "")
+{
+ STATIC_REQUIRE(!bx::isFinal<TestClass >() );
+ STATIC_REQUIRE( bx::isFinal<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassMemberPrivate >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassStaticOnly >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassPolymorphic >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassDerivedA >() );
+ STATIC_REQUIRE(!bx::isFinal<TestClassDerivedB >() );
+ STATIC_REQUIRE(!bx::isFinal<TestUnion >() );
+ STATIC_REQUIRE(!bx::isFinal<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isFinal<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isFinal<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isEmpty", "")
+{
+ STATIC_REQUIRE( bx::isEmpty<TestClass >() );
+ STATIC_REQUIRE( bx::isEmpty<TestClassFinal >() );
+ STATIC_REQUIRE( bx::isEmpty<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isEmpty<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isEmpty<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestClassPolymorphic >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestUnion >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isEmpty<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isEmpty<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isStandardLayout", "")
+{
+ STATIC_REQUIRE( bx::isStandardLayout<TestClass >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassFinal >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isStandardLayout<TestClassMemberPrivate >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassStaticOnly >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isStandardLayout<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isStandardLayout<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isStandardLayout<TestClassPolymorphic >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestClassDerivedB >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestUnion >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestUnionEmpty >() );
+ STATIC_REQUIRE( bx::isStandardLayout<TestUnion[] >() );
+ STATIC_REQUIRE( bx::isStandardLayout<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isTrivial", "")
+{
+ STATIC_REQUIRE( bx::isTrivial<TestClass >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isTrivial<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassMember >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassMemberPrivate >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassStaticOnly >() );
+ STATIC_REQUIRE(!bx::isTrivial<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isTrivial<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isTrivial<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isTrivial<TestClassPolymorphic >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isTrivial<TestClassDerivedB >() );
+ STATIC_REQUIRE( bx::isTrivial<TestUnion >() );
+ STATIC_REQUIRE( bx::isTrivial<TestUnionEmpty >() );
+ STATIC_REQUIRE( bx::isTrivial<TestUnion[] >() );
+ STATIC_REQUIRE( bx::isTrivial<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isPod", "")
+{
+ STATIC_REQUIRE( bx::isPod<TestClass >() );
+ STATIC_REQUIRE( bx::isPod<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isPod<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassMemberPrivate >() );
+ STATIC_REQUIRE( bx::isPod<TestClassStaticOnly >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassDefaultCtor >() );
+ STATIC_REQUIRE( bx::isPod<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassPolymorphic >() );
+ STATIC_REQUIRE(!bx::isPod<TestClassAbstractBase >() );
+ STATIC_REQUIRE( bx::isPod<TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isPod<TestClassDerivedB >() );
+ STATIC_REQUIRE( bx::isPod<TestUnion >() );
+ STATIC_REQUIRE( bx::isPod<TestUnionEmpty >() );
+ STATIC_REQUIRE( bx::isPod<TestUnion[] >() );
+ STATIC_REQUIRE( bx::isPod<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isPolymorphic", "")
+{
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClass >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassMemberPrivate >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassStaticOnly >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassDefaultDtor >() );
+ STATIC_REQUIRE( bx::isPolymorphic<TestClassVirtualDtor >() );
+ STATIC_REQUIRE( bx::isPolymorphic<TestClassAbstractBase >() );
+ STATIC_REQUIRE( bx::isPolymorphic<TestClassPolymorphic >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassDerivedA >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestClassDerivedB >() );
+ STATIC_REQUIRE( bx::isPolymorphic<TestClassDerivedX >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestUnion >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isPolymorphic<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isDestructorVirtual", "")
+{
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClass >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassCtor >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassMemberPrivate >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassStaticOnly >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDefaultCtor >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDefaultDtor >() );
+ STATIC_REQUIRE( bx::isDestructorVirtual<TestClassVirtualDtor >() );
+ STATIC_REQUIRE( bx::isDestructorVirtual<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassPolymorphic >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDerivedA >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDerivedB >() );
+ STATIC_REQUIRE( bx::isDestructorVirtual<TestClassDerivedX >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnion >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnionEmpty >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnion[] >() );
+ STATIC_REQUIRE(!bx::isDestructorVirtual<int32_t[] >() );
+}
+
+TEST_CASE("type-traits isBaseOf", "")
+{
+ STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClass >() );
+ STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClassDerivedB >() );
+ STATIC_REQUIRE(!bx::isBaseOf<TestClass, TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isBaseOf<TestClassDerivedB, TestClassDerivedA >() );
+ STATIC_REQUIRE(!bx::isBaseOf<TestClassDerivedB, TestClassDerivedX >() );
+ STATIC_REQUIRE(!bx::isBaseOf<int32_t, int32_t >() );
+}
+
+TEST_CASE("type-traits isAggregate", "")
+{
+ STATIC_REQUIRE( bx::isAggregate<TestClass >() );
+ STATIC_REQUIRE( bx::isAggregate<TestClassFinal >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassCtor >() );
+ STATIC_REQUIRE( bx::isAggregate<TestClassMember >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassMemberPrivate >() );
+ STATIC_REQUIRE( bx::isAggregate<TestClassStaticOnly >() );
+#if __cplusplus < BX_LANGUAGE_CPP20
+ STATIC_REQUIRE( bx::isAggregate<TestClassDefaultCtor >() );
+#else
+ STATIC_REQUIRE(!bx::isAggregate<TestClassDefaultCtor >() );
+#endif
+ STATIC_REQUIRE( bx::isAggregate<TestClassDefaultDtor >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassVirtualDtor >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassAbstractBase >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassPolymorphic >() );
+#if __cplusplus < BX_LANGUAGE_CPP17
+ STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedA >() );
+ STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedB >() );
+#else
+ STATIC_REQUIRE( bx::isAggregate<TestClassDerivedA >() );
+ STATIC_REQUIRE( bx::isAggregate<TestClassDerivedB >() );
+#endif
+ STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedX >() );
+ STATIC_REQUIRE( bx::isAggregate<TestUnion >() );
+ STATIC_REQUIRE( bx::isAggregate<TestUnionEmpty >() );
+ STATIC_REQUIRE( bx::isAggregate<TestUnion[] >() );
+ STATIC_REQUIRE( bx::isAggregate<int32_t[] >() );
+}
diff --git a/3rdparty/bx/tests/uint32_test.cpp b/3rdparty/bx/tests/uint32_test.cpp
index bb7e0dccacd..572bcdf4880 100644
--- a/3rdparty/bx/tests/uint32_test.cpp
+++ b/3rdparty/bx/tests/uint32_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -14,28 +14,57 @@ TEST_CASE("StrideAlign")
REQUIRE(12 == bx::strideAlign(ii+1, 12) );
}
- REQUIRE(0 == bx::strideAlign16(0, 12) );
+ REQUIRE(0 == bx::strideAlign<16>(0, 12) );
for (uint32_t ii = 0; ii < 12; ++ii)
{
- REQUIRE(48 == bx::strideAlign16(ii+1, 12) );
+ REQUIRE(48 == bx::strideAlign<16>(ii+1, 12) );
}
+
+ uint32_t offset = 11;
+ offset = bx::strideAlign(offset, 32);
+ REQUIRE(offset == 32);
+
+ offset = bx::strideAlign(offset, 24);
+ REQUIRE(offset == 48);
}
TEST_CASE("uint32_cnt")
{
- REQUIRE( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
-
- REQUIRE(31 == bx::uint32_cntlz(UINT32_C(1) ) );
-
- REQUIRE( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
-
- REQUIRE(63 == bx::uint64_cntlz(UINT64_C(1) ) );
-
+ REQUIRE( 0 == bx::uint32_cnttz<uint8_t >(1) );
+ REQUIRE( 7 == bx::uint32_cnttz<uint8_t >(1<<7) );
+ REQUIRE( 8 == bx::uint32_cnttz<uint8_t >(0) );
+ REQUIRE( 1 == bx::uint32_cnttz<uint8_t >(0x3e) );
+ REQUIRE( 0 == bx::uint32_cnttz<uint16_t>(1) );
+ REQUIRE(15 == bx::uint32_cnttz<uint16_t>(1<<15) );
+ REQUIRE(16 == bx::uint32_cnttz<uint16_t>(0) );
+ REQUIRE( 0 == bx::uint32_cnttz<uint32_t>(1) );
+ REQUIRE(32 == bx::uint32_cnttz<uint32_t>(0) );
+ REQUIRE(31 == bx::uint32_cnttz<uint32_t>(1u<<31) );
+ REQUIRE( 0 == bx::uint32_cnttz<uint64_t>(1) );
+ REQUIRE(64 == bx::uint32_cnttz<uint64_t>(0) );
+
+ REQUIRE( 7 == bx::uint32_cntlz<uint8_t >(1) );
+ REQUIRE( 8 == bx::uint32_cntlz<uint8_t >(0) );
+ REQUIRE( 2 == bx::uint32_cntlz<uint8_t >(0x3e) );
+ REQUIRE(15 == bx::uint32_cntlz<uint16_t>(1) );
+ REQUIRE(16 == bx::uint32_cntlz<uint16_t>(0) );
+ REQUIRE(31 == bx::uint32_cntlz<uint32_t>(1) );
+ REQUIRE(32 == bx::uint32_cntlz<uint32_t>(0) );
+ REQUIRE(63 == bx::uint32_cntlz<uint64_t>(1) );
+ REQUIRE(64 == bx::uint32_cntlz<uint64_t>(0) );
+
+ REQUIRE( 0 == bx::uint32_cntbits(0) );
REQUIRE( 1 == bx::uint32_cntbits(1) );
- REQUIRE(16 == bx::uint32_cntbits(UINT16_MAX) );
+ REQUIRE( 4 == bx::uint32_cntbits<uint8_t>(0x55) );
+ REQUIRE( 8 == bx::uint32_cntbits<uint16_t>(0x5555) );
+ REQUIRE(16 == bx::uint32_cntbits<uint32_t>(0x55555555) );
+ REQUIRE(32 == bx::uint32_cntbits<uint64_t>(0x5555555555555555) );
+ REQUIRE( 8 == bx::uint32_cntbits(UINT8_MAX) );
+ REQUIRE(16 == bx::uint32_cntbits(UINT16_MAX) );
REQUIRE(32 == bx::uint32_cntbits(UINT32_MAX) );
+ REQUIRE(64 == bx::uint32_cntbits(UINT64_MAX) );
}
TEST_CASE("uint32_part")
@@ -88,3 +117,35 @@ TEST_CASE("uint64_roX", "")
REQUIRE(bx::uint64_rol(0x8000000000000000, 1) == 1);
REQUIRE(bx::uint64_ror(1, 1) == 0x8000000000000000);
}
+
+TEST_CASE("align", "")
+{
+ REQUIRE( bx::isAligned(0, 8) );
+ REQUIRE(!bx::isAligned(7, 8) );
+ REQUIRE( bx::isAligned(64, 8) );
+ REQUIRE(!bx::isAligned(63, 8) );
+
+ REQUIRE( 0 == bx::alignUp( 0, 16) );
+ REQUIRE( 16 == bx::alignUp( 1, 16) );
+ REQUIRE( 16 == bx::alignUp( 15, 16) );
+ REQUIRE( 16 == bx::alignUp( 16, 16) );
+ REQUIRE(256 == bx::alignUp(255, 16) );
+ REQUIRE( 0 == bx::alignUp(-1, 16) );
+ REQUIRE(-16 == bx::alignUp(-31, 16) );
+
+ REQUIRE( 0 == bx::alignUp( 0, 256) );
+ REQUIRE(256 == bx::alignUp( 1, 256) );
+ REQUIRE(256 == bx::alignUp( 15, 256) );
+ REQUIRE(256 == bx::alignUp(255, 256) );
+ REQUIRE(256 == bx::alignUp(256, 256) );
+ REQUIRE(256 == bx::alignUp(256, 256) );
+ REQUIRE(512 == bx::alignUp(511, 256) );
+
+ REQUIRE( 0 == bx::alignDown( 0, 16) );
+ REQUIRE( 0 == bx::alignDown( 1, 16) );
+ REQUIRE( 0 == bx::alignDown( 15, 16) );
+ REQUIRE( 16 == bx::alignDown( 16, 16) );
+ REQUIRE(240 == bx::alignDown(255, 16) );
+ REQUIRE(-16 == bx::alignDown(-1, 16) );
+ REQUIRE(-32 == bx::alignDown(-31, 16) );
+}
diff --git a/3rdparty/bx/tests/url_test.cpp b/3rdparty/bx/tests/url_test.cpp
index 50d2c3924d5..a488ae9e545 100644
--- a/3rdparty/bx/tests/url_test.cpp
+++ b/3rdparty/bx/tests/url_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
diff --git a/3rdparty/bx/tests/vsnprintf_test.cpp b/3rdparty/bx/tests/vsnprintf_test.cpp
index 844f6363ce2..de7649b74f5 100644
--- a/3rdparty/bx/tests/vsnprintf_test.cpp
+++ b/3rdparty/bx/tests/vsnprintf_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -66,6 +66,76 @@ TEST_CASE("vsnprintf f")
REQUIRE(test(" inf", "%8f", std::numeric_limits<double>::infinity() ) );
REQUIRE(test("inf ", "%-8f", std::numeric_limits<double>::infinity() ) );
REQUIRE(test(" -INF", "%8F", -std::numeric_limits<double>::infinity() ) );
+
+ REQUIRE(test(" 1.0", "%4.1f", 1.0) );
+ REQUIRE(test(" 1.500", "%6.3f", 1.5) );
+ REQUIRE(test("0001.500", "%08.3f", 1.5) );
+ REQUIRE(test("+001.500", "%+08.3f", 1.5) );
+ REQUIRE(test("-001.500", "%+08.3f", -1.5) );
+ REQUIRE(test("0.0039", "%.4f", 0.00390625) );
+
+ REQUIRE(test("0.003906", "%f", 0.00390625) );
+ REQUIRE(test("-1.234567e-9", "%f", -1.234567e-9) );
+
+ REQUIRE(test("-1e-9", "%.0f", -1.234567e-9) );
+ REQUIRE(test("-1.2e-9", "%.1f", -1.234567e-9) );
+ REQUIRE(test("-1.23e-9", "%.2f", -1.234567e-9) );
+ REQUIRE(test("-1.234e-9", "%.3f", -1.234567e-9) );
+ REQUIRE(test("-1.2345e-9", "%.4f", -1.234567e-9) );
+ REQUIRE(test("-1.23456e-9", "%.5f", -1.234567e-9) );
+ REQUIRE(test("-1.234567e-9", "%.6f", -1.234567e-9) );
+ REQUIRE(test("-1.2345670e-9", "%.7f", -1.234567e-9) );
+ REQUIRE(test("-1.23456700e-9", "%.8f", -1.234567e-9) );
+ REQUIRE(test("-1.234567000e-9", "%.9f", -1.234567e-9) );
+ REQUIRE(test("-1.2345670000e-9", "%.10f", -1.234567e-9) );
+
+ REQUIRE(test("3.141592", "%f", 3.1415926535897932) );
+ REQUIRE(test("3.141592", "%F", 3.1415926535897932) );
+ REQUIRE(test("3", "%.0f", 3.1415926535897932) );
+ REQUIRE(test("3.1", "%.1f", 3.1415926535897932) );
+ REQUIRE(test("3.14", "%.2f", 3.1415926535897932) );
+ REQUIRE(test("3.141", "%.3f", 3.1415926535897932) );
+ REQUIRE(test("3.1415", "%.4f", 3.1415926535897932) );
+ REQUIRE(test("3.14159", "%.5f", 3.1415926535897932) );
+ REQUIRE(test("3.141592", "%.6f", 3.1415926535897932) );
+ REQUIRE(test("3.1415926", "%.7f", 3.1415926535897932) );
+ REQUIRE(test("3.14159265", "%.8f", 3.1415926535897932) );
+ REQUIRE(test("3.141592653", "%.9f", 3.1415926535897932) );
+ REQUIRE(test("3.1415926535", "%.10f", 3.1415926535897932) );
+ REQUIRE(test("3.14159265358", "%.11f", 3.1415926535897932) );
+ REQUIRE(test("3.141592653589", "%.12f", 3.1415926535897932) );
+ REQUIRE(test("3.1415926535897", "%.13f", 3.1415926535897932) );
+ REQUIRE(test("3.14159265358979", "%.14f", 3.1415926535897932) );
+ REQUIRE(test("3.141592653589793", "%.15f", 3.1415926535897932) );
+ REQUIRE(test("3.1415926535897930", "%.16f", 3.1415926535897932) );
+ REQUIRE(test("3.1415926535897930", "%.16F", 3.1415926535897932) );
+
+ REQUIRE(test("-3.141592e-9", "%f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141592E-9", "%F", -3.1415926535897932e-9) );
+ REQUIRE(test("-3e-9", "%.0f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1e-9", "%.1f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.14e-9", "%.2f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141e-9", "%.3f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415e-9", "%.4f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.14159e-9", "%.5f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141592e-9", "%.6f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415926e-9", "%.7f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.14159265e-9", "%.8f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141592653e-9", "%.9f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415926535e-9", "%.10f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.14159265358e-9", "%.11f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141592653589e-9", "%.12f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415926535897e-9", "%.13f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.14159265358979e-9", "%.14f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.141592653589793e-9", "%.15f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415926535897930e-9", "%.16f", -3.1415926535897932e-9) );
+ REQUIRE(test("-3.1415926535897930E-9", "%.16F", -3.1415926535897932e-9) );
+
+ REQUIRE(test("1e-12", "%f", 1e-12));
+
+ REQUIRE(test("0.00390625", "%.8f", 0.00390625) );
+ REQUIRE(test("-0.00390625", "%.8f", -0.00390625) );
+ REQUIRE(test("1.50000000000000000", "%.17f", 1.5) );
}
TEST_CASE("vsnprintf d/i/o/u/x")
@@ -82,6 +152,8 @@ TEST_CASE("vsnprintf d/i/o/u/x")
REQUIRE(test("2471", "%o", 1337) );
REQUIRE(test("1337 ", "%-20o", 01337) );
REQUIRE(test("37777776441 ", "%-20o", -01337) );
+ REQUIRE(test(" 2471", "%20o", 1337) );
+ REQUIRE(test("00000000000000002471", "%020o", 1337) );
REQUIRE(test("1337", "%u", 1337) );
REQUIRE(test("1337 ", "%-20u", 1337) );
@@ -92,11 +164,40 @@ TEST_CASE("vsnprintf d/i/o/u/x")
REQUIRE(test("1234ABCD ", "%-20X", 0x1234abcd) );
REQUIRE(test("edcb5433 ", "%-20x", -0x1234abcd) );
REQUIRE(test("EDCB5433 ", "%-20X", -0x1234abcd) );
+ REQUIRE(test(" 1234abcd", "% 20x", 0x1234abcd) );
+ REQUIRE(test(" 1234ABCD", "% 20X", 0x1234abcd) );
+ REQUIRE(test(" edcb5433", "% 20x", -0x1234abcd) );
+ REQUIRE(test(" EDCB5433", "% 20X", -0x1234abcd) );
REQUIRE(test("0000000000001234abcd", "%020x", 0x1234abcd) );
REQUIRE(test("0000000000001234ABCD", "%020X", 0x1234abcd) );
REQUIRE(test("000000000000edcb5433", "%020x", -0x1234abcd) );
REQUIRE(test("000000000000EDCB5433", "%020X", -0x1234abcd) );
+ REQUIRE(test("0xf", "0x%01x", -1) );
+ REQUIRE(test("0xff", "0x%02x", -1) );
+ REQUIRE(test("0xfff", "0x%03x", -1) );
+ REQUIRE(test("0xffff", "0x%04x", -1) );
+ REQUIRE(test("0xfffff", "0x%05x", -1) );
+ REQUIRE(test("0xffffff", "0x%06x", -1) );
+ REQUIRE(test("0xfffffff", "0x%07x", -1) );
+ REQUIRE(test("0xffffffff", "0x%08x", -1) );
+
+ REQUIRE(test(" -1", "% 4i", -1) );
+ REQUIRE(test(" -1", "% 4i", -1) );
+ REQUIRE(test(" 0", "% 4i", 0) );
+ REQUIRE(test(" 1", "% 4i", 1) );
+ REQUIRE(test(" 1", "% 4o", 1) );
+ REQUIRE(test(" +1", "%+4i", 1) );
+ REQUIRE(test(" +1", "%+4o", 1) );
+ REQUIRE(test(" +0", "%+4i", 0) );
+ REQUIRE(test(" -1", "%+4i", -1) );
+ REQUIRE(test("0001", "%04i", 1) );
+ REQUIRE(test("0001", "%04o", 1) );
+ REQUIRE(test("0000", "%04i", 0) );
+ REQUIRE(test("0000", "%04o", 0) );
+ REQUIRE(test("-001", "%04i", -1) );
+ REQUIRE(test("+001", "%+04i", 1) );
+
if (BX_ENABLED(BX_ARCH_32BIT) )
{
REQUIRE(test("2147483647", "%jd", INTMAX_MAX) );
@@ -136,6 +237,29 @@ TEST_CASE("vsnprintf s")
REQUIRE(test("(null)", "%s", NULL) );
}
+TEST_CASE("vsnprintf t")
+{
+ size_t size = size_t(-1);
+
+ REQUIRE(test("-1", "%td", size) );
+
+ REQUIRE(test("3221225472", "%td", size_t(3221225472) ) );
+}
+
+TEST_CASE("vsnprintf n")
+{
+ char temp[64];
+
+ int32_t p0, p1, p2;
+ bx::snprintf(temp, sizeof(temp), "%n", &p0);
+ REQUIRE(0 == p0);
+
+ bx::snprintf(temp, sizeof(temp), "01%n23%n45%n", &p0, &p1, &p2);
+ REQUIRE(2 == p0);
+ REQUIRE(4 == p1);
+ REQUIRE(6 == p2);
+}
+
TEST_CASE("vsnprintf g")
{
REQUIRE(test(" 0.01", "%7.2g", .01) );
@@ -152,6 +276,12 @@ TEST_CASE("vsnprintf")
REQUIRE(test("hello ", "%-20s", "hello") );
REQUIRE(test("hello, world!", "%s, %s!", "hello", "world") );
+ REQUIRE(test("h", "%1s", "hello") );
+ REQUIRE(test("he", "%2s", "hello") );
+ REQUIRE(test("hel", "%3s", "hello") );
+ REQUIRE(test("hell", "%4s", "hello") );
+ REQUIRE(test("hello", "%5s", "hello") );
+
bx::StringView str("0hello1world2");
bx::StringView hello(str, 1, 5);
bx::StringView world(str, 7, 5);
@@ -159,6 +289,11 @@ TEST_CASE("vsnprintf")
, hello.getLength(), hello.getPtr()
, world.getLength(), world.getPtr()
) );
+
+ REQUIRE(test("hello, world!", "%S, %S!"
+ , &hello
+ , &world
+ ) );
}
TEST_CASE("vsnprintf write")
@@ -175,3 +310,15 @@ TEST_CASE("vsnprintf write")
bx::StringView str(tmp, len);
REQUIRE(0 == bx::strCmp(str, "1389") );
}
+
+TEST_CASE("snprintf invalid")
+{
+ char temp[64];
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-0", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-03", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-03.", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-03.0", 1) );
+ REQUIRE(0 == bx::snprintf(temp, sizeof(temp), "%-03.0t", 1) );
+}