Compare commits

..

No commits in common. "main" and "feature_serialization" have entirely different histories.

6 changed files with 59 additions and 243 deletions

View file

@ -10,7 +10,7 @@ FROM archlinux@sha256:a10e51dd0694d6c4142754e9d06cbce7baf91ace8031a30df37064d109
RUN pacman -Syyu --noconfirm \ RUN pacman -Syyu --noconfirm \
&& pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \ && pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \
&& pacman -Syyu --noconfirm cmake make gcc ninja meson shellcheck \ && 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' # Create a non-root user 'dev'
RUN useradd -ms /bin/bash 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 # Create the LLVM directory and extract only binaries into it
RUN sudo mkdir -p /home/LLVM-${LLVM_VER} 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 \ 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-19 \
LLVM-${LLVM_VER}-Linux-X64/bin/clang \ LLVM-${LLVM_VER}-Linux-X64/bin/clang \
LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \ LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \

View file

@ -13,9 +13,9 @@ jobs:
pacman -S --noconfirm cmake make gcc ninja meson pacman -S --noconfirm cmake make gcc ninja meson
pacman -S --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0 gtest 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: | run: |
export LLVM_VER=19.1.3 export LLVM_VER=19.1.1
echo "::group::Download LLVM-${LLVM_VER}" 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 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 # key: LLVM-${LLVM_VER}-Linux-X64-small
- name: Check clang-format - name: Check clang-format
id: clang_format_check
continue-on-error: true
run: | run: |
export LLVM_VER=19.1.3 export LLVM_VER=19.1.1
export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}" export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
cd ${{ github.workspace }} cd ${{ github.workspace }}
export REPO_FILES=$(cat repo_files_to_check.txt) export REPO_FILES=$(cat repo_files_to_check.txt)
@ -122,8 +120,6 @@ jobs:
echo "No clang-format violations detected!" echo "No clang-format violations detected!"
- name: GCC build - name: GCC build
id: gcc_build
continue-on-error: true
run: | run: |
mkdir -p ${{ github.workspace }}/build_gcc mkdir -p ${{ github.workspace }}/build_gcc
cmake -Wno-dev \ cmake -Wno-dev \
@ -138,51 +134,28 @@ jobs:
cmake --build ${{ github.workspace }}/build_gcc --parallel `nproc` cmake --build ${{ github.workspace }}/build_gcc --parallel `nproc`
- name: GCC unit tests - name: GCC unit tests
id: gcc_unit_tests
continue-on-error: true
run: | run: |
cd ${{ github.workspace }}/build_gcc cd ${{ github.workspace }}/build_gcc
./larra_xmpp_tests ./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 - name: Check clang-tidy
id: clang_tidy
continue-on-error: true
run: | run: |
export LLVM_VER=19.1.3 export LLVM_VER=19.1.1
export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}" export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
cd ${{ github.workspace }} 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 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 \ python run-clang-tidy.py \
-warnings-as-errors=* \ -warnings-as-errors=* \
-use-color \ -use-color \
-exclude-header-filter .*build.* \ -exclude-header-filter .*build.* \
-header-filter .hpp \ -header-filter .hpp \
-p ${{ github.workspace }}/build_clang/ \ -p ${{ github.workspace }}/build_gcc/ \
-config-file ${{ github.workspace }}/.clang-tidy \ -config-file ${{ github.workspace }}/.clang-tidy \
\ \
${{ github.workspace }}/examples \ ${{ github.workspace }}/examples \
@ -191,13 +164,26 @@ jobs:
echo "No clang-tidy violations detected!" echo "No clang-tidy violations detected!"
- name: Check on failures #- name: Clang build with -fsanitize=address
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: |
run: exit 1 # 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 #- name: Clang unit tests with -fsanitize=address
# run: | # run: |
# export LLVM_VER=19.1.3 # export LLVM_VER=19.1.1
# export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}" # export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
# cd ${{ github.workspace }}/build_clang # 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 # 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

View file

@ -35,8 +35,6 @@ template <typename Socket>
struct PrintStream : Socket { struct PrintStream : Socket {
using Socket::Socket; using Socket::Socket;
PrintStream(PrintStream&&) = default; PrintStream(PrintStream&&) = default;
constexpr PrintStream(Socket&& sock) : Socket(std::move(sock)) {
}
using Executor = Socket::executor_type; using Executor = Socket::executor_type;
template <typename ConstBufferSequence, template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(boost::system::error_code, std::size_t)) BOOST_ASIO_COMPLETION_TOKEN_FOR(void(boost::system::error_code, std::size_t))

View file

@ -4,7 +4,6 @@
#include <larra/serialization/error.hpp> #include <larra/serialization/error.hpp>
#include <nameof.hpp> #include <nameof.hpp>
#include <ranges>
#include <string> #include <string>
#include <utempl/utils.hpp> #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 { static constexpr auto Serialize(xmlpp::Element* element, const std::variant<Ts...>& object) -> void {
std::visit( std::visit(
[&]<typename T>(const T& object) { [&](const auto& object) {
Serialization<T>::Serialize(element, object); element << object;
}, },
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 } // namespace larra::xmpp

View file

@ -4,7 +4,6 @@
#include <boost/pfr.hpp> #include <boost/pfr.hpp>
#include <larra/serialization.hpp> #include <larra/serialization.hpp>
#include <larra/serialization/error.hpp> #include <larra/serialization/error.hpp>
#include <ranges>
#include <utempl/constexpr_string.hpp> #include <utempl/constexpr_string.hpp>
#include <utempl/tuple.hpp> #include <utempl/tuple.hpp>
#include <utempl/utils.hpp> #include <utempl/utils.hpp>
@ -28,11 +27,6 @@ constexpr auto Parse(xmlpp::Element* element, Tag<T> = {}) -> T
template <typename T> template <typename T>
constexpr auto Parse(xmlpp::Element* element, Tag<T> = {}) -> 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> template <typename T>
constexpr auto Serialize(xmlpp::Element* node, const T& element) -> void constexpr auto Serialize(xmlpp::Element* node, const T& element) -> void
requires(!std::same_as<std::decay_t<decltype(kSerializationConfig<T>)>, std::monostate>); requires(!std::same_as<std::decay_t<decltype(kSerializationConfig<T>)>, std::monostate>);
@ -69,7 +63,9 @@ struct FieldInfo {
}; };
template <typename T> template <typename T>
struct Config {}; struct Config {
std::optional<T> defaultValue;
};
// GCC workaround: operator== // GCC workaround: operator==
@ -90,11 +86,9 @@ constexpr auto operator==(const Config<T>&, const Config<T>&) -> bool {
return false; return false;
} }
template <typename T> template <>
struct Config<std::optional<T>> { struct Config<std::string> {
std::optional<T> defaultValue = std::nullopt; std::optional<std::string_view> defaultValue;
bool strict = true;
std::optional<Config<T>> main = std::nullopt;
}; };
namespace impl { namespace impl {
@ -136,7 +130,7 @@ struct ElementSerializer {
throw ElementParsingError(std::format("[{}: {}] parsing error: [ Not found ]", Info::kName, nameof::nameof_full_type<T>())); throw ElementParsingError(std::format("[{}: {}] parsing error: [ Not found ]", Info::kName, nameof::nameof_full_type<T>()));
} }
auto elementNode = dynamic_cast<xmlpp::Element*>(node); 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>())); throw ElementParsingError(std::format("[{}: {}] parsing error: [ Invalid node ]", Info::kName, nameof::nameof_full_type<T>()));
} }
try { try {
@ -145,7 +139,6 @@ struct ElementSerializer {
throw ElementParsingError(std::format("[{}: {}] parsing error: [ {} ]", Info::kName, nameof::nameof_full_type<T>(), error.what())); 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) { static constexpr auto Serialize(xmlpp::Element* node, const T& element) {
auto created = node->add_child_element(Info::kName); auto created = node->add_child_element(Info::kName);
if(!node) { 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 { namespace impl {
template <typename T> template <typename T>
@ -262,7 +166,15 @@ template <auto& Config, typename Info>
auto ParseField(xmlpp::Element* main) -> std::decay_t<decltype(Config)>::type { auto ParseField(xmlpp::Element* main) -> std::decay_t<decltype(Config)>::type {
using Type = std::decay_t<decltype(Config)>::type; using Type = std::decay_t<decltype(Config)>::type;
if constexpr(std::holds_alternative<AttributeConfig>(Config.Base())) { 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 { } else {
return ElementSerializer<Type, Config, Info>::Parse(main); 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> template <auto& Config, typename Info, typename T>
auto SerializeField(xmlpp::Element* main, const T& obj) { auto SerializeField(xmlpp::Element* main, const T& obj) {
if constexpr(std::holds_alternative<AttributeConfig>(Config.Base())) { 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 { } else {
ElementSerializer<T, Config, Info>::Serialize(main, obj); ElementSerializer<T, Config, Info>::Serialize(main, obj);
} }

View file

@ -37,7 +37,6 @@ struct SomeStruct {
std::string value; std::string value;
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> SomeStruct; [[nodiscard]] static auto Parse(xmlpp::Element* element) -> SomeStruct;
friend auto operator<<(xmlpp::Element* element, const SomeStruct& self); friend auto operator<<(xmlpp::Element* element, const SomeStruct& self);
constexpr auto operator==(const SomeStruct&) const -> bool = default;
}; };
struct SomeStruct2 { struct SomeStruct2 {
@ -66,18 +65,6 @@ struct SomeStruct5 {
friend auto operator<<(xmlpp::Element* element, const SomeStruct5& self); 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 tests::serialization
namespace serialization { namespace serialization {
@ -94,13 +81,6 @@ constexpr auto kSerializationConfig<tests::serialization::SomeStruct4> = Seriali
template <> template <>
constexpr auto kSerializationConfig<tests::serialization::SomeStruct5> = SerializationConfig<tests::serialization::SomeStruct5>{}; 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 serialization
namespace tests::serialization { namespace tests::serialization {
@ -125,14 +105,6 @@ auto SomeStruct5::Parse(xmlpp::Element* element) -> SomeStruct5 {
return ::larra::xmpp::serialization::Parse<tests::serialization::SomeStruct5>(element); 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) { auto operator<<(xmlpp::Element* element, const SomeStruct& self) {
::larra::xmpp::serialization::Serialize(element, self); ::larra::xmpp::serialization::Serialize(element, self);
} }
@ -172,30 +144,6 @@ TEST(AutoParse, Attribute) {
EXPECT_EQ(a.value.username, "user"sv); 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) { TEST(AutoSerialize, Basic) {
xmlpp::Document doc; xmlpp::Document doc;
auto node = doc.create_root_node("some2"); auto node = doc.create_root_node("some2");