[ox] Make tests more consistent

This commit is contained in:
Gary Talent 2023-12-04 00:22:00 -06:00
parent 775efbddc8
commit b61f81abf0
7 changed files with 157 additions and 151 deletions

View File

@ -8,11 +8,7 @@
#undef NDEBUG
#include <cassert>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <ox/claw/format.hpp>
#include <ox/claw/read.hpp>
#include <ox/claw/write.hpp>
@ -107,7 +103,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
return OxError(0);
}
static std::map<std::string_view, ox::Error(*)()> tests = {
static std::map<ox::StringView, ox::Error(*)()> tests = {
{
{
"ClawHeaderReader",
@ -192,14 +188,14 @@ static std::map<std::string_view, ox::Error(*)()> tests = {
};
int main(int argc, const char **args) {
int retval = -1;
if (argc > 0) {
auto testName = args[1];
if (tests.find(testName) != tests.end()) {
retval = static_cast<int>(tests[testName]());
} else {
retval = 1;
}
if (argc < 2) {
oxError("Must specify test to run");
}
return retval;
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return -1;
}

View File

@ -21,7 +21,7 @@ struct TestStruct: public ox::SignalHandler {
}
};
std::map<std::string, std::function<ox::Error()>> tests = {
std::map<ox::StringView, std::function<ox::Error()>> tests = {
{
"test1",
[] {
@ -39,12 +39,14 @@ std::map<std::string, std::function<ox::Error()>> tests = {
};
int main(int argc, const char **args) {
if (argc > 1) {
auto testName = args[1];
if (tests.find(testName) != tests.end()) {
oxAssert(tests[testName](), "Test returned Error");
return 0;
}
if (argc < 2) {
oxError("Must specify test to run");
}
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return -1;
}

View File

@ -26,11 +26,11 @@ struct OX_PACKED NodeType: public ox::ptrarith::Item<T> {
}
};
const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tests = {
const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests = {
{
{
"PtrArith::setSize",
[](std::string_view) {
[](ox::StringView) {
using BuffPtr_t = uint32_t;
ox::Vector<char> buff(5 * ox::units::MB);
auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer<BuffPtr_t, NodeType<BuffPtr_t>>(buff.size());
@ -57,7 +57,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::next1",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("/usr/share/charset.gbag");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -69,7 +69,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::next2",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("/usr/share/");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -80,7 +80,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::next3",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("/");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -90,7 +90,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::next4",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("usr/share/charset.gbag");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -102,7 +102,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::next5",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("usr/share/");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -113,7 +113,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::dirPath",
[] (std::string_view) {
[] (ox::StringView) {
auto const path = ox::String("/usr/share/charset.gbag");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -123,7 +123,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::fileName",
[](std::string_view) {
[](ox::StringView) {
auto const path = ox::String("/usr/share/charset.gbag");
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
@ -133,7 +133,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"PathIterator::hasNext",
[](std::string_view) {
[](ox::StringView) {
const auto path = "/file1";
ox::PathIterator it(path, ox_strlen(path));
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
@ -143,7 +143,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"Ptr::subPtr",
[](std::string_view) {
[](ox::StringView) {
constexpr auto buffLen = 5000;
ox::ptrarith::Ptr<uint8_t, uint32_t> p(ox_alloca(buffLen), buffLen, 500, 500);
oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid.");
@ -155,7 +155,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"NodeBuffer::insert",
[](std::string_view) {
[](ox::StringView) {
constexpr auto buffLen = 5000;
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
oxAssert(list->malloc(50).value.valid(), "NodeBuffer::insert: malloc 1 failed");
@ -168,7 +168,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"FileStore::readWrite",
[](std::string_view) {
[](ox::StringView) {
constexpr auto buffLen = 5000;
constexpr auto str1 = "Hello, World!";
constexpr auto str1Len = ox_strlen(str1) + 1;
@ -189,7 +189,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"Directory",
[](std::string_view) {
[](ox::StringView) {
ox::Vector<uint8_t> fsBuff(5000);
oxAssert(ox::FileStore32::format(fsBuff.data(), fsBuff.size()), "FS format failed");
ox::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
@ -216,7 +216,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
},
{
"FileSystem",
[](std::string_view) {
[](ox::StringView) {
ox::Vector<uint8_t> fsBuff(5000);
oxTrace("ox.fs.test.FileSystem") << "format";
oxAssert(ox::FileSystem32::format(fsBuff.data(), fsBuff.size()), "FileSystem format failed");
@ -237,16 +237,15 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
};
int main(int argc, const char **args) {
int retval = -1;
if (argc > 1) {
std::string_view testName = args[1];
std::string_view testArg;
if (args[2]) {
testArg = args[2];
}
if (tests.find(testName) != tests.end()) {
retval = static_cast<int>(tests.at(testName)(testArg));
}
if (argc < 3) {
oxError("Must specify test to run and test argument");
}
return retval;
ox::StringView const testName = args[1];
ox::StringView const testArg = args[2] ? args[2] : nullptr;
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(testArg), "Test returned Error");
return 0;
}
return -1;
}

View File

@ -105,10 +105,10 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexce
return OxError(0);
}
std::map<ox::String, ox::Error(*)()> tests = {
std::map<ox::StringView, ox::Error(*)()> tests = {
{
{
ox::String("MetalClawWriter"),
"MetalClawWriter",
[] {
// This test doesn't confirm much, but it does show that the writer
// doesn't segfault
@ -121,7 +121,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
},
{
ox::String("MetalClawReader"),
"MetalClawReader",
[] {
// setup for tests
TestStruct testIn, testOut;
@ -180,7 +180,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
},
{
ox::String("encodeInteger"),
"encodeInteger",
[] {
using ox::MaxValue;
using ox::mc::McInt;
@ -251,7 +251,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
},
{
ox::String("decodeInteger"),
"decodeInteger",
[] {
using ox::MaxValue;
using ox::mc::McInt;
@ -293,7 +293,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
{
ox::String("MetalClawModelValue"),
"MetalClawModelValue",
[] {
static constexpr size_t dataBuffLen = ox::units::MB;
ox::Buffer dataBuff(dataBuffLen);
@ -345,7 +345,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
},
{
ox::String("MetalClawDef"),
"MetalClawDef",
[] {
//constexpr size_t descBuffLen = 1024;
//uint8_t descBuff[descBuffLen];
@ -460,11 +460,14 @@ std::map<ox::String, ox::Error(*)()> tests = {
};
int main(int argc, const char **args) {
if (argc > 0) {
auto testName = ox::String(args[1]);
if (tests.find(testName) != tests.end()) {
oxAssert(tests[testName](), "Test failed...");
}
if (argc < 2) {
oxError("Must specify test to run");
}
return 0;
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return -1;
}

View File

@ -32,10 +32,10 @@ constexpr auto getModelTypeVersion(TestType2*) noexcept {
return 2;
}
std::map<ox::String, ox::Error(*)()> tests = {
std::map<ox::StringView, ox::Error(*)()> tests = {
{
{
ox::String("ModelValue"),
"ModelValue",
[] {
ox::ModelValue v;
oxReturnError(v.setType<int32_t>());
@ -47,16 +47,18 @@ std::map<ox::String, ox::Error(*)()> tests = {
return ox::Error{};
}
},
{
ox::String("getModelTypeName"),
"getModelTypeName",
[] {
oxAssert(ox::getModelTypeName<TestType>() == TestType::TypeName, "getModelTypeName call failed");
oxAssert(ox::getModelTypeName<TestType2>() == ox::StringView("net.drinkingtea.model.test.TestType2"), "getModelTypeName call failed");
return ox::Error{};
}
},
{
ox::String("getModelTypeVersion"),
"getModelTypeVersion",
[] {
oxAssert(ox::getModelTypeVersion<TestType>() == TestType::TypeVersion, "getModelTypeVersion call failed");
oxAssert(ox::getModelTypeVersion<TestType2>() == 2, "getModelTypeVersion call failed");
@ -67,11 +69,14 @@ std::map<ox::String, ox::Error(*)()> tests = {
};
int main(int argc, const char **args) {
if (argc > 0) {
auto testName = ox::String(args[1]);
if (tests.find(testName) != tests.end()) {
oxAssert(tests[testName](), "Test failed...");
}
if (argc < 2) {
oxError("Must specify test to run");
}
return 0;
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return -1;
}

View File

@ -124,7 +124,7 @@ constexpr TestStruct &TestStruct::operator=(TestStruct &&other) noexcept {
return *this;
}
const std::map<std::string_view, ox::Error(*)()> tests = {
const std::map<ox::StringView, ox::Error(*)()> tests = {
{
{
"OrganicClawWriter",
@ -189,53 +189,53 @@ const std::map<std::string_view, ox::Error(*)()> tests = {
},
{
"OrganicClawModelValue",
[] {
ox::Buffer dataBuff;
TestStruct testIn;
testIn.Bool = true;
testIn.Int = 42;
testIn.String = "Test String 1";
testIn.List[0] = 1;
testIn.List[1] = 2;
testIn.List[2] = 3;
testIn.List[3] = 4;
testIn.Struct.Bool = false;
testIn.Struct.Int = 300;
testIn.Struct.String = "Test String 2";
testIn.unionIdx = 1;
testIn.Union.Int = 93;
oxAssert(ox::writeOC(testIn).moveTo(&dataBuff), "Data generation failed");
ox::TypeStore typeStore;
auto type = ox::buildTypeDef(&typeStore, &testIn);
oxAssert(type.error, "Descriptor write failed");
ox::ModelObject testOut;
oxReturnError(testOut.setType(type.value));
oxAssert(ox::readOC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed");
oxAssert(testOut.get("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed");
oxAssert(testOut.get("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed");
oxAssert(testOut.get("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");
auto &testOutStruct = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
auto &testOutUnion = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
auto &testOutList = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
auto testOutStructCopy = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
auto testOutUnionCopy = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
auto testOutListCopy = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed");
oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed");
oxAssert(testOutStruct.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed");
oxAssert(testOutStruct.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String failed");
oxAssert(testOut.get("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed");
oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong");
oxAssert(testOutUnion.get("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed");
oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed");
oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed");
oxAssert(testOutStructCopy.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed");
oxAssert(testOutStructCopy.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String (copy) failed");
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
return OxError(0);
}
"OrganicClawModelValue",
[] {
ox::Buffer dataBuff;
TestStruct testIn;
testIn.Bool = true;
testIn.Int = 42;
testIn.String = "Test String 1";
testIn.List[0] = 1;
testIn.List[1] = 2;
testIn.List[2] = 3;
testIn.List[3] = 4;
testIn.Struct.Bool = false;
testIn.Struct.Int = 300;
testIn.Struct.String = "Test String 2";
testIn.unionIdx = 1;
testIn.Union.Int = 93;
oxAssert(ox::writeOC(testIn).moveTo(&dataBuff), "Data generation failed");
ox::TypeStore typeStore;
auto type = ox::buildTypeDef(&typeStore, &testIn);
oxAssert(type.error, "Descriptor write failed");
ox::ModelObject testOut;
oxReturnError(testOut.setType(type.value));
oxAssert(ox::readOC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed");
oxAssert(testOut.get("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed");
oxAssert(testOut.get("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed");
oxAssert(testOut.get("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");
auto &testOutStruct = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
auto &testOutUnion = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
auto &testOutList = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
auto testOutStructCopy = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
auto testOutUnionCopy = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
auto testOutListCopy = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed");
oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed");
oxAssert(testOutStruct.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed");
oxAssert(testOutStruct.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String failed");
oxAssert(testOut.get("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed");
oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong");
oxAssert(testOutUnion.get("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed");
oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed");
oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed");
oxAssert(testOutStructCopy.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed");
oxAssert(testOutStructCopy.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String (copy) failed");
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
return OxError(0);
}
},
{
@ -354,13 +354,11 @@ int main(int argc, const char **args) {
if (argc < 2) {
oxError("Must specify test to run");
}
const auto testName = args[1];
ox::Error(*test)();
try {
test = tests.at(testName);
} catch (const std::out_of_range&) {
oxErrorf("Test {} not found", testName);
return 1;
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return static_cast<int>(test());
return -1;
}

View File

@ -12,9 +12,9 @@
#include <ox/std/uuid.hpp>
#include <ox/std/std.hpp>
static std::map<ox::String, ox::Error(*)()> tests = {
static std::map<ox::StringView, ox::Error(*)()> tests = {
{
ox::String("malloc"),
"malloc",
[] {
ox::Buffer buff(ox::units::MB);
ox::heapmgr::initHeap(&buff[0], &buff[buff.size()-1]);
@ -26,7 +26,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("itoa"),
"itoa",
[]() {
ox::Array<char, 10> buff;
ox::CharBuffWriter bw(buff);
@ -42,31 +42,31 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("ABCDEFG != HIJKLMN"),
"ABCDEFG != HIJKLMN",
[]() {
return OxError(ox_memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
}
},
{
ox::String("HIJKLMN != ABCDEFG"),
"HIJKLMN != ABCDEFG",
[]() {
return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
}
},
{
ox::String("ABCDEFG == ABCDEFG"),
"ABCDEFG == ABCDEFG",
[]() {
return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
}
},
{
ox::String("ABCDEFGHI == ABCDEFG"),
"ABCDEFGHI == ABCDEFG",
[]() {
return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
}
},
{
ox::String("BString"),
"BString",
[]() {
ox::BString<5> s;
s += "A";
@ -82,7 +82,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("String"),
"String",
[]() {
ox::String s;
s += "A";
@ -113,10 +113,11 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("Vector"),
"Vector",
[] {
ox::Vector<int> v;
oxAssert(v.size() == 0, "Initial Vector size not 0");
oxAssert(v.empty(), "Vector::empty() is broken");
auto insertTest = [&v](int val, [[maybe_unused]] std::size_t size) {
v.push_back(val);
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
@ -130,7 +131,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("HashMap"),
"HashMap",
[] {
ox::HashMap<const char*, int> si;
si["asdf"] = 42;
@ -146,7 +147,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("Serialize-Int"),
"Serialize-Int",
[] {
using BA = ox::Array<char, 4>;
const auto actual = ox::serialize<uint32_t>(256).unwrap();
@ -163,7 +164,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("BufferWriter"),
"BufferWriter",
[] {
ox::Buffer b;
ox::BufferWriter w(&b);
@ -172,7 +173,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
oxAssert(w.write("aoeu", 4), "write failed");
oxExpect(b.size(), 8u);
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeu");
ox::StringView qwerty = "qwerty";
ox::StringView constexpr qwerty = "qwerty";
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
oxExpect(b.size(), 14u);
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
@ -180,7 +181,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("FromHex"),
"FromHex",
[] {
oxExpect(ox::detail::fromHex("01").unwrap(), 0x01);
oxExpect(ox::detail::fromHex("02").unwrap(), 0x02);
@ -203,7 +204,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("ToHex"),
"ToHex",
[] {
oxExpect(ox::detail::toHex(0x01), "01");
oxExpect(ox::detail::toHex(0x02), "02");
@ -223,7 +224,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("UUID"),
"UUID",
[] {
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
oxRequire(uuid, ox::UUID::fromString(uuidStr));
@ -234,7 +235,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("UUID::generate"),
"UUID::generate",
[] {
ox::UUID::seedGenerator({1234, 4321});
oxExpect(ox::UUID::generate().unwrap().toString(), "5c3f4b5e-ccbf-4727-7f03-3053dedc8827");
@ -244,7 +245,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
}
},
{
ox::String("StringSplit"),
"StringSplit",
[] {
ox::StringView sv = "ab.cd";
auto list = ox::split(sv, ".");
@ -313,12 +314,14 @@ static std::map<ox::String, ox::Error(*)()> tests = {
};
int main(int argc, const char **args) {
if (argc > 1) {
auto testName = ox::String(args[1]);
if (tests.find(testName) != tests.end()) {
oxAssert(tests[testName](), "Test returned Error");
return 0;
}
if (argc < 2) {
oxError("Must specify test to run");
}
auto const testName = args[1];
auto const func = tests.find(testName);
if (func != tests.end()) {
oxAssert(func->second(), "Test returned Error");
return 0;
}
return -1;
}