[ox/fs] Cleanup tests
This commit is contained in:
parent
b3dff0a184
commit
b825e88d29
89
deps/ox/src/ox/fs/test/tests.cpp
vendored
89
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -9,15 +9,14 @@
|
|||||||
// make sure asserts are enabled for the test file
|
// make sure asserts are enabled for the test file
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string_view>
|
||||||
#include <ox/std/std.hpp>
|
#include <ox/std/std.hpp>
|
||||||
#include <ox/fs/ptrarith/nodebuffer.hpp>
|
#include <ox/fs/ptrarith/nodebuffer.hpp>
|
||||||
#include <ox/fs/filestore/filestoretemplate.hpp>
|
#include <ox/fs/filestore/filestoretemplate.hpp>
|
||||||
#include <ox/fs/filesystem/filesystem.hpp>
|
#include <ox/fs/filesystem/filesystem.hpp>
|
||||||
|
|
||||||
using namespace ox;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct OX_PACKED NodeType: public ox::ptrarith::Item<T> {
|
struct OX_PACKED NodeType: public ox::ptrarith::Item<T> {
|
||||||
public:
|
public:
|
||||||
@ -26,15 +25,15 @@ struct OX_PACKED NodeType: public ox::ptrarith::Item<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tests = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"PtrArith::setSize",
|
"PtrArith::setSize",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
using BuffPtr_t = uint32_t;
|
using BuffPtr_t = uint32_t;
|
||||||
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());
|
||||||
using String = BString<6>;
|
using String = ox::BString<6>;
|
||||||
auto a1 = buffer->malloc(sizeof(String));
|
auto a1 = buffer->malloc(sizeof(String));
|
||||||
auto a2 = buffer->malloc(sizeof(String));
|
auto a2 = buffer->malloc(sizeof(String));
|
||||||
oxAssert(a1.valid(), "Allocation 1 failed.");
|
oxAssert(a1.valid(), "Allocation 1 failed.");
|
||||||
@ -54,76 +53,76 @@ std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
|||||||
{
|
{
|
||||||
"PathIterator::next1",
|
"PathIterator::next1",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "/usr/share/charset.gbag";
|
ox::String path = "/usr/share/charset.gbag";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::next2",
|
"PathIterator::next2",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "/usr/share/";
|
ox::String path = "/usr/share/";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::next3",
|
"PathIterator::next3",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "/";
|
ox::String path = "/";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::next4",
|
"PathIterator::next4",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "usr/share/charset.gbag";
|
ox::String path = "usr/share/charset.gbag";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::next5",
|
"PathIterator::next5",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "usr/share/";
|
ox::String path = "usr/share/";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||||
oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::dirPath",
|
"PathIterator::dirPath",
|
||||||
[] (std::string_view) {
|
[] (std::string_view) {
|
||||||
std::string path = "/usr/share/charset.gbag";
|
ox::String path = "/usr/share/charset.gbag";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.dirPath(buff, path.size()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
oxAssert(it.dirPath(buff, path.len()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PathIterator::fileName",
|
"PathIterator::fileName",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
std::string path = "/usr/share/charset.gbag";
|
ox::String path = "/usr/share/charset.gbag";
|
||||||
PathIterator it(path.c_str(), path.size());
|
ox::PathIterator it(path.c_str(), path.len());
|
||||||
auto buff = static_cast<char*>(ox_alloca(path.size() + 1));
|
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||||
oxAssert(it.fileName(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name");
|
oxAssert(it.fileName(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -131,7 +130,7 @@ std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
|||||||
"PathIterator::hasNext",
|
"PathIterator::hasNext",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
const auto path = "/file1";
|
const auto path = "/file1";
|
||||||
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");
|
||||||
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
|
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
@ -186,7 +185,7 @@ std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
|||||||
{
|
{
|
||||||
"Directory",
|
"Directory",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
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());
|
||||||
ox::Directory32 dir(fileStore, 105);
|
ox::Directory32 dir(fileStore, 105);
|
||||||
@ -213,7 +212,7 @@ std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
|||||||
{
|
{
|
||||||
"FileSystem",
|
"FileSystem",
|
||||||
[](std::string_view) {
|
[](std::string_view) {
|
||||||
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");
|
||||||
ox::FileSystem32 fs(ox::FileStore32(fsBuff.data(), fsBuff.size()));
|
ox::FileSystem32 fs(ox::FileStore32(fsBuff.data(), fsBuff.size()));
|
||||||
@ -235,13 +234,13 @@ std::map<std::string_view, Error(*)(std::string_view)> tests = {
|
|||||||
int main(int argc, const char **args) {
|
int main(int argc, const char **args) {
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
auto testName = args[1];
|
std::string_view testName = args[1];
|
||||||
std::string_view testArg = "";
|
std::string_view testArg = "";
|
||||||
if (args[2]) {
|
if (args[2]) {
|
||||||
testArg = args[2];
|
testArg = args[2];
|
||||||
}
|
}
|
||||||
if (tests.find(testName) != tests.end()) {
|
if (tests.find(testName) != tests.end()) {
|
||||||
retval = tests[testName](testArg);
|
retval = tests.at(testName)(testArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user