diff --git a/tests/os_test.cpp b/tests/os_test.cpp index 388d50d3b..956117fba 100644 --- a/tests/os_test.cpp +++ b/tests/os_test.cpp @@ -10,8 +10,12 @@ TEST_CASE("getProcessMemoryUsed", "") { + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + SKIP("Not supported by wasm."); + } + REQUIRE(0 != bx::getProcessMemoryUsed() ); -// DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() ); } #if BX_CONFIG_SUPPORTS_THREADING diff --git a/tests/run_test.cpp b/tests/run_test.cpp index 973a820d7..0602eed5a 100644 --- a/tests/run_test.cpp +++ b/tests/run_test.cpp @@ -26,7 +26,7 @@ bool testAssertHandler(const bx::Location& _location, const char* _format, va_li return true; } -int runAllTests(int _argc, const char* _argv[]) +int runAllTests(int32_t _argc, const char* _argv[]) { bx::setAssertHandler(testAssertHandler); @@ -58,12 +58,25 @@ int runAllTests(int _argc, const char* _argv[]) "\n\n" ); + bx::printf("Args:\n"); + + for (int32_t ii = 0; ii < _argc; ++ii) + { + bx::printf("\t%2d: \"%s\"", ii, _argv[ii]); + } + + bx::printf("\n\n"); + using namespace Catch; Session session; ConfigData config; - config.defaultColourMode = BX_PLATFORM_EMSCRIPTEN ? ColourMode::None : ColourMode::PlatformDefault; + config.defaultColourMode = BX_PLATFORM_EMSCRIPTEN + ? ColourMode::None + : ColourMode::PlatformDefault + ; + config.showDurations = ShowDurations::Always; session.useConfigData(config); diff --git a/tests/vsnprintf_test.cpp b/tests/vsnprintf_test.cpp index a4a432b51..ccbf508c3 100644 --- a/tests/vsnprintf_test.cpp +++ b/tests/vsnprintf_test.cpp @@ -12,9 +12,10 @@ TEST_CASE("No output buffer provided.", "[string][printf]") { - REQUIRE(4 == bx::snprintf(NULL, 0, "test") ); - - REQUIRE(1 == bx::snprintf(NULL, 0, "%d", 1) ); + REQUIRE(4 == bx::snprintf(NULL, 0, "test") ); + REQUIRE(4 == bx::snprintf(NULL, 10, "test") ); + REQUIRE(1 == bx::snprintf(NULL, 0, "%d", 1) ); + REQUIRE(1 == bx::snprintf(NULL, 10, "%d", 1) ); } TEST_CASE("Truncated output buffer.", "[string][printf]") @@ -58,7 +59,8 @@ TEST_CASE("Truncated output buffer.", "[string][printf]") template static bool test(const char* _expected, const char* _format, va_list _argList) { - int32_t max = (int32_t)bx::strLen(_expected) + 1; + const int32_t expectedLen = bx::strLen(_expected); + int32_t max = expectedLen + 1024; char* bxTemp = (char*)alloca(max); va_list argList; @@ -66,7 +68,7 @@ static bool test(const char* _expected, const char* _format, va_list _argList) const int32_t bxLen = bx::vsnprintf(bxTemp, max, _format, argList); bool result = true - && bxLen == max-1 + && bxLen == expectedLen && 0 == bx::strCmp(_expected, bxTemp) ; @@ -96,8 +98,8 @@ static bool test(const char* _expected, const char* _format, va_list _argList) { printf("---\n"); printf("printf format '%s'\n", _format); - printf(" result (%4d) '%s'\n", bxLen, bxTemp); - printf(" expected (%4d) '%s'\n", max-1, _expected); + printf(" bx result (%4d) '%s'\n", bxLen, bxTemp); + printf(" expected (%4d) '%s'\n", expectedLen, _expected); printf("CRT vsnprintf (%4d) '%s'\n", crtLen, crtTemp); } @@ -133,6 +135,9 @@ TEST_CASE("Format %f", "[string][printf]") REQUIRE(test(" 13.370", "%*.*f", 8, 3, 13.37) ); REQUIRE(test("13.370 ", "%-8.3f", 13.37) ); REQUIRE(test("13.370 ", "%*.*f", -8, 3, 13.37) ); + REQUIRE(test(" -13.370", "% 8.3f", -13.37) ); + REQUIRE(test(" 13.370", "% 16.3f", 13.37) ); + REQUIRE(test(" -13.370", "% 16.3f", -13.37) ); REQUIRE(test("nan ", "%-8f", std::numeric_limits::quiet_NaN() ) ); REQUIRE(test(" nan", "%8f", std::numeric_limits::quiet_NaN() ) ); @@ -216,8 +221,10 @@ TEST_CASE("Format %f", "[string][printf]") TEST_CASE("Format %d, %i, %o, %u, %x", "[string][printf]") { REQUIRE(test("1337", "%d", 1337) ); + REQUIRE(test("-1337", "% d", -1337) ); REQUIRE(test("1337 ", "%-20d", 1337) ); REQUIRE(test("-1337 ", "%-20d", -1337) ); + REQUIRE(test(" -1337", "% 20d", -1337) ); REQUIRE(test("1337", "%i", 1337) ); REQUIRE(test("1337 ", "%-20i", 1337) ); @@ -273,7 +280,7 @@ TEST_CASE("Format %d, %i, %o, %u, %x", "[string][printf]") REQUIRE(test("-001", "%04i", -1) ); REQUIRE(test("+001", "%+04i", 1) ); - if (BX_ENABLED(BX_ARCH_32BIT) ) + if (sizeof(intmax_t) == 4) { REQUIRE(test("2147483647", "%jd", INTMAX_MAX) ); } @@ -318,11 +325,18 @@ TEST_CASE("Format %s", "[string][printf]") TEST_CASE("Format %td", "[string][printf]") { - size_t size = size_t(-1); + ptrdiff_t size = ptrdiff_t(-1); REQUIRE(test("-1", "%td", size) ); - REQUIRE(test("3221225472", "%td", size_t(3221225472) ) ); + if (4 == sizeof(ptrdiff_t) ) + { + REQUIRE(test("-1073741824", "%td", ptrdiff_t(3221225472) ) ); + } + else + { + REQUIRE(test("3221225472", "%td", ptrdiff_t(3221225472) ) ); + } } TEST_CASE("Format %n", "[string][printf]") @@ -353,6 +367,7 @@ TEST_CASE("Format %c, %s, %S", "[string][printf]") REQUIRE(test("x ", "%-20c", 'x') ); REQUIRE(test("hello ", "%-20s", "hello") ); + REQUIRE(test(" hello", "%10s", "hello") ); REQUIRE(test("hello, world!", "%s, %s!", "hello", "world") ); REQUIRE(testNotStdCompliant("h", "%1s", "hello") );