diff --git a/deps/ox/src/ox/fs/CMakeLists.txt b/deps/ox/src/ox/fs/CMakeLists.txt index 2ca883fc..a02c3961 100644 --- a/deps/ox/src/ox/fs/CMakeLists.txt +++ b/deps/ox/src/ox/fs/CMakeLists.txt @@ -76,5 +76,4 @@ install( if(OX_RUN_TESTS) add_subdirectory(test) - add_subdirectory(ptrarith/test) endif() diff --git a/deps/ox/src/ox/fs/ptrarith/test/CMakeLists.txt b/deps/ox/src/ox/fs/ptrarith/test/CMakeLists.txt deleted file mode 100644 index 144a6cd5..00000000 --- a/deps/ox/src/ox/fs/ptrarith/test/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_executable( - PtrArithTests - tests.cpp -) - -target_link_libraries( - PtrArithTests - OxStd -) - -add_test("[ox/fs] PtrArith::setSize" PtrArithTests PtrArith::setSize) diff --git a/deps/ox/src/ox/fs/ptrarith/test/tests.cpp b/deps/ox/src/ox/fs/ptrarith/test/tests.cpp deleted file mode 100644 index af30ddb8..00000000 --- a/deps/ox/src/ox/fs/ptrarith/test/tests.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015 - 2021 gary@drinkingtea.net - * - * 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/. - */ - -// make sure asserts are enabled for the test file -#undef NDEBUG - -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace ox; - -template -struct OX_PACKED NodeType: public ox::ptrarith::Item { - public: - size_t fullSize() const { - return this->size() + sizeof(*this); - } -}; - -map tests = { - { - { - "PtrArith::setSize", - [](string) { - using BuffPtr_t = uint32_t; - std::vector buff(5 * ox::units::MB); - auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer>(buff.size()); - using String = BString<6>; - auto a1 = buffer->malloc(sizeof(String)); - auto a2 = buffer->malloc(sizeof(String)); - oxAssert(a1.valid(), "Allocation 1 failed."); - oxAssert(a2.valid(), "Allocation 2 failed."); - auto &s1 = *new (buffer->dataOf(a1)) String("asdf"); - auto &s2 = *new (buffer->dataOf(a2)) String("aoeu"); - oxTrace("test") << "s1: " << s1.c_str(); - oxTrace("test") << "s2: " << s2.c_str(); - oxAssert(s1 == "asdf", "Allocation 1 not as expected."); - oxAssert(s2 == "aoeu", "Allocation 2 not as expected."); - oxAssert(buffer->free(a1), "Free failed."); - oxAssert(buffer->free(a2), "Free failed."); - oxAssert(buffer->setSize(buffer->size() - buffer->available()), "Resize failed."); - return 0; - } - }, - }, -}; - -int main(int argc, const char **args) { - int retval = -1; - if (argc > 1) { - auto testName = args[1]; - string testArg = ""; - if (args[2]) { - testArg = args[2]; - } - if (tests.find(testName) != tests.end()) { - retval = tests[testName](testArg); - } - } - return retval; -} diff --git a/deps/ox/src/ox/fs/test/CMakeLists.txt b/deps/ox/src/ox/fs/test/CMakeLists.txt index d31d4fc0..57c93aa4 100644 --- a/deps/ox/src/ox/fs/test/CMakeLists.txt +++ b/deps/ox/src/ox/fs/test/CMakeLists.txt @@ -10,6 +10,8 @@ target_link_libraries( OxMetalClaw ) +add_test("[ox/fs] PtrArith::setSize" FSTests PtrArith::setSize) + add_test("[ox/fs] PathIterator::next1" FSTests PathIterator::next1) add_test("[ox/fs] PathIterator::next2" FSTests PathIterator::next2) add_test("[ox/fs] PathIterator::next3" FSTests PathIterator::next3) diff --git a/deps/ox/src/ox/fs/test/tests.cpp b/deps/ox/src/ox/fs/test/tests.cpp index e6972fbf..f9b8270a 100644 --- a/deps/ox/src/ox/fs/test/tests.cpp +++ b/deps/ox/src/ox/fs/test/tests.cpp @@ -9,130 +9,149 @@ // make sure asserts are enabled for the test file #undef NDEBUG -#include #include -#include #include #include +#include #include #include - -using namespace std; using namespace ox; -map tests = { +template +struct OX_PACKED NodeType: public ox::ptrarith::Item { + public: + size_t fullSize() const { + return this->size() + sizeof(*this); + } +}; + +std::map tests = { { + { + "PtrArith::setSize", + [](std::string_view) { + using BuffPtr_t = uint32_t; + Vector buff(5 * ox::units::MB); + auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer>(buff.size()); + using String = BString<6>; + auto a1 = buffer->malloc(sizeof(String)); + auto a2 = buffer->malloc(sizeof(String)); + oxAssert(a1.valid(), "Allocation 1 failed."); + oxAssert(a2.valid(), "Allocation 2 failed."); + auto &s1 = *new (buffer->dataOf(a1)) String("asdf"); + auto &s2 = *new (buffer->dataOf(a2)) String("aoeu"); + oxTrace("test") << "s1: " << s1.c_str(); + oxTrace("test") << "s2: " << s2.c_str(); + oxAssert(s1 == "asdf", "Allocation 1 not as expected."); + oxAssert(s2 == "aoeu", "Allocation 2 not as expected."); + oxAssert(buffer->free(a1), "Free failed."); + oxAssert(buffer->free(a2), "Free failed."); + oxAssert(buffer->setSize(buffer->size() - buffer->available()), "Resize failed."); + return OxError(0); + } + }, { "PathIterator::next1", - [](string) { - int retval = 0; - string path = "/usr/share/charset.gbag"; + [](std::string_view) { + std::string path = "/usr/share/charset.gbag"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0); - return retval; + oxAssert(it.next(buff, path.size()) == 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.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); + return OxError(0); } }, { "PathIterator::next2", - [](string) { - int retval = 0; - string path = "/usr/share/"; + [](std::string_view) { + std::string path = "/usr/share/"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0); - return retval; + oxAssert(it.next(buff, path.size()) == 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"); + return OxError(0); } }, { "PathIterator::next3", - [](string) { - int retval = 0; - string path = "/"; + [](std::string_view) { + std::string path = "/"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "\0") == 0); - return retval; + oxAssert(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next"); + return OxError(0); } }, { "PathIterator::next4", - [](string) { - int retval = 0; - string path = "usr/share/charset.gbag"; + [](std::string_view) { + std::string path = "usr/share/charset.gbag"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0); - return retval; + oxAssert(it.next(buff, path.size()) == 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.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); + return OxError(0); } }, { "PathIterator::next5", - [](string) { - int retval = 0; - string path = "usr/share/"; + [](std::string_view) { + std::string path = "usr/share/"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "usr") == 0); - retval |= !(it.next(buff, path.size()) == 0 && ox_strcmp(buff, "share") == 0); - return retval; + oxAssert(it.next(buff, path.size()) == 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"); + return OxError(0); } }, { "PathIterator::dirPath", - [] (string) { - int retval = 0; - string path = "/usr/share/charset.gbag"; + [] (std::string_view) { + std::string path = "/usr/share/charset.gbag"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.dirPath(buff, path.size()) == 0 && ox_strcmp(buff, "/usr/share/") == 0); - return retval; + oxAssert(it.dirPath(buff, path.size()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path"); + return OxError(0); } }, { "PathIterator::fileName", - [](string) { - int retval = 0; - string path = "/usr/share/charset.gbag"; + [](std::string_view) { + std::string path = "/usr/share/charset.gbag"; PathIterator it(path.c_str(), path.size()); auto buff = static_cast(ox_alloca(path.size() + 1)); - retval |= !(it.fileName(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0); - return retval; + oxAssert(it.fileName(buff, path.size()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name"); + return OxError(0); } }, { "PathIterator::hasNext", - [](string) { - int retval = 0; + [](std::string_view) { const auto path = "/file1"; PathIterator it(path, ox_strlen(path)); oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext"); oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext"); - return retval; + return OxError(0); } }, { "Ptr::subPtr", - [](string) { + [](std::string_view) { constexpr auto buffLen = 5000; ox::ptrarith::Ptr p(ox_alloca(buffLen), buffLen, 500, 500); oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid."); auto subPtr = p.subPtr(50); oxAssert(subPtr.valid(), "Ptr::subPtr: Ptr subPtr is invalid."); - return 0; + return OxError(0); } }, { "NodeBuffer::insert", - [](string) { - int err = 0; + [](std::string_view) { constexpr auto buffLen = 5000; auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer>(buffLen); oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 1 failed"); @@ -140,12 +159,12 @@ map tests = { auto first = list->firstItem(); oxAssert(first.valid(), "NodeBuffer::insert: Could not access first item"); oxAssert(first->size() == 50, "NodeBuffer::insert: First item size invalid"); - return err; + return OxError(0); } }, { "FileStore::readWrite", - [](string) { + [](std::string_view) { constexpr auto buffLen = 5000; constexpr auto str1 = "Hello, World!"; constexpr auto str1Len = ox_strlen(str1) + 1; @@ -161,13 +180,13 @@ map tests = { size_t str1ReadSize = 0; oxAssert(fileStore.read(4, reinterpret_cast(str1Read), str1Len, &str1ReadSize), "FileStore::read 1 failed."); - return 0; + return OxError(0); } }, { "Directory", - [](string) { - std::vector fsBuff(5000); + [](std::string_view) { + Vector fsBuff(5000); oxAssert(ox::FileStore32::format(fsBuff.data(), fsBuff.size()), "FS format failed"); ox::FileStore32 fileStore(fsBuff.data(), fsBuff.size()); ox::Directory32 dir(fileStore, 105); @@ -188,13 +207,13 @@ map tests = { oxTrace("ox::fs::test::Directory") << "write 3"; oxAssert(dir.write("/file2", 2), "Directory write of file2 failed"); - return 0; + return OxError(0); } }, { "FileSystem", - [](string) { - std::vector fsBuff(5000); + [](std::string_view) { + Vector fsBuff(5000); oxTrace("ox::fs::test::FileSystem") << "format"; oxAssert(ox::FileSystem32::format(fsBuff.data(), fsBuff.size()), "FileSystem format failed"); ox::FileSystem32 fs(ox::FileStore32(fsBuff.data(), fsBuff.size())); @@ -207,7 +226,7 @@ map tests = { oxAssert(fs.mkdir("/l1d1/l2d2", true), "mkdir failed"); oxAssert(fs.stat("/l1d1/l2d2").error, "mkdir failed"); - return 0; + return OxError(0); } }, }, @@ -217,7 +236,7 @@ int main(int argc, const char **args) { int retval = -1; if (argc > 1) { auto testName = args[1]; - string testArg = ""; + std::string_view testArg = ""; if (args[2]) { testArg = args[2]; }