Fix ox_strcmp and add tests for it
This commit is contained in:
@@ -20,7 +20,7 @@ int ox_strcmp(const char *str1, const char *str2) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
} while (str1[i] == str2[i] && str1[i]);
|
} while (str1[i] || str2[i]);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG")
|
||||||
add_test("Test\\ ox_memcmp\\ ABCDEFG\\ ==\\ ABCDEFG" StdTest "ABCDEFG == ABCDEFG")
|
add_test("Test\\ ox_memcmp\\ ABCDEFG\\ ==\\ ABCDEFG" StdTest "ABCDEFG == ABCDEFG")
|
||||||
add_test("Test\\ ox_memcmp\\ ABCDEFGHI\\ ==\\ ABCDEFG" StdTest "ABCDEFGHI == 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")
|
||||||
|
|||||||
@@ -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 <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
#include <ox/std/std.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
map<string, function<int()>> 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user