diff --git a/src/keel/CMakeLists.txt b/src/keel/CMakeLists.txt index f9fbca2f..67c55c7a 100644 --- a/src/keel/CMakeLists.txt +++ b/src/keel/CMakeLists.txt @@ -45,3 +45,7 @@ install( LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) + +if(TURBINE_BUILD_TYPE STREQUAL "Native") + add_subdirectory(test) +endif() \ No newline at end of file diff --git a/src/keel/asset.hpp b/src/keel/asset.hpp index 25c95c9a..2a59dbaf 100644 --- a/src/keel/asset.hpp +++ b/src/keel/asset.hpp @@ -18,8 +18,9 @@ ox::Result readUuidHeader(const ox::Buffer &buff) noexcept; ox::Result readUuidHeader(const char *buff, std::size_t buffLen) noexcept; ox::Error writeUuidHeader(ox::Writer_c auto &writer, const ox::UUID &uuid) noexcept { - const auto hdr = ox::sfmt>("K1;{};", uuid.toString()); - return write(writer, hdr); + oxReturnError(write(writer, "K1;")); + oxReturnError(uuid.toString(writer)); + return writer.put(';'); } template diff --git a/src/keel/test/CMakeLists.txt b/src/keel/test/CMakeLists.txt new file mode 100644 index 00000000..54652a1a --- /dev/null +++ b/src/keel/test/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable( + KeelTest + tests.cpp +) + +target_link_libraries( + KeelTest + Keel +) + +add_test("[keel] KeelTest writeUuidHeader" KeelTest writeUuidHeader) diff --git a/src/keel/test/tests.cpp b/src/keel/test/tests.cpp new file mode 100644 index 00000000..2a987548 --- /dev/null +++ b/src/keel/test/tests.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#undef NDEBUG + +#include +#include +#include + +#include + +static std::map tests = { + { + "writeUuidHeader", + [] { + constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db"; + constexpr ox::StringView hdr = "K1;8d814442-f46e-4cc3-8edc-ca3c01cc86db;"; + oxRequire(uuid, ox::UUID::fromString(uuidStr)); + ox::Array buff; + ox::CharBuffWriter bw(buff); + oxReturnError(keel::writeUuidHeader(bw, uuid)); + oxExpect(ox::StringView(buff.data(), buff.size()), hdr); + return OxError(0); + } + }, +}; + +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(tests[testName]()); + } else { + retval = 1; + } + } + return retval; +} diff --git a/src/keel/typestore.cpp b/src/keel/typestore.cpp index 9fdd799f..4e2028eb 100644 --- a/src/keel/typestore.cpp +++ b/src/keel/typestore.cpp @@ -6,6 +6,11 @@ namespace keel { +TypeStore::TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept: + m_fs(fs), + m_descPath(std::move(descPath)) { +} + ox::Result> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept { auto path = ox::sfmt("{}/{}", m_descPath, typeId); oxRequire(buff, m_fs->read(path)); diff --git a/src/keel/typestore.hpp b/src/keel/typestore.hpp index 1bacb743..94f79133 100644 --- a/src/keel/typestore.hpp +++ b/src/keel/typestore.hpp @@ -16,10 +16,7 @@ class TypeStore: public ox::TypeStore { ox::String m_descPath; public: - constexpr explicit TypeStore(ox::FileSystem *fs, ox::String descPath = "/.keel/type_descriptors") noexcept: - m_fs(fs), - m_descPath(std::move(descPath)) { - } + explicit TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept; protected: ox::Result> loadDescriptor(ox::CRStringView typeId) noexcept override;