Renamed iq to stanza error. Added log level as cmake param
All checks were successful
PR Check / on-push-commit-check (push) Successful in 14m30s

This commit is contained in:
Ivan-lis 2024-12-22 22:39:58 +00:00
parent 1ac4f0905c
commit 284250a69f
7 changed files with 166 additions and 163 deletions

View file

@ -134,6 +134,8 @@ jobs:
-GNinja -DCMAKE_BUILD_TYPE=Release \ -GNinja -DCMAKE_BUILD_TYPE=Release \
-DENABLE_EXAMPLES=ON \ -DENABLE_EXAMPLES=ON \
-DENABLE_TESTS=ON \ -DENABLE_TESTS=ON \
-DLOG_LEVEL=0 \
-DTEST_LOG_LEVEL=0 \
-DCMAKE_CXX_FLAGS="-ftemplate-backtrace-limit=0" -DCMAKE_CXX_FLAGS="-ftemplate-backtrace-limit=0"
cmake --build ${{ github.workspace }}/build_gcc --parallel `nproc` cmake --build ${{ github.workspace }}/build_gcc --parallel `nproc`
@ -160,6 +162,8 @@ jobs:
-GNinja -DCMAKE_BUILD_TYPE=Release \ -GNinja -DCMAKE_BUILD_TYPE=Release \
-DENABLE_EXAMPLES=ON \ -DENABLE_EXAMPLES=ON \
-DENABLE_TESTS=ON \ -DENABLE_TESTS=ON \
-DLOG_LEVEL=0 \
-DTEST_LOG_LEVEL=0 \
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -I/home/LLVM-${LLVM_VER}/include/c++/v1 -fno-modules" -DCMAKE_CXX_FLAGS="-stdlib=libc++ -I/home/LLVM-${LLVM_VER}/include/c++/v1 -fno-modules"
echo "::group::compile_commands.json content" echo "::group::compile_commands.json content"

5
.vscode/tasks.json vendored
View file

@ -80,7 +80,7 @@
"cd ${workspaceFolder} &&", "cd ${workspaceFolder} &&",
"mkdir -p build && cd build &&", "mkdir -p build && cd build &&",
"cmake cmake -Wno-dev ", "cmake cmake -Wno-dev ",
" -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .." " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON -DLOG_LEVEL=0 -DTEST_LOG_LEVEL=0 .."
], ],
"options": { "options": {
"env": { "env": {
@ -138,6 +138,7 @@
"mkdir -p build_clang && cd build_clang &&", "mkdir -p build_clang && cd build_clang &&",
"cmake -Wno-dev ", "cmake -Wno-dev ",
" -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ", " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ",
" -DLOG_LEVEL=0 -DTEST_LOG_LEVEL=0",
" -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++\"", " -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++\"",
" -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++\" .." " -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++\" .."
], ],
@ -160,6 +161,7 @@
"mkdir -p build_clang && cd build_clang &&", "mkdir -p build_clang && cd build_clang &&",
"cmake -Wno-dev ", "cmake -Wno-dev ",
" -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON", " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON",
" -DLOG_LEVEL=0 -DTEST_LOG_LEVEL=0"
// //
// Uncomment for GCC standart library: libstdc++ // Uncomment for GCC standart library: libstdc++
//" -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr\"", //" -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr\"",
@ -211,6 +213,7 @@
"mkdir -p build_clang && cd build_clang &&", "mkdir -p build_clang && cd build_clang &&",
"cmake -Wno-dev ", "cmake -Wno-dev ",
" -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ", " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ",
" -DLOG_LEVEL=0 -DTEST_LOG_LEVEL=0",
" -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\"", " -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\"",
" -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\" ..", " -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\" ..",
], ],

View file

@ -22,7 +22,8 @@ set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization")
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON) option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF) option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF)
option(BUILD_EXECUTABLE ON) option(BUILD_EXECUTABLE ON)
set(LOG_LEVEL 0 "Available log levels: 0=TRACE, 1=DEBUG,2= INFO,3= WARN, 4=ERROR, 5=CRITICAL, 6=OFF") # Compile program with highest available log levle to trace everything set(LOG_LEVEL 2 CACHE STRING "Available log levels: 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=CRITICAL, 6=OFF")
set(TEST_LOG_LEVEL 2 CACHE STRING "Available log levels: 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=CRITICAL, 6=OFF")
set(UTEMPL_URL set(UTEMPL_URL
"https://sha512sum.xyz/git/sha512sum/utempl" "https://sha512sum.xyz/git/sha512sum/utempl"
CACHE STRING "utempl repository URL") CACHE STRING "utempl repository URL")
@ -260,7 +261,7 @@ if(ENABLE_TESTS)
target_sources(larra_xmpp_tests PUBLIC ${SOURCES}) target_sources(larra_xmpp_tests PUBLIC ${SOURCES})
target_link_libraries(larra_xmpp_tests GTest::gtest_main target_link_libraries(larra_xmpp_tests GTest::gtest_main
larra_xmpp) larra_xmpp)
target_compile_definitions(larra_xmpp_tests PRIVATE SPDLOG_ACTIVE_LEVEL=0) # SPDLOG_LEVEL_TRACE=0. Check LOG_LEVEL variable and spdlog documentation for more details target_compile_definitions(larra_xmpp_tests PRIVATE SPDLOG_ACTIVE_LEVEL=${TEST_LOG_LEVEL})
set_property(TARGET larra_xmpp_tests PROPERTY CXX_STANDARD 23) set_property(TARGET larra_xmpp_tests PROPERTY CXX_STANDARD 23)
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(larra_xmpp_tests) gtest_discover_tests(larra_xmpp_tests)
@ -272,8 +273,7 @@ if(ENABLE_EXAMPLES)
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SRC} NAME_WE) get_filename_component(EXAMPLE_NAME ${EXAMPLE_SRC} NAME_WE)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC}) add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC})
target_link_libraries(${EXAMPLE_NAME} larra_xmpp) target_link_libraries(${EXAMPLE_NAME} larra_xmpp)
# TODO(unknown): Fixed 'command line' error occured and uncomment below target_compile_definitions(${EXAMPLE_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=${TEST_LOG_LEVEL})
# target_compile_definitions(${EXAMPLE_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=${LOG_LEVEL})
set_property(TARGET ${EXAMPLE_NAME} PROPERTY CXX_STANDARD 23) set_property(TARGET ${EXAMPLE_NAME} PROPERTY CXX_STANDARD 23)
set_target_properties(${EXAMPLE_NAME} PROPERTIES set_target_properties(${EXAMPLE_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/output") RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/output")

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <larra/iq_error.hpp>
#include <larra/jid.hpp> #include <larra/jid.hpp>
#include <larra/serialization.hpp> #include <larra/serialization.hpp>
#include <larra/stanza_error.hpp>
#include <larra/utils.hpp> #include <larra/utils.hpp>
#include <optional> #include <optional>
#include <stdexcept> #include <stdexcept>
@ -118,7 +118,7 @@ using Error = BaseImplWithPayload<kErrorName, Payload>;
} // namespace iq } // namespace iq
using IqError = iq::Error<iq::error::IqError>; using IqError = iq::Error<stanza::error::StanzaError>;
template <typename Payload> template <typename Payload>
using Iq = std::variant<iq::Get<Payload>, iq::Set<Payload>, iq::Result<Payload>, IqError>; using Iq = std::variant<iq::Get<Payload>, iq::Set<Payload>, iq::Result<Payload>, IqError>;

View file

@ -1,152 +0,0 @@
#pragma once
#include <libxml++/libxml++.h>
#include <larra/utils.hpp>
#include <optional>
#include <variant>
namespace larra::xmpp::iq::error {
namespace impl {
struct IqBaseError : std::exception {};
// DO NOT MOVE TO ANOTHER NAMESPACE(where no heirs). VIA friend A FUNCTION IS ADDED THAT VIA ADL WILL BE SEARCHED FOR HEIRS
// C++20 modules very unstable in clangd :(
template <typename T>
struct IqErrorImpl : IqBaseError {
static constexpr auto kDefaultName = "error";
static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
static constexpr auto kErrorMessage = [] -> std::string_view {
static constexpr auto name = nameof::nameof_short_type<T>();
static constexpr auto str = [] {
return std::array{std::string_view{"Stanza IQ Error: "}, std::string_view{name}, std::string_view{"\0", 1}} | std::views::join;
};
static constexpr auto array = str() | std::ranges::to<utils::RangeToWrapper<std::array<char, std::ranges::distance(str())>>>();
return {array.data(), array.size() - 1};
}();
std::optional<std::string> by{};
std::string type;
// TODO(unknown): Add "optional text children" support for stanza error. Check "XML Stanzas" -> "Syntax" for more details
static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<T> {
if(not element) {
return std::nullopt;
}
auto by = element->get_attribute("by");
auto type = element->get_attribute("type");
if(not type) {
return std::nullopt;
}
auto node = element->get_first_child(kKebabCaseName);
if(not node) {
return std::nullopt;
}
T obj;
obj.type = type->get_value();
if(by) {
obj.by = std::optional{by->get_value()};
}
return obj;
}
static constexpr auto Parse(xmlpp::Element* element) -> T {
return TryParse(element).value();
}
friend constexpr auto operator<<(xmlpp::Element* element, const T& obj) -> void {
element->set_attribute("type", obj.type);
if(obj.by) {
element->set_attribute("by", *obj.by);
}
auto node = element->add_child_element(kKebabCaseName);
node->set_namespace_declaration(kDefaultNamespace);
}
constexpr auto operator==(const IqErrorImpl<T>&) const -> bool {
return true;
};
[[nodiscard]] constexpr auto what() const noexcept -> const char* override {
return kErrorMessage.data();
}
};
// Helper class to prevent parsing response stream into an expected return type if its name is an 'error'
struct UnknownIqError : IqBaseError {
static constexpr auto kDefaultName = "stream:error";
static constexpr std::string_view kErrorMessage = "Unknown XMPP stream error";
static constexpr auto TryParse(xmlpp::Element* element) {
return std::optional{UnknownIqError{}};
}
static constexpr auto Parse(xmlpp::Element* element) {
return TryParse(element).value();
}
friend constexpr auto operator<<(xmlpp::Element* element, const UnknownIqError& obj) -> void {
throw std::format("'{}' must never be written into the real stream!", kErrorMessage);
}
constexpr auto operator==(const UnknownIqError&) const -> bool {
return true;
};
[[nodiscard]] constexpr auto what() const noexcept -> const char* override {
return kErrorMessage.data();
}
};
struct BadRequest : IqErrorImpl<BadRequest> {};
struct Conflict : IqErrorImpl<Conflict> {};
struct FeatureNotImplemented : IqErrorImpl<FeatureNotImplemented> {};
struct Forbidden : IqErrorImpl<Forbidden> {};
struct Gone : IqErrorImpl<Gone> {};
struct InternalServerError : IqErrorImpl<InternalServerError> {};
struct ItemNotFound : IqErrorImpl<ItemNotFound> {};
struct JidMalformed : IqErrorImpl<JidMalformed> {};
struct NotAcceptable : IqErrorImpl<NotAcceptable> {};
struct NotAllowed : IqErrorImpl<NotAllowed> {};
struct NotAuthorized : IqErrorImpl<NotAuthorized> {};
struct PolicyViolation : IqErrorImpl<PolicyViolation> {};
struct RecipientUnavailable : IqErrorImpl<RecipientUnavailable> {};
struct Redirect : IqErrorImpl<Redirect> {};
struct RegistrationRequired : IqErrorImpl<RegistrationRequired> {};
struct RemoteServerNotFound : IqErrorImpl<RemoteServerNotFound> {};
struct RemoteServerTimeout : IqErrorImpl<RemoteServerTimeout> {};
struct ResourceConstraint : IqErrorImpl<ResourceConstraint> {};
struct ServiceUnavailable : IqErrorImpl<ServiceUnavailable> {};
struct SubscriptionRequired : IqErrorImpl<SubscriptionRequired> {};
struct UndefinedCondition : IqErrorImpl<UndefinedCondition> {};
struct UnexpectedRequest : IqErrorImpl<UnexpectedRequest> {};
} // namespace impl
using IqError = std::variant<impl::BadRequest,
impl::Conflict,
impl::FeatureNotImplemented,
impl::Forbidden,
impl::Gone,
impl::InternalServerError,
impl::ItemNotFound,
impl::JidMalformed,
impl::NotAcceptable,
impl::NotAllowed,
impl::NotAuthorized,
impl::PolicyViolation,
impl::RecipientUnavailable,
impl::Redirect,
impl::RegistrationRequired,
impl::RemoteServerNotFound,
impl::RemoteServerTimeout,
impl::ResourceConstraint,
impl::ServiceUnavailable,
impl::SubscriptionRequired,
impl::UndefinedCondition,
impl::UnexpectedRequest,
impl::UnknownIqError>;
static_assert(!std::is_same_v<typename std::variant_alternative_t<std::variant_size_v<IqError> - 1, IqError>, IqError>,
"'UnknownIqError' must be at the end of 'IqError' variant");
} // namespace larra::xmpp::iq::error

View file

@ -0,0 +1,148 @@
#pragma once
#include <libxml++/libxml++.h>
#include <larra/utils.hpp>
#include <optional>
#include <variant>
namespace larra::xmpp::stanza::error {
struct StanzaBaseError : std::exception {};
// DO NOT MOVE TO ANOTHER NAMESPACE(where no heirs). VIA friend A FUNCTION IS ADDED THAT VIA ADL WILL BE SEARCHED FOR HEIRS
// C++20 modules very unstable in clangd :(
template <typename T>
struct StanzaErrorImpl : StanzaBaseError {
static constexpr auto kDefaultName = "error";
static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
static constexpr auto kErrorMessage = [] -> std::string_view {
static constexpr auto name = nameof::nameof_short_type<T>();
static constexpr auto str = [] {
return std::array{std::string_view{"Stanza IQ Error: "}, std::string_view{name}, std::string_view{"\0", 1}} | std::views::join;
};
static constexpr auto array = str() | std::ranges::to<utils::RangeToWrapper<std::array<char, std::ranges::distance(str())>>>();
return {array.data(), array.size() - 1};
}();
std::optional<std::string> by{};
std::string type;
// TODO(unknown): Add "optional text children" support for stanza error. Check "XML Stanzas" -> "Syntax" for more details
static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<T> {
if(not element) {
return std::nullopt;
}
auto by = element->get_attribute("by");
auto type = element->get_attribute("type");
if(not type) {
return std::nullopt;
}
auto node = element->get_first_child(kKebabCaseName);
if(not node) {
return std::nullopt;
}
T obj;
obj.type = type->get_value();
if(by) {
obj.by = std::optional{by->get_value()};
}
return obj;
}
static constexpr auto Parse(xmlpp::Element* element) -> T {
return TryParse(element).value();
}
friend constexpr auto operator<<(xmlpp::Element* element, const T& obj) -> void {
element->set_attribute("type", obj.type);
if(obj.by) {
element->set_attribute("by", *obj.by);
}
auto node = element->add_child_element(kKebabCaseName);
node->set_namespace_declaration(kDefaultNamespace);
}
constexpr auto operator==(const StanzaErrorImpl<T>&) const -> bool {
return true;
};
[[nodiscard]] constexpr auto what() const noexcept -> const char* override {
return kErrorMessage.data();
}
};
// Helper class to prevent parsing response stream into an expected return type if its name is an 'error'
struct UnknownStanzaError : StanzaBaseError {
static constexpr auto kDefaultName = "stream:error";
static constexpr std::string_view kErrorMessage = "Unknown XMPP stream error";
static constexpr auto TryParse(xmlpp::Element* element) {
return std::optional{UnknownStanzaError{}};
}
static constexpr auto Parse(xmlpp::Element* element) {
return TryParse(element).value();
}
friend constexpr auto operator<<(xmlpp::Element* element, const UnknownStanzaError& obj) -> void {
throw std::format("'{}' must never be written into the real stream!", kErrorMessage);
}
constexpr auto operator==(const UnknownStanzaError&) const -> bool {
return true;
};
[[nodiscard]] constexpr auto what() const noexcept -> const char* override {
return kErrorMessage.data();
}
};
struct BadRequest : StanzaErrorImpl<BadRequest> {};
struct Conflict : StanzaErrorImpl<Conflict> {};
struct FeatureNotImplemented : StanzaErrorImpl<FeatureNotImplemented> {};
struct Forbidden : StanzaErrorImpl<Forbidden> {};
struct Gone : StanzaErrorImpl<Gone> {};
struct InternalServerError : StanzaErrorImpl<InternalServerError> {};
struct ItemNotFound : StanzaErrorImpl<ItemNotFound> {};
struct JidMalformed : StanzaErrorImpl<JidMalformed> {};
struct NotAcceptable : StanzaErrorImpl<NotAcceptable> {};
struct NotAllowed : StanzaErrorImpl<NotAllowed> {};
struct NotAuthorized : StanzaErrorImpl<NotAuthorized> {};
struct PolicyViolation : StanzaErrorImpl<PolicyViolation> {};
struct RecipientUnavailable : StanzaErrorImpl<RecipientUnavailable> {};
struct Redirect : StanzaErrorImpl<Redirect> {};
struct RegistrationRequired : StanzaErrorImpl<RegistrationRequired> {};
struct RemoteServerNotFound : StanzaErrorImpl<RemoteServerNotFound> {};
struct RemoteServerTimeout : StanzaErrorImpl<RemoteServerTimeout> {};
struct ResourceConstraint : StanzaErrorImpl<ResourceConstraint> {};
struct ServiceUnavailable : StanzaErrorImpl<ServiceUnavailable> {};
struct SubscriptionRequired : StanzaErrorImpl<SubscriptionRequired> {};
struct UndefinedCondition : StanzaErrorImpl<UndefinedCondition> {};
struct UnexpectedRequest : StanzaErrorImpl<UnexpectedRequest> {};
using StanzaError = std::variant<BadRequest,
Conflict,
FeatureNotImplemented,
Forbidden,
Gone,
InternalServerError,
ItemNotFound,
JidMalformed,
NotAcceptable,
NotAllowed,
NotAuthorized,
PolicyViolation,
RecipientUnavailable,
Redirect,
RegistrationRequired,
RemoteServerNotFound,
RemoteServerTimeout,
ResourceConstraint,
ServiceUnavailable,
SubscriptionRequired,
UndefinedCondition,
UnexpectedRequest,
UnknownStanzaError>;
static_assert(std::is_same_v<typename std::variant_alternative_t<std::variant_size_v<StanzaError> - 1, StanzaError>, UnknownStanzaError>,
"'UnknownStanzaError' must be at the end of 'StanzaError' variant");
} // namespace larra::xmpp::stanza::error

View file

@ -69,7 +69,7 @@ TEST(IQ, ParseForbiddenError) {
ASSERT_TRUE(std::holds_alternative<IqError>(iqRes)); ASSERT_TRUE(std::holds_alternative<IqError>(iqRes));
auto errorRes = std::get<IqError>(iqRes); auto errorRes = std::get<IqError>(iqRes);
ASSERT_TRUE(std::holds_alternative<iq::error::impl::Forbidden>(errorRes.payload)); ASSERT_TRUE(std::holds_alternative<stanza::error::Forbidden>(errorRes.payload));
} }
TEST(IQ, IqErrThrowVisitorThrow) { TEST(IQ, IqErrThrowVisitorThrow) {
@ -87,7 +87,7 @@ TEST(IQ, IqErrThrowVisitorThrow) {
static constexpr auto throwErrMsg = "Stanza IQ Error: Forbidden"; static constexpr auto throwErrMsg = "Stanza IQ Error: Forbidden";
try { try {
std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{visitorErrMsg}), std::move(iqRes)); std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{visitorErrMsg}), std::move(iqRes));
} catch(const iq::error::impl::IqBaseError& err) { } catch(const stanza::error::StanzaBaseError& err) {
ASSERT_STREQ(throwErrMsg, err.what()); ASSERT_STREQ(throwErrMsg, err.what());
return; return;
} catch(const std::runtime_error& err) { } catch(const std::runtime_error& err) {
@ -114,7 +114,7 @@ TEST(IQ, IqErrThrowVisitorThrowGet) {
static constexpr auto throwErrMsg = "Test Error: 'Get' is an invalid type for IQ result. Expected 'Result' or 'Error'"; static constexpr auto throwErrMsg = "Test Error: 'Get' is an invalid type for IQ result. Expected 'Result' or 'Error'";
try { try {
std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{"Test Error"}), std::move(iqRes)); std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{"Test Error"}), std::move(iqRes));
} catch(const iq::error::impl::IqBaseError& err) { } catch(const stanza::error::StanzaBaseError& err) {
ASSERT_TRUE(false) << "\tERROR: Invalid throw type throw"; ASSERT_TRUE(false) << "\tERROR: Invalid throw type throw";
} catch(const std::runtime_error& err) { } catch(const std::runtime_error& err) {
ASSERT_STREQ(throwErrMsg, err.what()); ASSERT_STREQ(throwErrMsg, err.what());
@ -141,7 +141,7 @@ TEST(IQ, IqErrThrowVisitorThrowSet) {
static constexpr auto throwErrMsg = "Test Error: 'Set' is an invalid type for IQ result. Expected 'Result' or 'Error'"; static constexpr auto throwErrMsg = "Test Error: 'Set' is an invalid type for IQ result. Expected 'Result' or 'Error'";
try { try {
std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{"Test Error"}), std::move(iqRes)); std::visit(utempl::Overloaded([](iq::Result<SomeStruct> r) {}, IqErrThrowVisitor<SomeStruct>{"Test Error"}), std::move(iqRes));
} catch(const iq::error::impl::IqBaseError& err) { } catch(const stanza::error::StanzaBaseError& err) {
ASSERT_TRUE(false) << "\tERROR: Invalid throw type throw"; ASSERT_TRUE(false) << "\tERROR: Invalid throw type throw";
} catch(const std::runtime_error& err) { } catch(const std::runtime_error& err) {
ASSERT_STREQ(throwErrMsg, err.what()); ASSERT_STREQ(throwErrMsg, err.what());