Pull in Ox as git subtree

This commit is contained in:
2017-05-06 12:09:42 -05:00
parent 346b01be07
commit 56fb5595f9
60 changed files with 5130 additions and 0 deletions

61
deps/ox/src/ox/std/test/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 2.8)
add_executable(
StdTest
tests.cpp
)
target_link_libraries(StdTest OxStd)
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")
add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest " == ")
add_test("Test\\ ox_strchr\\ 0" StrOpsTest "ox_strchr 0")
add_test("Test\\ ox_lastIndexOf\\ aaaa\\ a" StrOpsTest "ox_lastIndexOf aaaa a")
################################################################################
# Byte Swap Tests
add_executable(
ByteSwapTest
byteswap_test.cpp
)
target_link_libraries(ByteSwapTest OxStd)
add_test("Test\\ bigEndianAdapt\\ 0x00ff" ByteSwapTest bigEndianAdapt<uint16_t> 0x00ff)
add_test("Test\\ bigEndianAdapt\\ 0xff00" ByteSwapTest bigEndianAdapt<uint16_t> 0xff00)
add_test("Test\\ bigEndianAdapt\\ 0x000000ff" ByteSwapTest bigEndianAdapt<uint32_t> 0x000000ff)
add_test("Test\\ bigEndianAdapt\\ 0x0000ff00" ByteSwapTest bigEndianAdapt<uint32_t> 0x0000ff00)
add_test("Test\\ bigEndianAdapt\\ 0x00ff0000" ByteSwapTest bigEndianAdapt<uint32_t> 0x00ff0000)
add_test("Test\\ bigEndianAdapt\\ 0xff000000" ByteSwapTest bigEndianAdapt<uint32_t> 0xff000000)
add_test("Test\\ bigEndianAdapt\\ 0x00000000000000ff" ByteSwapTest bigEndianAdapt<uint64_t> 0x00000000000000ff)
add_test("Test\\ bigEndianAdapt\\ 0x000000000000ff00" ByteSwapTest bigEndianAdapt<uint64_t> 0x000000000000ff00)
add_test("Test\\ bigEndianAdapt\\ 0x0000000000ff0000" ByteSwapTest bigEndianAdapt<uint64_t> 0x0000000000ff0000)
add_test("Test\\ bigEndianAdapt\\ 0x00000000ff000000" ByteSwapTest bigEndianAdapt<uint64_t> 0x00000000ff000000)
add_test("Test\\ bigEndianAdapt\\ 0x000000ff00000000" ByteSwapTest bigEndianAdapt<uint64_t> 0x000000ff00000000)
add_test("Test\\ bigEndianAdapt\\ 0x0000ff0000000000" ByteSwapTest bigEndianAdapt<uint64_t> 0x0000ff0000000000)
add_test("Test\\ bigEndianAdapt\\ 0x00ff000000000000" ByteSwapTest bigEndianAdapt<uint64_t> 0x00ff000000000000)
add_test("Test\\ bigEndianAdapt\\ 0xff00000000000000" ByteSwapTest bigEndianAdapt<uint64_t> 0xff00000000000000)

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2015 - 2017 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 <map>
#include <string>
#include <ox/std/std.hpp>
using namespace std;
using namespace ox::std;
template<typename T>
int testBigEndianAdapt(string str) {
auto i = (T) stoull(str, nullptr, 16);
return !(bigEndianAdapt(bigEndianAdapt(i)) == i);
}
map<string, int(*)(string)> tests = {
{
{ "bigEndianAdapt<uint16_t>", testBigEndianAdapt<uint16_t> },
{ "bigEndianAdapt<uint32_t>", testBigEndianAdapt<uint32_t> },
{ "bigEndianAdapt<uint64_t>", testBigEndianAdapt<uint64_t> },
},
};
int main(int argc, const char **args) {
int retval = -1;
if (argc > 1) {
auto testName = args[1];
string testArg = args[2];
if (tests.find(testName) != tests.end()) {
retval = tests[testName](testArg);
}
}
return retval;
}

79
deps/ox/src/ox/std/test/strops_test.cpp vendored Normal file
View File

@@ -0,0 +1,79 @@
/*
* Copyright 2015 - 2017 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);
}
},
{
" == ",
[]() {
return !(ox_strcmp("", "") == 0);
}
},
{
"ox_strchr 0",
[]() {
auto testStr = "asdf";
return !(ox_strchr(testStr, 0, 4) == &testStr[4]);
}
},
{
"ox_lastIndexOf aaaa a",
[]() {
int retval = 0;
auto testStr = "aaaa";
retval |= !(ox_lastIndexOf((char*) testStr, 'a', ox_strlen(testStr)) == 3);
retval |= !(ox_lastIndexOf((const char*) testStr, 'a', ox_strlen(testStr)) == 3);
return retval;
}
},
};
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;
}

50
deps/ox/src/ox/std/test/tests.cpp vendored Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright 2015 - 2017 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 = {
{
"ABCDEFG != HIJKLMN",
[]() {
return !(ox_memcmp("ABCDEFG", "HIJKLMN", 7) < 0);
}
},
{
"HIJKLMN != ABCDEFG",
[]() {
return !(ox_memcmp("HIJKLMN", "ABCDEFG", 7) > 0);
}
},
{
"ABCDEFG == ABCDEFG",
[]() {
return !(ox_memcmp("ABCDEFG", "ABCDEFG", 7) == 0);
}
},
{
"ABCDEFGHI == ABCDEFG",
[]() {
return !(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) == 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;
}