diff --git a/src/ox/std/strops.cpp b/src/ox/std/strops.cpp index 76c8d5c53..630b1f2e3 100644 --- a/src/ox/std/strops.cpp +++ b/src/ox/std/strops.cpp @@ -20,7 +20,7 @@ int ox_strcmp(const char *str1, const char *str2) { break; } i++; - } while (str1[i] == str2[i] && str1[i]); + } while (str1[i] || str2[i]); return retval; } diff --git a/src/ox/std/test/CMakeLists.txt b/src/ox/std/test/CMakeLists.txt index c59bf7bca..3fd5793c5 100644 --- a/src/ox/std/test/CMakeLists.txt +++ b/src/ox/std/test/CMakeLists.txt @@ -11,3 +11,20 @@ add_test("Test\\ ox_memcmp\\ ABCDEFG\\ !=\\ HIJKLMN" StdTest "ABCDEFG != HIJKLMN add_test("Test\\ ox_memcmp\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG") add_test("Test\\ ox_memcmp\\ ABCDEFG\\ ==\\ ABCDEFG" StdTest "ABCDEFG == ABCDEFG") add_test("Test\\ ox_memcmp\\ ABCDEFGHI\\ ==\\ ABCDEFG" StdTest "ABCDEFGHI == ABCDEFG") + + +################################################################################ +# StrOps Tests + +add_executable( + StrOpsTest + strops_test.cpp +) + +target_link_libraries(StrOpsTest OxStd) + +add_test("Test\\ ox_strcmp\\ asdf\\ !=\\ hijk" StrOpsTest "asdf < hijk") +add_test("Test\\ ox_strcmp\\ hijk\\ !=\\ asdf" StrOpsTest "hijk > asdf") +add_test("Test\\ ox_strcmp\\ read\\ !=\\ resize" StrOpsTest "read < resize") +add_test("Test\\ ox_strcmp\\ resize\\ !=\\ read" StrOpsTest "resize > read") +add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest "resize == resize") diff --git a/src/ox/std/test/strops_test.cpp b/src/ox/std/test/strops_test.cpp new file mode 100644 index 000000000..567a4f0da --- /dev/null +++ b/src/ox/std/test/strops_test.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2015 - 2016 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include +#include +#include +#include + +using namespace std; + +map> tests = { + { + "asdf < hijk", + []() { + return !(ox_strcmp("asdf", "hijk") < 0); + } + }, + { + "hijk > asdf", + []() { + return !(ox_strcmp("hijk", "asdf") > 0); + } + }, + { + "resize > read", + []() { + return !(ox_strcmp("resize", "read") > 0); + } + }, + { + "read < resize", + []() { + return !(ox_strcmp("read", "resize") < 0); + } + }, + { + "resize == resize", + []() { + return !(ox_strcmp("resize", "resize") == 0); + } + }, +}; + +int main(int argc, const char **args) { + if (argc > 1) { + auto testName = args[1]; + if (tests.find(testName) != tests.end()) { + return tests[testName](); + } + } + return -1; +}