diff --git a/.vscode/launch.json b/.vscode/launch.json index 2a94c2f..974f9e6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,18 @@ "args": [], "cwd": "${workspaceFolder}", "preLaunchTask": "GCC: Build" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug: tests", + "program": "${workspaceFolder}/build/larra_xmpp_tests", + "args": [ + // --gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS] + "--gtest_filter=Roster*" + ], + "cwd": "${workspaceFolder}", + "preLaunchTask": "GCC: Build" } ] } \ No newline at end of file diff --git a/library/include/larra/bind.hpp b/library/include/larra/bind.hpp index bac1e51..c9c01f0 100644 --- a/library/include/larra/bind.hpp +++ b/library/include/larra/bind.hpp @@ -47,7 +47,7 @@ using SetBind = Set; using ResultBind = Result; using IqBind = Iq; -auto MakeSetBind() { +inline auto MakeSetBind() { return SetBind{.id = "1", .payload = Bind{}}; } } // namespace larra::xmpp::iq diff --git a/library/include/larra/roster.hpp b/library/include/larra/roster.hpp index 5c8dba3..8486bf5 100644 --- a/library/include/larra/roster.hpp +++ b/library/include/larra/roster.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,8 @@ struct Roster { } friend constexpr auto operator<<(xmlpp::Element* element, const Roster& roster) { element->set_attribute("xmlns", "jabber:iq:roster"); + // TODO: Add adding elements to xmlpp::Element + assert(false); } [[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Roster { const auto& item_nodes = element->get_children("item"); @@ -68,7 +71,7 @@ using GetRoster = Get; using ResultRoster = Result; using IqRoster = Iq; -auto MakeGetRoster(const FullJid& jid) { +inline auto MakeGetRoster(const FullJid& jid) { return GetRoster{.id = "1", .from = ToString(jid), .payload = Roster{}}; } diff --git a/tests/roster.cpp b/tests/roster.cpp new file mode 100644 index 0000000..a7b79d3 --- /dev/null +++ b/tests/roster.cpp @@ -0,0 +1,30 @@ +#include + +#include +#include + +#include "larra/jid.hpp" + +namespace larra::xmpp { + +TEST(Roster, SerializeAndParse) { + FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT + auto roster = iq::MakeGetRoster(jid); + roster.payload.items.emplace_back("u1", "s1"); + roster.payload.items.emplace_back("u2", "s2"); + roster.payload.items.emplace_back("u3", "s3"); + + using S = Serialization; + xmlpp::Document doc; + auto node = doc.create_root_node("iq"); + node << roster; + auto parse_res = iq::Roster::Parse(node); + + ASSERT_EQ(roster.payload.items.size(), parse_res.items.size()); + for(const auto& [idx, expect_el, parsed_el] : std::views::zip(std::views::iota(0), roster.payload.items, parse_res.items)) { + EXPECT_EQ(expect_el, parsed_el) << "Mismatched on idx: " << idx; + // std::cerr << " " << "idx: " << idx << "; expect_el: " << expect_el << "; parsed_el: " << parsed_el << '\n'; + } +} + +} // namespace larra::xmpp