Compare commits
No commits in common. "main" and "feature_serialization" have entirely different histories.
main
...
feature_se
6 changed files with 59 additions and 243 deletions
|
@ -10,7 +10,7 @@ FROM archlinux@sha256:a10e51dd0694d6c4142754e9d06cbce7baf91ace8031a30df37064d109
|
|||
RUN pacman -Syyu --noconfirm \
|
||||
&& pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \
|
||||
&& pacman -Syyu --noconfirm cmake make gcc ninja meson shellcheck \
|
||||
&& pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0 gtest
|
||||
&& pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0
|
||||
|
||||
# Create a non-root user 'dev'
|
||||
RUN useradd -ms /bin/bash dev \
|
||||
|
@ -38,7 +38,6 @@ ADD https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}/L
|
|||
# Create the LLVM directory and extract only binaries into it
|
||||
RUN sudo mkdir -p /home/LLVM-${LLVM_VER}
|
||||
RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clangd \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-19 \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \
|
||||
|
|
|
@ -13,9 +13,9 @@ jobs:
|
|||
pacman -S --noconfirm cmake make gcc ninja meson
|
||||
pacman -S --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0 gtest
|
||||
|
||||
- name: Setup environment - Install LLVM-19.1.3
|
||||
- name: Setup environment - Install LLVM-19.1.1
|
||||
run: |
|
||||
export LLVM_VER=19.1.3
|
||||
export LLVM_VER=19.1.1
|
||||
|
||||
echo "::group::Download LLVM-${LLVM_VER}"
|
||||
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}/LLVM-${LLVM_VER}-Linux-X64.tar.xz -O /LLVM-${LLVM_VER}-Linux-X64.tar.xz
|
||||
|
@ -105,10 +105,8 @@ jobs:
|
|||
# key: LLVM-${LLVM_VER}-Linux-X64-small
|
||||
|
||||
- name: Check clang-format
|
||||
id: clang_format_check
|
||||
continue-on-error: true
|
||||
run: |
|
||||
export LLVM_VER=19.1.3
|
||||
export LLVM_VER=19.1.1
|
||||
export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
cd ${{ github.workspace }}
|
||||
export REPO_FILES=$(cat repo_files_to_check.txt)
|
||||
|
@ -122,8 +120,6 @@ jobs:
|
|||
echo "No clang-format violations detected!"
|
||||
|
||||
- name: GCC build
|
||||
id: gcc_build
|
||||
continue-on-error: true
|
||||
run: |
|
||||
mkdir -p ${{ github.workspace }}/build_gcc
|
||||
cmake -Wno-dev \
|
||||
|
@ -138,51 +134,28 @@ jobs:
|
|||
cmake --build ${{ github.workspace }}/build_gcc --parallel `nproc`
|
||||
|
||||
- name: GCC unit tests
|
||||
id: gcc_unit_tests
|
||||
continue-on-error: true
|
||||
run: |
|
||||
cd ${{ github.workspace }}/build_gcc
|
||||
./larra_xmpp_tests
|
||||
|
||||
- name: Clang build (only configuring)
|
||||
id: clang_build
|
||||
continue-on-error: true
|
||||
run: |
|
||||
export LLVM_VER=19.1.3
|
||||
export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
mkdir -p ${{ github.workspace }}/build_clang
|
||||
|
||||
cmake -Wno-dev \
|
||||
-DCMAKE_C_COMPILER=clang \
|
||||
-DCMAKE_CXX_COMPILER=clang++ \
|
||||
-S ${{ github.workspace }} \
|
||||
-B ${{ github.workspace }}/build_clang \
|
||||
-GNinja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DENABLE_EXAMPLES=ON \
|
||||
-DENABLE_TESTS=ON \
|
||||
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -I/home/LLVM-${LLVM_VER}/include/c++/v1 -fno-modules"
|
||||
|
||||
echo "::group::compile_commands.json content"
|
||||
cat ${{ github.workspace }}/build_clang/compile_commands.json
|
||||
echo "::endgroup::"
|
||||
|
||||
sed -i 's|@.*\.modmap||' ${{ github.workspace }}/build_clang/compile_commands.json
|
||||
|
||||
- name: Check clang-tidy
|
||||
id: clang_tidy
|
||||
continue-on-error: true
|
||||
run: |
|
||||
export LLVM_VER=19.1.3
|
||||
export LLVM_VER=19.1.1
|
||||
export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
cd ${{ github.workspace }}
|
||||
|
||||
sed -i 's|/usr/sbin/g++|/home/LLVM-19.1.1/bin/clang++ -stdlib=libc++ -I/home/LLVM-${LLVM_VER}/include/c++/v1|' build_gcc/compile_commands.json
|
||||
sed -i 's|-fdeps-format=p1689r5||' build_gcc/compile_commands.json
|
||||
sed -i 's|-fmodules-ts||' build_gcc/compile_commands.json
|
||||
sed -i 's|-fmodule-mapper=.*\.modmap||' build_gcc/compile_commands.json
|
||||
|
||||
wget https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/main/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
|
||||
python run-clang-tidy.py \
|
||||
-warnings-as-errors=* \
|
||||
-use-color \
|
||||
-exclude-header-filter .*build.* \
|
||||
-header-filter .hpp \
|
||||
-p ${{ github.workspace }}/build_clang/ \
|
||||
-p ${{ github.workspace }}/build_gcc/ \
|
||||
-config-file ${{ github.workspace }}/.clang-tidy \
|
||||
\
|
||||
${{ github.workspace }}/examples \
|
||||
|
@ -191,13 +164,26 @@ jobs:
|
|||
|
||||
echo "No clang-tidy violations detected!"
|
||||
|
||||
- name: Check on failures
|
||||
if: steps.clang_format_check.outcome != 'success' || steps.gcc_build.outcome != 'success' || steps.gcc_unit_tests.outcome != 'success' || steps.clang_build.outcome != 'success' || steps.clang_tidy.outcome != 'success'
|
||||
run: exit 1
|
||||
#- name: Clang build with -fsanitize=address
|
||||
# run: |
|
||||
# export LLVM_VER=19.1.1
|
||||
# export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
# mkdir -p ${{ github.workspace }}/build_clang
|
||||
# cmake -Wno-dev \
|
||||
# -DCMAKE_C_COMPILER=clang \
|
||||
# -DCMAKE_CXX_COMPILER=clang++ \
|
||||
# -S ${{ github.workspace }} \
|
||||
# -B ${{ github.workspace }}/build_clang \
|
||||
# -GNinja -DCMAKE_BUILD_TYPE=Release \
|
||||
# -DENABLE_EXAMPLES=ON \
|
||||
# -DENABLE_TESTS=ON \
|
||||
# -DCMAKE_CXX_FLAGS="-stdlib=libc++ -I/home/LLVM-${LLVM_VER}/include/c++/v1 -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr" \
|
||||
# -DCMAKE_EXE_LINKER_FLAGS="-L/home/LLVM-${LLVM_VER}/lib/ -Wl,-rpath,/home/LLVM-${LLVM_VER}/lib -lc++ -lc++abi -lm -lc -lgcc_s -lgcc -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr"
|
||||
# cmake --build ${{ github.workspace }}/build_clang --parallel `nproc`
|
||||
|
||||
#- name: Clang unit tests with -fsanitize=address
|
||||
# run: |
|
||||
# export LLVM_VER=19.1.3
|
||||
# export LLVM_VER=19.1.1
|
||||
# export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
# cd ${{ github.workspace }}/build_clang
|
||||
# ASAN_SYMBOLIZER_PATH=llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests
|
||||
|
|
|
@ -35,8 +35,6 @@ template <typename Socket>
|
|||
struct PrintStream : Socket {
|
||||
using Socket::Socket;
|
||||
PrintStream(PrintStream&&) = default;
|
||||
constexpr PrintStream(Socket&& sock) : Socket(std::move(sock)) {
|
||||
}
|
||||
using Executor = Socket::executor_type;
|
||||
template <typename ConstBufferSequence,
|
||||
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(boost::system::error_code, std::size_t))
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <larra/serialization/error.hpp>
|
||||
#include <nameof.hpp>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <utempl/utils.hpp>
|
||||
|
||||
|
@ -170,8 +169,8 @@ struct Serialization<std::variant<Ts...>> : SerializationBase<> {
|
|||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* element, const std::variant<Ts...>& object) -> void {
|
||||
std::visit(
|
||||
[&]<typename T>(const T& object) {
|
||||
Serialization<T>::Serialize(element, object);
|
||||
[&](const auto& object) {
|
||||
element << object;
|
||||
},
|
||||
object);
|
||||
}
|
||||
|
@ -192,42 +191,4 @@ struct Serialization<std::monostate> : SerializationBase<> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Serialization<std::vector<T>> : SerializationBase<> {
|
||||
static constexpr auto Parse(xmlpp::Element* element) -> std::vector<T> {
|
||||
return element->get_children(Serialization<T>::kDefaultName) | std::views::transform([](xmlpp::Node* node) {
|
||||
auto itemElement = dynamic_cast<xmlpp::Element*>(node);
|
||||
if(!itemElement) {
|
||||
throw serialization::ParsingError{"Can't convert xmlpp::Node to xmlpp::Element ]"};
|
||||
}
|
||||
return Serialization<T>::Parse(itemElement);
|
||||
}) |
|
||||
std::ranges::to<std::vector<T>>();
|
||||
}
|
||||
static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<std::vector<T>> {
|
||||
auto chd = element->get_children(Serialization<T>::kDefaultName);
|
||||
auto range = chd | std::views::transform([](xmlpp::Node* node) -> std::optional<T> {
|
||||
auto itemElement = dynamic_cast<xmlpp::Element*>(node);
|
||||
if(!itemElement) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return Serialization<T>::TryParse(itemElement);
|
||||
});
|
||||
std::vector<T> response;
|
||||
response.reserve(chd.size());
|
||||
for(auto& value : range) {
|
||||
if(!value) {
|
||||
return std::nullopt;
|
||||
}
|
||||
response.push_back(std::move(*value));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* node, const std::vector<T>& value) -> void {
|
||||
for(const T& element : value) {
|
||||
Serialization<T>::Serialize(node->add_child_element(Serialization<T>::kDefaultName), element);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace larra::xmpp
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <boost/pfr.hpp>
|
||||
#include <larra/serialization.hpp>
|
||||
#include <larra/serialization/error.hpp>
|
||||
#include <ranges>
|
||||
#include <utempl/constexpr_string.hpp>
|
||||
#include <utempl/tuple.hpp>
|
||||
#include <utempl/utils.hpp>
|
||||
|
@ -28,11 +27,6 @@ constexpr auto Parse(xmlpp::Element* element, Tag<T> = {}) -> T
|
|||
template <typename T>
|
||||
constexpr auto Parse(xmlpp::Element* element, Tag<T> = {}) -> T;
|
||||
|
||||
template <typename T>
|
||||
constexpr auto TryParse(xmlpp::Element* element, Tag<T> = {}) -> std::optional<T> {
|
||||
return Serialization<std::optional<T>>::Parse(element);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr auto Serialize(xmlpp::Element* node, const T& element) -> void
|
||||
requires(!std::same_as<std::decay_t<decltype(kSerializationConfig<T>)>, std::monostate>);
|
||||
|
@ -69,7 +63,9 @@ struct FieldInfo {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct Config {};
|
||||
struct Config {
|
||||
std::optional<T> defaultValue;
|
||||
};
|
||||
|
||||
// GCC workaround: operator==
|
||||
|
||||
|
@ -90,11 +86,9 @@ constexpr auto operator==(const Config<T>&, const Config<T>&) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Config<std::optional<T>> {
|
||||
std::optional<T> defaultValue = std::nullopt;
|
||||
bool strict = true;
|
||||
std::optional<Config<T>> main = std::nullopt;
|
||||
template <>
|
||||
struct Config<std::string> {
|
||||
std::optional<std::string_view> defaultValue;
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
|
@ -136,7 +130,7 @@ struct ElementSerializer {
|
|||
throw ElementParsingError(std::format("[{}: {}] parsing error: [ Not found ]", Info::kName, nameof::nameof_full_type<T>()));
|
||||
}
|
||||
auto elementNode = dynamic_cast<xmlpp::Element*>(node);
|
||||
if(!elementNode) {
|
||||
if(!node) {
|
||||
throw ElementParsingError(std::format("[{}: {}] parsing error: [ Invalid node ]", Info::kName, nameof::nameof_full_type<T>()));
|
||||
}
|
||||
try {
|
||||
|
@ -145,7 +139,6 @@ struct ElementSerializer {
|
|||
throw ElementParsingError(std::format("[{}: {}] parsing error: [ {} ]", Info::kName, nameof::nameof_full_type<T>(), error.what()));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr auto Serialize(xmlpp::Element* node, const T& element) {
|
||||
auto created = node->add_child_element(Info::kName);
|
||||
if(!node) {
|
||||
|
@ -161,95 +154,6 @@ struct ElementSerializer {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T, auto& Config, typename Info>
|
||||
struct ElementSerializer<std::optional<T>, Config, Info> {
|
||||
static constexpr auto Parse(xmlpp::Element* element) -> std::optional<T> {
|
||||
return [&] {
|
||||
auto node = element->get_first_child(Info::kName);
|
||||
if(!node) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto elementNode = dynamic_cast<xmlpp::Element*>(node);
|
||||
if(!elementNode) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if constexpr(Config.strict) {
|
||||
return ElementSerializer<T, Config.main, Info>::Parse(element);
|
||||
} else {
|
||||
return ElementSerializer<T, Config.main, Info>::TryParse(element);
|
||||
}
|
||||
}()
|
||||
.or_else([] {
|
||||
return Config.defaultValue;
|
||||
});
|
||||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* node, const std::optional<T>& element) {
|
||||
if(element) {
|
||||
ElementSerializer<T, Config.main, Info>::Serialize(node, *element);
|
||||
} else if(Config.defaultValue) {
|
||||
Serialize(node, Config.defaultValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto& Config, typename Info>
|
||||
struct ElementSerializer<std::vector<T>, Config, Info> {
|
||||
// TODO(sha512sum): Add Config and main options instead use Serialization<std::vector<T>>
|
||||
static constexpr auto Parse(xmlpp::Element* element) {
|
||||
try {
|
||||
return Serialization<std::vector<T>>::Parse(element);
|
||||
} catch(const std::exception& error) {
|
||||
throw ElementParsingError(
|
||||
std::format("[{}: {}] parsing error: [ {} ]", Info::kName, nameof::nameof_full_type<std::vector<T>>(), error.what()));
|
||||
}
|
||||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* node, const std::vector<T>& element) {
|
||||
try {
|
||||
return Serialization<std::vector<T>>::Serialize(node, element);
|
||||
} catch(const std::exception& error) {
|
||||
throw ElementSerializaionError(
|
||||
std::format("[{}: {}] serialization error: [ {} ]", Info::kName, nameof::nameof_full_type<std::vector<T>>(), error.what()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Info>
|
||||
struct AttributeSerializer {
|
||||
static constexpr auto Parse(xmlpp::Element* element) -> T {
|
||||
auto node = element->get_attribute(Info::kName);
|
||||
if(!node) {
|
||||
throw AttributeParsingError(std::format("Attribute [{}: {}] parsing error", Info::kName, nameof::nameof_full_type<T>()));
|
||||
}
|
||||
if constexpr(requires(std::string_view view) { T::Parse(view); }) {
|
||||
return T::Parse(node->get_value());
|
||||
} else {
|
||||
return node->get_value();
|
||||
}
|
||||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* element, const T& obj) {
|
||||
if constexpr(requires {
|
||||
{ ToString(obj) } -> std::convertible_to<const std::string&>;
|
||||
}) {
|
||||
element->set_attribute(Info::kName, ToString(obj));
|
||||
} else {
|
||||
element->set_attribute(Info::kName, obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Info>
|
||||
struct AttributeSerializer<std::optional<T>, Info> {
|
||||
static constexpr auto Parse(xmlpp::Element* element) -> std::optional<T> {
|
||||
auto node = element->get_attribute(Info::kName);
|
||||
return node ? std::optional{AttributeSerializer<T, Info>::Parse(element)} : std::nullopt;
|
||||
}
|
||||
static constexpr auto Serialize(xmlpp::Element* element, const std::optional<T>& obj) {
|
||||
if(obj) {
|
||||
AttributeSerializer<T, Info>::Serialize(element, *obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
|
||||
template <typename T>
|
||||
|
@ -262,7 +166,15 @@ template <auto& Config, typename Info>
|
|||
auto ParseField(xmlpp::Element* main) -> std::decay_t<decltype(Config)>::type {
|
||||
using Type = std::decay_t<decltype(Config)>::type;
|
||||
if constexpr(std::holds_alternative<AttributeConfig>(Config.Base())) {
|
||||
return AttributeSerializer<Type, Info>::Parse(main);
|
||||
xmlpp::Attribute* node = main->get_attribute(Info::kName);
|
||||
if(!node) {
|
||||
throw AttributeParsingError(std::format("Attribute [{}: {}] parsing error", Info::kName, nameof::nameof_full_type<Type>()));
|
||||
}
|
||||
if constexpr(requires(std::string_view view) { Type::Parse(view); }) {
|
||||
return Type::Parse(node->get_value());
|
||||
} else {
|
||||
return node->get_value();
|
||||
}
|
||||
} else {
|
||||
return ElementSerializer<Type, Config, Info>::Parse(main);
|
||||
}
|
||||
|
@ -271,7 +183,19 @@ auto ParseField(xmlpp::Element* main) -> std::decay_t<decltype(Config)>::type {
|
|||
template <auto& Config, typename Info, typename T>
|
||||
auto SerializeField(xmlpp::Element* main, const T& obj) {
|
||||
if constexpr(std::holds_alternative<AttributeConfig>(Config.Base())) {
|
||||
AttributeSerializer<T, Info>::Serialize(main, obj);
|
||||
auto node = main->set_attribute(Info::kName, [&] -> decltype(auto) {
|
||||
if constexpr(requires {
|
||||
{ ToString(obj) } -> std::convertible_to<const std::string&>;
|
||||
}) {
|
||||
return ToString(obj);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
}());
|
||||
if(!node) {
|
||||
throw AttributeSerializationError(
|
||||
std::format("[{}: {}] parsing error: [ node creation failed ]", Info::kName, nameof::nameof_full_type<T>()));
|
||||
}
|
||||
} else {
|
||||
ElementSerializer<T, Config, Info>::Serialize(main, obj);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ struct SomeStruct {
|
|||
std::string value;
|
||||
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> SomeStruct;
|
||||
friend auto operator<<(xmlpp::Element* element, const SomeStruct& self);
|
||||
constexpr auto operator==(const SomeStruct&) const -> bool = default;
|
||||
};
|
||||
|
||||
struct SomeStruct2 {
|
||||
|
@ -66,18 +65,6 @@ struct SomeStruct5 {
|
|||
friend auto operator<<(xmlpp::Element* element, const SomeStruct5& self);
|
||||
};
|
||||
|
||||
struct SomeStruct6 {
|
||||
static constexpr auto kDefaultName = "some6";
|
||||
std::vector<SomeStruct> some;
|
||||
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> SomeStruct6;
|
||||
};
|
||||
|
||||
struct SomeStruct7 {
|
||||
static constexpr auto kDefaultName = "some7";
|
||||
std::optional<FullJid> value;
|
||||
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> SomeStruct7;
|
||||
};
|
||||
|
||||
} // namespace tests::serialization
|
||||
|
||||
namespace serialization {
|
||||
|
@ -94,13 +81,6 @@ constexpr auto kSerializationConfig<tests::serialization::SomeStruct4> = Seriali
|
|||
template <>
|
||||
constexpr auto kSerializationConfig<tests::serialization::SomeStruct5> = SerializationConfig<tests::serialization::SomeStruct5>{};
|
||||
|
||||
template <>
|
||||
constexpr auto kSerializationConfig<tests::serialization::SomeStruct6> =
|
||||
SerializationConfig<tests::serialization::SomeStruct6>{}.With<"some">({Config<std::vector<tests::serialization::SomeStruct>>{}});
|
||||
|
||||
template <>
|
||||
constexpr auto kSerializationConfig<tests::serialization::SomeStruct7> = SerializationConfig<tests::serialization::SomeStruct7>{};
|
||||
|
||||
} // namespace serialization
|
||||
|
||||
namespace tests::serialization {
|
||||
|
@ -125,14 +105,6 @@ auto SomeStruct5::Parse(xmlpp::Element* element) -> SomeStruct5 {
|
|||
return ::larra::xmpp::serialization::Parse<tests::serialization::SomeStruct5>(element);
|
||||
}
|
||||
|
||||
auto SomeStruct6::Parse(xmlpp::Element* element) -> SomeStruct6 {
|
||||
return ::larra::xmpp::serialization::Parse<tests::serialization::SomeStruct6>(element);
|
||||
}
|
||||
|
||||
auto SomeStruct7::Parse(xmlpp::Element* element) -> SomeStruct7 {
|
||||
return ::larra::xmpp::serialization::Parse<tests::serialization::SomeStruct7>(element);
|
||||
}
|
||||
|
||||
auto operator<<(xmlpp::Element* element, const SomeStruct& self) {
|
||||
::larra::xmpp::serialization::Serialize(element, self);
|
||||
}
|
||||
|
@ -172,30 +144,6 @@ TEST(AutoParse, Attribute) {
|
|||
EXPECT_EQ(a.value.username, "user"sv);
|
||||
}
|
||||
|
||||
TEST(AutoParse, Vector) {
|
||||
xmlpp::Document doc;
|
||||
auto node = doc.create_root_node("some6");
|
||||
for(auto i : std::views::iota(0, 10)) {
|
||||
auto child = node->add_child_element("some");
|
||||
child->set_attribute("value", std::format("Hello {}", i));
|
||||
}
|
||||
auto value = Serialization<tests::serialization::SomeStruct6>::Parse(node);
|
||||
EXPECT_EQ(value.some, std::views::iota(0, 10) | std::views::transform([](auto i) -> tests::serialization::SomeStruct {
|
||||
return {.value = std::format("Hello {}", i)};
|
||||
}) | std::ranges::to<std::vector<tests::serialization::SomeStruct>>());
|
||||
}
|
||||
|
||||
TEST(AutoParse, Optional) {
|
||||
xmlpp::Document doc;
|
||||
auto node = doc.create_root_node("some7");
|
||||
auto value = Serialization<tests::serialization::SomeStruct7>::Parse(node).value;
|
||||
EXPECT_EQ(value, std::nullopt);
|
||||
node->set_attribute("value", "user@server.i2p/resource");
|
||||
auto value2 = Serialization<tests::serialization::SomeStruct7>::Parse(node).value;
|
||||
FullJid expectData{.username = "user", .server = "server.i2p", .resource = "resource"};
|
||||
EXPECT_EQ(value2, expectData);
|
||||
}
|
||||
|
||||
TEST(AutoSerialize, Basic) {
|
||||
xmlpp::Document doc;
|
||||
auto node = doc.create_root_node("some2");
|
||||
|
|
Loading…
Reference in a new issue