[Yunq] Add a basic yunq test into libyunq.
This commit is contained in:
parent
9c860dd6a4
commit
fecaa387b0
21 changed files with 189 additions and 936 deletions
|
|
@ -1,10 +1,2 @@
|
|||
find_package(Catch2 3 REQUIRED)
|
||||
find_program(MEMORYCHECK_COMMAND valgrind)
|
||||
set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")
|
||||
|
||||
add_subdirectory(container)
|
||||
|
||||
add_custom_target(build_test)
|
||||
add_dependencies(build_test
|
||||
glc_vec_test)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,3 +2,7 @@ add_executable(glc_vec_test vector.cpp)
|
|||
target_link_libraries(glc_vec_test glacier Catch2::Catch2WithMain)
|
||||
target_include_directories(glc_vec_test PRIVATE "../..")
|
||||
add_test(NAME glc_vec_test COMMAND $<TARGET_FILE:glc_vec_test>)
|
||||
|
||||
add_dependencies(build_test
|
||||
glc_vec_test)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,3 +16,7 @@ target_include_directories(yunq
|
|||
|
||||
set_target_properties(yunq PROPERTIES
|
||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}")
|
||||
|
||||
if (enable_testing)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
|
|
|||
42
lib/yunq/test/CMakeLists.txt
Normal file
42
lib/yunq/test/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
add_executable(yunq_test yunq_test.cpp)
|
||||
|
||||
add_dependencies(yunq_test
|
||||
example_yunq)
|
||||
|
||||
target_link_libraries(yunq_test
|
||||
Catch2::Catch2WithMain
|
||||
example_yunq)
|
||||
|
||||
target_include_directories(yunq_test PRIVATE "." "../../../zion/include")
|
||||
|
||||
add_test(NAME yunq_test COMMAND $<TARGET_FILE:yunq_test>)
|
||||
|
||||
add_dependencies(build_test
|
||||
yunq_test)
|
||||
|
||||
|
||||
# Build the yunq manualy rather than using the generator
|
||||
# because we don't want to link against mammoth and overrite new.
|
||||
set(target example_yunq)
|
||||
add_library(example_yunq
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq.cpp
|
||||
)
|
||||
|
||||
target_include_directories(example_yunq
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/example"
|
||||
)
|
||||
|
||||
target_link_libraries(${target}
|
||||
glacier
|
||||
yunq
|
||||
zion_stub
|
||||
)
|
||||
|
||||
set(PYTHON "${CMAKE_SOURCE_DIR}/yunq/venv/bin/python")
|
||||
set(YUNQ "${CMAKE_SOURCE_DIR}/yunq/yunq.py")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT example/example.yunq.cpp
|
||||
COMMAND ${PYTHON} ${YUNQ} ${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq
|
||||
)
|
||||
5
lib/yunq/test/example/example.yunq
Normal file
5
lib/yunq/test/example/example.yunq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ex;
|
||||
|
||||
message Basic {
|
||||
u64 field;
|
||||
}
|
||||
58
lib/yunq/test/example/example.yunq.cpp
Normal file
58
lib/yunq/test/example/example.yunq.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Generated file -- DO NOT MODIFY.
|
||||
#include "example.yunq.h"
|
||||
|
||||
#include <yunq/message_view.h>
|
||||
#include <yunq/serialize.h>
|
||||
|
||||
|
||||
namespace ex {
|
||||
|
||||
namespace {
|
||||
|
||||
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
||||
|
||||
struct ExtPointer {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) {
|
||||
RETURN_ERROR(ParseFromBytesInternal(message));
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::Status Basic::ParseFromBytesInternal(const yunq::MessageView& message) {
|
||||
RETURN_ERROR(message.CheckHeader());
|
||||
// Parse field.
|
||||
ASSIGN_OR_RETURN(field_, message.ReadField<uint64_t>(0));
|
||||
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||
yunq::Serializer serializer(bytes, offset, 1, caps);
|
||||
return SerializeInternal(serializer);
|
||||
}
|
||||
|
||||
uint64_t Basic::SerializeInternal(yunq::Serializer& serializer) const {
|
||||
// Write field.
|
||||
serializer.WriteField<uint64_t>(0, field_);
|
||||
|
||||
serializer.WriteHeader();
|
||||
|
||||
return serializer.size();
|
||||
}
|
||||
|
||||
|
||||
} // namepace ex
|
||||
43
lib/yunq/test/example/example.yunq.h
Normal file
43
lib/yunq/test/example/example.yunq.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Generated file - DO NOT MODIFY
|
||||
#pragma once
|
||||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <glacier/status/status.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <yunq/message_view.h>
|
||||
#include <yunq/serialize.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
|
||||
namespace ex {
|
||||
|
||||
class Basic {
|
||||
public:
|
||||
Basic() {}
|
||||
// Delete copy and move until implemented.
|
||||
Basic(const Basic&) = delete;
|
||||
Basic(Basic&&) = default;
|
||||
Basic& operator=(Basic&&) = default;
|
||||
|
||||
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message);
|
||||
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&);
|
||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||
|
||||
const uint64_t& field() const { return field_; }
|
||||
uint64_t& mutable_field() { return field_; }
|
||||
void set_field(const uint64_t& value) { field_ = value; }
|
||||
|
||||
private:
|
||||
uint64_t field_;
|
||||
|
||||
// Parses everything except for caps.
|
||||
glcr::Status ParseFromBytesInternal(const yunq::MessageView& message);
|
||||
|
||||
uint64_t SerializeInternal(yunq::Serializer& serializer) const;
|
||||
};
|
||||
|
||||
|
||||
} // namepace ex
|
||||
23
lib/yunq/test/yunq_test.cpp
Normal file
23
lib/yunq/test/yunq_test.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "example/example.yunq.h"
|
||||
|
||||
TEST_CASE("Basic Setter/Getter", "[yunq]") {
|
||||
ex::Basic b;
|
||||
b.set_field(1);
|
||||
REQUIRE(b.field() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Basic serialization", "[yunq]") {
|
||||
ex::Basic a;
|
||||
a.set_field(1);
|
||||
|
||||
glcr::ByteBuffer buf(1024);
|
||||
a.SerializeToBytes(buf, 0);
|
||||
|
||||
ex::Basic b;
|
||||
yunq::MessageView v(buf, 0);
|
||||
REQUIRE(b.ParseFromBytes(v).ok() == true);
|
||||
|
||||
REQUIRE(b.field() == 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue