Compare commits
2 Commits
952a2f153e
...
bb85e6ab6c
Author | SHA1 | Date | |
---|---|---|---|
bb85e6ab6c | |||
fb43c956e7 |
27
deps/ox/src/ox/std/uuid.hpp
vendored
27
deps/ox/src/ox/std/uuid.hpp
vendored
@@ -145,6 +145,33 @@ class UUID {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr ox::Error toString(Writer_c auto &writer) const noexcept {
|
||||||
|
auto valueI = 0u;
|
||||||
|
constexpr auto printChars = [](
|
||||||
|
Writer_c auto &writer,
|
||||||
|
const Array<uint8_t, 16> &value,
|
||||||
|
std::size_t cnt,
|
||||||
|
unsigned &valueI) {
|
||||||
|
for (auto i = 0u; i < cnt; ++i) {
|
||||||
|
const auto v = value[valueI];
|
||||||
|
const auto h = detail::toHex(v);
|
||||||
|
oxIgnoreError(writer.write(h.c_str(), h.len()));
|
||||||
|
++valueI;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
printChars(writer, m_value, 4, valueI);
|
||||||
|
oxReturnError(writer.put('-'));
|
||||||
|
printChars(writer, m_value, 2, valueI);
|
||||||
|
oxReturnError(writer.put('-'));
|
||||||
|
printChars(writer, m_value, 2, valueI);
|
||||||
|
oxReturnError(writer.put('-'));
|
||||||
|
printChars(writer, m_value, 2, valueI);
|
||||||
|
oxReturnError(writer.put('-'));
|
||||||
|
printChars(writer, m_value, 6, valueI);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr UUIDStr toString() const noexcept {
|
constexpr UUIDStr toString() const noexcept {
|
||||||
UUIDStr out;
|
UUIDStr out;
|
||||||
|
@@ -45,3 +45,7 @@ install(
|
|||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION lib
|
||||||
ARCHIVE DESTINATION lib
|
ARCHIVE DESTINATION lib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(TURBINE_BUILD_TYPE STREQUAL "Native")
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
@@ -18,8 +18,9 @@ ox::Result<ox::UUID> readUuidHeader(const ox::Buffer &buff) noexcept;
|
|||||||
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
|
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
|
||||||
|
|
||||||
ox::Error writeUuidHeader(ox::Writer_c auto &writer, const ox::UUID &uuid) noexcept {
|
ox::Error writeUuidHeader(ox::Writer_c auto &writer, const ox::UUID &uuid) noexcept {
|
||||||
const auto hdr = ox::sfmt<ox::BString<K1HdrSz>>("K1;{};", uuid.toString());
|
oxReturnError(write(writer, "K1;"));
|
||||||
return write(writer, hdr);
|
oxReturnError(uuid.toString(writer));
|
||||||
|
return writer.put(';');
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
11
src/keel/test/CMakeLists.txt
Normal file
11
src/keel/test/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
add_executable(
|
||||||
|
KeelTest
|
||||||
|
tests.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
KeelTest
|
||||||
|
Keel
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test("[keel] KeelTest writeUuidHeader" KeelTest writeUuidHeader)
|
40
src/keel/test/tests.cpp
Normal file
40
src/keel/test/tests.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <ox/std/std.hpp>
|
||||||
|
|
||||||
|
#include <keel/keel.hpp>
|
||||||
|
|
||||||
|
static std::map<std::string, ox::Error(*)()> 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<char, hdr.len()> 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<int>(tests[testName]());
|
||||||
|
} else {
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
@@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
namespace keel {
|
namespace keel {
|
||||||
|
|
||||||
|
TypeStore::TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept:
|
||||||
|
m_fs(fs),
|
||||||
|
m_descPath(std::move(descPath)) {
|
||||||
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept {
|
ox::Result<ox::UniquePtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept {
|
||||||
auto path = ox::sfmt("{}/{}", m_descPath, typeId);
|
auto path = ox::sfmt("{}/{}", m_descPath, typeId);
|
||||||
oxRequire(buff, m_fs->read(path));
|
oxRequire(buff, m_fs->read(path));
|
||||||
|
@@ -16,10 +16,7 @@ class TypeStore: public ox::TypeStore {
|
|||||||
ox::String m_descPath;
|
ox::String m_descPath;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr explicit TypeStore(ox::FileSystem *fs, ox::String descPath = "/.keel/type_descriptors") noexcept:
|
explicit TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept;
|
||||||
m_fs(fs),
|
|
||||||
m_descPath(std::move(descPath)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
|
ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
|
||||||
|
Reference in New Issue
Block a user