[ox] Make tests more consistent
This commit is contained in:
51
deps/ox/src/ox/fs/test/tests.cpp
vendored
51
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",
|
||||
[](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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user