summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bx/tests')
-rw-r--r--3rdparty/bx/tests/atomic_test.cpp46
-rw-r--r--3rdparty/bx/tests/easing_test.cpp58
-rw-r--r--3rdparty/bx/tests/filepath_test.cpp136
-rw-r--r--3rdparty/bx/tests/handle_bench.cpp2
-rw-r--r--3rdparty/bx/tests/handle_test.cpp10
-rw-r--r--3rdparty/bx/tests/hash_test.cpp79
-rw-r--r--3rdparty/bx/tests/macros_test.cpp2
-rw-r--r--3rdparty/bx/tests/main_test.cpp19
-rw-r--r--3rdparty/bx/tests/math_test.cpp (renamed from 3rdparty/bx/tests/fpumath_test.cpp)24
-rw-r--r--3rdparty/bx/tests/os_test.cpp16
-rw-r--r--3rdparty/bx/tests/queue_test.cpp6
-rw-r--r--3rdparty/bx/tests/rng_test.cpp88
-rw-r--r--3rdparty/bx/tests/settings_test.cpp49
-rw-r--r--3rdparty/bx/tests/simd_bench.cpp14
-rw-r--r--3rdparty/bx/tests/simd_test.cpp9
-rw-r--r--3rdparty/bx/tests/sort_test.cpp10
-rw-r--r--3rdparty/bx/tests/string_test.cpp300
-rw-r--r--3rdparty/bx/tests/thread_test.cpp41
-rw-r--r--3rdparty/bx/tests/tokenizecmd_test.cpp18
-rw-r--r--3rdparty/bx/tests/url_test.cpp69
-rw-r--r--3rdparty/bx/tests/vsnprintf_test.cpp6
21 files changed, 876 insertions, 126 deletions
diff --git a/3rdparty/bx/tests/atomic_test.cpp b/3rdparty/bx/tests/atomic_test.cpp
new file mode 100644
index 00000000000..81b3318e8c0
--- /dev/null
+++ b/3rdparty/bx/tests/atomic_test.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/cpu.h>
+
+TEST_CASE("atomic", "")
+{
+ uint32_t test = 1337;
+ uint32_t fetched;
+
+ fetched = bx::atomicFetchAndAdd(&test, 52u);
+ REQUIRE(fetched == 1337);
+ REQUIRE(test == 1389);
+
+ fetched = bx::atomicAddAndFetch(&test, 64u);
+ REQUIRE(fetched == 1453);
+ REQUIRE(test == 1453);
+
+ fetched = bx::atomicFetchAndSub(&test, 64u);
+ REQUIRE(fetched == 1453);
+ REQUIRE(test == 1389);
+
+ fetched = bx::atomicSubAndFetch(&test, 52u);
+ REQUIRE(fetched == 1337);
+ REQUIRE(test == 1337);
+
+ fetched = bx::atomicFetchAndAddsat(&test, 52u, 1453u);
+ REQUIRE(fetched == 1337);
+ REQUIRE(test == 1389);
+
+ fetched = bx::atomicFetchAndAddsat(&test, 1000u, 1453u);
+ REQUIRE(fetched == 1389);
+ REQUIRE(test == 1453);
+
+ fetched = bx::atomicFetchAndSubsat(&test, 64u, 1337u);
+ REQUIRE(fetched == 1453);
+ REQUIRE(test == 1389);
+
+ fetched = bx::atomicFetchAndSubsat(&test, 1000u, 1337u);
+ REQUIRE(fetched == 1389);
+ REQUIRE(test == 1337);
+
+}
diff --git a/3rdparty/bx/tests/easing_test.cpp b/3rdparty/bx/tests/easing_test.cpp
new file mode 100644
index 00000000000..9bf3c996798
--- /dev/null
+++ b/3rdparty/bx/tests/easing_test.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+
+#include <bx/easing.h>
+#include <bx/file.h>
+
+TEST_CASE("easing", "")
+{
+ bx::WriterI* writer = bx::getNullOut();
+
+ for (uint32_t ee = 0; ee < bx::Easing::Count; ++ee)
+ {
+ bx::writePrintf(writer, "\n\n%d\n", ee);
+
+ const bx::EaseFn easing = bx::getEaseFunc(bx::Easing::Enum(ee) );
+
+ const int32_t nx = 64;
+ const int32_t ny = 10;
+
+ bx::writePrintf(writer, "\t/// ^\n");
+
+ for (int32_t yy = ny+4; yy >= -5; --yy)
+ {
+ const float ys = float(yy )/float(ny);
+ const float ye = float(yy+1.0)/float(ny);
+
+ bx::writePrintf(writer, "\t/// %c", yy != 0 ? '|' : '+');
+
+ for (int32_t xx = 0; xx < nx; ++xx)
+ {
+ int32_t jj = 0;
+ for (; jj < 10; ++jj)
+ {
+ const float tt = float(xx*10+jj)/10.0f/float(nx);
+ const float vv = easing(tt);
+
+ if (vv >= ys
+ && vv < ye)
+ {
+ bx::writePrintf(writer, "*");
+ break;
+ }
+ }
+
+ if (jj == 10)
+ {
+ bx::writePrintf(writer, "%c", yy != 0 ? ' ' : '-');
+ }
+ }
+
+ bx::writePrintf(writer, "%s\n", yy != 0 ? "" : ">");
+ }
+ }
+}
diff --git a/3rdparty/bx/tests/filepath_test.cpp b/3rdparty/bx/tests/filepath_test.cpp
new file mode 100644
index 00000000000..5b743c66c23
--- /dev/null
+++ b/3rdparty/bx/tests/filepath_test.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/filepath.h>
+
+struct FilePathTest
+{
+ const char* filePath;
+ const char* expected;
+};
+
+FilePathTest s_filePathTest[] =
+{
+ // Already clean
+ {"", "."},
+ {"abc", "abc"},
+ {"abc/def", "abc/def"},
+ {"a/b/c", "a/b/c"},
+ {".", "."},
+ {"..", ".."},
+ {"../..", "../.."},
+ {"../../abc", "../../abc"},
+ {"/abc", "/abc"},
+ {"/", "/"},
+
+ // Do not remove trailing slash
+ {"abc/", "abc/"},
+ {"abc/def/", "abc/def/"},
+ {"a/b/c/", "a/b/c/"},
+ {"./", "./"},
+ {"../", "../"},
+ {"../../", "../../"},
+ {"/abc/", "/abc/"},
+
+ // Remove doubled slash
+ {"abc//def//ghi", "abc/def/ghi"},
+ {"//abc", "/abc"},
+ {"///abc", "/abc"},
+ {"//abc//", "/abc/"},
+ {"abc//", "abc/"},
+
+ // Remove . elements
+ {"abc/./def", "abc/def"},
+ {"/./abc/def", "/abc/def"},
+ {"abc/.", "abc"},
+
+ // Remove .. elements
+ {"abc/def/ghi/../jkl", "abc/def/jkl"},
+ {"abc/def/../ghi/../jkl", "abc/jkl"},
+ {"abc/def/..", "abc"},
+ {"abc/def/../..", "."},
+ {"/abc/def/../..", "/"},
+ {"abc/def/../../..", ".."},
+ {"/abc/def/../../..", "/"},
+ {"abc/def/../../../ghi/jkl/../../../mno", "../../mno"},
+
+ // Combinations
+ {"abc/./../def", "def"},
+ {"abc//./../def", "def"},
+ {"abc/../../././../def", "../../def"},
+
+ {"abc\\/../..\\/././../def", "../../def"},
+ {"\\abc/def\\../..\\..", "/"},
+};
+
+struct FilePathSplit
+{
+ const char* filePath;
+ bool absolute;
+ const char* path;
+ const char* fileName;
+ const char* baseName;
+ const char* extension;
+};
+
+static const FilePathSplit s_filePathSplit[] =
+{
+ { "\\abc/def\\../..\\../test.txt", true, "/", "test.txt", "test", ".txt" },
+ { "/abv/gd/555/333/pod.mac", true, "/abv/gd/555/333/", "pod.mac", "pod", ".mac" },
+ { "archive.tar.gz", false, "", "archive.tar.gz", "archive", ".tar.gz" },
+ { "tmp/archive.tar.gz", false, "tmp/", "archive.tar.gz", "archive", ".tar.gz" },
+ { "/tmp/archive.tar.gz", true, "/tmp/", "archive.tar.gz", "archive", ".tar.gz" },
+ { "d:/tmp/archive.tar.gz", true, "D:/tmp/", "archive.tar.gz", "archive", ".tar.gz" },
+ { "/tmp/abv/gd", true, "/tmp/abv/", "gd", "gd", "" },
+ { "/tmp/abv/gd/", true, "/tmp/abv/gd/", "", "", "" },
+};
+
+TEST_CASE("FilePath", "")
+{
+ bx::FilePath fp;
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_filePathTest); ++ii)
+ {
+ const FilePathTest& test = s_filePathTest[ii];
+
+ fp.set(test.filePath);
+ const bx::StringView result = fp.get();
+
+ REQUIRE(0 == bx::strCmp(test.expected, result) );
+ }
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_filePathSplit); ++ii)
+ {
+ const FilePathSplit& test = s_filePathSplit[ii];
+
+ fp.set(test.filePath);
+ const bx::StringView path = fp.getPath();
+ const bx::StringView fileName = fp.getFileName();
+ const bx::StringView baseName = fp.getBaseName();
+ const bx::StringView ext = fp.getExt();
+
+ REQUIRE(0 == bx::strCmp(test.path, path) );
+ REQUIRE(0 == bx::strCmp(test.fileName, fileName) );
+ REQUIRE(0 == bx::strCmp(test.baseName, baseName) );
+ REQUIRE(0 == bx::strCmp(test.extension, ext) );
+ REQUIRE(test.absolute == fp.isAbsolute() );
+ };
+}
+
+TEST_CASE("FilePath temp", "")
+{
+ bx::FilePath tmp(bx::Dir::Temp);
+ REQUIRE(0 != bx::strCmp(".", tmp.getPath().getPtr() ) );
+
+ bx::Error err;
+ tmp.join("test/abvgd/555333/test");
+ REQUIRE(bx::makeAll(tmp, &err) );
+ REQUIRE(err.isOk() );
+
+ tmp.set(bx::Dir::Temp);
+ tmp.join("test");
+ REQUIRE(bx::removeAll(tmp, &err) );
+ REQUIRE(err.isOk() );
+}
diff --git a/3rdparty/bx/tests/handle_bench.cpp b/3rdparty/bx/tests/handle_bench.cpp
index e8d8bee11cf..e5bd3007233 100644
--- a/3rdparty/bx/tests/handle_bench.cpp
+++ b/3rdparty/bx/tests/handle_bench.cpp
@@ -106,5 +106,5 @@ int main()
extern void simd_bench();
simd_bench();
- return EXIT_SUCCESS;
+ return bx::kExitSuccess;
}
diff --git a/3rdparty/bx/tests/handle_test.cpp b/3rdparty/bx/tests/handle_test.cpp
index b82e1da3174..05392922511 100644
--- a/3rdparty/bx/tests/handle_test.cpp
+++ b/3rdparty/bx/tests/handle_test.cpp
@@ -89,26 +89,26 @@ TEST_CASE("HandleHashTable", "")
bx::StringView sv0("test0");
- bool ok = hm.insert(bx::hashMurmur2A(sv0), 0);
+ bool ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
REQUIRE(ok);
- ok = hm.insert(bx::hashMurmur2A(sv0), 0);
+ ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
REQUIRE(!ok);
REQUIRE(1 == hm.getNumElements() );
bx::StringView sv1("test1");
- ok = hm.insert(bx::hashMurmur2A(sv1), 0);
+ ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv1), 0);
REQUIRE(ok);
REQUIRE(2 == hm.getNumElements() );
hm.removeByHandle(0);
REQUIRE(0 == hm.getNumElements() );
- ok = hm.insert(bx::hashMurmur2A(sv0), 0);
+ ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
REQUIRE(ok);
- hm.removeByKey(bx::hashMurmur2A(sv0) );
+ hm.removeByKey(bx::hash<bx::HashMurmur2A>(sv0) );
REQUIRE(0 == hm.getNumElements() );
for (uint32_t ii = 0, num = hm.getMaxCapacity(); ii < num; ++ii)
diff --git a/3rdparty/bx/tests/hash_test.cpp b/3rdparty/bx/tests/hash_test.cpp
new file mode 100644
index 00000000000..8fbc542af94
--- /dev/null
+++ b/3rdparty/bx/tests/hash_test.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/hash.h>
+
+void makeCrcTable(uint32_t _poly)
+{
+ for (uint32_t ii = 0; ii < 256; ++ii)
+ {
+ uint32_t crc = ii;
+ for (uint32_t jj = 0; jj < 8; ++jj)
+ {
+ if (1 == (crc & 1) )
+ {
+ crc = (crc >> 1) ^ _poly;
+ }
+ else
+ {
+ crc >>= 1;
+ }
+ }
+
+ printf("0x%08x,%c", crc, 7 == (ii & 7) ? '\n' : ' ');
+ }
+}
+
+struct HashTest
+{
+ uint32_t crc32;
+ uint32_t adler32;
+ const char* input;
+};
+
+const HashTest s_hashTest[] =
+{
+ { 0, 1, "" },
+ { 0xe8b7be43, 0x00620062, "a" },
+ { 0x9e83486d, 0x012600c4, "ab" },
+ { 0xc340daab, 0x06060205, "abvgd" },
+ { 0x07642fe2, 0x020a00d6, "1389" },
+ { 0x26d75737, 0x04530139, "555333" },
+};
+
+TEST_CASE("HashCrc32", "")
+{
+#if 0
+ makeCrcTable(0xedb88320);
+ printf("\n");
+ makeCrcTable(0x82f63b78);
+ printf("\n");
+ makeCrcTable(0xeb31d82e);
+#endif // 0
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_hashTest); ++ii)
+ {
+ const HashTest& test = s_hashTest[ii];
+
+ bx::HashCrc32 hash;
+ hash.begin();
+ hash.add(test.input, bx::strLen(test.input) );
+ REQUIRE(test.crc32 == hash.end() );
+ }
+}
+
+TEST_CASE("HashAdler32", "")
+{
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_hashTest); ++ii)
+ {
+ const HashTest& test = s_hashTest[ii];
+
+ bx::HashAdler32 hash;
+ hash.begin();
+ hash.add(test.input, bx::strLen(test.input) );
+ REQUIRE(test.adler32 == hash.end() );
+ }
+}
diff --git a/3rdparty/bx/tests/macros_test.cpp b/3rdparty/bx/tests/macros_test.cpp
index bae4bb896cf..092bbd61726 100644
--- a/3rdparty/bx/tests/macros_test.cpp
+++ b/3rdparty/bx/tests/macros_test.cpp
@@ -61,5 +61,5 @@ TEST(macros)
CHECK_EQUAL(5, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
- CHECK_EQUAL(0, bx::strncmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
+ CHECK_EQUAL(0, bx::strCmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
}
diff --git a/3rdparty/bx/tests/main_test.cpp b/3rdparty/bx/tests/main_test.cpp
index b9d66db2fd6..261b62a2139 100644
--- a/3rdparty/bx/tests/main_test.cpp
+++ b/3rdparty/bx/tests/main_test.cpp
@@ -16,25 +16,6 @@ void ANativeActivity_onCreate(ANativeActivity*, void*, size_t)
{
exit(runAllTests(BX_COUNTOF(s_argv), s_argv) );
}
-#elif BX_PLATFORM_NACL
-# include <ppapi/c/pp_errors.h>
-# include <ppapi/c/ppp.h>
-
-PP_EXPORT const void* PPP_GetInterface(const char* /*_name*/)
-{
- return NULL;
-}
-
-PP_EXPORT int32_t PPP_InitializeModule(PP_Module /*_module*/, PPB_GetInterface /*_interface*/)
-{
- DBG("PPAPI version: %d", PPAPI_RELEASE);
- runAllTests(BX_COUNTOF(s_argv), s_argv);
- return PP_ERROR_NOINTERFACE;
-}
-
-PP_EXPORT void PPP_ShutdownModule()
-{
-}
#else
int main(int _argc, const char* _argv[])
{
diff --git a/3rdparty/bx/tests/fpumath_test.cpp b/3rdparty/bx/tests/math_test.cpp
index ae843872e43..2005a67908c 100644
--- a/3rdparty/bx/tests/fpumath_test.cpp
+++ b/3rdparty/bx/tests/math_test.cpp
@@ -4,7 +4,7 @@
*/
#include "test.h"
-#include <bx/fpumath.h>
+#include <bx/math.h>
#if !BX_COMPILER_MSVC || BX_COMPILER_MSVC >= 1800
#include <cmath>
@@ -13,13 +13,25 @@ TEST_CASE("isFinite, isInfinite, isNan", "")
for (uint64_t ii = 0; ii < UINT32_MAX; ii += rand()%(1<<13)+1)
{
union { uint32_t ui; float f; } u = { uint32_t(ii) };
- REQUIRE(std::isnan(u.f) == bx::isNan(u.f) );
+ REQUIRE(std::isnan(u.f) == bx::isNan(u.f) );
REQUIRE(std::isfinite(u.f) == bx::isFinite(u.f) );
- REQUIRE(std::isinf(u.f) == bx::isInfinite(u.f) );
+ REQUIRE(std::isinf(u.f) == bx::isInfinite(u.f) );
}
}
#endif // !BX_COMPILER_MSVC || BX_COMPILER_MSVC >= 1800
+
+bool flog2_test(float _a)
+{
+ return bx::flog2(_a) == bx::flog(_a) * (1.0f / bx::flog(2.0f) );
+}
+
+TEST_CASE("flog2", "")
+{
+ flog2_test(0.0f);
+ flog2_test(256.0f);
+}
+
TEST_CASE("ToBits", "")
{
REQUIRE(UINT32_C(0x12345678) == bx::floatToBits( bx::bitsToFloat( UINT32_C(0x12345678) ) ) );
@@ -65,9 +77,9 @@ TEST_CASE("quaternion", "")
bx::mtxIdentity(mtx);
mtxCheck(mtxQ, mtx);
- float ax = bx::pi/27.0f;
- float ay = bx::pi/13.0f;
- float az = bx::pi/7.0f;
+ float ax = bx::kPi/27.0f;
+ float ay = bx::kPi/13.0f;
+ float az = bx::kPi/7.0f;
bx::quatRotateX(quat, ax);
bx::mtxQuat(mtxQ, quat);
diff --git a/3rdparty/bx/tests/os_test.cpp b/3rdparty/bx/tests/os_test.cpp
index e6aeb314fbe..1589416e543 100644
--- a/3rdparty/bx/tests/os_test.cpp
+++ b/3rdparty/bx/tests/os_test.cpp
@@ -5,6 +5,8 @@
#include "test.h"
#include <bx/os.h>
+#include <bx/semaphore.h>
+#include <bx/timer.h>
TEST_CASE("getProcessMemoryUsed", "")
{
@@ -12,9 +14,15 @@ TEST_CASE("getProcessMemoryUsed", "")
// DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() );
}
-TEST_CASE("getTempPath", "")
+TEST_CASE("semaphore_timeout", "")
{
- char tmpDir[512];
- uint32_t len = BX_COUNTOF(tmpDir);
- REQUIRE(bx::getTempPath(tmpDir, &len) );
+ bx::Semaphore sem;
+
+ 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);
+ REQUIRE(!ok);
}
diff --git a/3rdparty/bx/tests/queue_test.cpp b/3rdparty/bx/tests/queue_test.cpp
index 48fd270a274..81a2b44e676 100644
--- a/3rdparty/bx/tests/queue_test.cpp
+++ b/3rdparty/bx/tests/queue_test.cpp
@@ -21,14 +21,16 @@ uintptr_t ptrToBits(void* _ptr)
TEST_CASE("SpSc", "")
{
- bx::SpScUnboundedQueue queue;
+ bx::DefaultAllocator allocator;
+ bx::SpScUnboundedQueue queue(&allocator);
queue.push(bitsToPtr(0xdeadbeef) );
REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) );
}
TEST_CASE("MpSc", "")
{
- bx::MpScUnboundedQueueT<void> queue;
+ bx::DefaultAllocator allocator;
+ bx::MpScUnboundedQueueT<void> queue(&allocator);
queue.push(bitsToPtr(0xdeadbeef) );
REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) );
}
diff --git a/3rdparty/bx/tests/rng_test.cpp b/3rdparty/bx/tests/rng_test.cpp
new file mode 100644
index 00000000000..89fef3f05d7
--- /dev/null
+++ b/3rdparty/bx/tests/rng_test.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+
+#include <bx/rng.h>
+#include <bx/file.h>
+
+const uint32_t kMax = 10<<20;
+
+template<typename Ty>
+void testRng(const char* _name, Ty* _rng)
+{
+ uint32_t histBits[32];
+ uint32_t histUint8[256];
+
+ bx::memSet(histBits, 0, sizeof(histBits) );
+ bx::memSet(histUint8, 0, sizeof(histUint8) );
+
+ for (uint32_t ii = 0; ii < kMax; ++ii)
+ {
+ uint32_t val = _rng->gen();
+
+ for (uint32_t shift = 0; shift < 32; ++shift)
+ {
+ const uint32_t mask = 1<<shift;
+ histBits[shift] += !!(0 != (val & mask) );
+ }
+
+ const uint32_t mf000 = (val & 0xff000000)>>24;
+ const uint32_t m0f00 = (val & 0x00ff0000)>>16;
+ const uint32_t m00f0 = (val & 0x0000ff00)>> 8;
+ const uint32_t m000f = (val & 0x000000ff)>> 0;
+
+ histUint8[mf000]++;
+ histUint8[m0f00]++;
+ histUint8[m00f0]++;
+ histUint8[m000f]++;
+ }
+
+ bx::WriterI* writer = bx::getNullOut();
+ bx::writePrintf(writer, "%s\n", _name);
+
+ {
+ bx::writePrintf(writer, "\tbits histogram:\n");
+ uint32_t min = UINT32_MAX;
+ uint32_t max = 0;
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(histBits); ++ii)
+ {
+ bx::writePrintf(writer, "\t\t%3d: %d\n", ii, histBits[ii]);
+ min = bx::min(min, histBits[ii]);
+ max = bx::max(max, histBits[ii]);
+ }
+
+ bx::writePrintf(writer, "\tmin: %d, max: %d (diff: %d)\n", min, max, max-min);
+
+ REQUIRE(max-min < 8000);
+ }
+
+ {
+ bx::writePrintf(writer, "\tuint8_t histogram:\n");
+ uint32_t min = UINT32_MAX;
+ uint32_t max = 0;
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(histUint8); ++ii)
+ {
+ bx::writePrintf(writer, "\t\t%3d: %d\n", ii, histUint8[ii]);
+ min = bx::min(min, histUint8[ii]);
+ max = bx::max(max, histUint8[ii]);
+ }
+
+ bx::writePrintf(writer, "\tmin: %d, max: %d (diff: %d)\n", min, max, max-min);
+
+ REQUIRE(max-min < 8000);
+ }
+}
+
+TEST_CASE("Rng", "")
+{
+ bx::RngMwc mwc;
+ testRng("RngMwc", &mwc);
+
+ bx::RngShr3 shr3;
+ testRng("RngShr3", &shr3);
+}
diff --git a/3rdparty/bx/tests/settings_test.cpp b/3rdparty/bx/tests/settings_test.cpp
new file mode 100644
index 00000000000..9f94cfd9fa8
--- /dev/null
+++ b/3rdparty/bx/tests/settings_test.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/settings.h>
+#include <bx/file.h>
+
+TEST_CASE("Settings", "")
+{
+ bx::FilePath filePath;
+ filePath.set(bx::Dir::Temp);
+ filePath.join("settings.ini");
+
+ bx::DefaultAllocator allocator;
+
+ bx::Settings settings(&allocator);
+
+ settings.set("meh/podmac", "true");
+ settings.set("test/foo/bar/abvgd", "1389");
+
+ bx::FileWriter writer;
+ if (bx::open(&writer, filePath) )
+ {
+ bx::write(&writer, settings);
+ bx::close(&writer);
+ }
+
+ REQUIRE(NULL == settings.get("meh") );
+ REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
+ REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );
+
+ settings.remove("meh/podmac");
+ REQUIRE(NULL == settings.get("meh/podmac") );
+
+ settings.clear();
+
+ bx::FileReader reader;
+ if (bx::open(&reader, filePath) )
+ {
+ bx::read(&reader, settings);
+ bx::close(&reader);
+ }
+
+ REQUIRE(NULL == settings.get("meh") );
+ REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
+ REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );
+}
diff --git a/3rdparty/bx/tests/simd_bench.cpp b/3rdparty/bx/tests/simd_bench.cpp
index d8ace20c117..0f0c9c4671c 100644
--- a/3rdparty/bx/tests/simd_bench.cpp
+++ b/3rdparty/bx/tests/simd_bench.cpp
@@ -3,9 +3,9 @@
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
-#include <bx/simd_t.h>
+#include <bx/allocator.h>
#include <bx/rng.h>
-#include <bx/crtimpl.h>
+#include <bx/simd_t.h>
#include <bx/timer.h>
#include <stdio.h>
@@ -98,7 +98,7 @@ void simd_bench_pass(bx::simd128_t* _dst, bx::simd128_t* _src, uint32_t _numVert
void simd_bench()
{
- bx::CrtAllocator allocator;
+ bx::DefaultAllocator allocator;
bx::RngMwc rng;
const uint32_t numVertices = 1024*1024;
@@ -121,10 +121,10 @@ void simd_bench()
for (uint32_t ii = 0; ii < numVertices; ++ii)
{
float* ptr = (float*)&src[ii];
- ptr[0] = bx::fabsolute(ptr[0]);
- ptr[1] = bx::fabsolute(ptr[1]);
- ptr[2] = bx::fabsolute(ptr[2]);
- ptr[3] = bx::fabsolute(ptr[3]);
+ ptr[0] = bx::fabs(ptr[0]);
+ ptr[1] = bx::fabs(ptr[1]);
+ ptr[2] = bx::fabs(ptr[2]);
+ ptr[3] = bx::fabs(ptr[3]);
}
simd_bench_pass(dst, src, numVertices);
diff --git a/3rdparty/bx/tests/simd_test.cpp b/3rdparty/bx/tests/simd_test.cpp
index ca46fd00bc3..fcdc7a9cb1f 100644
--- a/3rdparty/bx/tests/simd_test.cpp
+++ b/3rdparty/bx/tests/simd_test.cpp
@@ -5,7 +5,7 @@
#include "test.h"
#include <bx/simd_t.h>
-#include <bx/fpumath.h>
+#include <bx/math.h>
#include <bx/string.h>
#if 0
@@ -206,7 +206,7 @@ void simd_check_string(const char* _str, bx::simd128_t _a)
SIMD_DBG("%s %s", _str, test);
- CHECK(0 == bx::strncmp(_str, test) );
+ CHECK(0 == bx::strCmp(_str, test) );
}
TEST_CASE("simd_swizzle", "")
@@ -235,13 +235,14 @@ TEST_CASE("simd_shuffle", "")
const simd128_t ABCD = simd_ild(0x41414141, 0x42424242, 0x43434343, 0x44444444);
simd_check_string("xyAB", simd_shuf_xyAB(xyzw, ABCD) );
simd_check_string("ABxy", simd_shuf_ABxy(xyzw, ABCD) );
- simd_check_string("zwCD", simd_shuf_zwCD(xyzw, ABCD) );
simd_check_string("CDzw", simd_shuf_CDzw(xyzw, ABCD) );
+ simd_check_string("zwCD", simd_shuf_zwCD(xyzw, ABCD) );
simd_check_string("xAyB", simd_shuf_xAyB(xyzw, ABCD) );
+ simd_check_string("AxBy", simd_shuf_AxBy(xyzw, ABCD) );
simd_check_string("zCwD", simd_shuf_zCwD(xyzw, ABCD) );
+ simd_check_string("CzDw", simd_shuf_CzDw(xyzw, ABCD) );
simd_check_string("xAzC", simd_shuf_xAzC(xyzw, ABCD) );
simd_check_string("yBwD", simd_shuf_yBwD(xyzw, ABCD) );
- simd_check_string("CzDw", simd_shuf_CzDw(xyzw, ABCD) );
}
TEST_CASE("simd_compare", "")
diff --git a/3rdparty/bx/tests/sort_test.cpp b/3rdparty/bx/tests/sort_test.cpp
index d271a3ffa03..0b078e23d90 100644
--- a/3rdparty/bx/tests/sort_test.cpp
+++ b/3rdparty/bx/tests/sort_test.cpp
@@ -23,13 +23,13 @@ TEST_CASE("quickSort", "")
{
const char* lhs = *(const char**)_lhs;
const char* rhs = *(const char**)_rhs;
- return bx::strncmp(lhs, rhs);
+ return bx::strCmp(lhs, rhs);
});
- REQUIRE(0 == bx::strncmp(str[0], "jabuka") );
- REQUIRE(0 == bx::strncmp(str[1], "jagoda") );
- REQUIRE(0 == bx::strncmp(str[2], "kruska") );
- REQUIRE(0 == bx::strncmp(str[3], "malina") );
+ 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") );
int8_t byte[128];
bx::RngMwc rng;
diff --git a/3rdparty/bx/tests/string_test.cpp b/3rdparty/bx/tests/string_test.cpp
index 35e1dac4445..d848f3de142 100644
--- a/3rdparty/bx/tests/string_test.cpp
+++ b/3rdparty/bx/tests/string_test.cpp
@@ -4,9 +4,10 @@
*/
#include "test.h"
+#include <bx/filepath.h>
#include <bx/string.h>
-#include <bx/crtimpl.h>
#include <bx/handlealloc.h>
+#include <bx/sort.h>
bx::AllocatorI* g_allocator;
@@ -23,110 +24,185 @@ TEST_CASE("chars", "")
}
}
-TEST_CASE("strnlen", "")
+TEST_CASE("strLen", "")
{
const char* test = "test";
- REQUIRE(0 == bx::strnlen(test, 0) );
- REQUIRE(2 == bx::strnlen(test, 2) );
- REQUIRE(4 == bx::strnlen(test, INT32_MAX) );
+ REQUIRE(0 == bx::strLen(test, 0) );
+ REQUIRE(2 == bx::strLen(test, 2) );
+ REQUIRE(4 == bx::strLen(test, INT32_MAX) );
}
-TEST_CASE("strlncpy", "")
+TEST_CASE("strCopy", "")
{
char dst[128];
size_t num;
- num = bx::strlncpy(dst, 1, "blah");
+ num = bx::strCopy(dst, 1, "blah");
REQUIRE(num == 0);
- num = bx::strlncpy(dst, 3, "blah", 3);
- REQUIRE(0 == bx::strncmp(dst, "bl") );
+ num = bx::strCopy(dst, 3, "blah", 3);
+ REQUIRE(0 == bx::strCmp(dst, "bl") );
REQUIRE(num == 2);
- num = bx::strlncpy(dst, sizeof(dst), "blah", 3);
- REQUIRE(0 == bx::strncmp(dst, "bla") );
+ num = bx::strCopy(dst, sizeof(dst), "blah", 3);
+ REQUIRE(0 == bx::strCmp(dst, "bla") );
REQUIRE(num == 3);
- num = bx::strlncpy(dst, sizeof(dst), "blah");
- REQUIRE(0 == bx::strncmp(dst, "blah") );
+ num = bx::strCopy(dst, sizeof(dst), "blah");
+ REQUIRE(0 == bx::strCmp(dst, "bl", 2) );
+ REQUIRE(0 == bx::strCmp(dst, "blah") );
REQUIRE(num == 4);
}
-TEST_CASE("strlncat", "")
+TEST_CASE("strCat", "")
{
char dst[128] = { '\0' };
- REQUIRE(0 == bx::strlncat(dst, 1, "cat") );
+ REQUIRE(0 == bx::strCat(dst, 1, "cat") );
- REQUIRE(4 == bx::strlncpy(dst, 5, "copy") );
- REQUIRE(3 == bx::strlncat(dst, 8, "cat") );
- REQUIRE(0 == bx::strncmp(dst, "copycat") );
+ REQUIRE(4 == bx::strCopy(dst, 5, "copy") );
+ REQUIRE(3 == bx::strCat(dst, 8, "cat") );
+ REQUIRE(0 == bx::strCmp(dst, "copycat") );
+ REQUIRE(0 == bx::strCmp(dst, "copy", 4) );
- REQUIRE(1 == bx::strlncat(dst, BX_COUNTOF(dst), "------", 1) );
- REQUIRE(3 == bx::strlncat(dst, BX_COUNTOF(dst), "cat") );
- REQUIRE(0 == bx::strncmp(dst, "copycat-cat") );
+ REQUIRE(1 == bx::strCat(dst, BX_COUNTOF(dst), "------", 1) );
+ REQUIRE(3 == bx::strCat(dst, BX_COUNTOF(dst), "cat") );
+ REQUIRE(0 == bx::strCmp(dst, "copycat-cat") );
}
-TEST_CASE("strincmp", "")
+TEST_CASE("strCmp", "")
{
- REQUIRE(0 == bx::strincmp("test", "test") );
- REQUIRE(0 == bx::strincmp("test", "testestes", 4) );
- REQUIRE(0 == bx::strincmp("testestes", "test", 4) );
- REQUIRE(0 != bx::strincmp("preprocess", "platform") );
+ REQUIRE(0 != bx::strCmp("meh", "meh/") );
+}
+
+TEST_CASE("strCmpI", "")
+{
+ REQUIRE(0 == bx::strCmpI("test", "test") );
+ REQUIRE(0 == bx::strCmpI("test", "testestes", 4) );
+ REQUIRE(0 == bx::strCmpI("testestes", "test", 4) );
+ REQUIRE(0 != bx::strCmpI("preprocess", "platform") );
const char* abvgd = "abvgd";
const char* abvgx = "abvgx";
const char* empty = "";
- REQUIRE(0 == bx::strincmp(abvgd, abvgd) );
- REQUIRE(0 == bx::strincmp(abvgd, abvgx, 4) );
+ REQUIRE(0 == bx::strCmpI(abvgd, abvgd) );
+ REQUIRE(0 == bx::strCmpI(abvgd, abvgx, 4) );
+ REQUIRE(0 == bx::strCmpI(empty, empty) );
- REQUIRE(0 > bx::strincmp(abvgd, abvgx) );
- REQUIRE(0 > bx::strincmp(empty, abvgd) );
+ REQUIRE(0 > bx::strCmpI(abvgd, abvgx) );
+ REQUIRE(0 > bx::strCmpI(empty, abvgd) );
- REQUIRE(0 < bx::strincmp(abvgx, abvgd) );
- REQUIRE(0 < bx::strincmp(abvgd, empty) );
+ REQUIRE(0 < bx::strCmpI(abvgx, abvgd) );
+ REQUIRE(0 < bx::strCmpI(abvgd, empty) );
}
-TEST_CASE("strnchr", "")
+TEST_CASE("strCmpV", "")
{
- const char* test = "test";
- REQUIRE(NULL == bx::strnchr(test, 's', 0) );
- REQUIRE(NULL == bx::strnchr(test, 's', 2) );
- REQUIRE(&test[2] == bx::strnchr(test, 's') );
+ REQUIRE(0 == bx::strCmpV("test", "test") );
+ REQUIRE(0 == bx::strCmpV("test", "testestes", 4) );
+ REQUIRE(0 == bx::strCmpV("testestes", "test", 4) );
+ REQUIRE(0 != bx::strCmpV("preprocess", "platform") );
+
+ const char* abvgd = "abvgd";
+ const char* abvgx = "abvgx";
+ const char* empty = "";
+ REQUIRE(0 == bx::strCmpV(abvgd, abvgd) );
+ REQUIRE(0 == bx::strCmpV(abvgd, abvgx, 4) );
+ REQUIRE(0 == bx::strCmpV(empty, empty) );
+
+ REQUIRE(0 > bx::strCmpV(abvgd, abvgx) );
+ REQUIRE(0 > bx::strCmpV(empty, abvgd) );
+
+ REQUIRE(0 < bx::strCmpV(abvgx, abvgd) );
+ REQUIRE(0 < bx::strCmpV(abvgd, empty) );
+}
+
+static int32_t strCmpV(const void* _lhs, const void* _rhs)
+{
+ const char* lhs = *(const char**)_lhs;
+ const char* rhs = *(const char**)_rhs;
+ int32_t result = bx::strCmpV(lhs, rhs);
+ return result;
+}
+
+TEST_CASE("strCmpV sort", "")
+{
+ const char* test[] =
+ {
+ "test_1.txt",
+ "test_10.txt",
+ "test_100.txt",
+ "test_15.txt",
+ "test_11.txt",
+ "test_23.txt",
+ "test_3.txt",
+ };
+
+ const char* expected[] =
+ {
+ "test_1.txt",
+ "test_3.txt",
+ "test_10.txt",
+ "test_11.txt",
+ "test_15.txt",
+ "test_23.txt",
+ "test_100.txt",
+ };
+
+ BX_STATIC_ASSERT(BX_COUNTOF(test) == BX_COUNTOF(expected) );
+
+ bx::quickSort(test, BX_COUNTOF(test), sizeof(const char*), strCmpV);
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(test); ++ii)
+ {
+ REQUIRE(0 == bx::strCmp(test[ii], expected[ii]) );
+ }
}
-TEST_CASE("strnrchr", "")
+TEST_CASE("strRFind", "")
{
const char* test = "test";
- REQUIRE(NULL == bx::strnrchr(test, 's', 0) );
- REQUIRE(NULL == bx::strnrchr(test, 's', 1) );
- REQUIRE(&test[2] == bx::strnrchr(test, 's') );
+ REQUIRE(NULL == bx::strRFind(bx::StringView(test, 0), 's') );
+ REQUIRE(NULL == bx::strRFind(bx::StringView(test, 1), 's') );
+ REQUIRE(&test[2] == bx::strRFind(test, 's') );
}
-TEST_CASE("stristr", "")
+TEST_CASE("strFindI", "")
{
const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
- REQUIRE(NULL == bx::stristr(test, "quick", 8) );
- REQUIRE(NULL == bx::stristr(test, "quick1") );
- REQUIRE(&test[4] == bx::stristr(test, "quick", 9) );
- REQUIRE(&test[4] == bx::stristr(test, "quick") );
+ REQUIRE(NULL == bx::strFindI(bx::StringView(test, 8), "quick") );
+ REQUIRE(NULL == bx::strFindI(test, "quick1") );
+ REQUIRE(&test[4] == bx::strFindI(bx::StringView(test, 9), "quick") );
+ REQUIRE(&test[4] == bx::strFindI(test, "quick") );
}
-TEST_CASE("strnstr", "")
+TEST_CASE("strFind", "")
{
- const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
+ {
+ const char* test = "test";
- REQUIRE(NULL == bx::strnstr(test, "quick", 8) );
- REQUIRE(NULL == bx::strnstr(test, "quick1") );
- REQUIRE(NULL == bx::strnstr(test, "quick", 9) );
- REQUIRE(NULL == bx::strnstr(test, "quick") );
+ REQUIRE(NULL == bx::strFind(bx::StringView(test, 0), 's') );
+ REQUIRE(NULL == bx::strFind(bx::StringView(test, 2), 's') );
+ REQUIRE(&test[2] == bx::strFind(test, 's') );
+ }
- REQUIRE(NULL == bx::strnstr(test, "Quick", 8) );
- REQUIRE(NULL == bx::strnstr(test, "Quick1") );
- REQUIRE(&test[4] == bx::strnstr(test, "Quick", 9) );
- REQUIRE(&test[4] == bx::strnstr(test, "Quick") );
+ {
+ const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
+
+ REQUIRE(NULL == bx::strFind(bx::StringView(test, 8), "quick") );
+ REQUIRE(NULL == bx::strFind(test, "quick1") );
+ REQUIRE(NULL == bx::strFind(bx::StringView(test, 9), "quick") );
+ REQUIRE(NULL == bx::strFind(test, "quick") );
+
+ REQUIRE(NULL == bx::strFind(bx::StringView(test, 8), "Quick") );
+ REQUIRE(NULL == bx::strFind(test, "Quick1") );
+ REQUIRE(&test[4] == bx::strFind(bx::StringView(test, 9), "Quick") );
+ REQUIRE(&test[4] == bx::strFind(test, "Quick") );
+
+ REQUIRE(NULL == bx::strFind("vgd", 'a') );
+ }
}
template<typename Ty>
@@ -134,8 +210,8 @@ static bool testToString(Ty _value, const char* _expected)
{
char tmp[1024];
int32_t num = bx::toString(tmp, BX_COUNTOF(tmp), _value);
- int32_t len = (int32_t)bx::strnlen(_expected);
- if (0 == bx::strncmp(tmp, _expected)
+ int32_t len = (int32_t)bx::strLen(_expected);
+ if (0 == bx::strCmp(tmp, _expected)
&& num == len)
{
return true;
@@ -178,6 +254,86 @@ TEST_CASE("toString double", "")
REQUIRE(testToString(1231231.23, "1231231.23") );
REQUIRE(testToString(0.000000000123123, "1.23123e-10") );
REQUIRE(testToString(0.0000000001, "1e-10") );
+ REQUIRE(testToString(-270.000000, "-270.0") );
+}
+
+static bool testFromString(double _value, const char* _input)
+{
+ char tmp[1024];
+ bx::toString(tmp, BX_COUNTOF(tmp), _value);
+
+ double lhs;
+ bx::fromString(&lhs, tmp);
+
+ double rhs;
+ bx::fromString(&rhs, _input);
+
+ if (lhs == rhs)
+ {
+ return true;
+ }
+
+ printf("result '%f', input '%s'\n", _value, _input);
+ return false;
+}
+
+TEST_CASE("fromString double", "")
+{
+ REQUIRE(testFromString(0.0, "0.0") );
+ REQUIRE(testFromString(-0.0, "-0.0") );
+ REQUIRE(testFromString(1.0, "1.0") );
+ REQUIRE(testFromString(-1.0, "-1.0") );
+ REQUIRE(testFromString(1.2345, "1.2345") );
+ REQUIRE(testFromString(1.2345678, "1.2345678") );
+ REQUIRE(testFromString(0.123456789012, "0.123456789012") );
+ REQUIRE(testFromString(1234567.8, "1234567.8") );
+ REQUIRE(testFromString(-79.39773355813419, "-79.39773355813419") );
+ REQUIRE(testFromString(0.000001, "0.000001") );
+ REQUIRE(testFromString(0.0000001, "1e-7") );
+ REQUIRE(testFromString(1e30, "1e30") );
+ REQUIRE(testFromString(1.234567890123456e30, "1.234567890123456e30") );
+ REQUIRE(testFromString(-5e-324, "-5e-324") );
+ REQUIRE(testFromString(2.225073858507201e-308, "2.225073858507201e-308") );
+ REQUIRE(testFromString(2.2250738585072014e-308, "2.2250738585072014e-308") );
+ REQUIRE(testFromString(1.7976931348623157e308, "1.7976931348623157e308") );
+ REQUIRE(testFromString(0.00000123123123, "0.00000123123123") );
+ REQUIRE(testFromString(0.000000123123123, "1.23123123e-7") );
+ REQUIRE(testFromString(123123.123, "123123.123") );
+ REQUIRE(testFromString(1231231.23, "1231231.23") );
+ REQUIRE(testFromString(0.000000000123123, "1.23123e-10") );
+ REQUIRE(testFromString(0.0000000001, "1e-10") );
+ REQUIRE(testFromString(-270.000000, "-270.0") );
+}
+
+static bool testFromString(int32_t _value, const char* _input)
+{
+ char tmp[1024];
+ bx::toString(tmp, BX_COUNTOF(tmp), _value);
+
+ double lhs;
+ bx::fromString(&lhs, tmp);
+
+ double rhs;
+ bx::fromString(&rhs, _input);
+
+ if (lhs == rhs)
+ {
+ return true;
+ }
+
+ printf("result '%d', input '%s'\n", _value, _input);
+ return false;
+}
+
+TEST_CASE("fromString int32_t", "")
+{
+ REQUIRE(testFromString(1389, "1389") );
+ REQUIRE(testFromString(1389, " 1389") );
+ REQUIRE(testFromString(1389, "+1389") );
+ REQUIRE(testFromString(-1389, "-1389") );
+ REQUIRE(testFromString(-1389, " -1389") );
+ REQUIRE(testFromString(555333, "555333") );
+ REQUIRE(testFromString(-21, "-021") );
}
TEST_CASE("StringView", "")
@@ -185,7 +341,7 @@ TEST_CASE("StringView", "")
bx::StringView sv("test");
REQUIRE(4 == sv.getLength() );
- bx::CrtAllocator crt;
+ bx::DefaultAllocator crt;
g_allocator = &crt;
typedef bx::StringT<&g_allocator> String;
@@ -196,10 +352,10 @@ TEST_CASE("StringView", "")
st.append("test");
REQUIRE(8 == st.getLength() );
- st.append("test", 2);
+ st.append(bx::StringView("test", 2) );
REQUIRE(10 == st.getLength() );
- REQUIRE(0 == bx::strncmp(st.getPtr(), "testtestte") );
+ REQUIRE(0 == bx::strCmp(st.getPtr(), "testtestte") );
st.clear();
REQUIRE(0 == st.getLength() );
@@ -211,3 +367,25 @@ TEST_CASE("StringView", "")
sv.clear();
REQUIRE(0 == sv.getLength() );
}
+
+TEST_CASE("Trim", "")
+{
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "ab"), "vgd") );
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "") );
+ 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"), "") );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "abv"), "abvgd") );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("/555333/podmac/", "/"), "/555333/podmac") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrim("abvgd", "da"), "bvg") );
+ REQUIRE(0 == bx::strCmp(bx::strTrim("<1389>", "<>"), "1389") );
+ REQUIRE(0 == bx::strCmp(bx::strTrim("/555333/podmac/", "/"), "555333/podmac") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrim("abvgd", ""), "abvgd") );
+ REQUIRE(0 == bx::strCmp(bx::strTrim(" \t a b\tv g d \t ", " \t"), "a b\tv g d") );
+
+ bx::FilePath uri("/555333/podmac/");
+ REQUIRE(0 == bx::strCmp(bx::strTrim(uri.getPath(), "/"), "555333/podmac") );
+}
diff --git a/3rdparty/bx/tests/thread_test.cpp b/3rdparty/bx/tests/thread_test.cpp
index 8d099311835..713781956fb 100644
--- a/3rdparty/bx/tests/thread_test.cpp
+++ b/3rdparty/bx/tests/thread_test.cpp
@@ -6,17 +6,37 @@
#include "test.h"
#include <bx/thread.h>
-int32_t threadExit0(void*)
+bx::DefaultAllocator s_allocator;
+bx::MpScUnboundedBlockingQueue<void> s_mpsc(&s_allocator);
+
+int32_t threadExit0(bx::Thread* _thread, void*)
{
- return 0;
+ _thread->pop();
+
+ s_mpsc.push(reinterpret_cast<void*>(uintptr_t(0x1300) ) );
+
+ return bx::kExitSuccess;
+}
+
+int32_t threadExit1(bx::Thread* _thread, void*)
+{
+ BX_UNUSED(_thread);
+
+ s_mpsc.push(reinterpret_cast<void*>(uintptr_t(0x89) ) );
+
+ return bx::kExitFailure;
}
-int32_t threadExit1(void*)
+TEST_CASE("Semaphore", "")
{
- return 1;
+ bx::Semaphore sem;
+ REQUIRE(!sem.wait(10) );
+
+ sem.post(1);
+ REQUIRE(sem.wait() );
}
-TEST_CASE("thread", "")
+TEST_CASE("Thread", "")
{
bx::Thread th;
@@ -24,6 +44,7 @@ TEST_CASE("thread", "")
th.init(threadExit0);
REQUIRE(th.isRunning() );
+ th.push(NULL);
th.shutdown();
REQUIRE(!th.isRunning() );
@@ -36,3 +57,13 @@ TEST_CASE("thread", "")
REQUIRE(!th.isRunning() );
REQUIRE(th.getExitCode() == 1);
}
+
+TEST_CASE("MpScUnboundedBlockingQueue", "")
+{
+ void* p0 = s_mpsc.pop();
+ void* p1 = s_mpsc.pop();
+
+ uintptr_t result = uintptr_t(p0) | uintptr_t(p1);
+
+ REQUIRE(result == 0x1389);
+}
diff --git a/3rdparty/bx/tests/tokenizecmd_test.cpp b/3rdparty/bx/tests/tokenizecmd_test.cpp
index d1495b28796..fece7ea2f25 100644
--- a/3rdparty/bx/tests/tokenizecmd_test.cpp
+++ b/3rdparty/bx/tests/tokenizecmd_test.cpp
@@ -15,12 +15,24 @@ TEST_CASE("commandLine", "")
"--long",
"--platform",
"x",
+ "--num", "1389",
+ "--foo",
+ "--", // it should not parse arguments after argument terminator
+ "--bar",
};
bx::CommandLine cmdLine(BX_COUNTOF(args), args);
- REQUIRE(cmdLine.hasArg("long") );
- REQUIRE(cmdLine.hasArg('s') );
+ REQUIRE( cmdLine.hasArg("long") );
+ REQUIRE( cmdLine.hasArg('s') );
+
+ int32_t num;
+ REQUIRE(cmdLine.hasArg(num, '\0', "num") );
+ REQUIRE(1389 == num);
+
+ // test argument terminator
+ REQUIRE( cmdLine.hasArg("foo") );
+ REQUIRE(!cmdLine.hasArg("bar") );
// non-existing argument
REQUIRE(!cmdLine.hasArg('x') );
@@ -46,7 +58,7 @@ static bool test(const char* _input, int32_t _argc, ...)
for (int32_t ii = 0; ii < _argc; ++ii)
{
const char* arg = va_arg(argList, const char*);
- if (0 != bx::strncmp(argv[ii], arg) )
+ if (0 != bx::strCmp(argv[ii], arg) )
{
return false;
}
diff --git a/3rdparty/bx/tests/url_test.cpp b/3rdparty/bx/tests/url_test.cpp
new file mode 100644
index 00000000000..504f4d2bc4d
--- /dev/null
+++ b/3rdparty/bx/tests/url_test.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/string.h>
+#include <bx/url.h>
+
+struct UrlTest
+{
+ bool result;
+ const char* url;
+ const char* tokens[bx::UrlView::Count];
+};
+
+static const UrlTest s_urlTest[] =
+{
+ { true
+ , "scheme://username:password@host.rs:80/this/is/path/index.php?query=\"value\"#fragment",
+ { "scheme", "username", "password", "host.rs", "80", "/this/is/path/index.php", "query=\"value\"", "fragment" }
+ },
+ { true
+ , "scheme://host.rs/",
+ { "scheme", "", "", "host.rs", "", "/", "", "" },
+ },
+ { true
+ , "scheme://host.rs:1389/",
+ { "scheme", "", "", "host.rs", "1389", "/", "", "" },
+ },
+ { true
+ , "host.rs/abvgd.html",
+ { "", "", "", "host.rs", "", "/abvgd.html", "", "" },
+ },
+ { true
+ , "https://192.168.0.1:8080/",
+ { "https", "", "", "192.168.0.1", "8080", "/", "", "" },
+ },
+
+ { true
+ , "file:///d:/tmp/archive.tar.gz",
+ { "file", "", "", "", "", "/d:/tmp/archive.tar.gz", "", "" },
+ },
+};
+
+TEST_CASE("tokenizeUrl", "")
+{
+ bx::UrlView url;
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_urlTest); ++ii)
+ {
+ const UrlTest& urlTest = s_urlTest[ii];
+
+ bool result = url.parse(urlTest.url);
+ REQUIRE(urlTest.result == result);
+
+ if (result)
+ {
+ for (uint32_t token = 0; token < bx::UrlView::Count; ++token)
+ {
+// char tmp[1024];
+// strCopy(tmp, BX_COUNTOF(tmp), url.get(bx::UrlView::Enum(token)) );
+// printf("`%s`, expected: `%s`\n", tmp, urlTest.tokens[token]);
+
+ REQUIRE(0 == bx::strCmp(urlTest.tokens[token], url.get(bx::UrlView::Enum(token)) ) );
+ }
+ }
+ }
+}
diff --git a/3rdparty/bx/tests/vsnprintf_test.cpp b/3rdparty/bx/tests/vsnprintf_test.cpp
index 12aea7bbb25..8498ec39096 100644
--- a/3rdparty/bx/tests/vsnprintf_test.cpp
+++ b/3rdparty/bx/tests/vsnprintf_test.cpp
@@ -20,12 +20,12 @@ TEST_CASE("vsnprintf truncated", "Truncated output buffer.")
char buffer[7];
REQUIRE(10 == bx::snprintf(buffer, BX_COUNTOF(buffer), "Ten chars!") );
- REQUIRE(0 == bx::strncmp(buffer, "Ten ch") );
+ REQUIRE(0 == bx::strCmp(buffer, "Ten ch") );
}
static bool test(const char* _expected, const char* _format, ...)
{
- int32_t max = (int32_t)bx::strnlen(_expected) + 1;
+ int32_t max = (int32_t)bx::strLen(_expected) + 1;
char* temp = (char*)alloca(max);
va_list argList;
@@ -35,7 +35,7 @@ static bool test(const char* _expected, const char* _format, ...)
bool result = true
&& len == max-1
- && 0 == bx::strncmp(_expected, temp)
+ && 0 == bx::strCmp(_expected, temp)
;
if (!result)