diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 4 | ||||
-rw-r--r-- | main/tests/test_oa_hash_map.cpp | 29 | ||||
-rw-r--r-- | main/tests/test_string.cpp | 173 |
3 files changed, 164 insertions, 42 deletions
diff --git a/main/main.cpp b/main/main.cpp index 41ae368087..e9cd183d8a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -729,7 +729,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph #ifdef TOOLS_ENABLED editor = false; #else - OS::get_singleton()->print("Error: Could not load game path '%s'.\n", project_path.ascii().get_data()); + String error_msg = "Error: Could not load game data at path '" + project_path + "'. Is the .pck file missing?\n"; + OS::get_singleton()->print(error_msg.ascii().get_data()); + OS::get_singleton()->alert(error_msg); goto error; #endif diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp index 26e728d3aa..deaba285cf 100644 --- a/main/tests/test_oa_hash_map.cpp +++ b/main/tests/test_oa_hash_map.cpp @@ -92,6 +92,35 @@ MainLoop *test() { } } + // stress test / test for issue #22928 + { + OAHashMap<int, int> map; + int dummy; + const int N = 1000; + uint32_t *keys = new uint32_t[N]; + + Math::seed(0); + + // insert a couple of random keys (with a dummy value, which is ignored) + for (int i = 0; i < N; i++) { + keys[i] = Math::rand(); + map.set(keys[i], dummy); + + if (!map.lookup(keys[i], dummy)) + OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i])); + } + + // check whether the keys are still present + for (int i = 0; i < N; i++) { + if (!map.lookup(keys[i], dummy)) { + OS::get_singleton()->print("could not find 0x%X despite it has been inserted previously! (not checking the other keys, breaking...)\n", unsigned(keys[i])); + break; + } + } + + delete[] keys; + } + return NULL; } } // namespace TestOAHashMap diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index 74157d63c9..7e19c7bf3e 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -480,7 +480,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish % frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; //////// INTS @@ -491,7 +491,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Int left padded with zeroes. format = "fish %05d frog"; @@ -500,7 +500,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 00005 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Int left padded with spaces. format = "fish %5d frog"; @@ -509,7 +509,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Int right padded with spaces. format = "fish %-5d frog"; @@ -518,7 +518,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Int with sign (positive). format = "fish %+d frog"; @@ -527,7 +527,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish +5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Negative int. format = "fish %d frog"; @@ -536,7 +536,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish -5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Hex (lower) format = "fish %x frog"; @@ -545,7 +545,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 2d frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Hex (upper) format = "fish %X frog"; @@ -554,7 +554,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 2D frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Octal format = "fish %o frog"; @@ -563,7 +563,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 143 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ////// REALS @@ -574,7 +574,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real left-padded format = "fish %11f frog"; @@ -583,7 +583,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real right-padded format = "fish %-11f frog"; @@ -592,7 +592,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real given int. format = "fish %f frog"; @@ -601,7 +601,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.000000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real with sign (positive). format = "fish %+f frog"; @@ -610,7 +610,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish +99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real with 1 decimals. format = "fish %.1f frog"; @@ -619,7 +619,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 100.0 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real with 12 decimals. format = "fish %.12f frog"; @@ -628,7 +628,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.990000000000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Real with no decimals. format = "fish %.f frog"; @@ -637,7 +637,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 100 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; /////// Strings. @@ -648,7 +648,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // String left-padded format = "fish %10s frog"; @@ -657,7 +657,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // String right-padded format = "fish %-10s frog"; @@ -666,7 +666,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ///// Characters @@ -677,7 +677,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish A frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Character as int. format = "fish %c frog"; @@ -686,7 +686,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish A frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ///// Dynamic width @@ -698,7 +698,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Int dynamic width format = "fish %*d frog"; @@ -708,7 +708,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Float dynamic width format = "fish %*.*f frog"; @@ -719,7 +719,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == String("fish 99.990 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ///// Errors @@ -730,7 +730,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "not enough arguments for format string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // More arguments than formats. format = "fish %s frog"; @@ -740,7 +740,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "not all arguments converted during string formatting" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Incomplete format. format = "fish %10"; @@ -749,7 +749,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "incomplete format" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Bad character in format string format = "fish %&f frog"; @@ -758,7 +758,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "unsupported format character" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Too many decimals. format = "fish %2.2.2f frog"; @@ -767,7 +767,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "too many decimal points in format" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // * not a number format = "fish %*f frog"; @@ -777,7 +777,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "* wants number" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Character too long. format = "fish %c frog"; @@ -786,7 +786,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "%c requires number or single-character string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; // Character bad type. format = "fish %c frog"; @@ -795,7 +795,7 @@ bool test_28() { output = format.sprintf(args, &error); success = (output == "%c requires number or single-character string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; return state; } @@ -819,37 +819,127 @@ bool test_29() { String ip4 = "192.168.0.1"; bool success = ip4.is_valid_ip_address(); OS::get_singleton()->print("Is valid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ip4 = "192.368.0.1"; success = (!ip4.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; String ip6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; success = ip6.is_valid_ip_address(); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ip6 = "2001:0db8:85j3:0000:0000:8a2e:0370:7334"; success = (!ip6.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ip6 = "2001:0db8:85f345:0000:0000:8a2e:0370:7334"; success = (!ip6.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ip6 = "2001:0db8::0:8a2e:370:7334"; success = (ip6.is_valid_ip_address()); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; ip6 = "::ffff:192.168.0.1"; success = (ip6.is_valid_ip_address()); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); - if (!success) state = false; + state = state && success; + + return state; +}; + +bool test_30() { + bool state = true; + bool success = true; + String input = "bytes2var"; + String output = "Bytes 2 Var"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "linear2db"; + output = "Linear 2 Db"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "vector3"; + output = "Vector 3"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "sha256"; + output = "Sha 256"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "2db"; + output = "2 Db"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "PascalCase"; + output = "Pascal Case"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "PascalPascalCase"; + output = "Pascal Pascal Case"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "snake_case"; + output = "Snake Case"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "snake_snake_case"; + output = "Snake Snake Case"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "sha256sum"; + output = "Sha 256 Sum"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "cat2dog"; + output = "Cat 2 Dog"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "function(name)"; + output = "Function(name)"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "snake_case_function(snake_case_arg)"; + output = "Snake Case Function(snake Case Arg)"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); + + input = "snake_case_function( snake_case_arg )"; + output = "Snake Case Function( Snake Case Arg )"; + success = (input.capitalize() == output); + state = state && success; + OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); return state; }; @@ -887,6 +977,7 @@ TestFunc test_funcs[] = { test_27, test_28, test_29, + test_30, 0 }; |