From 45f2dce3fc898d1f59d4e3cb901bdac2b5d288a0 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 8 Jul 2025 17:55:49 +0200 Subject: [PATCH] constexpr and checking if options object type is same --- slsReceiverSoftware/tests/test-Apps.cpp | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/slsReceiverSoftware/tests/test-Apps.cpp b/slsReceiverSoftware/tests/test-Apps.cpp index 9b323e6dd..e31ebd3ee 100644 --- a/slsReceiverSoftware/tests/test-Apps.cpp +++ b/slsReceiverSoftware/tests/test-Apps.cpp @@ -9,7 +9,7 @@ namespace sls { template - constexpr bool is_type(const U&) { + constexpr bool is_type() { return std::is_same_v, T>; } @@ -147,11 +147,12 @@ namespace sls { auto opts = s.parse({""}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.numReceivers == 1); // default REQUIRE(o.callbackEnabled == false); - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.numReceivers == 1); // default REQUIRE(o.printHeaders == false); } @@ -159,11 +160,12 @@ namespace sls { opts = s.parse({"", "-n", "5"}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.numReceivers == 5); REQUIRE(o.callbackEnabled == false); // default - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.numReceivers == 5); REQUIRE(o.printHeaders == false); // default } @@ -172,11 +174,12 @@ namespace sls { opts = s.parse({"", "-c", "-n", "3"}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.numReceivers == 3); REQUIRE(o.callbackEnabled == true); - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.numReceivers == 3); REQUIRE(o.printHeaders == true); } @@ -211,12 +214,13 @@ namespace sls { // default auto opts = s.parse({""}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.port == 1954); REQUIRE(o.numReceivers == 1); REQUIRE(o.callbackEnabled == false); - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.port == 1954); REQUIRE(o.numReceivers == 1); REQUIRE(o.printHeaders == false); // default @@ -225,12 +229,13 @@ namespace sls { opts = s.parse({"", "1958", "10"}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.port == 1958); REQUIRE(o.numReceivers == 10); REQUIRE(o.callbackEnabled == false); // default - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.port == 1958); REQUIRE(o.numReceivers == 10); REQUIRE(o.printHeaders == false); // default @@ -239,12 +244,13 @@ namespace sls { opts = s.parse({"", "1958", "10", "1"}); std::visit([&](const auto& o) { - if constexpr (is_type(o)) { + using T = decltype(o); + if constexpr (is_type()) { REQUIRE(o.port == 1958); REQUIRE(o.numReceivers == 10); REQUIRE(o.callbackEnabled == true); // default - } else if constexpr (is_type(o)) { + } else if constexpr (is_type()) { REQUIRE(o.port == 1958); REQUIRE(o.numReceivers == 10); REQUIRE(o.printHeaders == true); // default