[ox] Make tests more consistent
This commit is contained in:
parent
775efbddc8
commit
b61f81abf0
22
deps/ox/src/ox/claw/test/tests.cpp
vendored
22
deps/ox/src/ox/claw/test/tests.cpp
vendored
@ -8,11 +8,7 @@
|
|||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <ox/claw/format.hpp>
|
#include <ox/claw/format.hpp>
|
||||||
#include <ox/claw/read.hpp>
|
#include <ox/claw/read.hpp>
|
||||||
#include <ox/claw/write.hpp>
|
#include <ox/claw/write.hpp>
|
||||||
@ -107,7 +103,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<std::string_view, ox::Error(*)()> tests = {
|
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"ClawHeaderReader",
|
"ClawHeaderReader",
|
||||||
@ -192,14 +188,14 @@ static std::map<std::string_view, ox::Error(*)()> tests = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char **args) {
|
int main(int argc, const char **args) {
|
||||||
int retval = -1;
|
if (argc < 2) {
|
||||||
if (argc > 0) {
|
oxError("Must specify test to run");
|
||||||
auto testName = args[1];
|
|
||||||
if (tests.find(testName) != tests.end()) {
|
|
||||||
retval = static_cast<int>(tests[testName]());
|
|
||||||
} else {
|
|
||||||
retval = 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 retval;
|
return -1;
|
||||||
}
|
}
|
||||||
|
14
deps/ox/src/ox/event/test/tests.cpp
vendored
14
deps/ox/src/ox/event/test/tests.cpp
vendored
@ -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",
|
"test1",
|
||||||
[] {
|
[] {
|
||||||
@ -39,12 +39,14 @@ std::map<std::string, std::function<ox::Error()>> tests = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char **args) {
|
int main(int argc, const char **args) {
|
||||||
if (argc > 1) {
|
if (argc < 2) {
|
||||||
auto testName = args[1];
|
oxError("Must specify test to run");
|
||||||
if (tests.find(testName) != tests.end()) {
|
|
||||||
oxAssert(tests[testName](), "Test returned Error");
|
|
||||||
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
49
deps/ox/src/ox/fs/test/tests.cpp
vendored
49
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -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",
|
"PtrArith::setSize",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
using BuffPtr_t = uint32_t;
|
using BuffPtr_t = uint32_t;
|
||||||
ox::Vector<char> buff(5 * ox::units::MB);
|
ox::Vector<char> buff(5 * ox::units::MB);
|
||||||
auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer<BuffPtr_t, NodeType<BuffPtr_t>>(buff.size());
|
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",
|
"PathIterator::next1",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("/usr/share/charset.gbag");
|
auto const path = ox::String("/usr/share/charset.gbag");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::next2",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("/usr/share/");
|
auto const path = ox::String("/usr/share/");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::next3",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("/");
|
auto const path = ox::String("/");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::next4",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("usr/share/charset.gbag");
|
auto const path = ox::String("usr/share/charset.gbag");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::next5",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("usr/share/");
|
auto const path = ox::String("usr/share/");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::dirPath",
|
||||||
[] (std::string_view) {
|
[] (ox::StringView) {
|
||||||
auto const path = ox::String("/usr/share/charset.gbag");
|
auto const path = ox::String("/usr/share/charset.gbag");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::fileName",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
auto const path = ox::String("/usr/share/charset.gbag");
|
auto const path = ox::String("/usr/share/charset.gbag");
|
||||||
ox::PathIterator it(path.c_str(), path.len());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
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",
|
"PathIterator::hasNext",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
const auto path = "/file1";
|
const auto path = "/file1";
|
||||||
ox::PathIterator it(path, ox_strlen(path));
|
ox::PathIterator it(path, ox_strlen(path));
|
||||||
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
|
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",
|
"Ptr::subPtr",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
constexpr auto buffLen = 5000;
|
constexpr auto buffLen = 5000;
|
||||||
ox::ptrarith::Ptr<uint8_t, uint32_t> p(ox_alloca(buffLen), buffLen, 500, 500);
|
ox::ptrarith::Ptr<uint8_t, uint32_t> p(ox_alloca(buffLen), buffLen, 500, 500);
|
||||||
oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid.");
|
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",
|
"NodeBuffer::insert",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
constexpr auto buffLen = 5000;
|
constexpr auto buffLen = 5000;
|
||||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
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");
|
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",
|
"FileStore::readWrite",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
constexpr auto buffLen = 5000;
|
constexpr auto buffLen = 5000;
|
||||||
constexpr auto str1 = "Hello, World!";
|
constexpr auto str1 = "Hello, World!";
|
||||||
constexpr auto str1Len = ox_strlen(str1) + 1;
|
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",
|
"Directory",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
ox::Vector<uint8_t> fsBuff(5000);
|
ox::Vector<uint8_t> fsBuff(5000);
|
||||||
oxAssert(ox::FileStore32::format(fsBuff.data(), fsBuff.size()), "FS format failed");
|
oxAssert(ox::FileStore32::format(fsBuff.data(), fsBuff.size()), "FS format failed");
|
||||||
ox::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
|
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",
|
"FileSystem",
|
||||||
[](std::string_view) {
|
[](ox::StringView) {
|
||||||
ox::Vector<uint8_t> fsBuff(5000);
|
ox::Vector<uint8_t> fsBuff(5000);
|
||||||
oxTrace("ox.fs.test.FileSystem") << "format";
|
oxTrace("ox.fs.test.FileSystem") << "format";
|
||||||
oxAssert(ox::FileSystem32::format(fsBuff.data(), fsBuff.size()), "FileSystem format failed");
|
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 main(int argc, const char **args) {
|
||||||
int retval = -1;
|
if (argc < 3) {
|
||||||
if (argc > 1) {
|
oxError("Must specify test to run and test argument");
|
||||||
std::string_view testName = args[1];
|
|
||||||
std::string_view testArg;
|
|
||||||
if (args[2]) {
|
|
||||||
testArg = args[2];
|
|
||||||
}
|
}
|
||||||
if (tests.find(testName) != tests.end()) {
|
ox::StringView const testName = args[1];
|
||||||
retval = static_cast<int>(tests.at(testName)(testArg));
|
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;
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
27
deps/ox/src/ox/mc/test/tests.cpp
vendored
27
deps/ox/src/ox/mc/test/tests.cpp
vendored
@ -105,10 +105,10 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexce
|
|||||||
return OxError(0);
|
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
|
// This test doesn't confirm much, but it does show that the writer
|
||||||
// doesn't segfault
|
// doesn't segfault
|
||||||
@ -121,7 +121,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("MetalClawReader"),
|
"MetalClawReader",
|
||||||
[] {
|
[] {
|
||||||
// setup for tests
|
// setup for tests
|
||||||
TestStruct testIn, testOut;
|
TestStruct testIn, testOut;
|
||||||
@ -180,7 +180,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("encodeInteger"),
|
"encodeInteger",
|
||||||
[] {
|
[] {
|
||||||
using ox::MaxValue;
|
using ox::MaxValue;
|
||||||
using ox::mc::McInt;
|
using ox::mc::McInt;
|
||||||
@ -251,7 +251,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("decodeInteger"),
|
"decodeInteger",
|
||||||
[] {
|
[] {
|
||||||
using ox::MaxValue;
|
using ox::MaxValue;
|
||||||
using ox::mc::McInt;
|
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;
|
static constexpr size_t dataBuffLen = ox::units::MB;
|
||||||
ox::Buffer dataBuff(dataBuffLen);
|
ox::Buffer dataBuff(dataBuffLen);
|
||||||
@ -345,7 +345,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("MetalClawDef"),
|
"MetalClawDef",
|
||||||
[] {
|
[] {
|
||||||
//constexpr size_t descBuffLen = 1024;
|
//constexpr size_t descBuffLen = 1024;
|
||||||
//uint8_t descBuff[descBuffLen];
|
//uint8_t descBuff[descBuffLen];
|
||||||
@ -460,11 +460,14 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char **args) {
|
int main(int argc, const char **args) {
|
||||||
if (argc > 0) {
|
if (argc < 2) {
|
||||||
auto testName = ox::String(args[1]);
|
oxError("Must specify test to run");
|
||||||
if (tests.find(testName) != tests.end()) {
|
|
||||||
oxAssert(tests[testName](), "Test failed...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
auto const testName = args[1];
|
||||||
|
auto const func = tests.find(testName);
|
||||||
|
if (func != tests.end()) {
|
||||||
|
oxAssert(func->second(), "Test returned Error");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
23
deps/ox/src/ox/model/test/tests.cpp
vendored
23
deps/ox/src/ox/model/test/tests.cpp
vendored
@ -32,10 +32,10 @@ constexpr auto getModelTypeVersion(TestType2*) noexcept {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<ox::String, ox::Error(*)()> tests = {
|
std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ox::String("ModelValue"),
|
"ModelValue",
|
||||||
[] {
|
[] {
|
||||||
ox::ModelValue v;
|
ox::ModelValue v;
|
||||||
oxReturnError(v.setType<int32_t>());
|
oxReturnError(v.setType<int32_t>());
|
||||||
@ -47,16 +47,18 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("getModelTypeName"),
|
"getModelTypeName",
|
||||||
[] {
|
[] {
|
||||||
oxAssert(ox::getModelTypeName<TestType>() == TestType::TypeName, "getModelTypeName call failed");
|
oxAssert(ox::getModelTypeName<TestType>() == TestType::TypeName, "getModelTypeName call failed");
|
||||||
oxAssert(ox::getModelTypeName<TestType2>() == ox::StringView("net.drinkingtea.model.test.TestType2"), "getModelTypeName call failed");
|
oxAssert(ox::getModelTypeName<TestType2>() == ox::StringView("net.drinkingtea.model.test.TestType2"), "getModelTypeName call failed");
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
ox::String("getModelTypeVersion"),
|
"getModelTypeVersion",
|
||||||
[] {
|
[] {
|
||||||
oxAssert(ox::getModelTypeVersion<TestType>() == TestType::TypeVersion, "getModelTypeVersion call failed");
|
oxAssert(ox::getModelTypeVersion<TestType>() == TestType::TypeVersion, "getModelTypeVersion call failed");
|
||||||
oxAssert(ox::getModelTypeVersion<TestType2>() == 2, "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) {
|
int main(int argc, const char **args) {
|
||||||
if (argc > 0) {
|
if (argc < 2) {
|
||||||
auto testName = ox::String(args[1]);
|
oxError("Must specify test to run");
|
||||||
if (tests.find(testName) != tests.end()) {
|
|
||||||
oxAssert(tests[testName](), "Test failed...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
auto const testName = args[1];
|
||||||
|
auto const func = tests.find(testName);
|
||||||
|
if (func != tests.end()) {
|
||||||
|
oxAssert(func->second(), "Test returned Error");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
16
deps/ox/src/ox/oc/test/tests.cpp
vendored
16
deps/ox/src/ox/oc/test/tests.cpp
vendored
@ -124,7 +124,7 @@ constexpr TestStruct &TestStruct::operator=(TestStruct &&other) noexcept {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string_view, ox::Error(*)()> tests = {
|
const std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"OrganicClawWriter",
|
"OrganicClawWriter",
|
||||||
@ -354,13 +354,11 @@ int main(int argc, const char **args) {
|
|||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
oxError("Must specify test to run");
|
oxError("Must specify test to run");
|
||||||
}
|
}
|
||||||
const auto testName = args[1];
|
auto const testName = args[1];
|
||||||
ox::Error(*test)();
|
auto const func = tests.find(testName);
|
||||||
try {
|
if (func != tests.end()) {
|
||||||
test = tests.at(testName);
|
oxAssert(func->second(), "Test returned Error");
|
||||||
} catch (const std::out_of_range&) {
|
return 0;
|
||||||
oxErrorf("Test {} not found", testName);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
return static_cast<int>(test());
|
return -1;
|
||||||
}
|
}
|
||||||
|
51
deps/ox/src/ox/std/test/tests.cpp
vendored
51
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -12,9 +12,9 @@
|
|||||||
#include <ox/std/uuid.hpp>
|
#include <ox/std/uuid.hpp>
|
||||||
#include <ox/std/std.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::Buffer buff(ox::units::MB);
|
||||||
ox::heapmgr::initHeap(&buff[0], &buff[buff.size()-1]);
|
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::Array<char, 10> buff;
|
||||||
ox::CharBuffWriter bw(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);
|
return OxError(ox_memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("HIJKLMN != ABCDEFG"),
|
"HIJKLMN != ABCDEFG",
|
||||||
[]() {
|
[]() {
|
||||||
return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("ABCDEFG == ABCDEFG"),
|
"ABCDEFG == ABCDEFG",
|
||||||
[]() {
|
[]() {
|
||||||
return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("ABCDEFGHI == ABCDEFG"),
|
"ABCDEFGHI == ABCDEFG",
|
||||||
[]() {
|
[]() {
|
||||||
return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("BString"),
|
"BString",
|
||||||
[]() {
|
[]() {
|
||||||
ox::BString<5> s;
|
ox::BString<5> s;
|
||||||
s += "A";
|
s += "A";
|
||||||
@ -82,7 +82,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("String"),
|
"String",
|
||||||
[]() {
|
[]() {
|
||||||
ox::String s;
|
ox::String s;
|
||||||
s += "A";
|
s += "A";
|
||||||
@ -113,10 +113,11 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ox::String("Vector"),
|
"Vector",
|
||||||
[] {
|
[] {
|
||||||
ox::Vector<int> v;
|
ox::Vector<int> v;
|
||||||
oxAssert(v.size() == 0, "Initial Vector size not 0");
|
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) {
|
auto insertTest = [&v](int val, [[maybe_unused]] std::size_t size) {
|
||||||
v.push_back(val);
|
v.push_back(val);
|
||||||
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
|
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;
|
ox::HashMap<const char*, int> si;
|
||||||
si["asdf"] = 42;
|
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>;
|
using BA = ox::Array<char, 4>;
|
||||||
const auto actual = ox::serialize<uint32_t>(256).unwrap();
|
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::Buffer b;
|
||||||
ox::BufferWriter w(&b);
|
ox::BufferWriter w(&b);
|
||||||
@ -172,7 +173,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
oxAssert(w.write("aoeu", 4), "write failed");
|
oxAssert(w.write("aoeu", 4), "write failed");
|
||||||
oxExpect(b.size(), 8u);
|
oxExpect(b.size(), 8u);
|
||||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeu");
|
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");
|
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
|
||||||
oxExpect(b.size(), 14u);
|
oxExpect(b.size(), 14u);
|
||||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
|
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("01").unwrap(), 0x01);
|
||||||
oxExpect(ox::detail::fromHex("02").unwrap(), 0x02);
|
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(0x01), "01");
|
||||||
oxExpect(ox::detail::toHex(0x02), "02");
|
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";
|
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
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});
|
ox::UUID::seedGenerator({1234, 4321});
|
||||||
oxExpect(ox::UUID::generate().unwrap().toString(), "5c3f4b5e-ccbf-4727-7f03-3053dedc8827");
|
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";
|
ox::StringView sv = "ab.cd";
|
||||||
auto list = ox::split(sv, ".");
|
auto list = ox::split(sv, ".");
|
||||||
@ -313,12 +314,14 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char **args) {
|
int main(int argc, const char **args) {
|
||||||
if (argc > 1) {
|
if (argc < 2) {
|
||||||
auto testName = ox::String(args[1]);
|
oxError("Must specify test to run");
|
||||||
if (tests.find(testName) != tests.end()) {
|
|
||||||
oxAssert(tests[testName](), "Test returned Error");
|
|
||||||
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user