From 6ccd41428eaf1c70237b9a21d94876cd82274f13 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Mon, 7 Apr 2025 17:53:06 +0200 Subject: [PATCH 01/41] Fixed linter warnings in first test files --- lint/clang-tidy.sh | 2 +- .../client/usubscription/v3/ConsumerTest.cpp | 144 +++++++++++------- .../communication/NotificationSinkTest.cpp | 93 ++++++----- .../communication/NotificationSourceTest.cpp | 61 ++++---- test/coverage/communication/PublisherTest.cpp | 10 +- test/coverage/communication/RpcClientTest.cpp | 76 ++++----- 6 files changed, 213 insertions(+), 173 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index e2b490758..19e9ddc80 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,7 +58,7 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - for f in include/**/*.h src/**/*.cpp; do # test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/client/usubscription/v3/ConsumerTest.cpp b/test/coverage/client/usubscription/v3/ConsumerTest.cpp index 17ba73169..8d547ad4a 100644 --- a/test/coverage/client/usubscription/v3/ConsumerTest.cpp +++ b/test/coverage/client/usubscription/v3/ConsumerTest.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include "UTransportMock.h" @@ -28,19 +27,46 @@ void someCallBack(const uprotocol::v1::UMessage& message) { } class ConsumerTest : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. +private: std::shared_ptr mockTransportClient_; std::shared_ptr mockTransportServer_; uprotocol::v1::UUri client_uuri; uprotocol::v1::UUri server_uuri; uprotocol::v1::UUri subcription_uuri; +protected: + // Run once per TEST_F. + // Used to set up clean environments per test. + + std::shared_ptr getMockTransportClient() const { return mockTransportClient_; } + std::shared_ptr getMockTransportServer() const { return mockTransportServer_; } + uprotocol::v1::UUri& getClientUUri() { + return client_uuri; + } + const uprotocol::v1::UUri& getServerUUri() const { + return server_uuri; + } + const uprotocol::v1::UUri& getSubcriptionUUri() const { + return subcription_uuri; + } + void setMockTransportClient(const std::shared_ptr& client) { mockTransportClient_ = client; } + void setMockTransportServer(const std::shared_ptr& server) { mockTransportClient_ = server; } + void setClientUUri(const uprotocol::v1::UUri& uuri) { + client_uuri = uuri; + } + void setServerUUri(const uprotocol::v1::UUri& uuri) { + server_uuri = uuri; + } + void setSubcriptionUUri(const uprotocol::v1::UUri& uuri) { + subcription_uuri = uuri; + } + void SetUp() override { + constexpr uint32_t TEST_UE_ID = 0x18000; + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; // Create a generic transport uri client_uuri.set_authority_name("random_string"); - client_uuri.set_ue_id(0x18000); + client_uuri.set_ue_id(TEST_UE_ID); client_uuri.set_ue_version_major(3); client_uuri.set_resource_id(0); @@ -59,16 +85,15 @@ class ConsumerTest : public testing::Test { // Create a generic subscription uri subcription_uuri.set_authority_name("10.0.0.2"); - subcription_uuri.set_ue_id(0x18000); + subcription_uuri.set_ue_id(TEST_UE_ID); subcription_uuri.set_ue_version_major(3); - subcription_uuri.set_resource_id(0x8000); + subcription_uuri.set_resource_id(DEFAULT_RESOURCE_ID); }; void TearDown() override {} // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. ConsumerTest() = default; - ~ConsumerTest() = default; void buildDefaultSourceURI(); void buildValidNotificationURI(); @@ -78,125 +103,132 @@ class ConsumerTest : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~ConsumerTest() override = default; }; // Negative test case with no source filter -TEST_F(ConsumerTest, ConstructorTestSuccess) { - auto subcriptionCallback = someCallBack; - auto subscribe_request_ttl = std::chrono::milliseconds(1000); +TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT + constexpr int REQUEST_TTL_TIME = 0x8000; + auto subcription_callback = someCallBack; + auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; auto options = uprotocol::client::usubscription::v3::ConsumerOptions(); - auto consumerOrSatus = + auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - mockTransportClient_, subcription_uuri, - std::move(subcriptionCallback), priority, - std::move(subscribe_request_ttl), options); + getMockTransportClient(), getSubcriptionUUri(), + subcription_callback, priority, + subscribe_request_ttl, options); // Ensure that the consumer creation was successful - ASSERT_TRUE(consumerOrSatus.has_value()); + ASSERT_TRUE(consumer_or_status.has_value()); // Obtain a pointer to the created consumer instance - auto& consumerPtr = consumerOrSatus.value(); + const auto& consumer_ptr = consumer_or_status.value(); // Verify that the consumer pointer is not null, indicating successful // creation - ASSERT_NE(consumerPtr, nullptr); + ASSERT_NE(consumer_ptr, nullptr); } -TEST_F(ConsumerTest, SubscribeTestSuccess) { - auto subcriptionCallback = someCallBack; - auto subscribe_request_ttl = std::chrono::milliseconds(1000); +TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; + constexpr int REQUEST_TTL_TIME = 0x8000; + auto subcription_callback = someCallBack; + auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; auto options = uprotocol::client::usubscription::v3::ConsumerOptions(); - auto consumerOrSatus = + auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - mockTransportClient_, subcription_uuri, - std::move(subcriptionCallback), priority, - std::move(subscribe_request_ttl), options); + getMockTransportClient(), getSubcriptionUUri(), + subcription_callback, priority, + subscribe_request_ttl, options); // Ensure that the consumer creation was successful - ASSERT_TRUE(consumerOrSatus.has_value()); + ASSERT_TRUE(consumer_or_status.has_value()); // Obtain a pointer to the created consumer instance - auto& consumerPtr = consumerOrSatus.value(); + const auto& consumer_ptr = consumer_or_status.value(); // Verify that the consumer pointer is not null, indicating successful // creation - ASSERT_NE(consumerPtr, nullptr); + ASSERT_NE(consumer_ptr, nullptr); // Create notification source sink uri to match resource id of sink - auto notification_uuri = server_uuri; - notification_uuri.set_resource_id(0x8000); + auto notification_uuri = getServerUUri(); + notification_uuri.set_resource_id(DEFAULT_RESOURCE_ID); // set format UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY auto format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY; - auto norificationSource = uprotocol::communication::NotificationSource( - mockTransportServer_, std::move(notification_uuri), - std::move(client_uuri), format); + auto notification_source = uprotocol::communication::NotificationSource( + getMockTransportServer(), std::move(notification_uuri), + std::move(getClientUUri()), format); // Build payload const std::string data = "test"; auto payload = uprotocol::datamodel::builder::Payload(data, format); - norificationSource.notify(std::move(payload)); + notification_source.notify(std::move(payload)); // Check send count - EXPECT_TRUE(mockTransportServer_->send_count_ == 1); - EXPECT_TRUE(mockTransportClient_->send_count_ == 1); + EXPECT_TRUE(getMockTransportServer()->send_count_ == 1); + EXPECT_TRUE(getMockTransportClient()->send_count_ == 1); } -TEST_F(ConsumerTest, UnsubscribeTestSuccess) { - auto subcriptionCallback = someCallBack; - auto subscribe_request_ttl = std::chrono::milliseconds(1000); +TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; + constexpr int REQUEST_TTL_TIME = 0x8000; + auto subcription_callback = someCallBack; + auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; auto options = uprotocol::client::usubscription::v3::ConsumerOptions(); - auto consumerOrSatus = + auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - mockTransportClient_, subcription_uuri, - std::move(subcriptionCallback), priority, - std::move(subscribe_request_ttl), options); + getMockTransportClient(), getSubcriptionUUri(), + subcription_callback, priority, + subscribe_request_ttl, options); // Ensure that the consumer creation was successful - ASSERT_TRUE(consumerOrSatus.has_value()); + ASSERT_TRUE(consumer_or_status.has_value()); // Obtain a pointer to the created consumer instance - auto& consumerPtr = consumerOrSatus.value(); + const auto& consumer_ptr = consumer_or_status.value(); // Verify that the consumer pointer is not null, indicating successful // creation - ASSERT_NE(consumerPtr, nullptr); + ASSERT_NE(consumer_ptr, nullptr); // Create notification source sink uri to match resource id of sink - auto notification_uuri = server_uuri; - notification_uuri.set_resource_id(0x8000); + auto notification_uuri = getServerUUri(); + notification_uuri.set_resource_id(DEFAULT_RESOURCE_ID); // set format UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY auto format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY; - auto norificationSource = uprotocol::communication::NotificationSource( - mockTransportServer_, std::move(notification_uuri), - std::move(client_uuri), format); + auto notification_source = uprotocol::communication::NotificationSource( + getMockTransportServer(), std::move(notification_uuri), + std::move(getClientUUri()), format); // Build payload const std::string data = "test"; auto payload = uprotocol::datamodel::builder::Payload(data, format); - norificationSource.notify(std::move(payload)); + notification_source.notify(std::move(payload)); // Check send count - EXPECT_TRUE(mockTransportServer_->send_count_ == 1); - EXPECT_TRUE(mockTransportClient_->send_count_ == 1); + EXPECT_TRUE(getMockTransportServer()->send_count_ == 1); + EXPECT_TRUE(getMockTransportClient()->send_count_ == 1); - consumerPtr->unsubscribe(priority, subscribe_request_ttl); + consumer_ptr->unsubscribe(priority, subscribe_request_ttl); - EXPECT_TRUE(mockTransportClient_->send_count_ == 2); + EXPECT_TRUE(getMockTransportClient()->send_count_ == 2); } } // namespace diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index 2a545e36b..bb2ee18f1 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -13,18 +13,22 @@ #include #include -#include #include #include "UTransportMock.h" #include "up-cpp/datamodel/validator/UUri.h" -namespace { using MsgDiff = google::protobuf::util::MessageDifferencer; -using namespace uprotocol::communication; +namespace uprotocol::communication{ namespace UriValidator = uprotocol::datamodel::validator::uri; class NotificationSinkTest : public testing::Test { +private: + uprotocol::v1::UUri testTopicUUri_; + uprotocol::v1::UUri testInvalidTopicUUri_; + uprotocol::v1::UUri testDefaultSourceUUri_; + size_t capture_count_ = 0; + uprotocol::v1::UMessage capture_msg_; protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -34,7 +38,6 @@ class NotificationSinkTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. NotificationSinkTest() = default; - ~NotificationSinkTest() = default; void buildDefaultSourceURI(); void buildValidNotificationURI(); @@ -45,14 +48,21 @@ class NotificationSinkTest : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - uprotocol::v1::UUri testTopicUUri_; - uprotocol::v1::UUri testInvalidTopicUUri_; - uprotocol::v1::UUri testDefaultSourceUUri_; - size_t capture_count_ = 0; - uprotocol::v1::UMessage capture_msg_; + void setTestTopicUUri(const uprotocol::v1::UUri& uuri) { testTopicUUri_ = uuri; } + void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uuri) { testInvalidTopicUUri_ = uuri; } + void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uuri) { testDefaultSourceUUri_ = uuri; } + void setCaptureCount(size_t count) { capture_count_ = count; } + void setCaptureMsg(const uprotocol::v1::UMessage& msg) { capture_msg_ = msg; } + + const uprotocol::v1::UUri& getTestTopicUUri() const { return testTopicUUri_; } + const uprotocol::v1::UUri& getTestInvalidTopicUUri() const { return testInvalidTopicUUri_; } + const uprotocol::v1::UUri& getTestDefaultSourceUUri() const { return testDefaultSourceUUri_; } + size_t getCaptureCount() const { return capture_count_; } + const uprotocol::v1::UMessage& getCaptureMsg() const { return capture_msg_; } public: void handleCallbackMessage(const uprotocol::v1::UMessage& message); + ~ NotificationSinkTest() override = default; }; void NotificationSinkTest::SetUp() { @@ -104,9 +114,9 @@ std::string get_random_string(size_t length) { } // Negative test case with no source filter -TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { +TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { // NOLINT auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); auto callback = [this](const auto& arg) { return this->handleCallbackMessage(arg); @@ -116,7 +126,7 @@ TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { EXPECT_THROW( { - auto result = NotificationSink::create(transport, testTopicUUri_, + auto result = NotificationSink::create(transport, getTestTopicUUri(), std::move(callback), std::move(source_filter)); }, @@ -124,9 +134,9 @@ TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { } // Negative test case with invalid notification resource ID -TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { +TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // NOLINT auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); auto callback = [this](const auto& arg) { return this->handleCallbackMessage(arg); @@ -136,29 +146,30 @@ TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // Notification to invalid UUri topic with resource ID not in correct range EXPECT_THROW(auto result = NotificationSink::create( - transport, testInvalidTopicUUri_, std::move(callback), + transport, getTestInvalidTopicUUri(), std::move(callback), std::move(source_filter)), UriValidator::InvalidUUri); } // Positive test case with source filter -TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { +TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT + constexpr uint16_t RANDOM_STRING_LENGTH = 1400; auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); auto callback = [this](const auto& arg) { return this->handleCallbackMessage(arg); }; auto result = NotificationSink::create(transport, transport->getEntityUri(), - std::move(callback), testTopicUUri_); + std::move(callback), getTestTopicUUri()); EXPECT_TRUE(transport->listener_); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(testTopicUUri_, transport->source_filter_)); + EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->source_filter_)); EXPECT_TRUE( MsgDiff::Equals(transport->getEntityUri(), *transport->sink_filter_)); @@ -167,35 +178,35 @@ TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { uprotocol::v1::UMessage msg; auto attr = std::make_shared(); *msg.mutable_attributes() = *attr; - msg.set_payload(get_random_string(1400)); + msg.set_payload(get_random_string(RANDOM_STRING_LENGTH)); transport->mockMessage(msg); - EXPECT_EQ(i + 1, capture_count_); - EXPECT_TRUE(MsgDiff::Equals(msg, capture_msg_)); + EXPECT_EQ(i + 1, getCaptureCount()); + EXPECT_TRUE(MsgDiff::Equals(msg, getCaptureMsg())); } } // Simulate Error code from transport mock -TEST_F(NotificationSinkTest, FailWithErrorCode) { +TEST_F(NotificationSinkTest, FailWithErrorCode) { // NOLINT auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); auto callback = [this](const auto& arg) { return this->handleCallbackMessage(arg); }; - uprotocol::v1::UStatus expectedStatus; - expectedStatus.set_code(uprotocol::v1::UCode::ABORTED); - transport->registerListener_status_ = expectedStatus; + uprotocol::v1::UStatus expected_status; + expected_status.set_code(uprotocol::v1::UCode::ABORTED); + transport->registerListener_status_ = expected_status; auto result = NotificationSink::create(transport, transport->getEntityUri(), - std::move(callback), testTopicUUri_); + std::move(callback), getTestTopicUUri()); - auto actualStatus = std::move(result).error(); - EXPECT_EQ(actualStatus.code(), expectedStatus.code()); + auto actual_status = std::move(result).error(); + EXPECT_EQ(actual_status.code(), expected_status.code()); } // Notification sink with null transport -TEST_F(NotificationSinkTest, NullTransport) { +TEST_F(NotificationSinkTest, NullTransport) { // NOLINT // set transport to null auto transport = nullptr; std::optional source_filter; @@ -205,34 +216,32 @@ TEST_F(NotificationSinkTest, NullTransport) { }; EXPECT_THROW(auto result = NotificationSink::create( - transport, testDefaultSourceUUri_, std::move(callback), - testTopicUUri_), + transport, getTestDefaultSourceUUri(), std::move(callback), + getTestTopicUUri()), uprotocol::transport::NullTransport); } // notification sink with null callback -TEST_F(NotificationSinkTest, NullCallback) { +TEST_F(NotificationSinkTest, NullCallback) { // NOLINT auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); // bind to null callback auto test_create_nullptr = [transport, this]() { std::ignore = NotificationSink::create(transport, transport->getEntityUri(), - std::move(nullptr), testTopicUUri_); + nullptr, getTestTopicUUri()); }; - using namespace uprotocol::utils; - - EXPECT_THROW(test_create_nullptr(), callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_nullptr(), utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_create_empty = [transport, this]() { std::ignore = NotificationSink::create( - transport, transport->getEntityUri(), {}, testTopicUUri_); + transport, transport->getEntityUri(), {}, getTestTopicUUri()); }; - EXPECT_THROW(test_create_empty(), callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_empty(), utils::callbacks::EmptyFunctionObject); } -} // namespace +} // namespace uprotocol::communication diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index 1463876ef..319e4d218 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -16,7 +16,6 @@ #include #include "UTransportMock.h" -#include "up-cpp/datamodel/builder/UMessage.h" #include "up-cpp/datamodel/validator/UMessage.h" #include "up-cpp/transport/UTransport.h" @@ -24,7 +23,6 @@ using namespace uprotocol::communication; using namespace uprotocol::datamodel::builder; using namespace uprotocol::v1; using ::testing::_; -using ::testing::Return; namespace { @@ -57,7 +55,6 @@ class TestNotificationSource : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestNotificationSource() = default; - ~TestNotificationSource() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. @@ -70,20 +67,22 @@ class TestNotificationSource : public testing::Test { UPayloadFormat format_; std::optional priority_; std::optional ttl_; +public: + ~TestNotificationSource() override = default; }; -TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { - std::string testPayloadStr = "test_payload"; - NotificationSource notificationSource(transportMock_, std::move(source_), +TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT + std::string test_payload_str = "test_payload"; + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_), format_, priority_, ttl_); - Payload testPayload(testPayloadStr, format_); + Payload test_payload(test_payload_str, format_); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(std::move(testPayload)); + auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -93,17 +92,17 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { EXPECT_EQ(valid, true); } -TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { - std::string testPayloadStr = "test_payload"; - NotificationSource notificationSource(transportMock_, std::move(source_), +TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT + std::string test_payload_str = "test_payload"; + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_), format_, priority_); - Payload testPayload(testPayloadStr, format_); + Payload test_payload(test_payload_str, format_); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(std::move(testPayload)); + auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -115,18 +114,18 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { EXPECT_EQ(transportMock_->message_.attributes().ttl(), 0); } -TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { - std::string testPayloadStr = "test_payload"; +TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOLINT + std::string test_payload_str = "test_payload"; priority_.reset(); - NotificationSource notificationSource(transportMock_, std::move(source_), + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_), format_, priority_); - Payload testPayload(testPayloadStr, format_); + Payload test_payload(test_payload_str, format_); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(std::move(testPayload)); + auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -139,31 +138,31 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { UPriority::UPRIORITY_CS1); } -TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { - std::string testPayloadStr = "test_payload"; - NotificationSource notificationSource(transportMock_, std::move(source_), +TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT + std::string test_payload_str = "test_payload"; + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_), format_, priority_, ttl_); - Payload testPayload(testPayloadStr, format_); + Payload test_payload(test_payload_str, format_); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(std::move(testPayload)); + auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); } -TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { - NotificationSource notificationSource(transportMock_, std::move(source_), +TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_)); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(); + auto status = notification_source.notify(); EXPECT_EQ(status.code(), retval.code()); @@ -172,24 +171,24 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { UPriority::UPRIORITY_CS1); } -TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { - NotificationSource notificationSource(transportMock_, std::move(source_), +TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT + NotificationSource notification_source(transportMock_, std::move(source_), std::move(sink_)); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); transportMock_->send_status_ = retval; - auto status = notificationSource.notify(); + auto status = notification_source.notify(); EXPECT_EQ(status.code(), retval.code()); } // Test with Null transport -TEST_F(TestNotificationSource, NullTransport) { +TEST_F(TestNotificationSource, NullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(NotificationSource notificationSource( + EXPECT_THROW(NotificationSource notification_source( transport, std::move(source_), std::move(sink_), format_, priority_, ttl_), uprotocol::transport::NullTransport); diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index cea1943ff..b16fd446d 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -65,7 +65,7 @@ class TestPublisher : public testing::Test { uprotocol::v1::UMessage capture_msg_; }; -TEST_F(TestPublisher, PublisherSuccess) { +TEST_F(TestPublisher, PublisherSuccess) { // NOLINT std::string testPayloadStr = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_, ttl_); @@ -85,7 +85,7 @@ TEST_F(TestPublisher, PublisherSuccess) { EXPECT_EQ(valid, true); } -TEST_F(TestPublisher, PublishFailure) { +TEST_F(TestPublisher, PublishFailure) { // NOLINT std::string testPayloadStr = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_, ttl_); @@ -100,7 +100,7 @@ TEST_F(TestPublisher, PublishFailure) { EXPECT_EQ(status.code(), retval.code()); } -TEST_F(TestPublisher, PublishSuccessWithoutTTL) { +TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT std::string testPayloadStr = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_); @@ -121,7 +121,7 @@ TEST_F(TestPublisher, PublishSuccessWithoutTTL) { EXPECT_EQ(transportMock_->message_.attributes().ttl(), 0); } -TEST_F(TestPublisher, PublishSuccessWithoutPriority) { +TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT std::string testPayloadStr = "test_payload"; priority_.reset(); Publisher publisher(transportMock_, std::move(topic_), format_, priority_, @@ -146,7 +146,7 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { } // publisher with null transport -TEST_F(TestPublisher, PublisherWithNullTransport) { +TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; EXPECT_THROW(Publisher publisher(transport, std::move(topic_), format_, priority_, ttl_), diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index f45f3596c..f6b047128 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -131,7 +131,7 @@ uprotocol::datamodel::builder::Payload fakePayload() { /////////////////////////////////////////////////////////////////////////////// // Construction -TEST_F(RpcClientTest, CanConstructWithoutExceptions) { +TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT // Base parameters EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( transport_, methodUri(), @@ -155,7 +155,7 @@ TEST_F(RpcClientTest, CanConstructWithoutExceptions) { "Some token");); } -TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { +TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLINT // Bad method URI EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); auto client = uprotocol::communication::RpcClient( @@ -185,7 +185,7 @@ TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod() -TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -211,7 +211,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); @@ -224,7 +224,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { EXPECT_FALSE(transport_->listener_); } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -247,7 +247,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -269,7 +269,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -290,7 +290,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT uprotocol::communication::RpcClient::InvokeFuture invoke_future; { @@ -312,7 +312,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -338,7 +338,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload) -TEST_F(RpcClientTest, InvokeFutureWithPayload) { +TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -371,7 +371,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); @@ -405,7 +405,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); @@ -418,7 +418,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { EXPECT_FALSE(transport_->listener_); } -TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -441,7 +441,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -463,7 +463,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -484,7 +484,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT uprotocol::communication::RpcClient::InvokeFuture invoke_future; { @@ -505,7 +505,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { +TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -531,7 +531,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Callback) -TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -559,7 +559,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); @@ -573,7 +573,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { EXPECT_FALSE(transport_->listener_); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -603,7 +603,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -624,7 +624,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -644,7 +644,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT uprotocol::communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; @@ -665,7 +665,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -690,7 +690,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload, Callback) -TEST_F(RpcClientTest, InvokeCallbackWithPayload) { +TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -726,7 +726,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); @@ -763,7 +763,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); @@ -777,7 +777,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { EXPECT_FALSE(transport_->listener_); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -808,7 +808,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -830,7 +830,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -851,7 +851,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT uprotocol::communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; @@ -874,7 +874,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { +TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); @@ -900,7 +900,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { /////////////////////////////////////////////////////////////////////////////// // Usecases -TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { +TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT auto client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 250ms); @@ -991,7 +991,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // Intentionally leaving a couple pending requests to discard } -TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { +TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT constexpr size_t num_clients = 10; std::vector> clients; @@ -1060,7 +1060,7 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // the top. This results in the second request not expiring until after the // first request's expiration time (even though the expirations will be called // in order). -TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { +TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT auto slow_client = uprotocol::communication::RpcClient( transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10s); @@ -1088,7 +1088,7 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOTE: for some reason, when the above test fails, the _next_ test also // fails. I do not know how this is possible. -TEST_F(RpcClientTest, MultipleClientInstances) { +TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT constexpr size_t num_clients = 20; using UTransportMock = uprotocol::test::UTransportMock; @@ -1241,7 +1241,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // Discard the rest } -TEST_F(RpcClientTest, ParallelAccessSingleClient) { +TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array workers; auto client = uprotocol::communication::RpcClient( @@ -1280,7 +1280,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { EXPECT_EQ(call_count, num_requests_per_worker * workers.size()); } -TEST_F(RpcClientTest, ParallelAccessMultipleClients) { +TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::vector workers; constexpr size_t num_requests_per_worker = 1500; From 321d086ec6257fb462633df0115d09a7d3988c0f Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Mon, 7 Apr 2025 17:56:43 +0200 Subject: [PATCH 02/41] Fixed some namings --- test/coverage/communication/PublisherTest.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index b16fd446d..dc61dd304 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -66,7 +66,7 @@ class TestPublisher : public testing::Test { }; TEST_F(TestPublisher, PublisherSuccess) { // NOLINT - std::string testPayloadStr = "test_payload"; + std::string test_payload_str = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_, ttl_); @@ -74,8 +74,8 @@ TEST_F(TestPublisher, PublisherSuccess) { // NOLINT retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - Payload testPayload(testPayloadStr, format_); - auto status = publisher.publish(std::move(testPayload)); + Payload test_payload(test_payload_str, format_); + auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -86,7 +86,7 @@ TEST_F(TestPublisher, PublisherSuccess) { // NOLINT } TEST_F(TestPublisher, PublishFailure) { // NOLINT - std::string testPayloadStr = "test_payload"; + std::string test_payload_str = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_, ttl_); @@ -94,22 +94,22 @@ TEST_F(TestPublisher, PublishFailure) { // NOLINT retval.set_code(uprotocol::v1::UCode::DATA_LOSS); transportMock_->send_status_ = retval; - Payload testPayload(testPayloadStr, format_); - auto status = publisher.publish(std::move(testPayload)); + Payload test_payload(test_payload_str, format_); + auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); } TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT - std::string testPayloadStr = "test_payload"; + std::string test_payload_str = "test_payload"; Publisher publisher(transportMock_, std::move(topic_), format_, priority_); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - Payload testPayload(testPayloadStr, format_); - auto status = publisher.publish(std::move(testPayload)); + Payload test_payload(test_payload_str, format_); + auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -122,7 +122,7 @@ TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT } TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT - std::string testPayloadStr = "test_payload"; + std::string test_payload_str = "test_payload"; priority_.reset(); Publisher publisher(transportMock_, std::move(topic_), format_, priority_, ttl_); @@ -131,8 +131,8 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT retval.set_code(uprotocol::v1::UCode::OK); transportMock_->send_status_ = retval; - Payload testPayload(testPayloadStr, format_); - auto status = publisher.publish(std::move(testPayload)); + Payload test_payload(test_payload_str, format_); + auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); From 5ddc824e9358a12deac2654fe7849e84c827583b Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 11:55:14 +0200 Subject: [PATCH 03/41] Solve linting warnings in communication --- .../communication/NotificationSinkTest.cpp | 41 +- .../communication/NotificationSourceTest.cpp | 135 +++--- test/coverage/communication/PublisherTest.cpp | 110 +++-- test/coverage/communication/RpcClientTest.cpp | 439 +++++++++--------- 4 files changed, 387 insertions(+), 338 deletions(-) diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index bb2ee18f1..ac6fe02f9 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "UTransportMock.h" #include "up-cpp/datamodel/validator/UUri.h" @@ -72,25 +73,30 @@ void NotificationSinkTest::SetUp() { } void NotificationSinkTest::buildDefaultSourceURI() { + constexpr uint32_t DEFAULT_SOURCE_UURI_UE_ID = 0x00011102; testDefaultSourceUUri_.set_authority_name("192.168.1.10"); - testDefaultSourceUUri_.set_ue_id(0x00011102); + testDefaultSourceUUri_.set_ue_id(DEFAULT_SOURCE_UURI_UE_ID); testDefaultSourceUUri_.set_ue_version_major(0x1); testDefaultSourceUUri_.set_resource_id(0x0); } void NotificationSinkTest::buildValidNotificationURI() { + constexpr uint32_t TOPIC_UURI_UE_ID = 0x00011101; + constexpr uint32_t TOPIC_UURI_RESOURCE_ID = 0x8001; testTopicUUri_.set_authority_name("192.168.1.10"); - testTopicUUri_.set_ue_id(0x00011101); + testTopicUUri_.set_ue_id(TOPIC_UURI_UE_ID); testTopicUUri_.set_ue_version_major(0x1); - testTopicUUri_.set_resource_id(0x8001); + testTopicUUri_.set_resource_id(TOPIC_UURI_RESOURCE_ID); } void NotificationSinkTest::buildInValidNotificationURI() { + constexpr uint32_t TOPIC_UURI_UE_ID = 0x00011101; + constexpr uint32_t TOPIC_UURI_RESOURCE_ID = 0x1200; testInvalidTopicUUri_.set_authority_name("192.168.1.10"); - testInvalidTopicUUri_.set_ue_id(0x00011101); + testInvalidTopicUUri_.set_ue_id(TOPIC_UURI_UE_ID); testInvalidTopicUUri_.set_ue_version_major(0x1); // Resource ID should be in the range of 0x8000 to 0xFFFF - testInvalidTopicUUri_.set_resource_id(0x1200); + testInvalidTopicUUri_.set_resource_id(TOPIC_UURI_RESOURCE_ID); } void NotificationSinkTest::handleCallbackMessage( @@ -101,12 +107,15 @@ void NotificationSinkTest::handleCallbackMessage( std::string get_random_string(size_t length) { auto randchar = []() -> char { - const char charset[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; - const size_t max_index = (sizeof(charset) - 1); - return charset[rand() % max_index]; + constexpr std::array CHARSET = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' + }; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distr(0, CHARSET.size() - 1); + return CHARSET.at(static_cast(distr(gen))); }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); @@ -124,7 +133,7 @@ TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { // NOLINT std::optional source_filter; - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto result = NotificationSink::create(transport, getTestTopicUUri(), std::move(callback), @@ -145,7 +154,7 @@ TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // NOLINT std::optional source_filter; // Notification to invalid UUri topic with resource ID not in correct range - EXPECT_THROW(auto result = NotificationSink::create( + EXPECT_THROW(auto result = NotificationSink::create( // NOLINT transport, getTestInvalidTopicUUri(), std::move(callback), std::move(source_filter)), UriValidator::InvalidUUri); @@ -215,7 +224,7 @@ TEST_F(NotificationSinkTest, NullTransport) { // NOLINT return this->handleCallbackMessage(arg); }; - EXPECT_THROW(auto result = NotificationSink::create( + EXPECT_THROW(auto result = NotificationSink::create( // NOLINT transport, getTestDefaultSourceUUri(), std::move(callback), getTestTopicUUri()), uprotocol::transport::NullTransport); @@ -233,7 +242,7 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT nullptr, getTestTopicUUri()); }; - EXPECT_THROW(test_create_nullptr(), utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_nullptr(), utils::callbacks::EmptyFunctionObject); // NOLINT // Default construct a function object auto test_create_empty = [transport, this]() { @@ -241,7 +250,7 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT transport, transport->getEntityUri(), {}, getTestTopicUUri()); }; - EXPECT_THROW(test_create_empty(), utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_empty(), utils::callbacks::EmptyFunctionObject); // NOLINT } } // namespace uprotocol::communication diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index 319e4d218..feee80f57 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -19,36 +19,43 @@ #include "up-cpp/datamodel/validator/UMessage.h" #include "up-cpp/transport/UTransport.h" -using namespace uprotocol::communication; -using namespace uprotocol::datamodel::builder; -using namespace uprotocol::v1; -using ::testing::_; - -namespace { +namespace uprotocol::communication{ class TestNotificationSource : public testing::Test { +private: + std::shared_ptr transportMock_; + uprotocol::v1::UUri source_; + uprotocol::v1::UUri sink_; + uprotocol::v1::UPayloadFormat format_ = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + std::optional priority_; + std::optional ttl_; + protected: // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { + constexpr uint32_t DEFAULT_UE_ID = 0x00011101; + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8101; + constexpr uint32_t SOURCE_VERSION_MAJOR = 0xF1; + constexpr uint32_t TOPIC_VERSION_MAJOR = 0xF8; + constexpr uint16_t DEFAULT_TTL_TIME = 1000; + source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(0x00011101); - source_.set_ue_version_major(0xF1); + source_.set_ue_id(DEFAULT_UE_ID); + source_.set_ue_version_major(SOURCE_VERSION_MAJOR); source_.set_resource_id(0x0); sink_.set_authority_name("10.0.0.1"); - sink_.set_ue_id(0x00011101); - sink_.set_ue_version_major(0xF8); - sink_.set_resource_id(0x8101); + sink_.set_ue_id(DEFAULT_UE_ID); + sink_.set_ue_version_major(TOPIC_VERSION_MAJOR); + sink_.set_resource_id(DEFAULT_RESOURCE_ID); transportMock_ = std::make_shared(source_); - source_.set_resource_id(0x8101); + source_.set_resource_id(DEFAULT_RESOURCE_ID); sink_.set_resource_id(0x0); - - format_ = UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - priority_ = UPriority::UPRIORITY_CS1; - ttl_ = std::chrono::milliseconds(1000); + priority_ = uprotocol::v1::UPriority::UPRIORITY_CS1; + ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); } void TearDown() override {} @@ -61,26 +68,34 @@ class TestNotificationSource : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - std::shared_ptr transportMock_; - UUri source_; - UUri sink_; - UPayloadFormat format_; - std::optional priority_; - std::optional ttl_; + std::shared_ptr getTransportMock() const { return transportMock_; } + uprotocol::v1::UUri getSource() const { return source_; } + uprotocol::v1::UUri getSink() const { return sink_; } + uprotocol::v1::UPayloadFormat getFormat() const { return format_; } + std::optional getPriority() const { return priority_; } + std::optional getTTL() const { return ttl_; } + + void setTransportMock(const std::shared_ptr& transport_mock) { transportMock_ = transport_mock; } + void setSource(const uprotocol::v1::UUri& source) { source_ = source; } + void setSink(const uprotocol::v1::UUri& sink) { sink_ = sink; } + void setFormat(const uprotocol::v1::UPayloadFormat& format) { format_ = format; } + void setPriority(const std::optional& priority) { priority_ = priority; } + void setTTL(const std::optional& ttl) { ttl_ = ttl; } + public: ~TestNotificationSource() override = default; }; TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT std::string test_payload_str = "test_payload"; - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_), format_, priority_, - ttl_); - Payload test_payload(test_payload_str, format_); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink(), getFormat(), getPriority(), + getTTL()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -88,19 +103,19 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); } TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT std::string test_payload_str = "test_payload"; - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_), format_, priority_); - Payload test_payload(test_payload_str, format_); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink(), getFormat(), getPriority()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -108,22 +123,22 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); - EXPECT_EQ(transportMock_->message_.attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); } TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOLINT std::string test_payload_str = "test_payload"; - priority_.reset(); - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_), format_, priority_); - Payload test_payload(test_payload_str, format_); + getPriority().reset(); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink(), getFormat(), getPriority()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -131,23 +146,23 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOL auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); - EXPECT_EQ(transportMock_->message_.attributes().priority(), - UPriority::UPRIORITY_CS1); + EXPECT_EQ(getTransportMock()->message_.attributes().priority(), + uprotocol::v1::UPriority::UPRIORITY_CS1); } TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT std::string test_payload_str = "test_payload"; - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_), format_, priority_, - ttl_); - Payload test_payload(test_payload_str, format_); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink(), getFormat(), getPriority(), + getTTL()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -155,29 +170,29 @@ TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT } TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_)); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(); EXPECT_EQ(status.code(), retval.code()); - EXPECT_EQ(transportMock_->message_.attributes().ttl(), 0); - EXPECT_EQ(transportMock_->message_.attributes().priority(), - UPriority::UPRIORITY_CS1); + EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->message_.attributes().priority(), + uprotocol::v1::UPriority::UPRIORITY_CS1); } TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT - NotificationSource notification_source(transportMock_, std::move(source_), - std::move(sink_)); + NotificationSource notification_source(getTransportMock(), getSource(), + getSink()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; auto status = notification_source.notify(); @@ -188,10 +203,10 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT TEST_F(TestNotificationSource, NullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(NotificationSource notification_source( - transport, std::move(source_), std::move(sink_), format_, - priority_, ttl_), + EXPECT_THROW(NotificationSource notification_source( // NOLINT + transport, getSource(), getSink(), getFormat(), + getPriority(), getTTL()), uprotocol::transport::NullTransport); } -} // namespace +} // namespace uprotocol::communication diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index dc61dd304..60dc91f30 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -16,32 +16,61 @@ #include "UTransportMock.h" -using namespace uprotocol::communication; -using namespace uprotocol; +namespace uprotocol{ -namespace { -using namespace uprotocol::datamodel::builder; +// namespace { +// using namespace uprotocol::datamodel::builder; class TestPublisher : public testing::Test { +private: + std::shared_ptr transportMock_; + v1::UUri source_; + v1::UUri topic_; + v1::UPayloadFormat format_ = v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + std::optional priority_; + std::optional ttl_; + uprotocol::v1::UMessage capture_msg_; protected: + std::shared_ptr getTransportMock() const { return transportMock_; } + v1::UUri getSource() const { return source_; } + v1::UUri getTopic() const { return topic_; } + v1::UPayloadFormat getFormat() const { return format_; } + std::optional getPriority() const { return priority_; } + std::optional getTTL() const { return ttl_; } + uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } + + void setTransportMock(const std::shared_ptr& transport_mock) { transportMock_ = transport_mock; } + void setSource(const v1::UUri& source) { source_ = source; } + void setTopic(const v1::UUri& topic) { topic_ = topic; } + void setFormat(const v1::UPayloadFormat& format) { format_ = format; } + void setPriority(const std::optional& priority) { priority_ = priority; } + void setTTL(const std::optional& ttl) { ttl_ = ttl; } + void setCaptureMsg(const uprotocol::v1::UMessage& capture_msg) { capture_msg_ = capture_msg; } + // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { + constexpr uint32_t DEFAULT_UE_ID = 0x00011101; + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8101; + constexpr uint32_t SOURCE_VERSION_MAJOR = 0xF1; + constexpr uint32_t TOPIC_VERSION_MAJOR = 0xF8; + constexpr uint16_t DEFAULT_TTL_TIME = 1000; + source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(0x00011101); - source_.set_ue_version_major(0xF1); + source_.set_ue_id(DEFAULT_UE_ID); + source_.set_ue_version_major(SOURCE_VERSION_MAJOR); source_.set_resource_id(0x0); topic_.set_authority_name("10.0.0.1"); - topic_.set_ue_id(0x00011101); - topic_.set_ue_version_major(0xF8); - topic_.set_resource_id(0x8101); + topic_.set_ue_id(DEFAULT_UE_ID); + topic_.set_ue_version_major(TOPIC_VERSION_MAJOR); + topic_.set_resource_id(DEFAULT_RESOURCE_ID); transportMock_ = std::make_shared(source_); - format_ = v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; priority_ = v1::UPriority::UPRIORITY_CS2; - ttl_ = std::chrono::milliseconds(1000); + ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); + } void TearDown() override {} @@ -49,52 +78,45 @@ class TestPublisher : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestPublisher() = default; - ~TestPublisher() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - - std::shared_ptr transportMock_; - v1::UUri source_; - v1::UUri topic_; - v1::UPayloadFormat format_; - std::optional priority_; - std::optional ttl_; - uprotocol::v1::UMessage capture_msg_; +public: + ~TestPublisher() override = default; }; TEST_F(TestPublisher, PublisherSuccess) { // NOLINT std::string test_payload_str = "test_payload"; - Publisher publisher(transportMock_, std::move(topic_), format_, priority_, - ttl_); + communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), + getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; - Payload test_payload(test_payload_str, format_); + datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); } TEST_F(TestPublisher, PublishFailure) { // NOLINT std::string test_payload_str = "test_payload"; - Publisher publisher(transportMock_, std::move(topic_), format_, priority_, - ttl_); + communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), + getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; - Payload test_payload(test_payload_str, format_); + datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); @@ -102,55 +124,55 @@ TEST_F(TestPublisher, PublishFailure) { // NOLINT TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT std::string test_payload_str = "test_payload"; - Publisher publisher(transportMock_, std::move(topic_), format_, priority_); + communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; - Payload test_payload(test_payload_str, format_); + datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); - EXPECT_EQ(transportMock_->message_.attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); } TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT std::string test_payload_str = "test_payload"; - priority_.reset(); - Publisher publisher(transportMock_, std::move(topic_), format_, priority_, - ttl_); + getPriority().reset(); + communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), + getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; - Payload test_payload(test_payload_str, format_); + datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); EXPECT_EQ(status.code(), retval.code()); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - transportMock_->message_); + getTransportMock()->message_); EXPECT_EQ(valid, true); - EXPECT_EQ(transportMock_->message_.attributes().priority(), + EXPECT_EQ(getTransportMock()->message_.attributes().priority(), v1::UPriority::UPRIORITY_CS1); } // publisher with null transport TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(Publisher publisher(transport, std::move(topic_), format_, - priority_, ttl_), + EXPECT_THROW(communication::Publisher publisher(transport, getTopic(), getFormat(), // NOLINT + getPriority(), getTTL()), uprotocol::transport::NullTransport); } -} // namespace +} // namespace uprotocol \ No newline at end of file diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index f6b047128..39ae1363c 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -23,20 +23,14 @@ #include "UTransportMock.h" -using namespace std::chrono_literals; - -namespace { - bool operator==(const uprotocol::v1::UUri& lhs, const uprotocol::v1::UUri& rhs) { - using namespace google::protobuf::util; - return MessageDifferencer::Equals(lhs, rhs); + return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } bool operator==(const uprotocol::v1::UMessage& lhs, const uprotocol::v1::UMessage& rhs) { - using namespace google::protobuf::util; - return MessageDifferencer::Equals(lhs, rhs); + return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } bool operator==(const uprotocol::v1::UStatus& lhs, @@ -44,7 +38,11 @@ bool operator==(const uprotocol::v1::UStatus& lhs, return lhs.code() == rhs; } +namespace uprotocol{ + class RpcClientTest : public testing::Test { +private: + std::shared_ptr transport_; protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -58,7 +56,6 @@ class RpcClientTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. RpcClientTest() = default; - ~RpcClientTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. @@ -69,10 +66,10 @@ class RpcClientTest : public testing::Test { // when the application exits. google::protobuf::ShutdownProtobufLibrary(); } - + static uprotocol::v1::UUri methodUri(const std::string& auth = "TestAuth", uint16_t ue_id = 0x8000, - uint16_t ue_instance = 1, + uint16_t ue_instance = 1, // NOLINT uint16_t ue_version_major = 1, uint16_t resource_id = 1) { uprotocol::v1::UUri uri; @@ -98,13 +95,20 @@ class RpcClientTest : public testing::Test { EXPECT_TRUE(*(transport_->sink_filter_) == defaultSourceUri()); } EXPECT_EQ(transport_->send_count_, expected_send_count); - using namespace uprotocol::datamodel::validator; auto [valid_request, _] = - message::isValidRpcRequest(transport_->message_); + datamodel::validator::message::isValidRpcRequest(transport_->message_); EXPECT_TRUE(valid_request); } - std::shared_ptr transport_; + std::shared_ptr getTransport() const { + return transport_; + } + void setTransport(const std::shared_ptr& transport) { + transport_ = transport; + } + +public: + ~RpcClientTest() override = default; }; template @@ -113,18 +117,17 @@ void checkErrorResponse( ExpectedT expected_status) { EXPECT_FALSE(maybe_response); if (!maybe_response) { - auto& status = maybe_response.error(); + const auto& status = maybe_response.error(); EXPECT_TRUE(status == expected_status); } } uprotocol::datamodel::builder::Payload fakePayload() { - using namespace uprotocol::datamodel; - auto uuid = builder::UuidBuilder::getBuilder(); - auto uuid_str = serializer::uuid::AsString::serialize(uuid.build()); + auto uuid = datamodel::builder::UuidBuilder::getBuilder(); + auto uuid_str = datamodel::serializer::uuid::AsString::serialize(uuid.build()); - return builder::Payload( + return datamodel::builder::Payload( std::move(uuid_str), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); } @@ -134,24 +137,24 @@ uprotocol::datamodel::builder::Payload fakePayload() { TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT // Base parameters EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms);); + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10));); // Optional format EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON);); // Optional permission level EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, {}, 9);); + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), {}, 9);); // Optional permission level EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, {}, {}, + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), {}, {}, "Some token");); } @@ -159,27 +162,27 @@ TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLIN // Bad method URI EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); auto client = uprotocol::communication::RpcClient( - transport_, std::move(uri), - uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), std::move(uri), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); , uprotocol::datamodel::validator::uri::InvalidUUri); // Bad priority EXPECT_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS3, 10ms); + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS3, std::chrono::milliseconds(10)); , std::out_of_range); // Bad ttl EXPECT_THROW(auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, 0ms); + getTransport(), methodUri(), + uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(0)); , std::out_of_range); // Bad payload format EXPECT_THROW( auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms, static_cast(-1)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(10), static_cast(-1)); , std::out_of_range); } @@ -187,21 +190,21 @@ TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLIN // RpcClient::invokeMethod() TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); - EXPECT_TRUE(transport_->message_.payload().empty()); + EXPECT_TRUE(getTransport()->message_.payload().empty()); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -213,31 +216,31 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); EXPECT_THROW( auto invoke_future = client.invokeMethod(), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(transport_->send_count_, 0); - EXPECT_FALSE(transport_->listener_); + EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); EXPECT_NO_THROW(invoke_future = client.invokeMethod()); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(150ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(150)); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), 10ms); - EXPECT_LE((when_expired - when_requested), 2 * 10ms); + EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); + EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -249,17 +252,17 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->registerListener_status_.set_code( + getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); - EXPECT_EQ(transport_->send_count_, 0); + EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -271,16 +274,16 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->send_status_.set_code( + getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -295,14 +298,14 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(10)); EXPECT_NO_THROW(invoke_future = client.invokeMethod()); } EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -314,19 +317,19 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -340,7 +343,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Payload) TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -351,17 +354,17 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; - EXPECT_EQ(transport_->message_.payload(), + EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); - EXPECT_EQ(transport_->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -373,7 +376,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); @@ -385,17 +388,17 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; - EXPECT_EQ(transport_->message_.payload(), + EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); - EXPECT_EQ(transport_->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -407,31 +410,31 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); EXPECT_THROW( auto invoke_future = client.invokeMethod(fakePayload()), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(transport_->send_count_, 0); - EXPECT_FALSE(transport_->listener_); + EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(150ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(150)); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), 10ms); - EXPECT_LE((when_expired - when_requested), 2 * 10ms); + EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); + EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -443,17 +446,17 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->registerListener_status_.set_code( + getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); - EXPECT_EQ(transport_->send_count_, 0); + EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -465,16 +468,16 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->send_status_.set_code( + getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -489,14 +492,14 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(10)); EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); } EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -507,19 +510,19 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(0ms); + auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -533,7 +536,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Callback) TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); bool callback_called = false; uprotocol::v1::UMessage received_response; @@ -541,19 +544,19 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - [this, &callback_called, &received_response](auto maybe_response) { + [&callback_called, &received_response](auto maybe_response) { callback_called = true; EXPECT_TRUE(maybe_response); received_response = std::move(maybe_response).value(); })); validateLastRequest(1); - EXPECT_TRUE(transport_->message_.payload().empty()); + EXPECT_TRUE(getTransport()->message_.payload().empty()); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -561,7 +564,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); uprotocol::communication::RpcClient::InvokeHandle handle; @@ -569,13 +572,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT handle = client.invokeMethod([](auto) {}), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(transport_->send_count_, 0); - EXPECT_FALSE(transport_->listener_); + EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); bool callback_called = false; std::condition_variable callback_event; @@ -584,7 +587,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - [this, &callback_called, &callback_event](auto maybe_response) { + [&callback_called, &callback_event](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::DEADLINE_EXCEEDED); @@ -594,47 +597,47 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, 150ms, [&callback_called]() { return callback_called; }); + lock, std::chrono::milliseconds(150), [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), 10ms); - EXPECT_LE((when_expired - when_requested), 2 * 10ms); + EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); + EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->registerListener_status_.set_code( + getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([this, &callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::RESOURCE_EXHAUSTED); })); - EXPECT_EQ(transport_->send_count_, 0); + EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->send_status_.set_code( + getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([this, &callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, @@ -652,10 +655,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(10)); - EXPECT_NO_THROW(handle = client.invokeMethod([this, &callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); @@ -667,12 +670,12 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([this, &callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, @@ -680,10 +683,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT })); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(callback_called); } @@ -692,7 +695,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Payload, Callback) TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -704,7 +707,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT EXPECT_NO_THROW( handle = client.invokeMethod( std::move(payload), - [this, &callback_called, &received_response](auto maybe_response) { + [&callback_called, &received_response](auto maybe_response) { callback_called = true; EXPECT_TRUE(maybe_response); received_response = std::move(maybe_response).value(); @@ -712,15 +715,15 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT validateLastRequest(1); using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; - EXPECT_EQ(transport_->message_.payload(), + EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); - EXPECT_EQ(transport_->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -728,7 +731,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); @@ -741,7 +744,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT EXPECT_NO_THROW( handle = client.invokeMethod( std::move(payload), - [this, &callback_called, &received_response](auto maybe_response) { + [&callback_called, &received_response](auto maybe_response) { callback_called = true; EXPECT_TRUE(maybe_response); received_response = std::move(maybe_response).value(); @@ -749,15 +752,15 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT validateLastRequest(1); using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; - EXPECT_EQ(transport_->message_.payload(), + EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); - EXPECT_EQ(transport_->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -765,7 +768,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms, + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); uprotocol::communication::RpcClient::InvokeHandle handle; @@ -773,13 +776,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT handle = client.invokeMethod(fakePayload(), [](auto) {}), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(transport_->send_count_, 0); - EXPECT_FALSE(transport_->listener_); + EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); bool callback_called = false; std::condition_variable callback_event; @@ -789,7 +792,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT EXPECT_NO_THROW( handle = client.invokeMethod( fakePayload(), - [this, &callback_called, &callback_event](auto maybe_response) { + [&callback_called, &callback_event](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::DEADLINE_EXCEEDED); @@ -799,20 +802,20 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, 150ms, [&callback_called]() { return callback_called; }); + lock, std::chrono::milliseconds(150), [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), 10ms); - EXPECT_LE((when_expired - when_requested), 2 * 10ms); + EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); + EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->registerListener_status_.set_code( + getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; @@ -820,21 +823,21 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - fakePayload(), [this, &callback_called](auto maybe_response) { + fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::RESOURCE_EXHAUSTED); })); - EXPECT_EQ(transport_->send_count_, 0); + EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - transport_->send_status_.set_code( + getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); bool callback_called = false; @@ -842,7 +845,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - fakePayload(), [this, &callback_called](auto maybe_response) { + fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::FAILED_PRECONDITION); @@ -859,12 +862,12 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(10)); EXPECT_NO_THROW( handle = client.invokeMethod( - fakePayload(), [this, &callback_called](auto maybe_response) { + fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); @@ -876,24 +879,24 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - fakePayload(), [this, &callback_called](auto maybe_response) { + fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::PERMISSION_DENIED); })); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(transport_->message_); + auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(transport_->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); EXPECT_TRUE(callback_called); } @@ -902,28 +905,28 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT // Usecases TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 250ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(250)); std::list futures; - std::listlistener_.value())>> callables; + std::listlistener_.value())>> callables; std::list requests; futures.push_back(client.invokeMethod()); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); futures.push_back(client.invokeMethod(fakePayload())); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); futures.push_back(client.invokeMethod()); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); futures.push_back(client.invokeMethod(fakePayload())); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); std::vector handles; @@ -931,25 +934,25 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT auto callback = [&callback_count](auto) { ++callback_count; }; handles.push_back(client.invokeMethod(callback)); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); handles.push_back(client.invokeMethod(fakePayload(), callback)); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); handles.push_back(client.invokeMethod(callback)); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); handles.push_back(client.invokeMethod(fakePayload(), callback)); - callables.push_back(transport_->listener_.value()); - requests.push_back(transport_->message_); + callables.push_back(getTransport()->listener_.value()); + requests.push_back(getTransport()->message_); auto readyFutures = [&futures]() { size_t ready = 0; for (auto& future : futures) { - auto is_ready = future.wait_for(0ms); + auto is_ready = future.wait_for(std::chrono::milliseconds(0)); if (is_ready == std::future_status::ready) { ++ready; } @@ -973,7 +976,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT EXPECT_EQ(callback_count, 1); EXPECT_EQ(readyFutures(), 1); - EXPECT_EQ(futures.front().wait_for(0ms), std::future_status::ready); + EXPECT_EQ(futures.front().wait_for(std::chrono::milliseconds(0)), std::future_status::ready); requests.pop_front(); requests.pop_back(); @@ -1002,11 +1005,11 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT std::vector expected_order; - constexpr auto per_client_ttl_increment = 5ms; - auto client_ttl = 200ms; + constexpr auto PER_CLIENT_TTL_INCREMENT = std::chrono::milliseconds(5); + auto client_ttl = std::chrono::milliseconds(200); for (size_t client_id = 0; client_id < num_clients; - ++client_id, client_ttl += per_client_ttl_increment) { + ++client_id, client_ttl += PER_CLIENT_TTL_INCREMENT) { auto transport = std::make_shared( defaultSourceUri()); @@ -1027,9 +1030,9 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT auto handle = client.invokeMethod([client_id, &expire_mtx, &expire_order, - &expire_signal](auto maybe_response) { + &expire_signal](const auto& maybe_response) { if (!maybe_response) { - auto some_status = maybe_response.error(); + const auto& some_status = maybe_response.error(); if (some_status.code() != uprotocol::v1::UCode::DEADLINE_EXCEEDED) { return; @@ -1043,7 +1046,7 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT } std::unique_lock lock(expire_mtx); - expire_signal.wait_for(lock, 2s, [&expire_order]() { + expire_signal.wait_for(lock, std::chrono::seconds(2), [&expire_order]() { return expire_order.size() == num_clients; }); EXPECT_EQ(expire_order.size(), num_clients); @@ -1062,25 +1065,25 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT // in order). TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT auto slow_client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10s); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::seconds(10)); auto slow_future = slow_client.invokeMethod(); // Waits long enough for the worker to wake and go back to sleep with the // 10s TTL for the slow request as the next scheduled wake time. - auto slow_ready = slow_future.wait_for(100ms); + auto slow_ready = slow_future.wait_for(std::chrono::milliseconds(100)); EXPECT_EQ(slow_ready, std::future_status::timeout); auto fast_client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 25ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(25)); auto fast_future = fast_client.invokeMethod(); // The request from the fast_client should expire within about 25ms, but // the request from the slow_client should still be pending for several // more seconds. - auto fast_ready = fast_future.wait_for(1s); - slow_ready = slow_future.wait_for(100ms); + auto fast_ready = fast_future.wait_for(std::chrono::seconds()); + slow_ready = slow_future.wait_for(std::chrono::milliseconds(100)); EXPECT_EQ(fast_ready, std::future_status::ready); EXPECT_EQ(slow_ready, std::future_status::timeout); @@ -1103,16 +1106,16 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT transport = std::make_shared(uri); } - std::array timeouts; - constexpr std::chrono::milliseconds timeout_step = 7ms; - constexpr std::chrono::milliseconds timeout_min = 200ms; - constexpr std::chrono::milliseconds timeout_max = timeout_min + 40ms; - std::chrono::milliseconds next_timeout = timeout_min; + std::array timeouts{}; + constexpr std::chrono::milliseconds TIMEOUT_STEP = std::chrono::milliseconds(7); + constexpr std::chrono::milliseconds TIMEOUT_MIN = std::chrono::milliseconds(200); + constexpr std::chrono::milliseconds TIMEOUT_MAX = TIMEOUT_MIN + std::chrono::milliseconds(40); + std::chrono::milliseconds next_timeout = TIMEOUT_MIN; for (auto& timeout : timeouts) { timeout = next_timeout; - next_timeout = ((next_timeout - timeout_min + timeout_step) % - (timeout_max - timeout_min)) + - timeout_min; + next_timeout = ((next_timeout - TIMEOUT_MIN + TIMEOUT_STEP) % + (TIMEOUT_MAX - TIMEOUT_MIN)) + + TIMEOUT_MIN; } std::vector clients; @@ -1154,7 +1157,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT size_t num_ready = 0; for (auto& request : pending) { auto& future = std::get<1>(request); - const bool is_ready = future.wait_for(0ms) == std::future_status::ready; + const bool is_ready = future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; if (is_ready) { ++num_ready; auto maybe_response = future.get(); @@ -1175,7 +1178,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT auto& future = std::get<1>(request); // Ignoring the futures we have already used if (future.valid() && - (future.wait_for(0ms) == std::future_status::ready)) { + (future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)) { auto maybe_response = future.get(); checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); ++num_cancelled; @@ -1207,7 +1210,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT auto& median_expire_future = std::get<1>(*pending_middle); median_expire_future.wait_until(std::get<0>(*pending_middle) + - timeout_step); + TIMEOUT_STEP); size_t expected_expired = 0; size_t ready_futures = 0; @@ -1219,7 +1222,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT (when_expire <= std::chrono::steady_clock::now())) { ++expected_expired; - if (future.wait_for(2 * timeout_step) == + if (future.wait_for(2 * TIMEOUT_STEP) == std::future_status::ready) { ++ready_futures; auto maybe_message = future.get(); @@ -1245,9 +1248,9 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array workers; auto client = uprotocol::communication::RpcClient( - transport_, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, 10ms); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); - constexpr size_t num_requests_per_worker = 10; + constexpr size_t NUM_REQUESTS_PER_WORKER = 10; std::atomic call_count = 0; std::array, @@ -1258,7 +1261,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT for (auto& worker : workers) { worker = std::thread([&call_count, &client, &handles = *(worker_handles++)]() { - for (auto remaining = num_requests_per_worker; remaining > 0; + for (auto remaining = NUM_REQUESTS_PER_WORKER; remaining > 0; --remaining) { handles.emplace_back( client.invokeMethod([&call_count](auto) { ++call_count; })); @@ -1272,25 +1275,25 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT for (int remaining_attempts = 10; remaining_attempts > 0; --remaining_attempts) { - std::this_thread::sleep_for(20ms); - if (call_count == num_requests_per_worker * workers.size()) { + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + if (call_count == NUM_REQUESTS_PER_WORKER * workers.size()) { break; } } - EXPECT_EQ(call_count, num_requests_per_worker * workers.size()); + EXPECT_EQ(call_count, NUM_REQUESTS_PER_WORKER * workers.size()); } TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::vector workers; - constexpr size_t num_requests_per_worker = 1500; + constexpr size_t NUM_REQUESTS_PER_WORKER = 1500; auto get_client = []() { auto transport = std::make_shared( defaultSourceUri()); return uprotocol::communication::RpcClient( transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); + std::chrono::milliseconds(10)); }; // Repeatedly creates a client, makes a request, then discards the client @@ -1298,7 +1301,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT workers.emplace_back([&discard_calls, &get_client]() { uprotocol::communication::RpcClient::InvokeHandle handle; - for (auto remaining_requests = num_requests_per_worker; + for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto client = get_client(); handle = client.invokeMethod( @@ -1313,11 +1316,11 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT workers.emplace_back([&abandon_calls, &get_client]() { auto client = get_client(); - for (auto remaining_requests = num_requests_per_worker; + for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto future = client.invokeMethod(); if (future.valid() && - (future.wait_for(0ms) == std::future_status::ready)) { + (future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)) { ++abandon_calls; } } @@ -1331,12 +1334,12 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT workers.emplace_back([&expire_calls, &broken_promises, &get_client]() { auto client = get_client(); std::vector futures; - for (auto remaining_requests = num_requests_per_worker; + for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { futures.emplace_back(client.invokeMethod()); } for (auto& future : futures) { - auto is_ready = future.wait_for(1s); + auto is_ready = future.wait_for(std::chrono::seconds()); if (is_ready == std::future_status::ready) { try { auto maybe_response = future.get(); @@ -1363,8 +1366,8 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT defaultSourceUri()); auto client = uprotocol::communication::RpcClient( transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - 10ms); - for (auto remaining_requests = num_requests_per_worker; + std::chrono::milliseconds(10)); + for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto handle = client.invokeMethod([&self_calls](auto) { ++self_calls; }); @@ -1389,11 +1392,11 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT worker.join(); } - EXPECT_EQ(discard_calls, num_requests_per_worker); + EXPECT_EQ(discard_calls, NUM_REQUESTS_PER_WORKER); EXPECT_EQ(abandon_calls, 0); EXPECT_EQ(broken_promises, 0); - EXPECT_EQ(expire_calls, num_requests_per_worker); - EXPECT_EQ(self_calls, num_requests_per_worker * num_self_responders); + EXPECT_EQ(expire_calls, NUM_REQUESTS_PER_WORKER); + EXPECT_EQ(self_calls, NUM_REQUESTS_PER_WORKER * num_self_responders); } -} // namespace +} // namespace uprotocol From 7945d9e84122360e856026898aa3b432c617eba8 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 12:42:59 +0200 Subject: [PATCH 04/41] Solve more linter warnings --- lint/clang-tidy.sh | 3 +- test/coverage/communication/RpcClientTest.cpp | 310 +++++++++--------- 2 files changed, 162 insertions(+), 151 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index 19e9ddc80..cc4a66cd9 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,7 +58,8 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + # for f in include/**/*.h src/**/*.cpp + for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 39ae1363c..0e0b239c2 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -23,6 +23,10 @@ #include "UTransportMock.h" +constexpr std::chrono::milliseconds TEN_MILLISECONDS(10); +constexpr std::chrono::milliseconds ONE_HUNDRED_FIFTY_MILLISECONDS(150); +constexpr uint32_t SHIFT_AMOUNT = 16; + bool operator==(const uprotocol::v1::UUri& lhs, const uprotocol::v1::UUri& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); @@ -74,7 +78,7 @@ class RpcClientTest : public testing::Test { uint16_t resource_id = 1) { uprotocol::v1::UUri uri; uri.set_authority_name(auth); - uri.set_ue_id(static_cast(ue_instance) << 16 | + uri.set_ue_id(static_cast(ue_instance) << SHIFT_AMOUNT | static_cast(ue_id)); uri.set_ue_version_major(ue_version_major); uri.set_resource_id(resource_id); @@ -100,7 +104,7 @@ class RpcClientTest : public testing::Test { EXPECT_TRUE(valid_request); } - std::shared_ptr getTransport() const { + [[nodiscard]] std::shared_ptr getTransport() const { return transport_; } void setTransport(const std::shared_ptr& transport) { @@ -136,53 +140,53 @@ uprotocol::datamodel::builder::Payload fakePayload() { // Construction TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT // Base parameters - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10));); + uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS);); // Optional format - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON);); // Optional permission level - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), {}, 9);); + uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, 9);); // Optional permission level - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), {}, {}, + uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, {}, "Some token");); } TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLINT // Bad method URI - EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); + EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); // NOLINT auto client = uprotocol::communication::RpcClient( getTransport(), std::move(uri), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); , uprotocol::datamodel::validator::uri::InvalidUUri); // Bad priority - EXPECT_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS3, std::chrono::milliseconds(10)); + uprotocol::v1::UPriority::UPRIORITY_CS3, TEN_MILLISECONDS); , std::out_of_range); // Bad ttl - EXPECT_THROW(auto client = uprotocol::communication::RpcClient( + EXPECT_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(0)); , std::out_of_range); // Bad payload format - EXPECT_THROW( + EXPECT_THROW( // NOLINT auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10), static_cast(-1)); + TEN_MILLISECONDS, static_cast(-1)); , std::out_of_range); } @@ -190,10 +194,10 @@ TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLIN // RpcClient::invokeMethod() TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -202,7 +206,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -216,10 +220,10 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); - EXPECT_THROW( + EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -229,18 +233,18 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(150)); + auto is_ready = invoke_future.wait_for(ONE_HUNDRED_FIFTY_MILLISECONDS); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); - EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); + EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); + EXPECT_LE((when_expired - when_requested), 2 * TEN_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -252,13 +256,13 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(invoke_future.valid()); @@ -274,13 +278,13 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -299,9 +303,9 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT } EXPECT_TRUE(invoke_future.valid()); @@ -309,7 +313,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { - EXPECT_NO_THROW(auto maybe_response = invoke_future.get(); + EXPECT_NO_THROW(auto maybe_response = invoke_future.get(); // NOLINT checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED);); } @@ -317,16 +321,16 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -343,13 +347,13 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Payload) TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -362,7 +366,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -376,14 +380,14 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -396,7 +400,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -410,10 +414,10 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); - EXPECT_THROW( + EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(fakePayload()), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -423,18 +427,18 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(150)); + auto is_ready = invoke_future.wait_for(ONE_HUNDRED_FIFTY_MILLISECONDS); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); - EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); + EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); + EXPECT_LE((when_expired - when_requested), 2 * TEN_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -446,13 +450,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_TRUE(invoke_future.valid()); @@ -468,13 +472,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -493,9 +497,9 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT } EXPECT_TRUE(invoke_future.valid()); @@ -510,16 +514,16 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -536,13 +540,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Callback) TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; uprotocol::v1::UMessage received_response; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( [&callback_called, &received_response](auto maybe_response) { callback_called = true; @@ -556,7 +560,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -564,11 +568,11 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_THROW( + EXPECT_THROW( // NOLINT handle = client.invokeMethod([](auto) {}), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -578,7 +582,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; @@ -587,7 +591,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( handle = client.invokeMethod( - [&callback_called, &callback_event](auto maybe_response) { + [&callback_called, &callback_event](const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::DEADLINE_EXCEEDED); @@ -597,18 +601,18 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, std::chrono::milliseconds(150), [&callback_called]() { return callback_called; }); + lock, ONE_HUNDRED_FIFTY_MILLISECONDS, [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); - EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); + EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); + EXPECT_LE((when_expired - when_requested), 2 * TEN_MILLISECONDS); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); @@ -617,7 +621,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( - auto maybe_response) { + const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::RESOURCE_EXHAUSTED); @@ -629,7 +633,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); @@ -638,7 +642,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( - auto maybe_response) { + const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::FAILED_PRECONDITION); @@ -656,10 +660,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( - auto maybe_response) { + const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); })); @@ -670,13 +674,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( - auto maybe_response) { + const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::PERMISSION_DENIED); @@ -695,7 +699,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT // RpcClient::invokeMethod(Payload, Callback) TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -731,7 +735,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); @@ -768,11 +772,11 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10), + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_THROW( + EXPECT_THROW( // NOLINT handle = client.invokeMethod(fakePayload(), [](auto) {}), uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -782,14 +786,14 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; uprotocol::communication::RpcClient::InvokeHandle handle; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called, &callback_event](auto maybe_response) { @@ -802,18 +806,18 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, std::chrono::milliseconds(150), [&callback_called]() { return callback_called; }); + lock, ONE_HUNDRED_FIFTY_MILLISECONDS, [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); - EXPECT_GE((when_expired - when_requested), std::chrono::milliseconds(10)); - EXPECT_LE((when_expired - when_requested), 2 * std::chrono::milliseconds(10)); + EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); + EXPECT_LE((when_expired - when_requested), 2 * TEN_MILLISECONDS); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( uprotocol::v1::UCode::RESOURCE_EXHAUSTED); @@ -821,7 +825,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; @@ -835,7 +839,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( uprotocol::v1::UCode::FAILED_PRECONDITION); @@ -843,7 +847,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; @@ -863,9 +867,9 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT { auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; @@ -879,12 +883,12 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; @@ -896,7 +900,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); } @@ -904,9 +908,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT /////////////////////////////////////////////////////////////////////////////// // Usecases TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT + constexpr std::chrono::milliseconds TWO_HUNDRED_FIFTY_MILLISECONDS(250); auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(250)); + TWO_HUNDRED_FIFTY_MILLISECONDS); std::list futures; std::listlistener_.value())>> callables; @@ -949,7 +954,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT callables.push_back(getTransport()->listener_.value()); requests.push_back(getTransport()->message_); - auto readyFutures = [&futures]() { + auto ready_futures = [&futures]() { size_t ready = 0; for (auto& future : futures) { auto is_ready = future.wait_for(std::chrono::milliseconds(0)); @@ -961,41 +966,42 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT }; EXPECT_EQ(callback_count, 0); - EXPECT_EQ(readyFutures(), 0); + EXPECT_EQ(ready_futures(), 0); using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; - auto deliverMessage = [&callables](uprotocol::v1::UMessage&& message) { + auto deliver_message = [&callables](const uprotocol::v1::UMessage& message) { for (auto& callable : callables) { - callable(std::move(message)); + callable(message); } }; - deliverMessage(UMessageBuilder::response(requests.front()).build()); - deliverMessage(UMessageBuilder::response(requests.back()).build()); + deliver_message(UMessageBuilder::response(requests.front()).build()); + deliver_message(UMessageBuilder::response(requests.back()).build()); EXPECT_EQ(callback_count, 1); - EXPECT_EQ(readyFutures(), 1); + EXPECT_EQ(ready_futures(), 1); EXPECT_EQ(futures.front().wait_for(std::chrono::milliseconds(0)), std::future_status::ready); requests.pop_front(); requests.pop_back(); - deliverMessage(UMessageBuilder::response(requests.front()).build()); - deliverMessage(UMessageBuilder::response(requests.back()).build()); + deliver_message(UMessageBuilder::response(requests.front()).build()); + deliver_message(UMessageBuilder::response(requests.back()).build()); requests.pop_front(); requests.pop_back(); - deliverMessage(UMessageBuilder::response(requests.front()).build()); - deliverMessage(UMessageBuilder::response(requests.back()).build()); + deliver_message(UMessageBuilder::response(requests.front()).build()); + deliver_message(UMessageBuilder::response(requests.back()).build()); EXPECT_EQ(callback_count, 3); - EXPECT_EQ(readyFutures(), 3); + EXPECT_EQ(ready_futures(), 3); // Intentionally leaving a couple pending requests to discard } TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT - constexpr size_t num_clients = 10; + constexpr std::chrono::milliseconds TWO_HUNDRED_MILLISECONDS(200); + constexpr size_t NUM_CLIENTS = 10; std::vector> clients; @@ -1006,9 +1012,9 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT std::vector expected_order; constexpr auto PER_CLIENT_TTL_INCREMENT = std::chrono::milliseconds(5); - auto client_ttl = std::chrono::milliseconds(200); + auto client_ttl = TWO_HUNDRED_MILLISECONDS; - for (size_t client_id = 0; client_id < num_clients; + for (size_t client_id = 0; client_id < NUM_CLIENTS; ++client_id, client_ttl += PER_CLIENT_TTL_INCREMENT) { auto transport = std::make_shared( defaultSourceUri()); @@ -1047,9 +1053,9 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT std::unique_lock lock(expire_mtx); expire_signal.wait_for(lock, std::chrono::seconds(2), [&expire_order]() { - return expire_order.size() == num_clients; + return expire_order.size() == NUM_CLIENTS; }); - EXPECT_EQ(expire_order.size(), num_clients); + EXPECT_EQ(expire_order.size(), NUM_CLIENTS); EXPECT_TRUE(std::is_sorted(expire_order.begin(), expire_order.end())); EXPECT_EQ(expire_order, expected_order); } @@ -1064,18 +1070,23 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT // first request's expiration time (even though the expirations will be called // in order). TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT + constexpr std::chrono::seconds TEN_SECONDS(10); + constexpr std::chrono::milliseconds TWENTY_FIVE_MILLISECONDS(25); + + constexpr std::chrono::milliseconds ONE_HUNDRED_MILLISECONDS(100); + auto slow_client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::seconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_SECONDS); auto slow_future = slow_client.invokeMethod(); // Waits long enough for the worker to wake and go back to sleep with the // 10s TTL for the slow request as the next scheduled wake time. - auto slow_ready = slow_future.wait_for(std::chrono::milliseconds(100)); + auto slow_ready = slow_future.wait_for(ONE_HUNDRED_MILLISECONDS); EXPECT_EQ(slow_ready, std::future_status::timeout); auto fast_client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(25)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TWENTY_FIVE_MILLISECONDS); auto fast_future = fast_client.invokeMethod(); @@ -1083,7 +1094,7 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT // the request from the slow_client should still be pending for several // more seconds. auto fast_ready = fast_future.wait_for(std::chrono::seconds()); - slow_ready = slow_future.wait_for(std::chrono::milliseconds(100)); + slow_ready = slow_future.wait_for(ONE_HUNDRED_MILLISECONDS); EXPECT_EQ(fast_ready, std::future_status::ready); EXPECT_EQ(slow_ready, std::future_status::timeout); @@ -1092,10 +1103,10 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT // fails. I do not know how this is possible. TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT - constexpr size_t num_clients = 20; + constexpr size_t NUM_CLIENTS = 20; using UTransportMock = uprotocol::test::UTransportMock; - std::array, num_clients> transports; + std::array, NUM_CLIENTS> transports; uint8_t last_authority_octet = 0; for (auto& transport : transports) { @@ -1106,7 +1117,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT transport = std::make_shared(uri); } - std::array timeouts{}; + std::array timeouts{}; constexpr std::chrono::milliseconds TIMEOUT_STEP = std::chrono::milliseconds(7); constexpr std::chrono::milliseconds TIMEOUT_MIN = std::chrono::milliseconds(200); constexpr std::chrono::milliseconds TIMEOUT_MAX = TIMEOUT_MIN + std::chrono::milliseconds(40); @@ -1121,7 +1132,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT std::vector clients; auto loop_init = - std::make_tuple(num_clients, transports.begin(), timeouts.begin()); + std::make_tuple(NUM_CLIENTS, transports.begin(), timeouts.begin()); for (auto [remaining, transport, timeout] = std::move(loop_init); remaining > 0; --remaining, ++transport, ++timeout) { @@ -1133,26 +1144,24 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT clients.push_back(std::move(client)); } - constexpr size_t requests_per_client = 8; - constexpr size_t num_invocations = num_clients * requests_per_client; + constexpr size_t REQUESTS_PER_CLIENT = 8; + constexpr size_t NUM_INVOCATIONS = NUM_CLIENTS * REQUESTS_PER_CLIENT; using PendingEntry = std::tuple; std::vector pending; - std::array client_invoke_count{0}; - - for (size_t remaining = num_invocations; remaining > 0; --remaining) { - const size_t client_index = remaining % num_clients; - ++client_invoke_count[client_index]; - pending.push_back( - {std::chrono::steady_clock::now() + timeouts[client_index], - clients[client_index].invokeMethod()}); + std::array client_invoke_count{0}; + + for (size_t remaining = NUM_INVOCATIONS; remaining > 0; --remaining) { + const size_t client_index = remaining % NUM_CLIENTS; + ++client_invoke_count.at(client_index); + pending.emplace_back(std::chrono::steady_clock::now() + timeouts.at(client_index), + clients[client_index].invokeMethod()); } // Reply to some for (auto& transport : transports) { - using namespace uprotocol::datamodel::builder; - auto reply = UMessageBuilder::response(transport->message_).build(); - transport->mockMessage(std::move(reply)); + auto reply = datamodel::builder::UMessageBuilder::response(transport->message_).build(); + transport->mockMessage(reply); } size_t num_ready = 0; for (auto& request : pending) { @@ -1169,8 +1178,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT EXPECT_EQ(num_ready, transports.size()); // Drop some by discarding the client - constexpr size_t num_discard = 2; - for (auto remaining = num_discard; remaining > 0; --remaining) { + constexpr size_t NUM_DISCARD = 2; + for (auto remaining = NUM_DISCARD; remaining > 0; --remaining) { clients.pop_back(); } size_t num_cancelled = 0; @@ -1185,7 +1194,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT } } // Note: removing two for the two futures already used earlier in the test - EXPECT_EQ(num_cancelled, num_discard * (requests_per_client - 1)); + EXPECT_EQ(num_cancelled, NUM_DISCARD * (REQUESTS_PER_CLIENT - 1)); // Prune all completed requests auto before_clean = pending.size(); @@ -1197,8 +1206,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT EXPECT_EQ(pending.size(), before_clean - num_cancelled - num_ready); // Wait for some to time out - decltype(pending.begin()) pending_middle = - pending.begin() + (pending.size() / 2); + auto pending_middle = + pending.begin() + static_cast((pending.size() / 2)); std::nth_element( pending.begin(), pending_middle, pending.end(), [](const auto& a, const auto& b) { @@ -1245,10 +1254,12 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT } TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT + constexpr std::chrono::milliseconds TWENTY_MILLISECONDS(20); + std::array workers; auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(10)); + getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); constexpr size_t NUM_REQUESTS_PER_WORKER = 10; std::atomic call_count = 0; @@ -1256,7 +1267,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array, workers.size()> handles; - auto worker_handles = handles.begin(); + auto *worker_handles = handles.begin(); for (auto& worker : workers) { worker = std::thread([&call_count, &client, @@ -1275,7 +1286,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT for (int remaining_attempts = 10; remaining_attempts > 0; --remaining_attempts) { - std::this_thread::sleep_for(std::chrono::milliseconds(20)); + std::this_thread::sleep_for(TWENTY_MILLISECONDS); if (call_count == NUM_REQUESTS_PER_WORKER * workers.size()) { break; } @@ -1293,7 +1304,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT defaultSourceUri()); return uprotocol::communication::RpcClient( transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); }; // Repeatedly creates a client, makes a request, then discards the client @@ -1361,12 +1372,12 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT // requests std::atomic self_calls = 0; - auto self_responder = [&self_calls, &get_client]() { + auto self_responder = [&self_calls]() { auto transport = std::make_shared( defaultSourceUri()); auto client = uprotocol::communication::RpcClient( transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(10)); + TEN_MILLISECONDS); for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto handle = @@ -1375,15 +1386,14 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT // in an InvalidUUri exception thrown from a thread. gtest can't // guard for that, so we avoid generating the exception. if (transport->send_count_ > 0) { - using namespace uprotocol::datamodel::builder; auto response = - UMessageBuilder::response(transport->message_).build(); + datamodel::builder::UMessageBuilder::response(transport->message_).build(); transport->mockMessage(response); } } }; - constexpr size_t num_self_responders = 3; - for (auto remaining = num_self_responders; remaining > 0; --remaining) { + constexpr size_t NUM_SELF_RESPONDERS = 3; + for (auto remaining = NUM_SELF_RESPONDERS; remaining > 0; --remaining) { workers.emplace_back(self_responder); } @@ -1396,7 +1406,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT EXPECT_EQ(abandon_calls, 0); EXPECT_EQ(broken_promises, 0); EXPECT_EQ(expire_calls, NUM_REQUESTS_PER_WORKER); - EXPECT_EQ(self_calls, NUM_REQUESTS_PER_WORKER * num_self_responders); + EXPECT_EQ(self_calls, NUM_REQUESTS_PER_WORKER * NUM_SELF_RESPONDERS); } } // namespace uprotocol From ceefdcf980b943fa40ab763cb9a496eb71f459ab Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 15:16:45 +0200 Subject: [PATCH 05/41] Solved linting warnings. Some tests unfortunately fail --- test/coverage/communication/RpcClientTest.cpp | 58 +++++++++----- test/coverage/communication/RpcServerTest.cpp | 80 +++++++++---------- 2 files changed, 76 insertions(+), 62 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 0e0b239c2..bdbdbe02b 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -92,15 +92,30 @@ class RpcClientTest : public testing::Test { } void validateLastRequest(size_t expected_send_count) { + validateTransportProperties(); + validateFilters(); + validateSendCount(expected_send_count); + validateMessage(); + } + + void validateTransportProperties() const { EXPECT_TRUE(transport_->listener_); + } + + void validateFilters() const { EXPECT_TRUE(transport_->source_filter_ == methodUri()); EXPECT_TRUE(transport_->sink_filter_); if (transport_->sink_filter_) { EXPECT_TRUE(*(transport_->sink_filter_) == defaultSourceUri()); } + } + + void validateSendCount(size_t expected_send_count) const { EXPECT_EQ(transport_->send_count_, expected_send_count); - auto [valid_request, _] = - datamodel::validator::message::isValidRpcRequest(transport_->message_); + } + + void validateMessage() const { + auto [valid_request, _] = datamodel::validator::message::isValidRpcRequest(transport_->message_); EXPECT_TRUE(valid_request); } @@ -131,9 +146,7 @@ uprotocol::datamodel::builder::Payload fakePayload() { auto uuid = datamodel::builder::UuidBuilder::getBuilder(); auto uuid_str = datamodel::serializer::uuid::AsString::serialize(uuid.build()); - return datamodel::builder::Payload( - std::move(uuid_str), - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + return { std::move(uuid_str), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT }; } /////////////////////////////////////////////////////////////////////////////// @@ -589,7 +602,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT auto when_requested = std::chrono::steady_clock::now(); uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( [&callback_called, &callback_event](const auto& maybe_response) { callback_called = true; @@ -620,7 +633,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, @@ -641,7 +654,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, @@ -662,7 +675,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); @@ -679,7 +692,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT bool callback_called = false; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( + EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, @@ -690,7 +703,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT auto response_builder = UMessageBuilder::response(getTransport()->message_); response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); } @@ -708,7 +721,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT uprotocol::v1::UMessage received_response; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), [&callback_called, &received_response](auto maybe_response) { @@ -727,7 +740,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -745,7 +758,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT uprotocol::v1::UMessage received_response; uprotocol::communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), [&callback_called, &received_response](auto maybe_response) { @@ -764,7 +777,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); @@ -936,7 +949,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT std::vector handles; int callback_count = 0; - auto callback = [&callback_count](auto) { ++callback_count; }; + auto callback = [&callback_count](const auto&) { ++callback_count; }; handles.push_back(client.invokeMethod(callback)); callables.push_back(getTransport()->listener_.value()); @@ -1254,14 +1267,15 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT } TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT + constexpr size_t NUM_REQUESTS_PER_WORKER = 10; + constexpr std::chrono::milliseconds TWENTY_MILLISECONDS(20); - std::array workers; + std::array workers; auto client = uprotocol::communication::RpcClient( getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - constexpr size_t NUM_REQUESTS_PER_WORKER = 10; std::atomic call_count = 0; std::array, @@ -1275,7 +1289,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT for (auto remaining = NUM_REQUESTS_PER_WORKER; remaining > 0; --remaining) { handles.emplace_back( - client.invokeMethod([&call_count](auto) { ++call_count; })); + client.invokeMethod([&call_count](const auto&) { ++call_count; })); } }); } @@ -1284,7 +1298,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT worker.join(); } - for (int remaining_attempts = 10; remaining_attempts > 0; + for (int remaining_attempts = NUM_REQUESTS_PER_WORKER; remaining_attempts > 0; --remaining_attempts) { std::this_thread::sleep_for(TWENTY_MILLISECONDS); if (call_count == NUM_REQUESTS_PER_WORKER * workers.size()) { @@ -1316,7 +1330,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT remaining_requests > 0; --remaining_requests) { auto client = get_client(); handle = client.invokeMethod( - [&discard_calls](auto) { ++discard_calls; }); + [&discard_calls](const auto&) { ++discard_calls; }); } }); @@ -1381,7 +1395,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto handle = - client.invokeMethod([&self_calls](auto) { ++self_calls; }); + client.invokeMethod([&self_calls](const auto&) { ++self_calls; }); // Attempting this without a request having ever been sent results // in an InvalidUUri exception thrown from a thread. gtest can't // guard for that, so we avoid generating the exception. diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 5bc68c664..556b58ece 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -15,7 +15,6 @@ #include #include -#include #include "UTransportMock.h" @@ -32,23 +31,24 @@ std::string get_random_string(size_t max_len = 32) { size_t len = len_dist(random_gen); std::string retval; retval.reserve(len); - for (size_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { retval += static_cast(char_dist(random_gen)); +} return retval; } std::optional RpcCallbackNoReturn( - const uprotocol::v1::UMessage& message) { + const uprotocol::v1::UMessage& /*message*/) { return std::nullopt; } std::optional RpcCallbackWithReturn( - const uprotocol::v1::UMessage& message) { + const uprotocol::v1::UMessage& /*message*/) { uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - std::string responseData = "RPC Response"; + std::string response_data = "RPC Response"; - uprotocol::datamodel::builder::Payload payload(responseData, format); + uprotocol::datamodel::builder::Payload payload(response_data, format); return payload; } @@ -118,18 +118,18 @@ TEST_F(TestRpcServer, ConstructorValidParams) { RpcCallbackNoReturn; // Attempt to create an RpcServer instance with valid parameters - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback)); // Ensure that the server creation was successful - ASSERT_TRUE(serverOrStatus.has_value()); + ASSERT_TRUE(server_or_status.has_value()); // Obtain a pointer to the created RpcServer instance - auto& serverPtr = serverOrStatus.value(); + const auto& server_ptr = server_or_status.value(); // Verify that the server pointer is not null, indicating successful // creation - ASSERT_NE(serverPtr, nullptr); + ASSERT_NE(server_ptr, nullptr); } // Null transport @@ -141,7 +141,7 @@ TEST_F(TestRpcServer, CreateWithNullTransport) { auto transport = nullptr; // Attempt to create an RpcServer instance with valid parameters EXPECT_THROW( - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( transport, *method_uri_, std::move(callback)), uprotocol::transport::NullTransport); } @@ -154,19 +154,19 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // Attempt to create an RpcServer instance with the provided callback and a // specific format - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format); // Ensure the server creation was successful and a valid instance was // returned - ASSERT_TRUE(serverOrStatus.has_value()); + ASSERT_TRUE(server_or_status.has_value()); // Retrieve the server instance from the optional return value - auto& serverPtr = serverOrStatus.value(); + const auto& server_ptr = server_or_status.value(); // Verify that the server instance is not null, indicating successful // creation - ASSERT_NE(serverPtr, nullptr); + ASSERT_NE(server_ptr, nullptr); } // Test to ensure RpcServer can be constructed with both a specific payload @@ -179,19 +179,19 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // Attempt to create an RpcServer instance with additional parameters: // payload format and TTL - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format, ttl_); // Verify that the server creation was successful and a valid instance was // returned - ASSERT_TRUE(serverOrStatus.has_value()); + ASSERT_TRUE(server_or_status.has_value()); // Retrieve the server instance from the optional return value - auto& serverPtr = serverOrStatus.value(); + const auto& server_ptr = server_or_status.value(); // Ensure that the server instance is not null, indicating successful // creation - ASSERT_NE(serverPtr, nullptr); + ASSERT_NE(server_ptr, nullptr); } // Test to verify RpcServer construction fails with invalid URI @@ -208,16 +208,16 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // Attempt to create an RpcServer instance with the invalid URI and verify // creation fails - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, invalid_uri, std::move(callback)); // Define the expected error code for this operation - uprotocol::v1::UCode expectedCode = uprotocol::v1::UCode::INVALID_ARGUMENT; + uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::INVALID_ARGUMENT; // Verify that the error code matches the expected error code for invalid // arguments - EXPECT_EQ(serverOrStatus.error().code(), expectedCode); - EXPECT_EQ(serverOrStatus.error().message(), error_message); + EXPECT_EQ(server_or_status.error().code(), expected_code); + EXPECT_EQ(server_or_status.error().message(), error_message); } // Test to verify RpcServer construction fails with invalid PaylodFormat @@ -235,16 +235,16 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // Attempt to create an RpcServer instance with the invalid PaylodFormat and // verify creation fails - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), invalid_format); // Define the expected error code for this operation - uprotocol::v1::UCode expectedCode = uprotocol::v1::UCode::OUT_OF_RANGE; + uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::OUT_OF_RANGE; // Verify that the error code matches the expected error code for invalid // arguments - EXPECT_EQ(serverOrStatus.error().code(), expectedCode); - EXPECT_EQ(serverOrStatus.error().message(), error_message); + EXPECT_EQ(server_or_status.error().code(), expected_code); + EXPECT_EQ(server_or_status.error().message(), error_message); } // Test case to verify successful connection with a valid handle @@ -254,15 +254,15 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { RpcCallbackWithReturn; // Attempt to create an RpcServer instance with mockTransport_ - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format); // Check if the RpcServer was successfully created and a valid handle was // returned - EXPECT_TRUE(serverOrStatus.has_value()); + EXPECT_TRUE(server_or_status.has_value()); - // Retrieve the handle from the serverOrStatus object - auto& handle = serverOrStatus.value(); + // Retrieve the handle from the server_or_status object + const auto& handle = server_or_status.value(); // Ensure that the handle is not null, indicating successful server creation EXPECT_NE(handle, nullptr); @@ -281,11 +281,11 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { RpcCallbackWithReturn; // Create a server to offer the RPC method - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format, ttl_); // Check if the server was created successfully - auto& handle = serverOrStatus.value(); + const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); EXPECT_TRUE(MsgDiff::Equals(*method_uri_, *mockTransport_->sink_filter_)); @@ -337,11 +337,11 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { RpcCallbackNoReturn; // Create a server to offer the RPC method - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback)); // Check if the server was created successfully - auto& handle = serverOrStatus.value(); + const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); EXPECT_TRUE(MsgDiff::Equals(*method_uri_, *mockTransport_->sink_filter_)); @@ -387,11 +387,11 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { RpcCallbackWithReturn; // Create a server to offer the RPC method - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format, ttl_); // Check if the server was created successfully - auto& handle = serverOrStatus.value(); + const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); // Create request umessage @@ -418,12 +418,12 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { RpcCallbackWithReturn; { - auto serverOrStatus = uprotocol::communication::RpcServer::create( + auto server_or_status = uprotocol::communication::RpcServer::create( mockTransport_, *method_uri_, std::move(callback), format); - EXPECT_TRUE(serverOrStatus.has_value()); + EXPECT_TRUE(server_or_status.has_value()); - auto& handle = serverOrStatus.value(); + const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); } From 59c8a63137eef9395d3a4193413dc4bc6c5e4778 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 15:37:44 +0200 Subject: [PATCH 06/41] Fixed 1 test fail --- test/coverage/communication/RpcClientTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index bdbdbe02b..67652c8ad 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1085,7 +1085,6 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT constexpr std::chrono::seconds TEN_SECONDS(10); constexpr std::chrono::milliseconds TWENTY_FIVE_MILLISECONDS(25); - constexpr std::chrono::milliseconds ONE_HUNDRED_MILLISECONDS(100); auto slow_client = uprotocol::communication::RpcClient( @@ -1106,12 +1105,13 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT // The request from the fast_client should expire within about 25ms, but // the request from the slow_client should still be pending for several // more seconds. - auto fast_ready = fast_future.wait_for(std::chrono::seconds()); + auto fast_ready = fast_future.wait_for(std::chrono::seconds(1)); slow_ready = slow_future.wait_for(ONE_HUNDRED_MILLISECONDS); EXPECT_EQ(fast_ready, std::future_status::ready); EXPECT_EQ(slow_ready, std::future_status::timeout); } + // NOTE: for some reason, when the above test fails, the _next_ test also // fails. I do not know how this is possible. From d6a582e6ae61b861a9b39f2de3b2e092d562a417 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 16:24:04 +0200 Subject: [PATCH 07/41] Solved failing tests. Next step is to fix linter warnings on RpcServerTest.cpp --- test/coverage/communication/NotificationSourceTest.cpp | 2 +- test/coverage/communication/PublisherTest.cpp | 2 +- test/coverage/communication/RpcClientTest.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index feee80f57..09a9bcc79 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -72,7 +72,7 @@ class TestNotificationSource : public testing::Test { uprotocol::v1::UUri getSource() const { return source_; } uprotocol::v1::UUri getSink() const { return sink_; } uprotocol::v1::UPayloadFormat getFormat() const { return format_; } - std::optional getPriority() const { return priority_; } + std::optional& getPriority() { return priority_; } std::optional getTTL() const { return ttl_; } void setTransportMock(const std::shared_ptr& transport_mock) { transportMock_ = transport_mock; } diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 60dc91f30..ab4400d42 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -35,7 +35,7 @@ class TestPublisher : public testing::Test { v1::UUri getSource() const { return source_; } v1::UUri getTopic() const { return topic_; } v1::UPayloadFormat getFormat() const { return format_; } - std::optional getPriority() const { return priority_; } + std::optional& getPriority() { return priority_; } std::optional getTTL() const { return ttl_; } uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 67652c8ad..38d5c581e 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1364,7 +1364,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT futures.emplace_back(client.invokeMethod()); } for (auto& future : futures) { - auto is_ready = future.wait_for(std::chrono::seconds()); + auto is_ready = future.wait_for(std::chrono::seconds(1)); if (is_ready == std::future_status::ready) { try { auto maybe_response = future.get(); From 43e261063412d395bdef3ab1a715a57f529ecfdd Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 8 Apr 2025 16:36:22 +0200 Subject: [PATCH 08/41] Finish day 2025_04_08. Continue with RpcServerTest.cpp --- test/coverage/communication/RpcServerTest.cpp | 140 ++++++++++-------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 556b58ece..244ad2479 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -54,20 +54,30 @@ std::optional RpcCallbackWithReturn( } class TestRpcServer : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. +private: std::shared_ptr mockTransport_; std::shared_ptr method_uri_; std::shared_ptr request_uri_; - std::chrono::milliseconds ttl_; - uprotocol::v1::UPayloadFormat format; + std::chrono::milliseconds ttl_ = std::chrono::milliseconds(1000); + uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - void SetUp() override { - // Set up default values for the test - ttl_ = std::chrono::milliseconds(1000); - format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; +protected: + // Run once per TEST_F. + // Used to set up clean environments per test. + + std::shared_ptr getMockTransport() const { return mockTransport_; } + std::shared_ptr getMethodUri() const { return method_uri_; } + std::shared_ptr getRequestUri() const { return request_uri_; } + std::chrono::milliseconds getTTL() const { return ttl_; } + uprotocol::v1::UPayloadFormat getFormat() const { return format; } + + void setMockTransport(const std::shared_ptr& mock_transport) { mockTransport_ = mock_transport; } + void setMethodUri(const std::shared_ptr& method_uri) { method_uri_ = method_uri; } + void setRequestUri(const std::shared_ptr& request_uri) { request_uri_ = request_uri; } + void setTTL(const std::chrono::milliseconds& ttl) { ttl_ = ttl; } + void setFormat(uprotocol::v1::UPayloadFormat format) { this->format = format; } + void SetUp() override { // Set up a transport URI uprotocol::v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); @@ -102,12 +112,14 @@ class TestRpcServer : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestRpcServer() = default; - ~TestRpcServer() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + +public: + ~TestRpcServer() override = default; }; // Test to ensure RpcServer constructor initializes correctly with valid @@ -119,7 +131,7 @@ TEST_F(TestRpcServer, ConstructorValidParams) { // Attempt to create an RpcServer instance with valid parameters auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback)); + getMockTransport(), *getMethodUri(), std::move(callback)); // Ensure that the server creation was successful ASSERT_TRUE(server_or_status.has_value()); @@ -142,7 +154,7 @@ TEST_F(TestRpcServer, CreateWithNullTransport) { // Attempt to create an RpcServer instance with valid parameters EXPECT_THROW( auto server_or_status = uprotocol::communication::RpcServer::create( - transport, *method_uri_, std::move(callback)), + transport, *getMethodUri(), std::move(callback)), uprotocol::transport::NullTransport); } @@ -155,7 +167,7 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // Attempt to create an RpcServer instance with the provided callback and a // specific format auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); // Ensure the server creation was successful and a valid instance was // returned @@ -180,7 +192,7 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // Attempt to create an RpcServer instance with additional parameters: // payload format and TTL auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format, ttl_); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Verify that the server creation was successful and a valid instance was // returned @@ -209,7 +221,7 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // Attempt to create an RpcServer instance with the invalid URI and verify // creation fails auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, invalid_uri, std::move(callback)); + getMockTransport(), invalid_uri, std::move(callback)); // Define the expected error code for this operation uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::INVALID_ARGUMENT; @@ -236,7 +248,7 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // Attempt to create an RpcServer instance with the invalid PaylodFormat and // verify creation fails auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), invalid_format); + getMockTransport(), *getMethodUri(), std::move(callback), invalid_format); // Define the expected error code for this operation uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::OUT_OF_RANGE; @@ -255,7 +267,7 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { // Attempt to create an RpcServer instance with mockTransport_ auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); // Check if the RpcServer was successfully created and a valid handle was // returned @@ -268,7 +280,7 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { EXPECT_NE(handle, nullptr); // Verify that the register listener uri mataches with input method uri - EXPECT_TRUE(MsgDiff::Equals(*method_uri_, *mockTransport_->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); } // Test case to verify RPC request handling with return payload and TTL @@ -282,51 +294,51 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // Create a server to offer the RPC method auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format, ttl_); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Check if the server was created successfully const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*method_uri_, *mockTransport_->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); // Create request umessage auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( - std::move(*method_uri_), std::move(*request_uri_), - uprotocol::v1::UPriority::UPRIORITY_CS5, ttl_); + std::move(*getMethodUri()), std::move(*getRequestUri()), + uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); // Ignore the return value - auto _ = mockTransport_->send(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 1); - EXPECT_TRUE(mockTransport_->listener_); - mockTransport_->mockMessage(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 2); + auto _ = getMockTransport()->send(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 1); + EXPECT_TRUE(getMockTransport()->listener_); + getMockTransport()->mockMessage(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 2); // Compare expected reposen message with actual response message auto expected_response_msg = uprotocol::datamodel::builder::UMessageBuilder::response(msg) - .withTtl(ttl_) - .withPayloadFormat(format) - .build({expected_response_payload, format}); + .withTtl(getTTL()) + .withPayloadFormat(getFormat()) + .build({expected_response_payload, getFormat()}); EXPECT_TRUE( MsgDiff::Equals(expected_response_msg.attributes().source(), - mockTransport_->message_.attributes().source())); + getMockTransport()->message_.attributes().source())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - mockTransport_->message_.attributes().sink())); + getMockTransport()->message_.attributes().sink())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - mockTransport_->message_.attributes().reqid())); + getMockTransport()->message_.attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(mockTransport_->message_.attributes().type())); + static_cast(getMockTransport()->message_.attributes().type())); EXPECT_EQ(static_cast(expected_response_msg.attributes().ttl()), - static_cast(mockTransport_->message_.attributes().ttl())); + static_cast(getMockTransport()->message_.attributes().ttl())); EXPECT_EQ( static_cast(expected_response_msg.attributes().priority()), - static_cast(mockTransport_->message_.attributes().priority())); - EXPECT_EQ(mockTransport_->message_.payload().data(), + static_cast(getMockTransport()->message_.attributes().priority())); + EXPECT_EQ(getMockTransport()->message_.payload().data(), expected_response_payload); } @@ -338,27 +350,27 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // Create a server to offer the RPC method auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback)); + getMockTransport(), *getMethodUri(), std::move(callback)); // Check if the server was created successfully const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*method_uri_, *mockTransport_->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); // Create request umessage auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( - std::move(*method_uri_), std::move(*request_uri_), - uprotocol::v1::UPriority::UPRIORITY_CS5, ttl_); + std::move(*getMethodUri()), std::move(*getRequestUri()), + uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); // Ignore the return value - auto _ = mockTransport_->send(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 1); - EXPECT_TRUE(mockTransport_->listener_); - mockTransport_->mockMessage(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 2); + auto _ = getMockTransport()->send(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 1); + EXPECT_TRUE(getMockTransport()->listener_); + getMockTransport()->mockMessage(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 2); // Compare expected reposen message with actual response message auto expected_response_msg = @@ -366,18 +378,18 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { EXPECT_TRUE( MsgDiff::Equals(expected_response_msg.attributes().source(), - mockTransport_->message_.attributes().source())); + getMockTransport()->message_.attributes().source())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - mockTransport_->message_.attributes().sink())); + getMockTransport()->message_.attributes().sink())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - mockTransport_->message_.attributes().reqid())); + getMockTransport()->message_.attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(mockTransport_->message_.attributes().type())); + static_cast(getMockTransport()->message_.attributes().type())); EXPECT_EQ( static_cast(expected_response_msg.attributes().priority()), - static_cast(mockTransport_->message_.attributes().priority())); - EXPECT_FALSE(mockTransport_->message_.has_payload()); + static_cast(getMockTransport()->message_.attributes().priority())); + EXPECT_FALSE(getMockTransport()->message_.has_payload()); } // Test case to verify RPC request handling with invalid request @@ -388,7 +400,7 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Create a server to offer the RPC method auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format, ttl_); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Check if the server was created successfully const auto& handle = server_or_status.value(); @@ -397,7 +409,7 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Create request umessage using namespace std::chrono_literals; auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( - std::move(*method_uri_), std::move(*request_uri_), + std::move(*getMethodUri()), std::move(*getRequestUri()), uprotocol::v1::UPriority::UPRIORITY_CS5, 300ms); auto msg = builder.build(); @@ -406,9 +418,9 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { msg.mutable_attributes()->mutable_sink()->set_resource_id(0); // Check results when invalid request is received - EXPECT_TRUE(mockTransport_->listener_); - mockTransport_->mockMessage(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 0); + EXPECT_TRUE(getMockTransport()->listener_); + getMockTransport()->mockMessage(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 0); } // Test case to verify RPC sever resets the listener when the server is @@ -419,7 +431,7 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { { auto server_or_status = uprotocol::communication::RpcServer::create( - mockTransport_, *method_uri_, std::move(callback), format); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); EXPECT_TRUE(server_or_status.has_value()); @@ -429,17 +441,17 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { // Create request umessage auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( - std::move(*method_uri_), std::move(*request_uri_), - uprotocol::v1::UPriority::UPRIORITY_CS5, ttl_); + std::move(*getMethodUri()), std::move(*getRequestUri()), + uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); // Ignore the return value - auto _ = mockTransport_->send(msg); - EXPECT_TRUE(mockTransport_->send_count_ == 1); - mockTransport_->mockMessage(msg); + auto _ = getMockTransport()->send(msg); + EXPECT_TRUE(getMockTransport()->send_count_ == 1); + getMockTransport()->mockMessage(msg); // Check if the listener is reset - EXPECT_FALSE(mockTransport_->send_count_ == 2); + EXPECT_FALSE(getMockTransport()->send_count_ == 2); } } // namespace From 7bc68ef323b8b87f9c51cc7375c160cc89d58f9c Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 9 Apr 2025 09:35:57 +0200 Subject: [PATCH 09/41] Solved few warnings --- test/coverage/communication/RpcClientTest.cpp | 4 +-- test/coverage/communication/RpcServerTest.cpp | 29 ++++++++++++------- .../coverage/communication/SubscriberTest.cpp | 7 ++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 38d5c581e..6a5ffe50e 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -27,6 +27,8 @@ constexpr std::chrono::milliseconds TEN_MILLISECONDS(10); constexpr std::chrono::milliseconds ONE_HUNDRED_FIFTY_MILLISECONDS(150); constexpr uint32_t SHIFT_AMOUNT = 16; +namespace uprotocol{ + bool operator==(const uprotocol::v1::UUri& lhs, const uprotocol::v1::UUri& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); @@ -42,8 +44,6 @@ bool operator==(const uprotocol::v1::UStatus& lhs, return lhs.code() == rhs; } -namespace uprotocol{ - class RpcClientTest : public testing::Test { private: std::shared_ptr transport_; diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 244ad2479..875f115fc 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -18,17 +18,19 @@ #include "UTransportMock.h" +constexpr size_t MAX_LEN_RANDOM_STRING = 32; + namespace { using MsgDiff = google::protobuf::util::MessageDifferencer; -static std::random_device random_dev; -static std::mt19937 random_gen(random_dev()); -static std::uniform_int_distribution char_dist('A', 'z'); +std::string get_random_string(size_t max_len = MAX_LEN_RANDOM_STRING) { + std::random_device random_dev; + std::mt19937 random_gen(random_dev()); + std::uniform_int_distribution char_dist('A', 'z'); -std::string get_random_string(size_t max_len = 32) { std::uniform_int_distribution len_dist(1, static_cast(max_len)); - size_t len = len_dist(random_gen); + auto len = static_cast(len_dist(random_gen)); std::string retval; retval.reserve(len); for (size_t i = 0; i < len; i++) { @@ -55,10 +57,11 @@ std::optional RpcCallbackWithReturn( class TestRpcServer : public testing::Test { private: + static constexpr uint16_t DEFAULT_TTL_TIME = 1000; std::shared_ptr mockTransport_; std::shared_ptr method_uri_; std::shared_ptr request_uri_; - std::chrono::milliseconds ttl_ = std::chrono::milliseconds(1000); + std::chrono::milliseconds ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; protected: @@ -78,10 +81,14 @@ class TestRpcServer : public testing::Test { void setFormat(uprotocol::v1::UPayloadFormat format) { this->format = format; } void SetUp() override { + constexpr uint32_t DEF_UE_ID = 0x18000; + constexpr uint32_t METHOD_UE_ID = 0x00010002; + constexpr uint32_t REQUEST_UE_ID = 0x00010001; + // Set up a transport URI uprotocol::v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); - def_src_uuri.set_ue_id(0x18000); + def_src_uuri.set_ue_id(DEF_UE_ID); def_src_uuri.set_ue_version_major(1); def_src_uuri.set_resource_id(0); @@ -92,14 +99,14 @@ class TestRpcServer : public testing::Test { // Set up a method URI method_uri_ = std::make_shared(); method_uri_->set_authority_name("10.0.0.2"); - method_uri_->set_ue_id(0x00010002); + method_uri_->set_ue_id(METHOD_UE_ID); method_uri_->set_ue_version_major(2); method_uri_->set_resource_id(0x2); // Create a src uri of entity request_uri_ = std::make_shared(); request_uri_->set_authority_name("10.0.0.1"); - request_uri_->set_ue_id(0x00010001); + request_uri_->set_ue_id(REQUEST_UE_ID); request_uri_->set_ue_version_major(1); request_uri_->set_resource_id(0x0); } @@ -234,8 +241,10 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // Test to verify RpcServer construction fails with invalid PaylodFormat TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { + constexpr uint16_t INVALID_PAYLOADFORMAT = 9999; + // Create an invalid PaylodFormat to simulate invalid input parameters - auto invalid_format = static_cast(9999); + auto invalid_format = static_cast(INVALID_PAYLOADFORMAT); // Expecte error message const std::string error_message = "Invalid payload format"; diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index c5f8414cc..ee399a2cf 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -13,15 +13,14 @@ #include #include -#include #include #include "UTransportMock.h" #include "up-cpp/datamodel/validator/UUri.h" -namespace { +namespace uprotocol{ using MsgDiff = google::protobuf::util::MessageDifferencer; -using namespace uprotocol::communication; +// using namespace uprotocol::communication; using namespace uprotocol::test; namespace UriValidator = uprotocol::datamodel::validator::uri; @@ -203,4 +202,4 @@ TEST_F(SubscriberTest, SubscribeNullCallback) { EXPECT_THROW(test_subscribe_empty(), callbacks::EmptyFunctionObject); } -} // namespace +} // namespace uprotocol From 9340df2c9ad34a54a76a7a2f497daf4575e9de0d Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 9 Apr 2025 10:10:39 +0200 Subject: [PATCH 10/41] Solved linter warnings in test/communication/ --- test/coverage/communication/RpcClientTest.cpp | 412 +++++++++--------- test/coverage/communication/RpcServerTest.cpp | 124 +++--- .../coverage/communication/SubscriberTest.cpp | 124 +++--- 3 files changed, 341 insertions(+), 319 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 6a5ffe50e..420b72794 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -29,29 +29,29 @@ constexpr uint32_t SHIFT_AMOUNT = 16; namespace uprotocol{ -bool operator==(const uprotocol::v1::UUri& lhs, - const uprotocol::v1::UUri& rhs) { +bool operator==(const v1::UUri& lhs, + const v1::UUri& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -bool operator==(const uprotocol::v1::UMessage& lhs, - const uprotocol::v1::UMessage& rhs) { +bool operator==(const v1::UMessage& lhs, + const v1::UMessage& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -bool operator==(const uprotocol::v1::UStatus& lhs, - const uprotocol::v1::UCode& rhs) { +bool operator==(const v1::UStatus& lhs, + const v1::UCode& rhs) { return lhs.code() == rhs; } class RpcClientTest : public testing::Test { private: - std::shared_ptr transport_; + std::shared_ptr transport_; protected: // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { - transport_ = std::make_shared( + transport_ = std::make_shared( defaultSourceUri()); } @@ -71,12 +71,12 @@ class RpcClientTest : public testing::Test { google::protobuf::ShutdownProtobufLibrary(); } - static uprotocol::v1::UUri methodUri(const std::string& auth = "TestAuth", + static v1::UUri methodUri(const std::string& auth = "TestAuth", uint16_t ue_id = 0x8000, uint16_t ue_instance = 1, // NOLINT uint16_t ue_version_major = 1, uint16_t resource_id = 1) { - uprotocol::v1::UUri uri; + v1::UUri uri; uri.set_authority_name(auth); uri.set_ue_id(static_cast(ue_instance) << SHIFT_AMOUNT | static_cast(ue_id)); @@ -85,7 +85,7 @@ class RpcClientTest : public testing::Test { return uri; } - static uprotocol::v1::UUri defaultSourceUri() { + static v1::UUri defaultSourceUri() { auto uri = methodUri(); uri.set_resource_id(0); return uri; @@ -119,10 +119,10 @@ class RpcClientTest : public testing::Test { EXPECT_TRUE(valid_request); } - [[nodiscard]] std::shared_ptr getTransport() const { + [[nodiscard]] std::shared_ptr getTransport() const { return transport_; } - void setTransport(const std::shared_ptr& transport) { + void setTransport(const std::shared_ptr& transport) { transport_ = transport; } @@ -132,7 +132,7 @@ class RpcClientTest : public testing::Test { template void checkErrorResponse( - const uprotocol::communication::RpcClient::MessageOrStatus& maybe_response, + const communication::RpcClient::MessageOrStatus& maybe_response, ExpectedT expected_status) { EXPECT_FALSE(maybe_response); if (!maybe_response) { @@ -141,73 +141,73 @@ void checkErrorResponse( } } -uprotocol::datamodel::builder::Payload fakePayload() { +datamodel::builder::Payload fakePayload() { auto uuid = datamodel::builder::UuidBuilder::getBuilder(); auto uuid_str = datamodel::serializer::uuid::AsString::serialize(uuid.build()); - return { std::move(uuid_str), uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT }; + return { std::move(uuid_str), v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT }; } /////////////////////////////////////////////////////////////////////////////// // Construction TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT // Base parameters - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS);); + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS);); // Optional format - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON);); + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON);); // Optional permission level - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, 9);); + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, 9);); // Optional permission level - EXPECT_NO_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, {}, + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, {}, "Some token");); } TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLINT // Bad method URI EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); // NOLINT - auto client = uprotocol::communication::RpcClient( + auto client = communication::RpcClient( getTransport(), std::move(uri), - uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - , uprotocol::datamodel::validator::uri::InvalidUUri); + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + , datamodel::validator::uri::InvalidUUri); // Bad priority - EXPECT_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS3, TEN_MILLISECONDS); + v1::UPriority::UPRIORITY_CS3, TEN_MILLISECONDS); , std::out_of_range); // Bad ttl - EXPECT_THROW(auto client = uprotocol::communication::RpcClient( // NOLINT + EXPECT_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - uprotocol::v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(0)); + v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(0)); , std::out_of_range); // Bad payload format EXPECT_THROW( // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS, static_cast(-1)); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, static_cast(-1)); , std::out_of_range); } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod() TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT @@ -216,7 +216,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT validateLastRequest(1); EXPECT_TRUE(getTransport()->message_.payload().empty()); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -232,21 +232,21 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(), - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); @@ -263,16 +263,16 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::DEADLINE_EXCEEDED); + v1::UCode::DEADLINE_EXCEEDED); } } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT @@ -285,16 +285,16 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); } } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT @@ -306,16 +306,16 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); } } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT - uprotocol::communication::RpcClient::InvokeFuture invoke_future; + communication::RpcClient::InvokeFuture invoke_future; { - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT @@ -328,20 +328,20 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT if (is_ready == std::future_status::ready) { EXPECT_NO_THROW(auto maybe_response = invoke_future.get(); // NOLINT checkErrorResponse(maybe_response, - uprotocol::v1::UCode::CANCELLED);); + v1::UCode::CANCELLED);); } } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); - response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); + response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -352,15 +352,15 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::PERMISSION_DENIED); + v1::UCode::PERMISSION_DENIED); } } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload) TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -370,13 +370,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); - using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; + using PayloadField = datamodel::builder::Payload::PayloadType; EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -392,9 +392,9 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT } TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -404,13 +404,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); - using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; + using PayloadField = datamodel::builder::Payload::PayloadType; EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -426,21 +426,21 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT } TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(fakePayload()), - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); @@ -457,16 +457,16 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::DEADLINE_EXCEEDED); + v1::UCode::DEADLINE_EXCEEDED); } } TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT @@ -479,16 +479,16 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); } } TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT @@ -500,16 +500,16 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); } } TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT - uprotocol::communication::RpcClient::InvokeFuture invoke_future; + communication::RpcClient::InvokeFuture invoke_future; { - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT @@ -521,20 +521,20 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); } } TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); - response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); + response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -545,20 +545,20 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, - uprotocol::v1::UCode::PERMISSION_DENIED); + v1::UCode::PERMISSION_DENIED); } } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Callback) TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; - uprotocol::v1::UMessage received_response; + v1::UMessage received_response; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( [&callback_called, &received_response](auto maybe_response) { @@ -570,7 +570,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT validateLastRequest(1); EXPECT_TRUE(getTransport()->message_.payload().empty()); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -580,34 +580,34 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_THROW( // NOLINT handle = client.invokeMethod([](auto) {}), - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; auto when_requested = std::chrono::steady_clock::now(); - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( [&callback_called, &callback_event](const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::DEADLINE_EXCEEDED); + v1::UCode::DEADLINE_EXCEEDED); callback_event.notify_all(); })); @@ -624,20 +624,20 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); })); EXPECT_EQ(getTransport()->send_count_, 0); @@ -645,40 +645,40 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); })); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT - uprotocol::communication::RpcClient::InvokeFuture invoke_future; + communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; { - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; - checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); })); } @@ -686,22 +686,22 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT const auto& maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::PERMISSION_DENIED); + v1::UCode::PERMISSION_DENIED); })); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); - response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); + response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -711,16 +711,16 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload, Callback) TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); bool callback_called = false; - uprotocol::v1::UMessage received_response; + v1::UMessage received_response; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), @@ -731,13 +731,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT })); validateLastRequest(1); - using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; + using PayloadField = datamodel::builder::Payload::PayloadType; EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -747,17 +747,17 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); bool callback_called = false; - uprotocol::v1::UMessage received_response; + v1::UMessage received_response; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), @@ -768,13 +768,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT })); validateLastRequest(1); - using PayloadField = uprotocol::datamodel::builder::Payload::PayloadType; + using PayloadField = datamodel::builder::Payload::PayloadType; EXPECT_EQ(getTransport()->message_.payload(), std::get(payload_content)); EXPECT_EQ(getTransport()->message_.attributes().payload_format(), std::get(payload_content)); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -784,27 +784,27 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, + v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_THROW( // NOLINT handle = client.invokeMethod(fakePayload(), [](auto) {}), - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); EXPECT_EQ(getTransport()->send_count_, 0); EXPECT_FALSE(getTransport()->listener_); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; auto when_requested = std::chrono::steady_clock::now(); EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( @@ -812,7 +812,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT [&callback_called, &callback_event](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::DEADLINE_EXCEEDED); + v1::UCode::DEADLINE_EXCEEDED); callback_event.notify_all(); })); @@ -829,21 +829,21 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->registerListener_status_.set_code( - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::RESOURCE_EXHAUSTED); + v1::UCode::RESOURCE_EXHAUSTED); })); EXPECT_EQ(getTransport()->send_count_, 0); @@ -851,35 +851,35 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); getTransport()->send_status_.set_code( - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::FAILED_PRECONDITION); + v1::UCode::FAILED_PRECONDITION); })); EXPECT_TRUE(callback_called); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT - uprotocol::communication::RpcClient::InvokeFuture invoke_future; + communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; { - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); EXPECT_NO_THROW( // NOLINT @@ -887,7 +887,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::CANCELLED); + v1::UCode::CANCELLED); })); } @@ -895,23 +895,23 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT } TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); bool callback_called = false; - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; checkErrorResponse(maybe_response, - uprotocol::v1::UCode::PERMISSION_DENIED); + v1::UCode::PERMISSION_DENIED); })); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = UMessageBuilder::response(getTransport()->message_); - response_builder.withCommStatus(uprotocol::v1::UCode::PERMISSION_DENIED); + response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -922,13 +922,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT // Usecases TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT constexpr std::chrono::milliseconds TWO_HUNDRED_FIFTY_MILLISECONDS(250); - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TWO_HUNDRED_FIFTY_MILLISECONDS); std::list futures; std::listlistener_.value())>> callables; - std::list requests; + std::list requests; futures.push_back(client.invokeMethod()); callables.push_back(getTransport()->listener_.value()); @@ -946,7 +946,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT callables.push_back(getTransport()->listener_.value()); requests.push_back(getTransport()->message_); - std::vector handles; + std::vector handles; int callback_count = 0; auto callback = [&callback_count](const auto&) { ++callback_count; }; @@ -981,9 +981,9 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT EXPECT_EQ(callback_count, 0); EXPECT_EQ(ready_futures(), 0); - using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; + using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto deliver_message = [&callables](const uprotocol::v1::UMessage& message) { + auto deliver_message = [&callables](const v1::UMessage& message) { for (auto& callable : callables) { callable(message); } @@ -1015,7 +1015,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT constexpr std::chrono::milliseconds TWO_HUNDRED_MILLISECONDS(200); constexpr size_t NUM_CLIENTS = 10; - std::vector> + std::vector> clients; std::mutex expire_mtx; @@ -1029,19 +1029,19 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT for (size_t client_id = 0; client_id < NUM_CLIENTS; ++client_id, client_ttl += PER_CLIENT_TTL_INCREMENT) { - auto transport = std::make_shared( + auto transport = std::make_shared( defaultSourceUri()); clients.emplace_back(std::make_tuple( client_id, - uprotocol::communication::RpcClient( - transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + communication::RpcClient( + transport, methodUri(), v1::UPriority::UPRIORITY_CS4, client_ttl))); expected_order.push_back(client_id); } - std::vector pending; + std::vector pending; for (auto entry = clients.rbegin(); entry != clients.rend(); ++entry) { auto client_id = std::get<0>(*entry); @@ -1053,7 +1053,7 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT if (!maybe_response) { const auto& some_status = maybe_response.error(); if (some_status.code() != - uprotocol::v1::UCode::DEADLINE_EXCEEDED) { + v1::UCode::DEADLINE_EXCEEDED) { return; } std::lock_guard lock(expire_mtx); @@ -1087,8 +1087,8 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT constexpr std::chrono::milliseconds TWENTY_FIVE_MILLISECONDS(25); constexpr std::chrono::milliseconds ONE_HUNDRED_MILLISECONDS(100); - auto slow_client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_SECONDS); + auto slow_client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_SECONDS); auto slow_future = slow_client.invokeMethod(); @@ -1097,8 +1097,8 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT auto slow_ready = slow_future.wait_for(ONE_HUNDRED_MILLISECONDS); EXPECT_EQ(slow_ready, std::future_status::timeout); - auto fast_client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TWENTY_FIVE_MILLISECONDS); + auto fast_client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TWENTY_FIVE_MILLISECONDS); auto fast_future = fast_client.invokeMethod(); @@ -1118,7 +1118,7 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT constexpr size_t NUM_CLIENTS = 20; - using UTransportMock = uprotocol::test::UTransportMock; + using UTransportMock = test::UTransportMock; std::array, NUM_CLIENTS> transports; uint8_t last_authority_octet = 0; @@ -1142,7 +1142,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT TIMEOUT_MIN; } - std::vector clients; + std::vector clients; auto loop_init = std::make_tuple(NUM_CLIENTS, transports.begin(), timeouts.begin()); @@ -1151,9 +1151,9 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT remaining > 0; --remaining, ++transport, ++timeout) { auto method_uri = (*transport)->getDefaultSource(); method_uri.set_resource_id(methodUri().resource_id()); - uprotocol::communication::RpcClient client( + communication::RpcClient client( *transport, std::move(method_uri), - uprotocol::v1::UPriority::UPRIORITY_CS4, *timeout); + v1::UPriority::UPRIORITY_CS4, *timeout); clients.push_back(std::move(client)); } @@ -1202,7 +1202,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT if (future.valid() && (future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)) { auto maybe_response = future.get(); - checkErrorResponse(maybe_response, uprotocol::v1::UCode::CANCELLED); + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); ++num_cancelled; } } @@ -1250,10 +1250,10 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT auto maybe_message = future.get(); if (!maybe_message && (maybe_message.error().code() == - uprotocol::v1::UCode::DEADLINE_EXCEEDED)) { + v1::UCode::DEADLINE_EXCEEDED)) { ++expired_futures; checkErrorResponse(maybe_message, - uprotocol::v1::UCode::DEADLINE_EXCEEDED); + v1::UCode::DEADLINE_EXCEEDED); } } } @@ -1273,12 +1273,12 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array workers; - auto client = uprotocol::communication::RpcClient( - getTransport(), methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient( + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); std::atomic call_count = 0; - std::array, + std::array, workers.size()> handles; auto *worker_handles = handles.begin(); @@ -1314,10 +1314,10 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT constexpr size_t NUM_REQUESTS_PER_WORKER = 1500; auto get_client = []() { - auto transport = std::make_shared( + auto transport = std::make_shared( defaultSourceUri()); - return uprotocol::communication::RpcClient( - transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + return communication::RpcClient( + transport, methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); }; @@ -1325,7 +1325,7 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::atomic discard_calls = 0; workers.emplace_back([&discard_calls, &get_client]() { - uprotocol::communication::RpcClient::InvokeHandle handle; + communication::RpcClient::InvokeHandle handle; for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto client = get_client(); @@ -1387,10 +1387,10 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::atomic self_calls = 0; auto self_responder = [&self_calls]() { - auto transport = std::make_shared( + auto transport = std::make_shared( defaultSourceUri()); - auto client = uprotocol::communication::RpcClient( - transport, methodUri(), uprotocol::v1::UPriority::UPRIORITY_CS4, + auto client = communication::RpcClient( + transport, methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 875f115fc..44bb50128 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -20,7 +20,7 @@ constexpr size_t MAX_LEN_RANDOM_STRING = 32; -namespace { +namespace uprotocol{ using MsgDiff = google::protobuf::util::MessageDifferencer; @@ -39,18 +39,18 @@ std::string get_random_string(size_t max_len = MAX_LEN_RANDOM_STRING) { return retval; } -std::optional RpcCallbackNoReturn( - const uprotocol::v1::UMessage& /*message*/) { +std::optional RpcCallbackNoReturn( + const v1::UMessage& /*message*/) { return std::nullopt; } -std::optional RpcCallbackWithReturn( - const uprotocol::v1::UMessage& /*message*/) { - uprotocol::v1::UPayloadFormat format = - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; +std::optional RpcCallbackWithReturn( + const v1::UMessage& /*message*/) { + v1::UPayloadFormat format = + v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; std::string response_data = "RPC Response"; - uprotocol::datamodel::builder::Payload payload(response_data, format); + datamodel::builder::Payload payload(response_data, format); return payload; } @@ -58,27 +58,27 @@ std::optional RpcCallbackWithReturn( class TestRpcServer : public testing::Test { private: static constexpr uint16_t DEFAULT_TTL_TIME = 1000; - std::shared_ptr mockTransport_; - std::shared_ptr method_uri_; - std::shared_ptr request_uri_; + std::shared_ptr mockTransport_; + std::shared_ptr method_uri_; + std::shared_ptr request_uri_; std::chrono::milliseconds ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); - uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + v1::UPayloadFormat format = v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; protected: // Run once per TEST_F. // Used to set up clean environments per test. - std::shared_ptr getMockTransport() const { return mockTransport_; } - std::shared_ptr getMethodUri() const { return method_uri_; } - std::shared_ptr getRequestUri() const { return request_uri_; } + std::shared_ptr getMockTransport() const { return mockTransport_; } + std::shared_ptr getMethodUri() const { return method_uri_; } + std::shared_ptr getRequestUri() const { return request_uri_; } std::chrono::milliseconds getTTL() const { return ttl_; } - uprotocol::v1::UPayloadFormat getFormat() const { return format; } + v1::UPayloadFormat getFormat() const { return format; } - void setMockTransport(const std::shared_ptr& mock_transport) { mockTransport_ = mock_transport; } - void setMethodUri(const std::shared_ptr& method_uri) { method_uri_ = method_uri; } - void setRequestUri(const std::shared_ptr& request_uri) { request_uri_ = request_uri; } + void setMockTransport(const std::shared_ptr& mock_transport) { mockTransport_ = mock_transport; } + void setMethodUri(const std::shared_ptr& method_uri) { method_uri_ = method_uri; } + void setRequestUri(const std::shared_ptr& request_uri) { request_uri_ = request_uri; } void setTTL(const std::chrono::milliseconds& ttl) { ttl_ = ttl; } - void setFormat(uprotocol::v1::UPayloadFormat format) { this->format = format; } + void setFormat(v1::UPayloadFormat format) { this->format = format; } void SetUp() override { constexpr uint32_t DEF_UE_ID = 0x18000; @@ -86,7 +86,7 @@ class TestRpcServer : public testing::Test { constexpr uint32_t REQUEST_UE_ID = 0x00010001; // Set up a transport URI - uprotocol::v1::UUri def_src_uuri; + v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); def_src_uuri.set_ue_id(DEF_UE_ID); def_src_uuri.set_ue_version_major(1); @@ -94,17 +94,17 @@ class TestRpcServer : public testing::Test { // Set up a transport mockTransport_ = - std::make_shared(def_src_uuri); + std::make_shared(def_src_uuri); // Set up a method URI - method_uri_ = std::make_shared(); + method_uri_ = std::make_shared(); method_uri_->set_authority_name("10.0.0.2"); method_uri_->set_ue_id(METHOD_UE_ID); method_uri_->set_ue_version_major(2); method_uri_->set_resource_id(0x2); // Create a src uri of entity - request_uri_ = std::make_shared(); + request_uri_ = std::make_shared(); request_uri_->set_authority_name("10.0.0.1"); request_uri_->set_ue_id(REQUEST_UE_ID); request_uri_->set_ue_version_major(1); @@ -133,11 +133,11 @@ class TestRpcServer : public testing::Test { // parameters TEST_F(TestRpcServer, ConstructorValidParams) { // Define a callback function to be used with the RpcServer - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with valid parameters - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback)); // Ensure that the server creation was successful @@ -154,26 +154,26 @@ TEST_F(TestRpcServer, ConstructorValidParams) { // Null transport TEST_F(TestRpcServer, CreateWithNullTransport) { // Define a callback function to be used with the RpcServer - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; auto transport = nullptr; // Attempt to create an RpcServer instance with valid parameters EXPECT_THROW( - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( transport, *getMethodUri(), std::move(callback)), - uprotocol::transport::NullTransport); + transport::NullTransport); } // Test to verify RpcServer construction with a specific payload format TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // Define a callback that returns a specific value, simulating a response - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with the provided callback and a // specific format - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); // Ensure the server creation was successful and a valid instance was @@ -193,12 +193,12 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // Define a callback that returns a specific value, simulating a server // response - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with additional parameters: // payload format and TTL - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Verify that the server creation was successful and a valid instance was @@ -216,22 +216,22 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // Test to verify RpcServer construction fails with invalid URI TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // Create an invalid URI object to simulate invalid input parameters - uprotocol::v1::UUri invalid_uri; + v1::UUri invalid_uri; // Expecte error message const std::string error_message = "Invalid rpc URI"; // Define a callback function to be used with the RpcServer, even though // it's expected to fail - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with the invalid URI and verify // creation fails - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), invalid_uri, std::move(callback)); // Define the expected error code for this operation - uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::INVALID_ARGUMENT; + v1::UCode expected_code = v1::UCode::INVALID_ARGUMENT; // Verify that the error code matches the expected error code for invalid // arguments @@ -244,23 +244,23 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { constexpr uint16_t INVALID_PAYLOADFORMAT = 9999; // Create an invalid PaylodFormat to simulate invalid input parameters - auto invalid_format = static_cast(INVALID_PAYLOADFORMAT); + auto invalid_format = static_cast(INVALID_PAYLOADFORMAT); // Expecte error message const std::string error_message = "Invalid payload format"; // Define a callback function to be used with the RpcServer, even though // it's expected to fail - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with the invalid PaylodFormat and // verify creation fails - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), invalid_format); // Define the expected error code for this operation - uprotocol::v1::UCode expected_code = uprotocol::v1::UCode::OUT_OF_RANGE; + v1::UCode expected_code = v1::UCode::OUT_OF_RANGE; // Verify that the error code matches the expected error code for invalid // arguments @@ -271,11 +271,11 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // Test case to verify successful connection with a valid handle TEST_F(TestRpcServer, ConnectwithValidHandle) { // Define a callback function that simulates a server response - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with mockTransport_ - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); // Check if the RpcServer was successfully created and a valid handle was @@ -298,11 +298,11 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { std::string expected_response_payload = "RPC Response"; // Create a callback to be called when request is received - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Create a server to offer the RPC method - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Check if the server was created successfully @@ -312,9 +312,9 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); // Create request umessage - auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( + auto builder = datamodel::builder::UMessageBuilder::request( std::move(*getMethodUri()), std::move(*getRequestUri()), - uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); + v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); @@ -327,7 +327,7 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // Compare expected reposen message with actual response message auto expected_response_msg = - uprotocol::datamodel::builder::UMessageBuilder::response(msg) + datamodel::builder::UMessageBuilder::response(msg) .withTtl(getTTL()) .withPayloadFormat(getFormat()) .build({expected_response_payload, getFormat()}); @@ -354,11 +354,11 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // Test case to verify RPC request handling without return payload TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // Create a callback to be called when request is received - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Create a server to offer the RPC method - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback)); // Check if the server was created successfully @@ -368,9 +368,9 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); // Create request umessage - auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( + auto builder = datamodel::builder::UMessageBuilder::request( std::move(*getMethodUri()), std::move(*getRequestUri()), - uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); + v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); @@ -383,7 +383,7 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // Compare expected reposen message with actual response message auto expected_response_msg = - uprotocol::datamodel::builder::UMessageBuilder::response(msg).build(); + datamodel::builder::UMessageBuilder::response(msg).build(); EXPECT_TRUE( MsgDiff::Equals(expected_response_msg.attributes().source(), @@ -404,11 +404,11 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // Test case to verify RPC request handling with invalid request TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Create a callback to be called when request is received - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Create a server to offer the RPC method - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); // Check if the server was created successfully @@ -417,9 +417,9 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Create request umessage using namespace std::chrono_literals; - auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( + auto builder = datamodel::builder::UMessageBuilder::request( std::move(*getMethodUri()), std::move(*getRequestUri()), - uprotocol::v1::UPriority::UPRIORITY_CS5, 300ms); + v1::UPriority::UPRIORITY_CS5, 300ms); auto msg = builder.build(); @@ -435,11 +435,11 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Test case to verify RPC sever resets the listener when the server is // destroyed TEST_F(TestRpcServer, RestRPCServerHandle) { - uprotocol::communication::RpcServer::RpcCallback callback = + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; { - auto server_or_status = uprotocol::communication::RpcServer::create( + auto server_or_status = communication::RpcServer::create( getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); EXPECT_TRUE(server_or_status.has_value()); @@ -449,9 +449,9 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { } // Create request umessage - auto builder = uprotocol::datamodel::builder::UMessageBuilder::request( + auto builder = datamodel::builder::UMessageBuilder::request( std::move(*getMethodUri()), std::move(*getRequestUri()), - uprotocol::v1::UPriority::UPRIORITY_CS5, getTTL()); + v1::UPriority::UPRIORITY_CS5, getTTL()); auto msg = builder.build(); @@ -463,4 +463,4 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { EXPECT_FALSE(getMockTransport()->send_count_ == 2); } -} // namespace +} // namespace uprotocol diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index ee399a2cf..f57949f87 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include "UTransportMock.h" @@ -20,11 +21,15 @@ namespace uprotocol{ using MsgDiff = google::protobuf::util::MessageDifferencer; -// using namespace uprotocol::communication; -using namespace uprotocol::test; -namespace UriValidator = uprotocol::datamodel::validator::uri; class SubscriberTest : public testing::Test { +private: + uprotocol::v1::UUri testTopicUUri_; + uprotocol::v1::UUri testInvalidTopicUUri_; + uprotocol::v1::UUri testDefaultSourceUUri_; + size_t capture_count_ = 0; + uprotocol::v1::UMessage capture_msg_; + protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -34,7 +39,6 @@ class SubscriberTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. SubscriberTest() = default; - ~SubscriberTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. @@ -45,14 +49,21 @@ class SubscriberTest : public testing::Test { void buildInValidSubscribeURI(); void buildDefaultSourceURI(); - uprotocol::v1::UUri testTopicUUri_; - uprotocol::v1::UUri testInvalidTopicUUri_; - uprotocol::v1::UUri testDefaultSourceUUri_; - size_t capture_count_ = 0; - uprotocol::v1::UMessage capture_msg_; + uprotocol::v1::UUri getTestTopicUUri() const { return testTopicUUri_; } + uprotocol::v1::UUri getTestInvalidTopicUUri() const { return testInvalidTopicUUri_; } + uprotocol::v1::UUri getTestDefaultSourceUUri() const { return testDefaultSourceUUri_; } + size_t getCaptureCount() const { return capture_count_; } + uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } + + void setTestTopicUUri(const uprotocol::v1::UUri& uri) { testTopicUUri_ = uri; } + void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uri) { testInvalidTopicUUri_ = uri; } + void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uri) { testDefaultSourceUUri_ = uri; } + void setCaptureCount(size_t count) { capture_count_ = count; } + void setCaptureMsg(const uprotocol::v1::UMessage& msg) { capture_msg_ = msg; } public: void handleCallbackMessage(const uprotocol::v1::UMessage& message); + ~SubscriberTest() override = default; }; void SubscriberTest::SetUp() { @@ -62,34 +73,45 @@ void SubscriberTest::SetUp() { } void SubscriberTest::buildValidSubscribeURI() { + constexpr uint32_t VALID_UE_ID = 0x00011101; + constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8001; + testTopicUUri_.set_authority_name("192.168.1.10"); - testTopicUUri_.set_ue_id(0x00011101); + testTopicUUri_.set_ue_id(VALID_UE_ID); testTopicUUri_.set_ue_version_major(0x1); - testTopicUUri_.set_resource_id(0x8001); + testTopicUUri_.set_resource_id(DEFAULT_RESOURCE_ID); } void SubscriberTest::buildInValidSubscribeURI() { + constexpr uint32_t VALID_UE_ID = 0x00011101; + // Resource ID should be in the range of 0x8000 to 0xFFFF + constexpr uint32_t INVALID_RESOURCE_ID = 0x1200; + testInvalidTopicUUri_.set_authority_name("192.168.1.10"); - testInvalidTopicUUri_.set_ue_id(0x00011101); + testInvalidTopicUUri_.set_ue_id(VALID_UE_ID); testInvalidTopicUUri_.set_ue_version_major(0x1); - // Resource ID should be in the range of 0x8000 to 0xFFFF - testInvalidTopicUUri_.set_resource_id(0x1200); + testInvalidTopicUUri_.set_resource_id(INVALID_RESOURCE_ID); } void SubscriberTest::buildDefaultSourceURI() { + constexpr uint32_t DEFAULT_UE_ID = 0x00011102; + testDefaultSourceUUri_.set_authority_name("192.168.1.10"); - testDefaultSourceUUri_.set_ue_id(0x00011102); + testDefaultSourceUUri_.set_ue_id(DEFAULT_UE_ID); testDefaultSourceUUri_.set_ue_version_major(0x1); testDefaultSourceUUri_.set_resource_id(0x0); } std::string get_random_string(size_t length) { auto randchar = []() -> char { - const char charset[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; - const size_t max_index = (sizeof(charset) - 1); - return charset[rand() % max_index]; + constexpr std::array CHARSET = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' + }; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distr(0, CHARSET.size() - 1); + return CHARSET.at(static_cast(distr(gen))); }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); @@ -104,21 +126,23 @@ void SubscriberTest::handleCallbackMessage( // Positive test case to subscribe to a valid topic TEST_F(SubscriberTest, SubscribeSuccess) { + constexpr uint16_t RANDOM_STRING_LENGTH = 1400; + auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); - auto callback = [this](auto arg1) { + auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; auto result = - Subscriber::subscribe(transport, testTopicUUri_, std::move(callback)); + communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); EXPECT_TRUE(transport->listener_); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(testTopicUUri_, transport->source_filter_)); + EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->source_filter_)); EXPECT_FALSE(transport->sink_filter_); const size_t max_count = 100; @@ -126,80 +150,78 @@ TEST_F(SubscriberTest, SubscribeSuccess) { uprotocol::v1::UMessage msg; auto attr = std::make_shared(); *msg.mutable_attributes() = *attr; - msg.set_payload(get_random_string(1400)); + msg.set_payload(get_random_string(RANDOM_STRING_LENGTH)); transport->mockMessage(msg); - EXPECT_EQ(i + 1, capture_count_); - EXPECT_TRUE(MsgDiff::Equals(msg, capture_msg_)); + EXPECT_EQ(i + 1, getCaptureCount()); + EXPECT_TRUE(MsgDiff::Equals(msg, getCaptureMsg())); } } // Negative test case to subscribe to a invalid topic TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); - auto callback = [this](auto arg1) { + auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; // Subscribe to invalid UUri topic with resource ID not in correct range - EXPECT_THROW(auto result = Subscriber::subscribe( - transport, testInvalidTopicUUri_, std::move(callback)), - UriValidator::InvalidUUri); + EXPECT_THROW(auto result = communication::Subscriber::subscribe( + transport, getTestInvalidTopicUUri(), std::move(callback)), + datamodel::validator::uri::InvalidUUri); } // Negative test case to subscribe to a topic with registerListener failure TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); - auto callback = [this](auto arg1) { + auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; - uprotocol::v1::UStatus expectedStatus; - expectedStatus.set_code(uprotocol::v1::UCode::ABORTED); - transport->registerListener_status_ = expectedStatus; + uprotocol::v1::UStatus expected_status; + expected_status.set_code(uprotocol::v1::UCode::ABORTED); + transport->registerListener_status_ = expected_status; auto result = - Subscriber::subscribe(transport, testTopicUUri_, std::move(callback)); + communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); - auto actualStatus = std::move(result).error(); - EXPECT_EQ(actualStatus.code(), expectedStatus.code()); + auto actual_status = std::move(result).error(); + EXPECT_EQ(actual_status.code(), expected_status.code()); } // subscribe to a topic with null transport TEST_F(SubscriberTest, SubscribeNullTransport) { // set transport to null auto transport = nullptr; - auto callback = [this](auto arg1) { + auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; - EXPECT_THROW(auto result = Subscriber::subscribe(transport, testTopicUUri_, + EXPECT_THROW(auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)), std::invalid_argument); } // subscribe to a topic with null callback TEST_F(SubscriberTest, SubscribeNullCallback) { auto transport = std::make_shared( - testDefaultSourceUUri_); + getTestDefaultSourceUUri()); // bind to null callback auto test_subscribe_nullptr = [transport, this]() { - std::ignore = Subscriber::subscribe(transport, testTopicUUri_, - std::move(nullptr)); + std::ignore = communication::Subscriber::subscribe(transport, getTestTopicUUri(), + nullptr); }; - using namespace uprotocol::utils; - - EXPECT_THROW(test_subscribe_nullptr(), callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_nullptr(), utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_subscribe_empty = [transport, this]() { - std::ignore = Subscriber::subscribe(transport, testTopicUUri_, {}); + std::ignore = communication::Subscriber::subscribe(transport, getTestTopicUUri(), {}); }; - EXPECT_THROW(test_subscribe_empty(), callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_empty(), utils::callbacks::EmptyFunctionObject); } } // namespace uprotocol From e83196a58b79c5ac344025bf4fdf5de2befcf467 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 9 Apr 2025 12:21:32 +0200 Subject: [PATCH 11/41] Continue fixing linter warnings in datamodel --- lint/clang-tidy.sh | 2 +- test/coverage/communication/RpcServerTest.cpp | 34 +- .../coverage/communication/SubscriberTest.cpp | 18 +- .../coverage/datamodel/PayloadBuilderTest.cpp | 353 +++++++++--------- .../datamodel/UMessageBuilderTest.cpp | 313 ++++++++-------- 5 files changed, 374 insertions(+), 346 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index cc4a66cd9..e667c0e81 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -59,7 +59,7 @@ if [ -z "$target_source" ]; then pushd "$PROJECT_ROOT" > /dev/null # for f in include/**/*.h src/**/*.cpp - for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in test/coverage/datamodel/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 44bb50128..e971a9ee2 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -68,11 +68,11 @@ class TestRpcServer : public testing::Test { // Run once per TEST_F. // Used to set up clean environments per test. - std::shared_ptr getMockTransport() const { return mockTransport_; } - std::shared_ptr getMethodUri() const { return method_uri_; } - std::shared_ptr getRequestUri() const { return request_uri_; } - std::chrono::milliseconds getTTL() const { return ttl_; } - v1::UPayloadFormat getFormat() const { return format; } + [[nodiscard]] std::shared_ptr getMockTransport() const { return mockTransport_; } + [[nodiscard]] std::shared_ptr getMethodUri() const { return method_uri_; } + [[nodiscard]] std::shared_ptr getRequestUri() const { return request_uri_; } + [[nodiscard]] std::chrono::milliseconds getTTL() const { return ttl_; } + [[nodiscard]] v1::UPayloadFormat getFormat() const { return format; } void setMockTransport(const std::shared_ptr& mock_transport) { mockTransport_ = mock_transport; } void setMethodUri(const std::shared_ptr& method_uri) { method_uri_ = method_uri; } @@ -131,7 +131,7 @@ class TestRpcServer : public testing::Test { // Test to ensure RpcServer constructor initializes correctly with valid // parameters -TEST_F(TestRpcServer, ConstructorValidParams) { +TEST_F(TestRpcServer, ConstructorValidParams) { // NOLINT // Define a callback function to be used with the RpcServer communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; @@ -152,21 +152,21 @@ TEST_F(TestRpcServer, ConstructorValidParams) { } // Null transport -TEST_F(TestRpcServer, CreateWithNullTransport) { +TEST_F(TestRpcServer, CreateWithNullTransport) { // NOLINT // Define a callback function to be used with the RpcServer communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; auto transport = nullptr; // Attempt to create an RpcServer instance with valid parameters - EXPECT_THROW( + EXPECT_THROW( // NOLINT auto server_or_status = communication::RpcServer::create( transport, *getMethodUri(), std::move(callback)), transport::NullTransport); } // Test to verify RpcServer construction with a specific payload format -TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { +TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // NOLINT // Define a callback that returns a specific value, simulating a response communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; @@ -190,7 +190,7 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // Test to ensure RpcServer can be constructed with both a specific payload // format and TTL -TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { +TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // NOLINT // Define a callback that returns a specific value, simulating a server // response communication::RpcServer::RpcCallback callback = @@ -214,7 +214,7 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { } // Test to verify RpcServer construction fails with invalid URI -TEST_F(TestRpcServer, ConstructorWithInvalidURI) { +TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // NOLINT // Create an invalid URI object to simulate invalid input parameters v1::UUri invalid_uri; @@ -240,7 +240,7 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { } // Test to verify RpcServer construction fails with invalid PaylodFormat -TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { +TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // NOLINT constexpr uint16_t INVALID_PAYLOADFORMAT = 9999; // Create an invalid PaylodFormat to simulate invalid input parameters @@ -269,7 +269,7 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { } // Test case to verify successful connection with a valid handle -TEST_F(TestRpcServer, ConnectwithValidHandle) { +TEST_F(TestRpcServer, ConnectwithValidHandle) { // NOLINT // Define a callback function that simulates a server response communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; @@ -293,7 +293,7 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { } // Test case to verify RPC request handling with return payload and TTL -TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { +TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT // Expected response by RPC method std::string expected_response_payload = "RPC Response"; @@ -352,7 +352,7 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { } // Test case to verify RPC request handling without return payload -TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { +TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT // Create a callback to be called when request is received communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; @@ -402,7 +402,7 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { } // Test case to verify RPC request handling with invalid request -TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { +TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT // Create a callback to be called when request is received communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; @@ -434,7 +434,7 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // Test case to verify RPC sever resets the listener when the server is // destroyed -TEST_F(TestRpcServer, RestRPCServerHandle) { +TEST_F(TestRpcServer, RestRPCServerHandle) { // NOLINT communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index f57949f87..3e1c7c5a6 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -125,7 +125,7 @@ void SubscriberTest::handleCallbackMessage( } // Positive test case to subscribe to a valid topic -TEST_F(SubscriberTest, SubscribeSuccess) { +TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT constexpr uint16_t RANDOM_STRING_LENGTH = 1400; auto transport = std::make_shared( @@ -158,7 +158,7 @@ TEST_F(SubscriberTest, SubscribeSuccess) { } // Negative test case to subscribe to a invalid topic -TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { +TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -167,13 +167,13 @@ TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { }; // Subscribe to invalid UUri topic with resource ID not in correct range - EXPECT_THROW(auto result = communication::Subscriber::subscribe( + EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT transport, getTestInvalidTopicUUri(), std::move(callback)), datamodel::validator::uri::InvalidUUri); } // Negative test case to subscribe to a topic with registerListener failure -TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { +TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -193,18 +193,18 @@ TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { } // subscribe to a topic with null transport -TEST_F(SubscriberTest, SubscribeNullTransport) { +TEST_F(SubscriberTest, SubscribeNullTransport) { // NOLINT // set transport to null auto transport = nullptr; auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; - EXPECT_THROW(auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), + EXPECT_THROW(auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), // NOLINT std::move(callback)), std::invalid_argument); } // subscribe to a topic with null callback -TEST_F(SubscriberTest, SubscribeNullCallback) { +TEST_F(SubscriberTest, SubscribeNullCallback) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -214,14 +214,14 @@ TEST_F(SubscriberTest, SubscribeNullCallback) { nullptr); }; - EXPECT_THROW(test_subscribe_nullptr(), utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_nullptr(), utils::callbacks::EmptyFunctionObject); // NOLINT // Default construct a function object auto test_subscribe_empty = [transport, this]() { std::ignore = communication::Subscriber::subscribe(transport, getTestTopicUUri(), {}); }; - EXPECT_THROW(test_subscribe_empty(), utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_empty(), utils::callbacks::EmptyFunctionObject); // NOLINT } } // namespace uprotocol diff --git a/test/coverage/datamodel/PayloadBuilderTest.cpp b/test/coverage/datamodel/PayloadBuilderTest.cpp index ac8d46da6..fcea10a77 100644 --- a/test/coverage/datamodel/PayloadBuilderTest.cpp +++ b/test/coverage/datamodel/PayloadBuilderTest.cpp @@ -14,8 +14,7 @@ #include -namespace { -using namespace uprotocol::datamodel::builder; +namespace uprotocol::datamodel::builder{ struct TimeAsPayloadSerializer { static Payload::Serialized serialize(std::chrono::milliseconds t) { @@ -33,6 +32,12 @@ struct TimeAsPayloadSerializer { }; class PayloadTest : public testing::Test { +private: + // Note : Need to make the std::string version longer to avoid SSO (small + // string optimization) as it will interfere with the move tests + const std::string testStringPayload_ = "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; + const std::vector testBytesPayload_{'T', 'e', 's', 't', + '0', '1', '2', '3'}; protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -42,107 +47,105 @@ class PayloadTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. PayloadTest() = default; - ~PayloadTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - // Note : Need to make the std::string version longer to avoid SSO (small - // string optimization) as it will interfere with the move tests - const std::string testStringPayload_ = - "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; - const std::vector testBytesPayload_{'T', 'e', 's', 't', - '0', '1', '2', '3'}; + [[nodiscard]] std::string getTestStringPayload() const { return testStringPayload_; } + [[nodiscard]] std::vector getTestBytesPayload() const { return testBytesPayload_; } + +public: + ~PayloadTest() override = default; }; /////////////////Serialized Protobuf Tests///////////////////////// // Create serialized protobuf payload and verify build payload -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndBuildTest) { +TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndBuildTest) { // NOLINT // Arrange - uprotocol::v1::UUri uriObject; - uriObject.set_authority_name(testStringPayload_); - auto expectedPayloadData = uriObject.SerializeAsString(); + uprotocol::v1::UUri uri_object; + uri_object.set_authority_name(getTestStringPayload()); + auto expected_payload_data = uri_object.SerializeAsString(); // Act - Payload payload(uriObject); + Payload payload(uri_object); // Assert auto [payloadData, payloadFormat] = payload.buildCopy(); EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); - EXPECT_EQ(payloadData, expectedPayloadData); + EXPECT_EQ(payloadData, expected_payload_data); } // Create serialized protobuf payload with empty message -TEST_F(PayloadTest, CreateEmptySerializedProtobufPayloadTest) { +TEST_F(PayloadTest, CreateEmptySerializedProtobufPayloadTest) { // NOLINT // Arrange - uprotocol::v1::UUri uriObject; - uriObject.set_authority_name(""); + uprotocol::v1::UUri uri_object; + uri_object.set_authority_name(""); // Act - Payload payload(uriObject); + Payload payload(uri_object); // Assert auto [payloadData, payloadFormat] = payload.buildCopy(); EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); - EXPECT_EQ(payloadData, uriObject.SerializeAsString()); + EXPECT_EQ(payloadData, uri_object.SerializeAsString()); } // Create serialized protobuf payload and verify moved payload -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { +TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { // NOLINT // Arrange - uprotocol::v1::UUri uriObject; - uriObject.set_authority_name(testStringPayload_); - auto expectedPayloadData = uriObject.SerializeAsString(); + uprotocol::v1::UUri uri_object; + uri_object.set_authority_name(getTestStringPayload()); + auto expected_payload_data = uri_object.SerializeAsString(); // Act - Payload payload(uriObject); - auto& [payload_reference, payload_format] = payload.buildCopy(); + Payload payload(uri_object); + const auto& [payload_reference, payload_format] = payload.buildCopy(); const void* original_address = payload_reference.data(); // Assert auto [payloadData, payloadFormat] = std::move(payload).buildMove(); EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); - EXPECT_EQ(payloadData, expectedPayloadData); + EXPECT_EQ(payloadData, expected_payload_data); - EXPECT_THROW(auto result = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(static_cast(payload.buildCopy()), Payload::PayloadMoved); // NOLINT EXPECT_EQ(original_address, payloadData.data()); } // Create serialized protobuf payload. Verify exception for move paylod twice -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { +TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { // NOLINT // Arrange - uprotocol::v1::UUri uriObject; - uriObject.set_authority_name(testStringPayload_); + uprotocol::v1::UUri uri_object; + uri_object.set_authority_name(getTestStringPayload()); // Act - Payload payload(uriObject); + Payload payload(uri_object); // Assert auto [payloadData, payloadFormat] = std::move(payload).buildMove(); EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); - EXPECT_EQ(payloadData, uriObject.SerializeAsString()); + EXPECT_EQ(payloadData, uri_object.SerializeAsString()); - EXPECT_THROW({ auto _ = std::move(payload).buildMove(); }, + EXPECT_THROW({ auto _ = std::move(payload).buildMove(); }, // NOLINT Payload::PayloadMoved); } // Create serialized protobuf payload. Call build after move. -TEST_F(PayloadTest, - CreateSerializedProtobufPayloadAndCallBuildAfterMoveExceptionTest) { +TEST_F(PayloadTest, // NOLINT + CreateSerializedProtobufPayloadAndCallBuildAfterMoveExceptionTest) { // Arrange - uprotocol::v1::UUri uriObject; - uriObject.set_authority_name(testStringPayload_); + uprotocol::v1::UUri uri_object; + uri_object.set_authority_name(getTestStringPayload()); // Act - Payload payload(uriObject); + Payload payload(uri_object); // Call move on payload first auto [payloadData, payloadFormat] = std::move(payload).buildMove(); @@ -150,106 +153,114 @@ TEST_F(PayloadTest, EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); - EXPECT_EQ(payloadData, uriObject.SerializeAsString()); + EXPECT_EQ(payloadData, uri_object.SerializeAsString()); // Call build on payload after move - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } /////////////Serializer Payload Protobuf Tests///////////////// // Create a serializer payload and verify build payload -TEST_F(PayloadTest, CreateSerializerPayloadAndBuildTest) { +TEST_F(PayloadTest, CreateSerializerPayloadAndBuildTest) { // NOLINT + constexpr uint16_t RANDOM_TIME = 1234; // Arrange - std::chrono::milliseconds t(1234); - TimeAsPayloadSerializer timeSerializer; - timeSerializer.setFormat( + std::chrono::milliseconds t(RANDOM_TIME); + TimeAsPayloadSerializer time_serializer; + uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat( uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW); - auto expectedSerializedObject = timeSerializer.serialize( + auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( std::chrono::duration_cast(t)); // Act - Payload payload(timeSerializer, t); + Payload payload(time_serializer, t); // Assert auto [payloadData, payloadFormat] = payload.buildCopy(); EXPECT_EQ(payloadData, - std::get(expectedSerializedObject)); + std::get(expected_serialized_object)); EXPECT_EQ(payloadFormat, - std::get(expectedSerializedObject)); + std::get(expected_serialized_object)); } // Create a serializer payload with invalid format -TEST_F(PayloadTest, CreateSerializerPayloadWithInvalidFormat) { +TEST_F(PayloadTest, CreateSerializerPayloadWithInvalidFormat) { // NOLINT + constexpr uint16_t RANDOM_TIME = 1234; + constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; + // Arrange - std::chrono::milliseconds t(1234); - TimeAsPayloadSerializer timeSerializer; - auto invalidFormat = static_cast(9999); + std::chrono::milliseconds t(RANDOM_TIME); + TimeAsPayloadSerializer time_serializer; + auto invalid_format = static_cast(INVALID_PAYLOAD_FORMAT); // Ovreide the format with invalid value - timeSerializer.setFormat(invalidFormat); + uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat(invalid_format); - auto expectedSerializedObject = timeSerializer.serialize( + auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( std::chrono::duration_cast(t)); // Act - EXPECT_THROW(Payload payload(timeSerializer, t), std::out_of_range); + EXPECT_THROW(Payload payload(time_serializer, t), std::out_of_range); // NOLINT } // Create a serializer payload and verify moved payload -TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { +TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { // NOLINT + constexpr uint16_t RANDOM_TIME = 12345; + // Arrange - std::chrono::milliseconds t(12345); - TimeAsPayloadSerializer timeSerializer; - timeSerializer.setFormat( + std::chrono::milliseconds t(RANDOM_TIME); + TimeAsPayloadSerializer time_serializer; + uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat( uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW); - auto expectedSerializedObject = timeSerializer.serialize( + auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( std::chrono::duration_cast(t)); // Act - Payload payload(timeSerializer, t); + Payload payload(time_serializer, t); // Assert auto [payloadData, payloadFormat] = std::move(payload).buildMove(); EXPECT_EQ(payloadData, - std::get(expectedSerializedObject)); + std::get(expected_serialized_object)); EXPECT_EQ(payloadFormat, - std::get(expectedSerializedObject)); + std::get(expected_serialized_object)); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } ////////////////////////Byte Array Payload Tests//////////////////////// // Create payload of Byte array and check if the payload is created correctly -TEST_F(PayloadTest, ByteArrayPayloadTest) { +TEST_F(PayloadTest, ByteArrayPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; // Act - Payload payload(testBytesPayload_, format); + Payload payload(getTestBytesPayload(), format); // Assert - auto [serializedData, payloadFormat] = payload.buildCopy(); + auto [serialized_data, payloadFormat] = payload.buildCopy(); - EXPECT_EQ(serializedData, "Test0123"); + EXPECT_EQ(serialized_data, "Test0123"); EXPECT_EQ(payloadFormat, format); } // Create payload of Byte array with invalid format and check if it throws // exception -TEST_F(PayloadTest, ConstructorInvalidFormatForByteArrayPayloadTest) { +TEST_F(PayloadTest, ConstructorInvalidFormatForByteArrayPayloadTest) { // NOLINT + constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; + // Arrange - uprotocol::v1::UPayloadFormat invalid_format = - static_cast(9999); + auto invalid_format = + static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(testBytesPayload_, invalid_format), + EXPECT_THROW(Payload payload(getTestBytesPayload(), invalid_format), // NOLINT std::out_of_range); } // Create empty byte array payload -TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { +TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { // NOLINT // Arrange std::vector value_bytes = {}; uprotocol::v1::UPayloadFormat format = @@ -259,60 +270,62 @@ TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { Payload payload(value_bytes, format); // Assert - auto [serializedData, payloadFormat] = payload.buildCopy(); + auto [serialized_data, payloadFormat] = payload.buildCopy(); - EXPECT_TRUE(serializedData.empty()); + EXPECT_TRUE(serialized_data.empty()); EXPECT_EQ(payloadFormat, format); } // Create byte array payload and call buildMove() -TEST_F(PayloadTest, MoveByteArrayPayloadTest) { +TEST_F(PayloadTest, MoveByteArrayPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; // Act - Payload payload(testBytesPayload_, format); - auto [serializedData, payloadFormat] = std::move(payload).buildMove(); + Payload payload(getTestBytesPayload(), format); + auto [serialized_data, payloadFormat] = std::move(payload).buildMove(); // Assert - EXPECT_EQ(serializedData, "Test0123"); + EXPECT_EQ(serialized_data, "Test0123"); EXPECT_EQ(payloadFormat, format); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } //////////////String Payload Tests////////////// // Create payload of std::string and check if the payload is created -TEST_F(PayloadTest, StringPayloadTest) { +TEST_F(PayloadTest, StringPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; // Act - Payload payload(testStringPayload_, format); + Payload payload(getTestStringPayload(), format); // Assert - auto [serializedData, payloadFormat] = payload.buildCopy(); - EXPECT_EQ(serializedData, testStringPayload_); + auto [serialized_data, payloadFormat] = payload.buildCopy(); + EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); } // Create payload of std::string with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForStringPayloadTest) { +TEST_F(PayloadTest, ConstructorInvalidFormatForStringPayloadTest) { // NOLINT + constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; + // Arrange - uprotocol::v1::UPayloadFormat invalid_format = - static_cast(9999); + auto invalid_format = + static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(testStringPayload_, invalid_format), + EXPECT_THROW(Payload payload(getTestStringPayload(), invalid_format), // NOLINT std::out_of_range); } // Create empty string payload -TEST_F(PayloadTest, EmptyStringPayloadTest) { +TEST_F(PayloadTest, EmptyStringPayloadTest) { // NOLINT // Arrange - std::string value_string = ""; + std::string value_string; uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -320,32 +333,32 @@ TEST_F(PayloadTest, EmptyStringPayloadTest) { Payload payload(value_string, format); // Assert - auto [serializedData, payloadFormat] = payload.buildCopy(); - EXPECT_TRUE(serializedData.empty()); + auto [serialized_data, payloadFormat] = payload.buildCopy(); + EXPECT_TRUE(serialized_data.empty()); EXPECT_EQ(payloadFormat, format); } // Create std::string payload and call move on payload object test -TEST_F(PayloadTest, StringMovePayloadTest) { +TEST_F(PayloadTest, StringMovePayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; // Act - Payload payload(testStringPayload_, format); - auto [serializedData, payloadFormat] = std::move(payload).buildMove(); + Payload payload(getTestStringPayload(), format); + auto [serialized_data, payloadFormat] = std::move(payload).buildMove(); // Assert - EXPECT_EQ(serializedData, testStringPayload_); + EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } // Create Any and move payload object test TEST_F(PayloadTest, AnyMovePayloadTest) { // NOLINT // Arrange uprotocol::v1::UUri uri_object; // NOLINT - uri_object.set_authority_name(testStringPayload_); + uri_object.set_authority_name(getTestStringPayload()); google::protobuf::Any any; any.PackFrom(uri_object, "hello_world"); @@ -363,15 +376,15 @@ TEST_F(PayloadTest, AnyMovePayloadTest) { // NOLINT uprotocol::v1::UUri parsed_uri_object; EXPECT_TRUE(parsed_uri_object.ParseFromString(parsed_any.value())); - EXPECT_EQ(parsed_uri_object.authority_name(), testStringPayload_); + EXPECT_EQ(parsed_uri_object.authority_name(), getTestStringPayload()); } /////////////////////RValue String Payload Tests///////////////////// // Create RValue String Payload -TEST_F(PayloadTest, RValueStringPayloadTest) { +TEST_F(PayloadTest, RValueStringPayloadTest) { // NOLINT // Arrange - std::string value_string = testStringPayload_; + std::string value_string = getTestStringPayload(); uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; const void* original_address = value_string.data(); @@ -380,28 +393,30 @@ TEST_F(PayloadTest, RValueStringPayloadTest) { Payload payload(std::move(value_string), format); // Assert - auto [serializedData, payloadFormat] = std::move(payload).buildMove(); - EXPECT_EQ(serializedData, testStringPayload_); + auto [serialized_data, payloadFormat] = std::move(payload).buildMove(); + EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_EQ(serializedData.data(), original_address); + EXPECT_EQ(serialized_data.data(), original_address); } // Create payload of RValue String with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForRValueStringPayloadTest) { +TEST_F(PayloadTest, ConstructorInvalidFormatForRValueStringPayloadTest) { // NOLINT + constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; + // Arrange - std::string value_string = testStringPayload_; - uprotocol::v1::UPayloadFormat invalid_format = - static_cast(9999); + std::string value_string = getTestStringPayload(); + auto invalid_format = + static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(std::move(value_string), invalid_format), + EXPECT_THROW(Payload payload(std::move(value_string), invalid_format), // NOLINT std::out_of_range); } // Create empty RValue String payload -TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { +TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { // NOLINT // Arrange - std::string value_string = ""; + std::string value_string; uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -409,42 +424,42 @@ TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { Payload payload(std::move(value_string), format); // Assert - auto [serializedData, payloadFormat] = payload.buildCopy(); - EXPECT_TRUE(serializedData.empty()); + auto [serialized_data, payloadFormat] = payload.buildCopy(); + EXPECT_TRUE(serialized_data.empty()); EXPECT_EQ(payloadFormat, format); } // Create RValue String and move payload object test -TEST_F(PayloadTest, RValueStringMovePayloadTest) { +TEST_F(PayloadTest, RValueStringMovePayloadTest) { // NOLINT // Arrange - std::string value_string = testStringPayload_; - const void* originalAddress = value_string.data(); + std::string value_string = getTestStringPayload(); + const void* original_address = value_string.data(); uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; // Act Payload payload(std::move(value_string), format); - auto [serializedData, payloadFormat] = std::move(payload).buildMove(); - const void* movedAddress = serializedData.data(); + auto [serialized_data, payloadFormat] = std::move(payload).buildMove(); + const void* moved_address = serialized_data.data(); // Assert - EXPECT_EQ(serializedData, testStringPayload_); + EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_EQ(originalAddress, movedAddress); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_EQ(original_address, moved_address); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } ///////////////////////RValue Serialized Payload Tests////////////////////// // Create RValue Serialized payload -TEST_F(PayloadTest, RvalueSerializedConstructorTest) { +TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; Payload::Serialized serialized = - std::make_tuple(testStringPayload_, format); - const void* originalAddress = + std::make_tuple(getTestStringPayload(), format); + const void* original_address = std::get(serialized).data(); // Act @@ -452,30 +467,32 @@ TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // Assert auto [payloadData, payloadFormat] = std::move(payload).buildMove(); - EXPECT_EQ(payloadData, testStringPayload_); + EXPECT_EQ(payloadData, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_EQ(payloadData.data(), originalAddress); + EXPECT_EQ(payloadData.data(), original_address); } // Create payload of RValue Serialized with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForRValueSerializedPayloadTest) { +TEST_F(PayloadTest, ConstructorInvalidFormatForRValueSerializedPayloadTest) { // NOLINT + constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; + // Arrange - uprotocol::v1::UPayloadFormat format = - static_cast(9999); + auto format = + static_cast(INVALID_PAYLOAD_FORMAT); Payload::Serialized serialized = - std::make_tuple(testStringPayload_, format); + std::make_tuple(getTestStringPayload(), format); // Act - EXPECT_THROW(Payload payload(std::move(serialized));, std::out_of_range); + EXPECT_THROW(Payload payload(std::move(serialized));, std::out_of_range); // NOLINT } // Create empty RValue Serialized payload and build. -TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { +TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { // NOLINT // Arrange - std::string serializedData = ""; + std::string serialized_data; uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; - Payload::Serialized serialized = std::make_tuple(serializedData, format); + Payload::Serialized serialized = std::make_tuple(serialized_data, format); // Act Payload payload(std::move(serialized)); @@ -487,103 +504,103 @@ TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { } // Create RValue Serialized and move payload object test -TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { +TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; Payload::Serialized serialized = - std::make_tuple(testStringPayload_, format); + std::make_tuple(getTestStringPayload(), format); - const void* originalAddress = + const void* original_address = std::get(serialized).data(); // Act Payload payload(std::move(serialized)); auto [payloadData, payloadFormat] = std::move(payload).buildMove(); - const void* movedAddress = payloadData.data(); + const void* moved_address = payloadData.data(); // Assert - EXPECT_EQ(payloadData, testStringPayload_); + EXPECT_EQ(payloadData, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_EQ(originalAddress, movedAddress); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); + EXPECT_EQ(original_address, moved_address); + EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT } //////////////////////Other Constructor Tests/////////////////////// // Move Constructor Test -TEST_F(PayloadTest, MoveConstructorTest) { +TEST_F(PayloadTest, MoveConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - Payload originalPayload(testStringPayload_, format); + Payload original_payload(getTestStringPayload(), format); // Act - Payload movedPayload(std::move(originalPayload).buildMove()); + Payload moved_payload(std::move(original_payload).buildMove()); // Assert - auto [movedData, movedFormat] = movedPayload.buildCopy(); - EXPECT_EQ(movedData, testStringPayload_); + auto [movedData, movedFormat] = moved_payload.buildCopy(); + EXPECT_EQ(movedData, getTestStringPayload()); EXPECT_EQ(movedFormat, format); - EXPECT_THROW(auto _ = originalPayload.buildCopy(), Payload::PayloadMoved); + EXPECT_THROW(auto _ = original_payload.buildCopy(), Payload::PayloadMoved); // NOLINT } // Cppy Constructor Test -TEST_F(PayloadTest, CopyConstructorTest) { +TEST_F(PayloadTest, CopyConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - Payload originalPayload(testStringPayload_, format); + Payload original_payload(getTestStringPayload(), format); // Act - Payload copiedPayload(originalPayload); + const Payload& copied_payload(original_payload); // Assert - auto [originalData, originalFormat] = originalPayload.buildCopy(); - auto [copiedData, copiedFormat] = copiedPayload.buildCopy(); + auto [originalData, originalFormat] = original_payload.buildCopy(); + auto [copiedData, copiedFormat] = copied_payload.buildCopy(); EXPECT_EQ(copiedData, originalData); EXPECT_EQ(copiedFormat, originalFormat); } // Move Assignment Operator Test -TEST_F(PayloadTest, MoveAssignmentOperatorTest) { +TEST_F(PayloadTest, MoveAssignmentOperatorTest) { // NOLINT // Arrange - uprotocol::v1::UUri uriObject1; - uriObject1.set_authority_name("test1"); - Payload payload1(uriObject1); + uprotocol::v1::UUri uri_object1; + uri_object1.set_authority_name("test1"); + Payload payload1(uri_object1); - uprotocol::v1::UUri uriObject2; - uriObject2.set_authority_name("test2"); - Payload payload2(uriObject2); + uprotocol::v1::UUri uri_object2; + uri_object2.set_authority_name("test2"); + Payload payload2(uri_object2); // Act payload1 = std::move(payload2); // Assert auto [payloadData, payloadFormat] = payload1.buildCopy(); - EXPECT_EQ(payloadData, uriObject2.SerializeAsString()); + EXPECT_EQ(payloadData, uri_object2.SerializeAsString()); EXPECT_EQ(payloadFormat, uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); } // Copy Assignment Operator Test -TEST_F(PayloadTest, CopyAssignmentOperatorTest) { +TEST_F(PayloadTest, CopyAssignmentOperatorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; - Payload originalPayload(testStringPayload_, format); - Payload copiedPayload(testStringPayload_, format); + Payload original_payload(getTestStringPayload(), format); + Payload copied_payload(getTestStringPayload(), format); // Act - copiedPayload = originalPayload; + copied_payload = original_payload; // Assert - auto [originalData, originalFormat] = originalPayload.buildCopy(); - auto [copiedData, copiedFormat] = copiedPayload.buildCopy(); + auto [originalData, originalFormat] = original_payload.buildCopy(); + auto [copiedData, copiedFormat] = copied_payload.buildCopy(); EXPECT_EQ(copiedData, originalData); EXPECT_EQ(copiedFormat, originalFormat); } -} // namespace +} // namespace uprotocol::datamodel::builder diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 87d76bb54..d0a844059 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -16,12 +16,10 @@ #include #include -namespace { -using namespace uprotocol::v1; -using namespace uprotocol::datamodel::serializer::uri; -using namespace uprotocol::datamodel::validator::uri; -using namespace uprotocol::datamodel::builder; -using namespace uprotocol::datamodel::validator::uuid; +constexpr uint16_t TTL_TIME = 5000; +constexpr uint32_t UI_ID_INVALID_TEST = 0xFFFF0000; + +namespace uprotocol{ class TestUMessageBuilder : public testing::Test { protected: @@ -30,28 +28,28 @@ class TestUMessageBuilder : public testing::Test { void SetUp() override {} void TearDown() override {} - UMessageBuilder createFakeRequest() { - UPriority priority = UPriority::UPRIORITY_CS4; - std::chrono::milliseconds ttl(5000); - UUri method = method_; - UUri source = sink_; + static datamodel::builder::UMessageBuilder createFakeRequest() { + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; + std::chrono::milliseconds ttl(TTL_TIME); + v1::UUri method = method_; + v1::UUri source = sink_; - return UMessageBuilder::request(std::move(method), std::move(source), + return datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); } - UMessageBuilder createFakeResponse() { - UUri sink = sink_; - UUri method = method_; - UUID request_id = reqId_; + static datamodel::builder::UMessageBuilder createFakeResponse() { + v1::UUri sink = sink_; + v1::UUri method = method_; + v1::UUID request_id = req_id_; - UPriority priority = UPriority::UPRIORITY_CS4; - return UMessageBuilder::response(std::move(sink), std::move(request_id), + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; + return datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); } - bool urisAreEqual(const uprotocol::v1::UUri& uri1, - const uprotocol::v1::UUri& uri2) { + static bool urisAreEqual(const v1::UUri& uri1, + const v1::UUri& uri2) { return uri1.authority_name() == uri2.authority_name() && uri1.ue_id() == uri2.ue_id() && uri1.ue_version_major() == uri2.ue_version_major() && @@ -60,154 +58,167 @@ class TestUMessageBuilder : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUMessageBuilder() = default; - ~TestUMessageBuilder() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() { + constexpr uint32_t SOURCE_UE_ID = 0x00011101; + constexpr uint32_t SINK_UE_ID = 0x00011102; + constexpr uint32_t METHOD_UE_ID = 0x00011103; + + constexpr uint32_t SOURCE_UE_VERSION_MAJOR = 0xF8; + constexpr uint32_t SINK_UE_VERSION_MAJOR = 0xF9; + constexpr uint32_t METHOD_UE_VERSION_MAJOR = 0xFA; + + constexpr uint32_t SOURCE_RESOURCE_ID = 0x8101; + constexpr uint32_t SINK_RESOURCE_ID = 0; + constexpr uint32_t METHOD_RESOURCE_ID = 0x0101; + // Create a UUri object for testing source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(0x00011101); - source_.set_ue_version_major(0xF8); - source_.set_resource_id(0x8101); + source_.set_ue_id(SOURCE_UE_ID); + source_.set_ue_version_major(SOURCE_UE_VERSION_MAJOR); + source_.set_resource_id(SOURCE_RESOURCE_ID); sink_.set_authority_name("10.0.0.2"); - sink_.set_ue_id(0x00011102); - sink_.set_ue_version_major(0xF9); - sink_.set_resource_id(0); + sink_.set_ue_id(SINK_UE_ID); + sink_.set_ue_version_major(SINK_UE_VERSION_MAJOR); + sink_.set_resource_id(SINK_RESOURCE_ID); method_.set_authority_name("10.0.0.3"); - method_.set_ue_id(0x00011103); - method_.set_ue_version_major(0xFA); - method_.set_resource_id(0x0101); + method_.set_ue_id(METHOD_UE_ID); + method_.set_ue_version_major(METHOD_UE_VERSION_MAJOR); + method_.set_resource_id(METHOD_RESOURCE_ID); - reqId_ = UuidBuilder::getBuilder().build(); + req_id_ = datamodel::builder::UuidBuilder::getBuilder().build(); } static void TearDownTestSuite() {} - static UUri source_; - static UUri sink_; - static UUri method_; - static UUID reqId_; + static v1::UUri source_; + static v1::UUri sink_; + static v1::UUri method_; + static v1::UUID req_id_; +public: + ~TestUMessageBuilder() override = default; }; -UUri TestUMessageBuilder::source_; -UUri TestUMessageBuilder::sink_; -UUri TestUMessageBuilder::method_; -UUID TestUMessageBuilder::reqId_; +v1::UUri TestUMessageBuilder::source_; +v1::UUri TestUMessageBuilder::sink_; +v1::UUri TestUMessageBuilder::method_; +v1::UUID TestUMessageBuilder:: req_id_; /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { - UUri topic = source_; + v1::UUri topic = source_; EXPECT_NO_THROW({ - auto builder = UMessageBuilder::publish(std::move(topic)); - UAttributes attr = builder.attributes(); - EXPECT_EQ(attr.type(), UMessageType::UMESSAGE_TYPE_PUBLISH); - EXPECT_EQ(AsString::serialize(attr.source()), - AsString::serialize(source_)); + auto builder = datamodel::builder::UMessageBuilder::publish(std::move(topic)); + const v1::UAttributes& attr = builder.attributes(); + EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_PUBLISH); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(source_)); }); } TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { - UUri topic; - EXPECT_THROW({ UMessageBuilder::publish(std::move(topic)); }, InvalidUUri); + v1::UUri topic; + EXPECT_THROW({ datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, datamodel::validator::uri::InvalidUUri); } /// @brief Test the notification function of the UMessageBuilder TEST_F(TestUMessageBuilder, NotificationTest) { // Call the notification function - UUri source = source_; - UUri sink = sink_; + v1::UUri source = source_; + v1::UUri sink = sink_; EXPECT_NO_THROW({ auto builder = - UMessageBuilder::notification(std::move(source), std::move(sink)); + datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); // Verify the result - UAttributes attr = builder.attributes(); - EXPECT_EQ(attr.type(), UMessageType::UMESSAGE_TYPE_NOTIFICATION); - EXPECT_EQ(AsString::serialize(attr.source()), - AsString::serialize(source_)); - EXPECT_EQ(AsString::serialize(attr.sink()), AsString::serialize(sink_)); + const v1::UAttributes& attr = builder.attributes(); + EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_NOTIFICATION); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(source_)); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), datamodel::serializer::uri::AsString::serialize(sink_)); }); } TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { - UUri source; + v1::UUri source; // Set the source Service Instance ID a wildcard (any) - source.set_ue_id(0xFFFF0000); - UUri sink = sink_; + source.set_ue_id(UI_ID_INVALID_TEST); + v1::UUri sink = sink_; EXPECT_THROW( - { UMessageBuilder::notification(std::move(source), std::move(sink)); }, - InvalidUUri); + { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, + datamodel::validator::uri::InvalidUUri); } TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { - UUri source = source_; - UUri sink; + v1::UUri source = source_; + v1::UUri sink; // Set the source Service Instance ID a wildcard (any) - sink.set_ue_id(0xFFFF0000); + sink.set_ue_id(UI_ID_INVALID_TEST); EXPECT_THROW( - { UMessageBuilder::notification(std::move(source), std::move(sink)); }, - InvalidUUri); + { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, + datamodel::validator::uri::InvalidUUri); } /// @brief Test the request function of the UMessageBuilder TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { - UPriority priority = UPriority::UPRIORITY_CS4; - std::chrono::milliseconds ttl(5000); - UUri method = method_; - UUri source = sink_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; + std::chrono::milliseconds ttl(TTL_TIME); + v1::UUri method = method_; + v1::UUri source = sink_; EXPECT_NO_THROW({ - auto builder = UMessageBuilder::request( + auto builder = datamodel::builder::UMessageBuilder::request( std::move(method), std::move(source), priority, ttl); auto attr = builder.build().attributes(); - EXPECT_EQ(attr.type(), UMessageType::UMESSAGE_TYPE_REQUEST); - EXPECT_EQ(AsString::serialize(attr.sink()), - AsString::serialize(method_)); - EXPECT_EQ(AsString::serialize(attr.source()), - AsString::serialize(sink_)); + EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_REQUEST); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), + datamodel::serializer::uri::AsString::serialize(method_)); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(sink_)); EXPECT_EQ(attr.priority(), priority); - EXPECT_EQ(attr.ttl(), 5000); + EXPECT_EQ(attr.ttl(), TTL_TIME); }); } TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { - UUri method; - UUri source = source_; - UPriority priority = UPriority::UPRIORITY_CS4; - std::chrono::milliseconds ttl(5000); + v1::UUri method; + v1::UUri source = source_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; + std::chrono::milliseconds ttl(TTL_TIME); EXPECT_THROW( { - UMessageBuilder::request(std::move(method), std::move(source), + datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); }, - InvalidUUri); + datamodel::validator::uri::InvalidUUri); } TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { - UUri source; + v1::UUri source; // Set the source Service Instance ID a wildcard (any) - source.set_ue_id(0xFFFF0000); - UUri method = method_; - UPriority priority = UPriority::UPRIORITY_CS4; - std::chrono::milliseconds ttl(5000); + source.set_ue_id(UI_ID_INVALID_TEST); + v1::UUri method = method_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; + std::chrono::milliseconds ttl(TTL_TIME); EXPECT_THROW( { - UMessageBuilder::request(std::move(method), std::move(source), + datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); }, - InvalidUUri); + datamodel::validator::uri::InvalidUUri); } TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { - UUri method = method_; - UUri source = sink_; - UPriority priority = UPriority::UPRIORITY_CS4; + v1::UUri method = method_; + v1::UUri source = sink_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(-1); // Invalid TTL EXPECT_THROW( { - UMessageBuilder::request(std::move(method), std::move(source), + datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); }, std::out_of_range); @@ -215,85 +226,85 @@ TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { /// @brief Test the response function of the UMessageBuilder TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { - UUri sink = sink_; - UUri method = method_; - UUID request_id = reqId_; + v1::UUri sink = sink_; + v1::UUri method = method_; + v1::UUID request_id = req_id_; - UPriority priority = UPriority::UPRIORITY_CS4; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_NO_THROW({ auto builder = - UMessageBuilder::response(std::move(sink), std::move(request_id), + datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); - UAttributes attr = builder.attributes(); - EXPECT_EQ(attr.type(), UMessageType::UMESSAGE_TYPE_RESPONSE); - EXPECT_EQ(AsString::serialize(attr.sink()), AsString::serialize(sink_)); - EXPECT_EQ(AsString::serialize(attr.source()), - AsString::serialize(method_)); - // EXPECT_EQ(attr.reqid(), reqId_); + const v1::UAttributes& attr = builder.attributes(); + EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_RESPONSE); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), datamodel::serializer::uri::AsString::serialize(sink_)); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(method_)); + // EXPECT_EQ(attr.reqid(), req_id_); EXPECT_EQ(attr.priority(), priority); }); } TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { - UUri sink = sink_; - UUri method; - UUID request_id = reqId_; - UPriority priority = UPriority::UPRIORITY_CS4; + v1::UUri sink = sink_; + v1::UUri method; + v1::UUID request_id = req_id_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( { - UMessageBuilder::response(std::move(sink), std::move(request_id), + datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); }, - InvalidUUri); + datamodel::validator::uri::InvalidUUri); } TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { - UUri sink; + v1::UUri sink; // Set the source Service Instance ID a wildcard (any) - sink.set_ue_id(0xFFFF0000); - UUri method = method_; - UUID request_id = reqId_; - UPriority priority = UPriority::UPRIORITY_CS4; + sink.set_ue_id(UI_ID_INVALID_TEST); + v1::UUri method = method_; + v1::UUID request_id = req_id_; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( { - UMessageBuilder::response(std::move(sink), std::move(request_id), + datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); }, - InvalidUUri); + datamodel::validator::uri::InvalidUUri); } TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { - UUri sink = sink_; - UUri method = method_; - UUID request_id; - UPriority priority = UPriority::UPRIORITY_CS4; + v1::UUri sink = sink_; + v1::UUri method = method_; + v1::UUID request_id; + v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( { - UMessageBuilder::response(std::move(sink), std::move(request_id), + datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); }, - InvalidUuid); + datamodel::validator::uuid::InvalidUuid); } /// @brief withPriority test TEST_F(TestUMessageBuilder, WithPriorityValidForRequestOrResponseSuccess) { auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPriority(UPriority::UPRIORITY_CS4); }); + EXPECT_NO_THROW({ builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); auto builder2 = createFakeResponse(); - EXPECT_NO_THROW({ builder2.withPriority(UPriority::UPRIORITY_CS4); }); + EXPECT_NO_THROW({ builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); } TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { auto builder = createFakeRequest(); EXPECT_THROW( - { builder.withPriority(static_cast(UPriority_MIN - 1)); }, + { builder.withPriority(static_cast(v1::UPriority_MIN - 1)); }, std::out_of_range); EXPECT_THROW( - { builder.withPriority(static_cast(UPriority_MAX + 1)); }, + { builder.withPriority(static_cast(v1::UPriority_MAX + 1)); }, std::out_of_range); } @@ -303,7 +314,7 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { EXPECT_THROW( { builder.withPriority( - static_cast(UPriority::UPRIORITY_CS4 - 1)); + static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); }, std::out_of_range); @@ -312,7 +323,7 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { EXPECT_THROW( { builder2.withPriority( - static_cast(UPriority::UPRIORITY_CS4 - 1)); + static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); }, std::out_of_range); } @@ -384,22 +395,22 @@ TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { /// @brief withCommStatus tests TEST_F(TestUMessageBuilder, WithCommStatusOnResponseSuccess) { auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(UCode::OK); }); + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); } TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(UCode::OK); }); + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); } TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withCommStatus(UCode::OK); }, std::domain_error); + EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, std::domain_error); } TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withCommStatus(static_cast(-1)); }, + EXPECT_THROW({ builder.withCommStatus(static_cast(-1)); }, std::out_of_range); } @@ -407,13 +418,13 @@ TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { TEST_F(TestUMessageBuilder, WithPayloadFormatOnRequestSuccess) { auto builder = createFakeRequest(); EXPECT_NO_THROW( - { builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); + { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); } TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { auto builder = createFakeResponse(); EXPECT_NO_THROW( - { builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); + { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); } TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { @@ -421,7 +432,7 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { EXPECT_THROW( { builder.withPayloadFormat( - static_cast(UPayloadFormat_MIN - 1)); + static_cast(v1::UPayloadFormat_MIN - 1)); }, std::out_of_range); } @@ -431,7 +442,7 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { EXPECT_THROW( { builder.withPayloadFormat( - static_cast(UPayloadFormat_MAX + 1)); + static_cast(v1::UPayloadFormat_MAX + 1)); }, std::out_of_range); } @@ -445,7 +456,7 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadFormatSuccess) { TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { auto builder = createFakeRequest(); auto message = builder.build(); - EXPECT_TRUE(typeid(message) == typeid(UMessage)); + EXPECT_TRUE(typeid(message) == typeid(v1::UMessage)); EXPECT_TRUE(builder.attributes().priority() == message.attributes().priority()); EXPECT_TRUE(builder.attributes().ttl() == message.attributes().ttl()); @@ -457,17 +468,17 @@ TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { auto builder = createFakeRequest(); - builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_JSON); + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); EXPECT_THROW( { auto message = builder.build(); }, - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); } TEST_F(TestUMessageBuilder, BuildWithPayloadWithPayloadFormatSuccess) { auto builder = createFakeRequest(); - builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; - Payload payload(data, UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); } @@ -475,19 +486,19 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadWithPayloadFormatSuccess) { TEST_F(TestUMessageBuilder, BuildWithPayloadWithoutPayloadFormatSuccess) { auto builder = createFakeRequest(); std::string data = "test-data"; - Payload payload(data, UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); } TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { auto builder = createFakeRequest(); - builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; - Payload payload(data, UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto message = builder.build(std::move(payload)); - EXPECT_TRUE(typeid(message) == typeid(UMessage)); + EXPECT_TRUE(typeid(message) == typeid(v1::UMessage)); EXPECT_TRUE(builder.attributes().priority() == message.attributes().priority()); EXPECT_TRUE(builder.attributes().ttl() == message.attributes().ttl()); @@ -496,18 +507,18 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { EXPECT_TRUE( urisAreEqual(builder.attributes().sink(), message.attributes().sink())); - EXPECT_TRUE(message.payload().data() == data); + EXPECT_TRUE(message.payload() == data); } TEST_F(TestUMessageBuilder, BuildWithPayloadMismatchedPayloadFormatThrows) { auto builder = createFakeRequest(); - builder.withPayloadFormat(UPayloadFormat::UPAYLOAD_FORMAT_JSON); + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); std::string data = "test-data"; - Payload payload(data, UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); EXPECT_THROW( { auto message = builder.build(std::move(payload)); }, - uprotocol::datamodel::builder::UMessageBuilder::UnexpectedFormat); + datamodel::builder::UMessageBuilder::UnexpectedFormat); } -} // namespace +} // namespace uprotocol From be386c85ab06f2a3dcc2bef096d0e14f02a027ec Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 9 Apr 2025 16:58:07 +0200 Subject: [PATCH 12/41] Finished UMessageValidatorTest --- .../datamodel/UMessageBuilderTest.cpp | 166 ++--- .../datamodel/UMessageValidatorTest.cpp | 613 +++++++++--------- 2 files changed, 406 insertions(+), 373 deletions(-) diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index d0a844059..f52c73622 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -108,9 +108,9 @@ v1::UUri TestUMessageBuilder::method_; v1::UUID TestUMessageBuilder:: req_id_; /// @brief Test the publish function of the UMessageBuilder -TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { +TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT v1::UUri topic = source_; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::publish(std::move(topic)); const v1::UAttributes& attr = builder.attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_PUBLISH); @@ -119,18 +119,18 @@ TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { }); } -TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { +TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { // NOLINT v1::UUri topic; - EXPECT_THROW({ datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, datamodel::validator::uri::InvalidUUri); + EXPECT_THROW({ datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, datamodel::validator::uri::InvalidUUri); // NOLINT } /// @brief Test the notification function of the UMessageBuilder -TEST_F(TestUMessageBuilder, NotificationTest) { +TEST_F(TestUMessageBuilder, NotificationTest) { // NOLINT // Call the notification function v1::UUri source = source_; v1::UUri sink = sink_; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); // Verify the result @@ -142,34 +142,34 @@ TEST_F(TestUMessageBuilder, NotificationTest) { }); } -TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { +TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); v1::UUri sink = sink_; - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { +TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { // NOLINT v1::UUri source = source_; v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, datamodel::validator::uri::InvalidUUri); } /// @brief Test the request function of the UMessageBuilder -TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { +TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); v1::UUri method = method_; v1::UUri source = sink_; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::request( std::move(method), std::move(source), priority, ttl); auto attr = builder.build().attributes(); @@ -183,12 +183,12 @@ TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { }); } -TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { +TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { // NOLINT v1::UUri method; v1::UUri source = source_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); @@ -196,14 +196,14 @@ TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { +TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); v1::UUri method = method_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); @@ -211,12 +211,12 @@ TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { +TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { // NOLINT v1::UUri method = method_; v1::UUri source = sink_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(-1); // Invalid TTL - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), priority, ttl); @@ -225,13 +225,13 @@ TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { } /// @brief Test the response function of the UMessageBuilder -TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { +TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { // NOLINT v1::UUri sink = sink_; v1::UUri method = method_; v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); @@ -245,12 +245,12 @@ TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { }); } -TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { +TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { // NOLINT v1::UUri sink = sink_; v1::UUri method; v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); @@ -258,14 +258,14 @@ TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { +TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { // NOLINT v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); v1::UUri method = method_; v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW( + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); @@ -273,12 +273,12 @@ TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { +TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { // NOLINT v1::UUri sink = sink_; v1::UUri method = method_; v1::UUID request_id; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW( + EXPECT_THROW(// NOLINT { datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), priority, std::move(method)); @@ -287,31 +287,31 @@ TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { } /// @brief withPriority test -TEST_F(TestUMessageBuilder, WithPriorityValidForRequestOrResponseSuccess) { +TEST_F(TestUMessageBuilder, WithPriorityValidForRequestOrResponseSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); + EXPECT_NO_THROW({ builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); // NOLINT auto builder2 = createFakeResponse(); - EXPECT_NO_THROW({ builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); + EXPECT_NO_THROW({ builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { +TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withPriority(static_cast(v1::UPriority_MIN - 1)); }, std::out_of_range); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withPriority(static_cast(v1::UPriority_MAX + 1)); }, std::out_of_range); } -TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { +TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withPriority( static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); @@ -320,7 +320,7 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { auto builder2 = createFakeResponse(); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder2.withPriority( static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); @@ -329,22 +329,22 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { } ///@brief withTtl() tests -TEST_F(TestUMessageBuilder, WithTtlValidSuccess) { +TEST_F(TestUMessageBuilder, WithTtlValidSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withTtl(std::chrono::milliseconds(1)); }); - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ builder.withTtl(std::chrono::milliseconds(1)); }); // NOLINT + EXPECT_NO_THROW({ // NOLINT builder.withTtl( std::chrono::milliseconds(std::numeric_limits::max())); }); } -TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { +TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(-1)); }, + EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(-1)); }, // NOLINT std::out_of_range); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withTtl(std::chrono::milliseconds( static_cast(std::numeric_limits::max()) + @@ -353,83 +353,83 @@ TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { std::out_of_range); } -TEST_F(TestUMessageBuilder, WithTtlZeroThrows) { +TEST_F(TestUMessageBuilder, WithTtlZeroThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(0)); }, + EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(0)); }, // NOLINT std::out_of_range); } /// @brief withToken tests -TEST_F(TestUMessageBuilder, WithTokenEmptyStringSuccess) { +TEST_F(TestUMessageBuilder, WithTokenEmptyStringSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withToken(""); }); + EXPECT_NO_THROW({ builder.withToken(""); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithTokenOnNonRequestThrows) { +TEST_F(TestUMessageBuilder, WithTokenOnNonRequestThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withToken("token"); }, std::domain_error); + EXPECT_THROW({ builder.withToken("token"); }, std::domain_error); // NOLINT } -TEST_F(TestUMessageBuilder, WithTokenOnRequestSuccess) { +TEST_F(TestUMessageBuilder, WithTokenOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withToken("token"); }); + EXPECT_NO_THROW({ builder.withToken("token"); }); // NOLINT } /// @brief withPermissionLevel tests -TEST_F(TestUMessageBuilder, WithPermissionLevelOnRequestSuccess) { +TEST_F(TestUMessageBuilder, WithPermissionLevelOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPermissionLevel(1); }); + EXPECT_NO_THROW({ builder.withPermissionLevel(1); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithPermissionLevelOnNonRequestThrows) { +TEST_F(TestUMessageBuilder, WithPermissionLevelOnNonRequestThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withPermissionLevel(1); }, std::domain_error); + EXPECT_THROW({ builder.withPermissionLevel(1); }, std::domain_error); // NOLINT } -TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { +TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPermissionLevel(0); }); + EXPECT_NO_THROW({ builder.withPermissionLevel(0); }); // NOLINT } /// @brief withCommStatus tests -TEST_F(TestUMessageBuilder, WithCommStatusOnResponseSuccess) { +TEST_F(TestUMessageBuilder, WithCommStatusOnResponseSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { +TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { +TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, std::domain_error); + EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, std::domain_error); // NOLINT } -TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { +TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withCommStatus(static_cast(-1)); }, + EXPECT_THROW({ builder.withCommStatus(static_cast(-1)); }, // NOLINT std::out_of_range); } /// @brief withPayloadFormat tests -TEST_F(TestUMessageBuilder, WithPayloadFormatOnRequestSuccess) { +TEST_F(TestUMessageBuilder, WithPayloadFormatOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); } -TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { +TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); } -TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { +TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withPayloadFormat( static_cast(v1::UPayloadFormat_MIN - 1)); @@ -437,9 +437,9 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { std::out_of_range); } -TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { +TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { builder.withPayloadFormat( static_cast(v1::UPayloadFormat_MAX + 1)); @@ -448,12 +448,12 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { } /// @brief build() tests -TEST_F(TestUMessageBuilder, BuildWithPayloadFormatSuccess) { +TEST_F(TestUMessageBuilder, BuildWithPayloadFormatSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ auto message = builder.build(); }); + EXPECT_NO_THROW({ auto message = builder.build(); }); // NOLINT } -TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { +TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { // NOLINT auto builder = createFakeRequest(); auto message = builder.build(); EXPECT_TRUE(typeid(message) == typeid(v1::UMessage)); @@ -466,32 +466,32 @@ TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { urisAreEqual(builder.attributes().sink(), message.attributes().sink())); } -TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { +TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto message = builder.build(); }, datamodel::builder::UMessageBuilder::UnexpectedFormat); } -TEST_F(TestUMessageBuilder, BuildWithPayloadWithPayloadFormatSuccess) { +TEST_F(TestUMessageBuilder, BuildWithPayloadWithPayloadFormatSuccess) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); + EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); // NOLINT } -TEST_F(TestUMessageBuilder, BuildWithPayloadWithoutPayloadFormatSuccess) { +TEST_F(TestUMessageBuilder, BuildWithPayloadWithoutPayloadFormatSuccess) { // NOLINT auto builder = createFakeRequest(); std::string data = "test-data"; datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); + EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); // NOLINT } -TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { +TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; @@ -510,13 +510,13 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { EXPECT_TRUE(message.payload() == data); } -TEST_F(TestUMessageBuilder, BuildWithPayloadMismatchedPayloadFormatThrows) { +TEST_F(TestUMessageBuilder, BuildWithPayloadMismatchedPayloadFormatThrows) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); std::string data = "test-data"; datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto message = builder.build(std::move(payload)); }, datamodel::builder::UMessageBuilder::UnexpectedFormat); } diff --git a/test/coverage/datamodel/UMessageValidatorTest.cpp b/test/coverage/datamodel/UMessageValidatorTest.cpp index 7624e584a..29fc10338 100644 --- a/test/coverage/datamodel/UMessageValidatorTest.cpp +++ b/test/coverage/datamodel/UMessageValidatorTest.cpp @@ -13,29 +13,37 @@ #include #include #include +#include -namespace { - -using namespace uprotocol::v1; -using namespace uprotocol::datamodel::validator::message; +namespace uprotocol::v1{ class TestUMessageValidator : public testing::Test { +private: + UUri source_; + UUri sink_; + // Note: this is used when intentionally setting an unexpected request ID + UUID reqId_; protected: // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { + constexpr uint32_t SOURCE_UE_ID = 0x00010001; + constexpr uint32_t SINK_UE_ID = 0x00010002; + constexpr uint32_t REQID_MSB = 0x1234; + constexpr uint32_t REQID_LSB = 0x5678; + source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(0x00010001); + source_.set_ue_id(SOURCE_UE_ID); source_.set_ue_version_major(1); source_.set_resource_id(1); sink_.set_authority_name("10.0.0.2"); - sink_.set_ue_id(0x00010002); + sink_.set_ue_id(SINK_UE_ID); sink_.set_ue_version_major(2); sink_.set_resource_id(2); - reqId_.set_msb(0x1234); - reqId_.set_lsb(0x5678); + reqId_.set_msb(REQID_MSB); + reqId_.set_lsb(REQID_LSB); } void TearDown() override {} @@ -43,20 +51,23 @@ class TestUMessageValidator : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUMessageValidator() = default; - ~TestUMessageValidator() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - UUri source_; - UUri sink_; - // Note: this is used when intentionally setting an unexpected request ID - UUID reqId_; + UUri& getSource() { return source_; } + UUri& getSink() { return sink_;} + const UUID& getReqId() const { return reqId_;} + +public: + ~TestUMessageValidator() override = default; }; UAttributes fakeRequest(const UUri& source, const UUri& sink) { + constexpr uint16_t DEFAULT_TTL = 1000; + UAttributes attributes; static auto uuid_builder = @@ -68,7 +79,7 @@ UAttributes fakeRequest(const UUri& source, const UUri& sink) { *attributes.mutable_sink() = sink; attributes.set_priority(UPRIORITY_CS4); attributes.set_payload_format(UPAYLOAD_FORMAT_PROTOBUF); - attributes.set_ttl(1000); + attributes.set_ttl(DEFAULT_TTL); return attributes; } @@ -91,6 +102,8 @@ UAttributes fakeResponse(const UUri& sink, const UUri& source) { } UAttributes fakePublish(const UUri& source) { + constexpr uint16_t DEFAULT_TTL = 1000; + UAttributes attributes; static auto uuid_builder = @@ -100,7 +113,7 @@ UAttributes fakePublish(const UUri& source) { *attributes.mutable_id() = uuid_builder.build(); *attributes.mutable_source() = source; attributes.set_payload_format(UPAYLOAD_FORMAT_PROTOBUF); - attributes.set_ttl(1000); + attributes.set_ttl(DEFAULT_TTL); return attributes; } @@ -126,215 +139,223 @@ UMessage build(UAttributes& attributes) { return umessage; } -void testCommonAttributes(UAttributes& attributesIn) { - { - // valid w/ttl - auto attributes = UAttributes(attributesIn); - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_TRUE(valid); - EXPECT_FALSE(reason.has_value()); - } +void testValidWithTTL(UAttributes& attributes_in) { + auto attributes = UAttributes(attributes_in); + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_TRUE(valid); + EXPECT_FALSE(reason.has_value()); +} - { - // valid w/o ttl - auto attributes = UAttributes(attributesIn); - attributes.clear_ttl(); - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_TRUE(valid); - EXPECT_FALSE(reason.has_value()); - } +void testValidWithoutTTL(UAttributes& attributes_in) { + auto attributes = UAttributes(attributes_in); + attributes.clear_ttl(); + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_TRUE(valid); + EXPECT_FALSE(reason.has_value()); +} - { - // missing id - auto attributes = UAttributes(attributesIn); - attributes.clear_id(); - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_ID); - } +void testMissingId(UAttributes& attributes_in) { + auto attributes = UAttributes(attributes_in); + attributes.clear_id(); + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); +} - { - // invalid id - auto attributes = UAttributes(attributesIn); - UUID local_id(attributes.id()); - local_id.set_lsb(0); - *attributes.mutable_id() = local_id; - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_ID); - } +void testInvalidId(UAttributes& attributes_in) { + auto attributes = UAttributes(attributes_in); + UUID local_id(attributes.id()); + local_id.set_lsb(0); + *attributes.mutable_id() = local_id; + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); +} - { - // expired ttl - auto attributes = UAttributes(attributesIn); - attributes.set_ttl(10); - usleep(20000); // sleep (id should be expired by now) - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::ID_EXPIRED); - } +void testExpiredTTL(UAttributes& attributes_in) { + constexpr uint16_t SLEEP_TIME = 20000; + constexpr uint16_t DEFAULT_TTL = 10; + + auto attributes = UAttributes(attributes_in); + attributes.set_ttl(DEFAULT_TTL); + usleep(SLEEP_TIME); // sleep (id should be expired by now) + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); +} - { - // out of range priority - auto attributes = UAttributes(attributesIn); - attributes.set_priority(UPriority(UPriority_MAX + 10)); - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::PRIORITY_OUT_OF_RANGE); - } +void testOutOfRangePriority(UAttributes& attributes_in) { + constexpr uint16_t DEFAULT_TTL = 10; - { - // out of range payload format - auto attributes = UAttributes(attributesIn); - attributes.set_payload_format(UPayloadFormat(UPayloadFormat_MAX + 10)); - auto umessage = build(attributes); - auto [valid, reason] = areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::PAYLOAD_FORMAT_OUT_OF_RANGE); - } + auto attributes = UAttributes(attributes_in); + attributes.set_priority(UPriority(UPriority_MAX + DEFAULT_TTL)); + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); +} + +void testOutOfRangePayloadFormat(UAttributes& attributes_in) { + constexpr uint16_t DEFAULT_TTL = 10; + + auto attributes = UAttributes(attributes_in); + attributes.set_payload_format(UPayloadFormat(UPayloadFormat_MAX + DEFAULT_TTL)); + auto umessage = build(attributes); + auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PAYLOAD_FORMAT_OUT_OF_RANGE); +} + +void testCommonAttributes(UAttributes& attributes_in) { + testValidWithTTL(attributes_in); + testValidWithoutTTL(attributes_in); + testMissingId(attributes_in); + testInvalidId(attributes_in); + testExpiredTTL(attributes_in); + testOutOfRangePriority(attributes_in); + testOutOfRangePayloadFormat(attributes_in); } -TEST_F(TestUMessageValidator, ValidRpcRequest) { - source_.set_resource_id(0); // must be 0 for valid requests +TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT + getSource().set_resource_id(0); // must be 0 for valid requests { // test common attributes for any message - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); testCommonAttributes(attributes); } { // valid - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { // set wrong type - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_RESPONSE); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); } { // missing source - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // missing sink - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // invalid source - UUri source = source_; + UUri source = getSource(); source.set_resource_id(1); // should be zero - auto attributes = fakeRequest(source, sink_); + auto attributes = fakeRequest(source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // invalid sink - UUri sink = sink_; + UUri sink = getSink(); sink.set_resource_id(0); // should NOT be zero - auto attributes = fakeRequest(source_, sink); + auto attributes = fakeRequest(getSource(), sink); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // wrong priority - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.set_priority(UPRIORITY_CS3); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); } { // Missing TTL - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_ttl(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::INVALID_TTL); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } { // Invalid TTL (zero) - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.set_ttl(0); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::INVALID_TTL); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } { // incorrectly set commstatus - auto attributes = fakeRequest(source_, sink_); + auto attributes = fakeRequest(getSource(), getSink()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // incorrectly set reqid - auto attributes = fakeRequest(source_, sink_); - *attributes.mutable_reqid() = reqId_; + auto attributes = fakeRequest(getSource(), getSink()); + *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcRequest(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidRpcResponse) { - source_.set_resource_id(0); +TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT + getSource().set_resource_id(0); { // test common attributes for any message - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); testCommonAttributes(attributes); } { // valid - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Only for debugging a test - should only happen if test is already @@ -346,65 +367,65 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { { // set wrong type - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); } { // missing source - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // missing sink - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // invalid source - UUri source = source_; + UUri source = getSource(); source.set_resource_id(1); // should be zero - auto attributes = fakeResponse(source, sink_); + auto attributes = fakeResponse(source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // invalid sink - UUri sink = sink_; + UUri sink = getSink(); sink.set_resource_id(0); // should NOT be zero - auto attributes = fakeResponse(source_, sink); + auto attributes = fakeResponse(getSource(), sink); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // missing reqid - UUri sink = sink_; - auto attributes = fakeResponse(source_, sink_); + UUri sink = getSink(); + auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_reqid(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::REQID_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { @@ -412,77 +433,79 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { UUID local_id; local_id.set_lsb(0); local_id.set_msb(0); - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); *attributes.mutable_reqid() = local_id; auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::REQID_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { // no ttl set - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_ttl(); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { // expired ttl - auto attributes = fakeResponse(source_, sink_); + constexpr uint16_t SLEEP_TIME = 20000; + auto attributes = fakeResponse(getSource(), getSink()); attributes.set_ttl(1); - usleep(20000); // sleep (id should be expired by now) + usleep(SLEEP_TIME); // sleep (id should be expired by now) auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::ID_EXPIRED); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); } { // invalid priority - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.set_priority(UPRIORITY_CS3); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); } { // set permission level (shouldn't be set) - auto attributes = fakeResponse(source_, sink_); - attributes.set_permission_level(7); + constexpr uint16_t ATTRIBUTES_PERMISSION_LEVEL = 7; + auto attributes = fakeResponse(getSource(), getSink()); + attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set token (shouldn't be set) - auto attributes = fakeResponse(source_, sink_); + auto attributes = fakeResponse(getSource(), getSink()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = isValidRpcResponse(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidRpcResponseFor) { - source_.set_resource_id(0); +TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT + getSource().set_resource_id(0); { // valid - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); *res_attr.mutable_reqid() = req_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Only for debugging test - shows reason when test is already failing @@ -493,293 +516,300 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { { // missing reqId - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); res_attr.clear_reqid(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::REQID_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { // invalid reqId (does NOT match the request's id) - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); *res_attr.mutable_reqid() = res_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::REQID_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { // URI Mismatch - the response's sink doesn't match the request source - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); res_attr.mutable_sink()->set_ue_version_major( res_attr.sink().ue_version_major() + 1); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::URI_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); } { // URI Mismatch - the response's source doesn't match the request sink - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); res_attr.mutable_source()->set_ue_version_major( res_attr.source().ue_version_major() + 1); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::URI_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); } { // mismatch the priority - auto req_attr = fakeRequest(source_, sink_); - auto res_attr = fakeResponse(source_, sink_); + auto req_attr = fakeRequest(getSource(), getSink()); + auto res_attr = fakeResponse(getSource(), getSink()); res_attr.set_priority(UPRIORITY_CS6); *res_attr.mutable_reqid() = req_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = isValidRpcResponseFor(request, response); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::PRIORITY_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_MISMATCH); // Test debugging - EXPECT_EQ(message(*reason), message(Reason::PRIORITY_MISMATCH)); + EXPECT_EQ(message(*reason), message(uprotocol::datamodel::validator::message::Reason::PRIORITY_MISMATCH)); } } -TEST_F(TestUMessageValidator, ValidPublish) { - source_.set_resource_id(0x8000); +TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT + constexpr uint32_t SOURCE_RESCOURCE_ID = 0x8000; + getSource().set_resource_id(SOURCE_RESCOURCE_ID); { // test common attributes for any message - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); testCommonAttributes(attributes); } { // valid - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { // wrong type - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); } { // missing source - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // invalid source - UUri source = source_; - source.set_resource_id(0x7FFF); // should greater than 0x8000 + constexpr uint32_t SOURCE_RESCOURCE_ID_INVALID = 0x7FFF; + UUri source = getSource(); + source.set_resource_id(SOURCE_RESCOURCE_ID_INVALID); // should greater than 0x8000 auto attributes = fakePublish(source); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // set a sink (unexpected) - auto attributes = fakePublish(source_); - *attributes.mutable_sink() = sink_; + auto attributes = fakePublish(getSource()); + *attributes.mutable_sink() = getSink(); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set commstat (unexpected) - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set reqid (unexpected) - auto attributes = fakePublish(source_); - *attributes.mutable_reqid() = reqId_; + auto attributes = fakePublish(getSource()); + *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set permission level (unexpected) - auto attributes = fakePublish(source_); - attributes.set_permission_level(7); + constexpr uint16_t ATTRIBUTES_PERMISSION_LEVEL = 7; + auto attributes = fakePublish(getSource()); + attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set token (unexpected) - auto attributes = fakePublish(source_); + auto attributes = fakePublish(getSource()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = isValidPublish(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidNotification) { - source_.set_resource_id(0x8001); - sink_.set_resource_id(0); +TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT + constexpr uint32_t SOURCE_RESCOURCE_ID = 0x8001; + getSource().set_resource_id(SOURCE_RESCOURCE_ID); + getSink().set_resource_id(0); { // test common attributes for any message - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); testCommonAttributes(attributes); } { // valid - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { // incorrect type - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); } { // missing source - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // missing sink - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // invalid source - UUri local_source = source_; - local_source.set_resource_id(0x7FFF); // should be greater than 0x8000 - auto attributes = fakeNotification(local_source, sink_); + constexpr uint32_t LOCAL_SOURCE_RESCOURCE_ID = 0x7FFF; + UUri local_source = getSource(); + local_source.set_resource_id(LOCAL_SOURCE_RESCOURCE_ID); // should be greater than 0x8000 + auto attributes = fakeNotification(local_source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // invalid sink - UUri local_sink = sink_; - local_sink.set_resource_id(0x7FFF); // should be greater than 0x8000 - auto attributes = fakeNotification(source_, local_sink); + constexpr uint32_t LOCAL_SOURCE_RESCOURCE_ID = 0x7FFF; + UUri local_sink = getSink(); + local_sink.set_resource_id(LOCAL_SOURCE_RESCOURCE_ID); // should be greater than 0x8000 + auto attributes = fakeNotification(getSource(), local_sink); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::BAD_SINK_URI); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // set commstatus (unexpected) - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set reqid (unexpected) - auto attributes = fakeNotification(source_, sink_); - *attributes.mutable_reqid() = reqId_; + auto attributes = fakeNotification(getSource(), getSink()); + *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set permission level (unexpected) - auto attributes = fakeNotification(source_, sink_); - attributes.set_permission_level(7); + constexpr uint16_t ATTRIBUTES_PERMISSION_LEVEL = 7; + auto attributes = fakeNotification(getSource(), getSink()); + attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } { // set token (unexpected) - auto attributes = fakeNotification(source_, sink_); + auto attributes = fakeNotification(getSource(), getSink()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = isValidNotification(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, IsValid) { +TEST_F(TestUMessageValidator, IsValid) { // NOLINT { // valid request - auto source = source_; - auto sink = sink_; + auto source = getSource(); + auto sink = getSink(); source.set_resource_id(0); auto attributes = fakeRequest(source, sink); auto umessage = build(attributes); { - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -790,10 +820,10 @@ TEST_F(TestUMessageValidator, IsValid) { uprotocol::v1::UMessageType::UMESSAGE_TYPE_UNSPECIFIED); umessage = build(attributes); { - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, Reason::UNSPECIFIED_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::UNSPECIFIED_MESSAGE_TYPE); } // Check with an invalid type @@ -802,10 +832,10 @@ TEST_F(TestUMessageValidator, IsValid) { static_cast(max_type + 1)); umessage = build(attributes); { - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, Reason::INVALID_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_MESSAGE_TYPE); } // Restore the message type to finish out the test @@ -815,22 +845,22 @@ TEST_F(TestUMessageValidator, IsValid) { attributes.set_ttl(0); umessage = build(attributes); { - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, Reason::INVALID_TTL); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } } { // valid response - auto source = source_; - auto sink = sink_; + auto source = getSource(); + auto sink = getSink(); source.set_resource_id(0); auto attributes = fakeResponse(source, sink); auto umessage = build(attributes); - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -838,43 +868,46 @@ TEST_F(TestUMessageValidator, IsValid) { attributes = fakeResponse(sink, source); umessage = build(attributes); - auto [valid2, reason2] = isValid(umessage); + auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, Reason::BAD_SOURCE_URI); + EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { + constexpr uint32_t ATTRIBUTES_INVALID_PRIORITY = 0xFFFF; // valid publish - auto source = source_; - source.set_resource_id(0x8000); + constexpr uint32_t PUBLISH_SOURCE_RESCOURCE_ID = 0x8000; + auto source = getSource(); + source.set_resource_id(PUBLISH_SOURCE_RESCOURCE_ID); auto attributes = fakePublish(source); auto umessage = build(attributes); - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Make the request invalid by making one change - attributes.set_priority(static_cast(0xFFFF)); + attributes.set_priority(static_cast(ATTRIBUTES_INVALID_PRIORITY)); umessage = build(attributes); - auto [valid2, reason2] = isValid(umessage); + auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); } { // valid notification - auto source = source_; - auto sink = sink_; - source.set_resource_id(0x8001); + constexpr uint32_t NOTIFICATION_SOURCE_RESCOURCE_ID = 0x8001; + auto source = getSource(); + auto sink = getSink(); + source.set_resource_id(NOTIFICATION_SOURCE_RESCOURCE_ID); sink.set_resource_id(0); auto attributes = fakeNotification(source, sink); auto umessage = build(attributes); - auto [valid, reason] = isValid(umessage); + auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -882,11 +915,11 @@ TEST_F(TestUMessageValidator, IsValid) { *(attributes.mutable_reqid()) = attributes.id(); umessage = build(attributes); - auto [valid2, reason2] = isValid(umessage); + auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); } } -} // namespace +} // namespace uprotocol::v1 From 2c71e6314af51ed55d7e17e554832af3f082e4ca Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 08:50:36 +0200 Subject: [PATCH 13/41] Solve linter warnings --- test/coverage/datamodel/UuidBuilderTest.cpp | 61 ++++----- .../coverage/datamodel/UuidSerializerTest.cpp | 122 ++++++++++-------- 2 files changed, 101 insertions(+), 82 deletions(-) diff --git a/test/coverage/datamodel/UuidBuilderTest.cpp b/test/coverage/datamodel/UuidBuilderTest.cpp index f6f7d1cea..f770f59b0 100644 --- a/test/coverage/datamodel/UuidBuilderTest.cpp +++ b/test/coverage/datamodel/UuidBuilderTest.cpp @@ -14,10 +14,8 @@ #include "up-cpp/datamodel/builder/Uuid.h" #include "up-cpp/datamodel/constants/UuidConstants.h" -namespace { - -using namespace uprotocol::datamodel::builder; -using namespace uprotocol::datamodel; +// using namespace uprotocol::datamodel::builder::; +namespace uprotocol::datamodel{ class TestUuidBuilder : public testing::Test { protected: @@ -25,15 +23,16 @@ class TestUuidBuilder : public testing::Test { void TearDown() override {} TestUuidBuilder() = default; - ~TestUuidBuilder() = default; static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestUuidBuilder() override = default; }; // Test getBuilder -TEST(UuidBuilderTest, GetBuilder) { - auto builder = UuidBuilder::getBuilder(); +TEST(UuidBuilderTest, GetBuilder) { // NOLINT + auto builder = builder::UuidBuilder::getBuilder(); auto uuid = builder.build(); EXPECT_TRUE(uuid.msb()); @@ -41,8 +40,8 @@ TEST(UuidBuilderTest, GetBuilder) { } // Test GetTestBuilder -TEST(UuidBuilderTest, GetTestBuilder) { - auto builder = UuidBuilder::getTestBuilder(); +TEST(UuidBuilderTest, GetTestBuilder) { // NOLINT + auto builder = builder::UuidBuilder::getTestBuilder(); auto uuid = builder.build(); EXPECT_TRUE(uuid.msb()); @@ -50,11 +49,12 @@ TEST(UuidBuilderTest, GetTestBuilder) { } // Test TestBuilder with time source -TEST(UuidBuilderTest, WithTimeSource) { - auto fixed_time = std::chrono::system_clock::from_time_t(1234567890); +TEST(UuidBuilderTest, WithTimeSource) { // NOLINT + constexpr std::time_t FIXED_TIME_T = 1234567890; + auto fixed_time = std::chrono::system_clock::from_time_t(FIXED_TIME_T); auto fixed_time_ms = std::chrono::time_point_cast(fixed_time); - auto builder = UuidBuilder::getTestBuilder().withTimeSource( + auto builder = builder::UuidBuilder::getTestBuilder().withTimeSource( [fixed_time]() { return fixed_time; }); auto uuid = builder.build(); @@ -63,9 +63,10 @@ TEST(UuidBuilderTest, WithTimeSource) { } // Test RandomSource -TEST(UuidBuilderTest, WithRandomSource) { - auto fixed_random = 0x1234567890ABCDEF; - auto builder = UuidBuilder::getTestBuilder().withRandomSource( +TEST(UuidBuilderTest, WithRandomSource) { // NOLINT + constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; + uint64_t fixed_random = FIXED_RANDOM_T; + auto builder = builder::UuidBuilder::getTestBuilder().withRandomSource( [fixed_random]() { return fixed_random; }); auto uuid = builder.build(); @@ -76,9 +77,9 @@ TEST(UuidBuilderTest, WithRandomSource) { } // Test independent state -TEST(UuidBuilderTest, Unguessability) { - auto builder1 = UuidBuilder::getBuilder(); - auto builder2 = UuidBuilder::getBuilder(); +TEST(UuidBuilderTest, Unguessability) { // NOLINT + auto builder1 = builder::UuidBuilder::getBuilder(); + auto builder2 = builder::UuidBuilder::getBuilder(); { // Check that rand fields generated by different builders are different @@ -104,19 +105,19 @@ TEST(UuidBuilderTest, Unguessability) { } // Test exception thrown -TEST(UuidBuilderTest, TestModeOnly) { - auto builder = UuidBuilder::getBuilder(); +TEST(UuidBuilderTest, TestModeOnly) { // NOLINT + auto builder = builder::UuidBuilder::getBuilder(); - EXPECT_THROW(builder.withTimeSource( + EXPECT_THROW(builder.withTimeSource( // NOLINT []() { return std::chrono::system_clock::now(); }), std::domain_error); - EXPECT_THROW(builder.withRandomSource([]() { return 0x1234567890ABCDEF; }), + EXPECT_THROW(builder.withRandomSource([]() { return 0x1234567890ABCDEF; }), // NOLINT std::domain_error); } // Test version and variant -TEST_F(TestUuidBuilder, CheckVersionAndVariant) { - auto builder = UuidBuilder::getBuilder(); +TEST_F(TestUuidBuilder, CheckVersionAndVariant) { // NOLINT + auto builder = builder::UuidBuilder::getBuilder(); auto uuid = builder.build(); EXPECT_EQ((uuid.msb() >> UUID_VERSION_SHIFT) & UUID_VERSION_MASK, @@ -126,17 +127,19 @@ TEST_F(TestUuidBuilder, CheckVersionAndVariant) { } // Test custom time and random source with builder -TEST(UuidBuilderTest, CustomTimeAndRandomSource) { +TEST(UuidBuilderTest, CustomTimeAndRandomSource) { // NOLINT + constexpr std::time_t FIXED_TIME_T = 1623456789; + constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; // Create a custom time source that returns a fixed timestamp - auto fixed_time = std::chrono::system_clock::from_time_t(1623456789); + auto fixed_time = std::chrono::system_clock::from_time_t(FIXED_TIME_T); auto time_source = [fixed_time]() { return fixed_time; }; // Create a custom random source that returns a fixed random value - uint64_t fixed_random = 0x1234567890ABCDEF; + uint64_t fixed_random = FIXED_RANDOM_T; auto random_source = [fixed_random]() { return fixed_random; }; // Create a UuidBuilder with the custom time and random sources - auto builder = UuidBuilder::getTestBuilder() + auto builder = builder::UuidBuilder::getTestBuilder() .withTimeSource(time_source) .withRandomSource(random_source); @@ -157,4 +160,4 @@ TEST(UuidBuilderTest, CustomTimeAndRandomSource) { EXPECT_EQ(random_value, fixed_random); } -} // namespace +} // namespace uprotocol::datamodel diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index 152f29fe5..9c3404598 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -13,10 +13,9 @@ #include #include -#include #include -namespace { +namespace uprotocol::datamodel::serializer::uuid{ class TestUuidSerializer : public testing::Test { protected: @@ -28,58 +27,67 @@ class TestUuidSerializer : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUuidSerializer() = default; - ~TestUuidSerializer() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestUuidSerializer() override = default; }; // Test string serialization TEST_F(TestUuidSerializer, SerializeToString) { + constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; + constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; uprotocol::v1::UUID uuid; - uuid.set_msb(0x1234567890ABCDEF); - uuid.set_lsb(0xFEDCBA0987654321); + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string serialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "12345678-90ab-cdef-fedc-ba0987654321"); } // Test serialization with leading zeros in each segment TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { + constexpr uint64_t UUID_MSB = 0x00001234007800AB; + constexpr uint64_t UUID_LSB = 0x00FE00BA09876543; uprotocol::v1::UUID uuid; - uuid.set_msb(0x00001234007800AB); - uuid.set_lsb(0x00FE00BA09876543); + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string serialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-0078-00ab-00fe-00ba09876543"); } // Test serialization with mixed case letters TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { + constexpr uint64_t UUID_MSB = 0x1234567890ABcDEF; + constexpr uint64_t UUID_LSB = 0x00dcbA0987654321; uprotocol::v1::UUID uuid; - uuid.set_msb(0x1234567890ABcDEF); - uuid.set_lsb(0x00dcbA0987654321); + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string serialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); // Assert the serialized UUID matches the expected value in lowercase EXPECT_EQ(serialized_uuid, "12345678-90ab-cdef-00dc-ba0987654321"); } // Test serialization with leading zeros and mixed case letters TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { + constexpr uint64_t UUID_MSB = 0x00001234567890AB; + constexpr uint64_t UUID_LSB = 0xFedcba0987654982; uprotocol::v1::UUID uuid; - uuid.set_msb(0x00001234567890AB); - uuid.set_lsb(0xFedcba0987654982); + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string serialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-5678-90ab-fedc-ba0987654982"); } @@ -87,12 +95,14 @@ TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { // Test serialization with leading/trailing zeros and mixed case letters TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndTrailingZerosAndMixedCaseLetters) { + constexpr uint64_t UUID_MSB = 0x00001234567890AB; + constexpr uint64_t UUID_LSB = 0xFedcba0987600000; uprotocol::v1::UUID uuid; - uuid.set_msb(0x00001234567890AB); - uuid.set_lsb(0xFedcba0987600000); + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string serialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-5678-90ab-fedc-ba0987600000"); } @@ -103,7 +113,7 @@ TEST(DeserializerTest, DeserializeUUID) { std::string uuid_str = "12345678-9abc-def0-fedc-ba9876543210"; // Deserialize the UUID string uprotocol::v1::UUID deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::deserialize(uuid_str); + AsString::deserialize(uuid_str); // Assert the deserialized UUID matches the expected values EXPECT_EQ(deserialized_uuid.msb(), 0x123456789ABCDEF0); EXPECT_EQ(deserialized_uuid.lsb(), 0xFEDCBA9876543210); @@ -115,7 +125,7 @@ TEST_F(TestUuidSerializer, std::string uuid_str = "00001234-5678-90ab-feDc-ba0987600000"; uprotocol::v1::UUID deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::deserialize(uuid_str); + AsString::deserialize(uuid_str); // Assert the deserialized UUID matches the expected values EXPECT_EQ(deserialized_uuid.msb(), 0x00001234567890aB); @@ -127,7 +137,7 @@ TEST(DeserializerTest, InvalidUUIDFormat) { // Define an invalid UUID string (missing dashes) std::string invalid_uuid_str = "123456789abcdef0123456789abcdef0"; // Assert that deserialization throws an invalid argument exception - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid_str), std::invalid_argument); } @@ -136,7 +146,7 @@ TEST(DeserializerTest, InvalidUUIDFormat) { TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { std::string invalid_uuid = "12345678-1234-5678-1234-56781234567"; // Missing one character - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid), std::invalid_argument); } @@ -145,7 +155,7 @@ TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { TEST(DeserializerTest, DeserializeWithExtraCharacter) { std::string invalid_uuid1 = "12345678-1234-5678-1234-1234567890123"; // Extra character at the end - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid1), std::invalid_argument); } @@ -154,25 +164,25 @@ TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { std::string invalid_uuid1 = "123456781-2345-6781-2345-67812345678"; // First Dash placement - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid1), std::invalid_argument); std::string invalid_uuid2 = "12345678-12345-6781-2345-67812345678"; // Second Dash placement - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid2), std::invalid_argument); std::string invalid_uuid3 = "12345678-1234-56781-2345-67812345678"; // Third Dash placement - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid3), std::invalid_argument); std::string invalid_uuid4 = "12345678-1234-5678-12345-67812345678"; // Fourth Dash placement - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid4), std::invalid_argument); } @@ -180,9 +190,9 @@ TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { // Test deserialization with a zero-length string TEST(DeserializerTest, DeserializeEmptyString) { // Define an empty UUID string - std::string empty_uuid_str = ""; + std::string empty_uuid_str; // Deserialize the empty UUID string - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( empty_uuid_str), std::invalid_argument); } @@ -191,7 +201,7 @@ TEST(DeserializerTest, DeserializeEmptyString) { TEST(DeserializerTest, DeserializeInvalidCharacter) { // Define a UUID string with an invalid character ('x' instead of valid hex) std::string invalid_uuid_str = "1234567890ab-cdef-1234-5678-90abcdefxabc"; - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsString::deserialize( + EXPECT_THROW(AsString::deserialize( invalid_uuid_str), std::invalid_argument); } @@ -199,25 +209,29 @@ TEST(DeserializerTest, DeserializeInvalidCharacter) { // Test byte serialization TEST_F(TestUuidSerializer, SerializeToBytes) { uprotocol::v1::UUID uuid; - uuid.set_msb(0x1234567890ABCDEF); - uuid.set_lsb(0xFEDCBA0987654321); + constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; + constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::vector uuid_bytes = - uprotocol::datamodel::serializer::uuid::AsBytes::serialize(uuid); - std::vector expected_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, - 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, - 0x87, 0x65, 0x43, 0x21}; + AsBytes::serialize(uuid); + constexpr std::array EXPECTED_BYTES = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 + }; - EXPECT_EQ(uuid_bytes, expected_bytes); + EXPECT_EQ(uuid_bytes, EXPECTED_BYTES); } // Test byte deserialization TEST_F(TestUuidSerializer, DeserializeFromBytes) { - std::vector uuid_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, - 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, - 0x87, 0x65, 0x43, 0x21}; + const std::vector UUID_BYTES = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 + }; uprotocol::v1::UUID uuid = - uprotocol::datamodel::serializer::uuid::AsBytes::deserialize( + AsBytes::deserialize( uuid_bytes); EXPECT_EQ(uuid.msb(), 0x1234567890ABCDEF); @@ -227,7 +241,7 @@ TEST_F(TestUuidSerializer, DeserializeFromBytes) { // Test invalid byte deserialization TEST_F(TestUuidSerializer, DeserializeInvalidBytes) { std::vector invalid_bytes = {0x12, 0x34, 0x56}; - EXPECT_THROW(uprotocol::datamodel::serializer::uuid::AsBytes::deserialize( + EXPECT_THROW(AsBytes::deserialize( invalid_bytes), std::invalid_argument); } @@ -239,21 +253,21 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { uuid.set_lsb(0x0000000000000000); std::string uuid_str = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); EXPECT_EQ(uuid_str, "00000000-0000-0000-0000-000000000000"); uprotocol::v1::UUID deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::deserialize(uuid_str); + AsString::deserialize(uuid_str); EXPECT_EQ(deserialized_uuid.msb(), 0x0000000000000000); EXPECT_EQ(deserialized_uuid.lsb(), 0x0000000000000000); std::vector uuid_bytes = - uprotocol::datamodel::serializer::uuid::AsBytes::serialize(uuid); + AsBytes::serialize(uuid); std::vector expected_bytes(16, 0x00); EXPECT_EQ(uuid_bytes, expected_bytes); deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsBytes::deserialize( + AsBytes::deserialize( uuid_bytes); EXPECT_EQ(deserialized_uuid.msb(), 0x0000000000000000); EXPECT_EQ(deserialized_uuid.lsb(), 0x0000000000000000); @@ -262,28 +276,30 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { // Test edge case: maximum values for msb and lsb TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { uprotocol::v1::UUID uuid; - uuid.set_msb(0xFFFFFFFFFFFFFFFF); - uuid.set_lsb(0xFFFFFFFFFFFFFFFF); + constexpr uint64_t UUID_MSB = 0xFFFFFFFFFFFFFFFF; + constexpr uint64_t UUID_LSB = 0xFFFFFFFFFFFFFFFF; + uuid.set_msb(UUID_MSB); + uuid.set_lsb(UUID_LSB); std::string uuid_str = - uprotocol::datamodel::serializer::uuid::AsString::serialize(uuid); + AsString::serialize(uuid); EXPECT_EQ(uuid_str, "ffffffff-ffff-ffff-ffff-ffffffffffff"); uprotocol::v1::UUID deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsString::deserialize(uuid_str); + AsString::deserialize(uuid_str); EXPECT_EQ(deserialized_uuid.msb(), 0xFFFFFFFFFFFFFFFF); EXPECT_EQ(deserialized_uuid.lsb(), 0xFFFFFFFFFFFFFFFF); std::vector uuid_bytes = - uprotocol::datamodel::serializer::uuid::AsBytes::serialize(uuid); + AsBytes::serialize(uuid); std::vector expected_bytes(16, 0xFF); EXPECT_EQ(uuid_bytes, expected_bytes); deserialized_uuid = - uprotocol::datamodel::serializer::uuid::AsBytes::deserialize( + AsBytes::deserialize( uuid_bytes); EXPECT_EQ(deserialized_uuid.msb(), 0xFFFFFFFFFFFFFFFF); EXPECT_EQ(deserialized_uuid.lsb(), 0xFFFFFFFFFFFFFFFF); } -} // namespace +} // namespace uprotocol::datamodel::serializer::uuid From 0743fc4f156c10fbbf7012fdbc0fb8bbe1c908c1 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 09:22:29 +0200 Subject: [PATCH 14/41] Update clang-tidy.sh --- lint/clang-tidy.sh | 3 +-- test/coverage/datamodel/UuidSerializerTest.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index e667c0e81..66519ee63 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,8 +58,7 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - # for f in include/**/*.h src/**/*.cpp - for f in test/coverage/datamodel/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index 9c3404598..a39e26535 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -232,7 +232,7 @@ TEST_F(TestUuidSerializer, DeserializeFromBytes) { }; uprotocol::v1::UUID uuid = AsBytes::deserialize( - uuid_bytes); + UUID_BYTES); EXPECT_EQ(uuid.msb(), 0x1234567890ABCDEF); EXPECT_EQ(uuid.lsb(), 0xFEDCBA0987654321); From 70530b4ca7b80cf203060829e6e7d2766c20074f Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 09:27:22 +0200 Subject: [PATCH 15/41] Solved building error --- lint/clang-tidy.sh | 3 ++- test/coverage/datamodel/UuidSerializerTest.cpp | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index 66519ee63..e667c0e81 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,7 +58,8 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + # for f in include/**/*.h src/**/*.cpp + for f in test/coverage/datamodel/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index a39e26535..46a34de29 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -216,23 +216,21 @@ TEST_F(TestUuidSerializer, SerializeToBytes) { std::vector uuid_bytes = AsBytes::serialize(uuid); - constexpr std::array EXPECTED_BYTES = { - 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, - 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 - }; + std::vector expected_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, + 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, + 0x87, 0x65, 0x43, 0x21}; - EXPECT_EQ(uuid_bytes, EXPECTED_BYTES); + EXPECT_EQ(uuid_bytes, expected_bytes); } // Test byte deserialization TEST_F(TestUuidSerializer, DeserializeFromBytes) { - const std::vector UUID_BYTES = { - 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, - 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 - }; + std::vector uuid_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, + 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, + 0x87, 0x65, 0x43, 0x21}; uprotocol::v1::UUID uuid = AsBytes::deserialize( - UUID_BYTES); + uuid_bytes); EXPECT_EQ(uuid.msb(), 0x1234567890ABCDEF); EXPECT_EQ(uuid.lsb(), 0xFEDCBA0987654321); From 12a7bfdb6ed40c4655c2c30b5a6d83025eeeabae Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 11:19:19 +0200 Subject: [PATCH 16/41] Added NOLINT behind makros of TEST_F, EXPECT_THROW and EXPECT_NO_THROW --- .../coverage/datamodel/UUriSerializerTest.cpp | 34 ++--- test/coverage/datamodel/UUriValidatorTest.cpp | 24 +-- .../coverage/datamodel/UuidSerializerTest.cpp | 89 ++++++----- test/coverage/datamodel/UuidValidatorTest.cpp | 141 +++++++++--------- test/coverage/transport/UTransportTest.cpp | 68 ++++----- 5 files changed, 185 insertions(+), 171 deletions(-) diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index ccf154e41..787daf220 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -46,7 +46,7 @@ v1::UUri buildValidTestURI(const std::string& authority = "192.168.1.10") { } // Positive test case - test serialization of UUri to string -TEST_F(TestUUriSerializer, SerializeUUriToString) { +TEST_F(TestUUriSerializer, SerializeUUriToString) { // NOLINT auto testUUri = buildValidTestURI(); const std::string expectedUUri = "//192.168.1.10/10010001/FE/7500"; const std::string actualUUri = AsString::serialize(testUUri); @@ -54,7 +54,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToString) { } // Positive test case - test serialization of UUri with no authority to string -TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { +TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT auto testUUri = buildValidTestURI(""); const std::string expectedUUri = "/10010001/FE/7500"; const std::string actualUUri = AsString::serialize(testUUri); @@ -63,7 +63,7 @@ TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // Test authority name '*' to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { // NOLINT v1::UUri testUUri; testUUri.set_authority_name("*"); // Wildcard testUUri.set_ue_id(0x1FFFE); @@ -76,7 +76,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { // Test Service ID in uEID field as a 0xFFFF to see if it serializes without // an exception for using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { // NOLINT v1::UUri testUUri; testUUri.set_authority_name("testAuthority"); testUUri.set_ue_id(0x1FFFF); // Wildcard @@ -89,7 +89,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { // Test Instance ID in uEID field as a 0x0 to see if it serializes without an // exception for using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { // NOLINT v1::UUri testUUri; testUUri.set_authority_name("testAuthority"); testUUri.set_ue_id(0x00001234); // Wildcard @@ -102,7 +102,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { // Test major version as 0xFF to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { // NOLINT v1::UUri testUUri; testUUri.set_authority_name("testAuthority"); testUUri.set_ue_id(0x12340000); @@ -115,7 +115,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { // Test resource id as 0xFFFF to see if it thorws an exception for using // wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { // NOLINT v1::UUri testUUri; testUUri.set_authority_name("testAuthority"); testUUri.set_ue_id(0x12340000); @@ -127,7 +127,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { } // Attempt to serialize invalid UUris and verify exceptions are thrown -TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { +TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT const v1::UUri baseUUri = []() { v1::UUri uuri; uuri.set_authority_name("testAuthority"); @@ -166,7 +166,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // Test deserialize by providing scheme "up:" which is allowed to have as per // spec -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT const std::string uuriAsString = "up://192.168.1.10/10010001/FE/7500"; const std::string expectedAuthority = "192.168.1.10"; const uint32_t expectedUEID = 0x10010001; @@ -181,14 +181,14 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { } // Test deserialize by providing incorrect scheme "uprotocol:" -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithIncorrectScheme) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithIncorrectScheme) { // NOLINT const std::string uuriAsString = "uprotocol://192.168.1.10/10010001/FE/7500"; ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); } // Test deserialize without providing scheme "up:" -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT const std::string uuriAsString = "//192.168.1.10/10010001/FE/7500"; const std::string expectedAuthority = "192.168.1.10"; const uint32_t expectedUEID = 0x10010001; @@ -203,13 +203,13 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { } // Test deserializing empty string to check if it thorws an exception -TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { +TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT const std::string uuriAsString = ""; ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); } // Test deserializing string with no authority -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT const std::string uuriAsString = "/10010001/FE/7500"; const std::string expectedAuthority = ""; const uint32_t expectedUEID = 0x10010001; @@ -224,7 +224,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { } // Test deserializing string with invalid number of arguments -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidNumberOfArgument) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidNumberOfArgument) { // NOLINT // Provided 5 arguments instead of 4 when authority exist std::string uuriAsString = "//192.168.1.10/10010001/FE/FE/7500"; @@ -261,7 +261,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidNumberOfArgument) { } // Test deserializing string with invalid arguments -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidArgument) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidArgument) { // NOLINT // UE ID provided is invalid. It should be hex numeric std::string uuriAsString = "//192.168.1.10/testUE/FE/7500"; ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); @@ -288,7 +288,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidArgument) { } // Test deserializing string with wildcard arguments to see if throws exception -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLINT uprotocol::v1::UUri uuri; auto check_uri = [&uuri](auto auth, uint32_t ueid, uint32_t mv, @@ -342,7 +342,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // Test deserializing string with invalid field values to verify exceptions are // thrown -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT uprotocol::v1::UUri uuri; // Major Version reserved diff --git a/test/coverage/datamodel/UUriValidatorTest.cpp b/test/coverage/datamodel/UUriValidatorTest.cpp index b8acca4e8..ec0db58a5 100644 --- a/test/coverage/datamodel/UUriValidatorTest.cpp +++ b/test/coverage/datamodel/UUriValidatorTest.cpp @@ -36,7 +36,7 @@ class TestUUriValidator : public testing::Test { static void TearDownTestSuite() {} }; -TEST_F(TestUUriValidator, Valid) { +TEST_F(TestUUriValidator, Valid) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -105,7 +105,7 @@ TEST_F(TestUUriValidator, Valid) { } } -TEST_F(TestUUriValidator, Wildcards) { +TEST_F(TestUUriValidator, Wildcards) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -152,7 +152,7 @@ TEST_F(TestUUriValidator, Wildcards) { } } -TEST_F(TestUUriValidator, ValidRpcMethod) { +TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -202,7 +202,7 @@ TEST_F(TestUUriValidator, ValidRpcMethod) { } } -TEST_F(TestUUriValidator, ValidRpcResponse) { +TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -252,7 +252,7 @@ TEST_F(TestUUriValidator, ValidRpcResponse) { } } -TEST_F(TestUUriValidator, ValidPublishTopic) { +TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -310,7 +310,7 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { } } -TEST_F(TestUUriValidator, ValidNotificationSource) { +TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -368,7 +368,7 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { } } -TEST_F(TestUUriValidator, ValidNotificationSink) { +TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -418,7 +418,7 @@ TEST_F(TestUUriValidator, ValidNotificationSink) { } } -TEST_F(TestUUriValidator, ValidSubscription) { +TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -469,7 +469,7 @@ TEST_F(TestUUriValidator, ValidSubscription) { } } -TEST_F(TestUUriValidator, ValidDefaultSource) { +TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -488,7 +488,7 @@ TEST_F(TestUUriValidator, ValidDefaultSource) { } } -TEST_F(TestUUriValidator, Empty) { +TEST_F(TestUUriValidator, Empty) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(""); @@ -546,7 +546,7 @@ TEST_F(TestUUriValidator, Empty) { } } -TEST_F(TestUUriValidator, ValidFilter) { +TEST_F(TestUUriValidator, ValidFilter) { // NOLINT auto getUuri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name("ValidFilterTest"); @@ -627,7 +627,7 @@ TEST_F(TestUUriValidator, ValidFilter) { } } -TEST_F(TestUUriValidator, ReasonMessages) { +TEST_F(TestUUriValidator, ReasonMessages) { // NOLINT std::array all_reasons{Reason::EMPTY, Reason::RESERVED_VERSION, Reason::RESERVED_RESOURCE, diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index 46a34de29..992da52bb 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -37,7 +37,7 @@ class TestUuidSerializer : public testing::Test { }; // Test string serialization -TEST_F(TestUuidSerializer, SerializeToString) { +TEST_F(TestUuidSerializer, SerializeToString) { // NOLINT constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; uprotocol::v1::UUID uuid; @@ -51,7 +51,7 @@ TEST_F(TestUuidSerializer, SerializeToString) { } // Test serialization with leading zeros in each segment -TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { +TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { // NOLINT constexpr uint64_t UUID_MSB = 0x00001234007800AB; constexpr uint64_t UUID_LSB = 0x00FE00BA09876543; uprotocol::v1::UUID uuid; @@ -65,7 +65,7 @@ TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { } // Test serialization with mixed case letters -TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { +TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { // NOLINT constexpr uint64_t UUID_MSB = 0x1234567890ABcDEF; constexpr uint64_t UUID_LSB = 0x00dcbA0987654321; uprotocol::v1::UUID uuid; @@ -79,7 +79,7 @@ TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { } // Test serialization with leading zeros and mixed case letters -TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { +TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { // NOLINT constexpr uint64_t UUID_MSB = 0x00001234567890AB; constexpr uint64_t UUID_LSB = 0xFedcba0987654982; uprotocol::v1::UUID uuid; @@ -93,7 +93,7 @@ TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { } // Test serialization with leading/trailing zeros and mixed case letters -TEST_F(TestUuidSerializer, +TEST_F(TestUuidSerializer, // NOLINT SerializeWithLeadingZerosAndTrailingZerosAndMixedCaseLetters) { constexpr uint64_t UUID_MSB = 0x00001234567890AB; constexpr uint64_t UUID_LSB = 0xFedcba0987600000; @@ -120,7 +120,7 @@ TEST(DeserializerTest, DeserializeUUID) { } // Test deserialization with leading/trailing zeros and mixed case letters -TEST_F(TestUuidSerializer, +TEST_F(TestUuidSerializer, // NOLINT DeserializeWithLeadingZerosAndTrailingZerosAndMixedCaseLetters) { std::string uuid_str = "00001234-5678-90ab-feDc-ba0987600000"; @@ -137,8 +137,8 @@ TEST(DeserializerTest, InvalidUUIDFormat) { // Define an invalid UUID string (missing dashes) std::string invalid_uuid_str = "123456789abcdef0123456789abcdef0"; // Assert that deserialization throws an invalid argument exception - EXPECT_THROW(AsString::deserialize( - invalid_uuid_str), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid_str)), std::invalid_argument); } @@ -146,8 +146,8 @@ TEST(DeserializerTest, InvalidUUIDFormat) { TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { std::string invalid_uuid = "12345678-1234-5678-1234-56781234567"; // Missing one character - EXPECT_THROW(AsString::deserialize( - invalid_uuid), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid)), std::invalid_argument); } @@ -155,8 +155,8 @@ TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { TEST(DeserializerTest, DeserializeWithExtraCharacter) { std::string invalid_uuid1 = "12345678-1234-5678-1234-1234567890123"; // Extra character at the end - EXPECT_THROW(AsString::deserialize( - invalid_uuid1), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid1)), std::invalid_argument); } @@ -164,26 +164,26 @@ TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { std::string invalid_uuid1 = "123456781-2345-6781-2345-67812345678"; // First Dash placement - EXPECT_THROW(AsString::deserialize( - invalid_uuid1), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid1)), std::invalid_argument); std::string invalid_uuid2 = "12345678-12345-6781-2345-67812345678"; // Second Dash placement - EXPECT_THROW(AsString::deserialize( - invalid_uuid2), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid2)), std::invalid_argument); std::string invalid_uuid3 = "12345678-1234-56781-2345-67812345678"; // Third Dash placement - EXPECT_THROW(AsString::deserialize( - invalid_uuid3), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid3)), std::invalid_argument); std::string invalid_uuid4 = "12345678-1234-5678-12345-67812345678"; // Fourth Dash placement - EXPECT_THROW(AsString::deserialize( - invalid_uuid4), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid4)), std::invalid_argument); } @@ -192,8 +192,8 @@ TEST(DeserializerTest, DeserializeEmptyString) { // Define an empty UUID string std::string empty_uuid_str; // Deserialize the empty UUID string - EXPECT_THROW(AsString::deserialize( - empty_uuid_str), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + empty_uuid_str)), std::invalid_argument); } @@ -201,33 +201,37 @@ TEST(DeserializerTest, DeserializeEmptyString) { TEST(DeserializerTest, DeserializeInvalidCharacter) { // Define a UUID string with an invalid character ('x' instead of valid hex) std::string invalid_uuid_str = "1234567890ab-cdef-1234-5678-90abcdefxabc"; - EXPECT_THROW(AsString::deserialize( - invalid_uuid_str), + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + invalid_uuid_str)), std::invalid_argument); } // Test byte serialization -TEST_F(TestUuidSerializer, SerializeToBytes) { +TEST_F(TestUuidSerializer, SerializeToBytes) { // NOLINT uprotocol::v1::UUID uuid; constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; + constexpr std::array EXPECTED_BYTES_ARRAY = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 + }; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); std::vector uuid_bytes = AsBytes::serialize(uuid); - std::vector expected_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, - 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, - 0x87, 0x65, 0x43, 0x21}; + std::vector expected_bytes(EXPECTED_BYTES_ARRAY.begin(), EXPECTED_BYTES_ARRAY.end()); EXPECT_EQ(uuid_bytes, expected_bytes); } // Test byte deserialization -TEST_F(TestUuidSerializer, DeserializeFromBytes) { - std::vector uuid_bytes = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, - 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, - 0x87, 0x65, 0x43, 0x21}; +TEST_F(TestUuidSerializer, DeserializeFromBytes) { // NOLINT + constexpr std::array UUID_BYTES_ARRAY = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 + }; + std::vector uuid_bytes(UUID_BYTES_ARRAY.begin(), UUID_BYTES_ARRAY.end()); uprotocol::v1::UUID uuid = AsBytes::deserialize( uuid_bytes); @@ -237,15 +241,17 @@ TEST_F(TestUuidSerializer, DeserializeFromBytes) { } // Test invalid byte deserialization -TEST_F(TestUuidSerializer, DeserializeInvalidBytes) { - std::vector invalid_bytes = {0x12, 0x34, 0x56}; - EXPECT_THROW(AsBytes::deserialize( - invalid_bytes), +TEST_F(TestUuidSerializer, DeserializeInvalidBytes) { // NOLINT + constexpr std::array INVALID_BYTES_ARRAY = {0x12, 0x34, 0x56}; + std::vector invalid_bytes(INVALID_BYTES_ARRAY.begin(), INVALID_BYTES_ARRAY.end()); + EXPECT_THROW(static_cast(AsBytes::deserialize( // NOLINT + invalid_bytes)), std::invalid_argument); } // Test edge case: minimum values for msb and lsb -TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { +TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { // NOLINT + constexpr uint16_t NUM_BYTES = 16; uprotocol::v1::UUID uuid; uuid.set_msb(0x0000000000000000); uuid.set_lsb(0x0000000000000000); @@ -261,7 +267,8 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { std::vector uuid_bytes = AsBytes::serialize(uuid); - std::vector expected_bytes(16, 0x00); + + std::vector expected_bytes(NUM_BYTES, 0x00); EXPECT_EQ(uuid_bytes, expected_bytes); deserialized_uuid = @@ -272,7 +279,9 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { } // Test edge case: maximum values for msb and lsb -TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { +TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { // NOLINT + constexpr uint16_t NUM_BYTES = 16; + constexpr uint16_t VAL_BYTES = 0xFF; uprotocol::v1::UUID uuid; constexpr uint64_t UUID_MSB = 0xFFFFFFFFFFFFFFFF; constexpr uint64_t UUID_LSB = 0xFFFFFFFFFFFFFFFF; @@ -290,7 +299,7 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { std::vector uuid_bytes = AsBytes::serialize(uuid); - std::vector expected_bytes(16, 0xFF); + std::vector expected_bytes(NUM_BYTES, VAL_BYTES); EXPECT_EQ(uuid_bytes, expected_bytes); deserialized_uuid = diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index aae1d32df..62f3a8554 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -15,13 +15,13 @@ #include #include "up-cpp/datamodel/constants/UuidConstants.h" +constexpr std::chrono::seconds HUNDRED_SECONDS(100); +constexpr std::chrono::seconds SIXTY_SECONDS(60); +constexpr std::chrono::seconds THIRTY_SECONDS(60); -namespace { -using namespace uprotocol::datamodel; -using namespace std::chrono_literals; -using namespace uprotocol::v1; -using namespace uprotocol::datamodel::validator::uuid; +namespace uprotocol::datamodel{ +// using namespace uprotocol::datamodel::validator::uuid::; class TestUuidValidator : public testing::Test { protected: @@ -33,16 +33,19 @@ class TestUuidValidator : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUuidValidator() = default; - ~TestUuidValidator() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestUuidValidator() override = default; }; // Helper fn for a fake UUID -UUID createFakeUuid(uint64_t timestamp = 0) { +uprotocol::v1::UUID createFakeUuid(uint64_t timestamp = 0) { + constexpr uint64_t UUID_MSB = 0x123ULL; + constexpr uint64_t UUID_LSB = 0xFFFFFFFFFFFFULL; uprotocol::v1::UUID uuid; // Create UUID with: // timestamp = 0 @@ -51,126 +54,128 @@ UUID createFakeUuid(uint64_t timestamp = 0) { // variant 0b10 (0x2) // random value = 0xFFFFFFFFFFFF uuid.set_msb((timestamp << UUID_TIMESTAMP_SHIFT) | - (UUID_VERSION_7 << UUID_VERSION_SHIFT) | (0x123ULL)); + (UUID_VERSION_7 << UUID_VERSION_SHIFT) | (UUID_MSB)); uuid.set_lsb((UUID_VARIANT_RFC4122 << UUID_VARIANT_SHIFT) | - (0xFFFFFFFFFFFFULL)); + (UUID_LSB)); return uuid; } // Test valid UUID v7 -TEST_F(TestUuidValidator, ValidUuid) { +TEST_F(TestUuidValidator, ValidUuid) { // NOLINT // Create a valid UUID with version 7 and correct variant (10) auto uuid = createFakeUuid(); - auto [valid, reason] = isUuid(uuid); + auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } // Test UUID with wrong version -TEST_F(TestUuidValidator, WrongVersion) { +TEST_F(TestUuidValidator, WrongVersion) { // NOLINT // Creating a UUID with wrong version (!7) + constexpr uint64_t UUID_MSB_VERSION8 = 8ULL; + constexpr uint64_t UUID_MSB = 0x123ULL; auto uuid = createFakeUuid(); - uuid.set_msb((8ULL << UUID_VERSION_SHIFT) | (0x123ULL)); // version 8 + uuid.set_msb((UUID_MSB_VERSION8 << UUID_VERSION_SHIFT) | (UUID_MSB)); // version 8 - auto [valid, reason] = isUuid(uuid); + auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); - EXPECT_EQ(reason.value(), Reason::WRONG_VERSION); - EXPECT_THROW(getVersion(uuid), InvalidUuid); + EXPECT_EQ(reason.value(), validator::uuid::Reason::WRONG_VERSION); + EXPECT_THROW(validator::uuid::getVersion(uuid), validator::uuid::InvalidUuid); // NOLINT } // Test UUID with unsupported variant -TEST_F(TestUuidValidator, UnsupportedVariant) { +TEST_F(TestUuidValidator, UnsupportedVariant) { // NOLINT // Creating UUID with unsupported variant.(!10) auto uuid = createFakeUuid(); uuid.set_lsb(uuid.lsb() | (3ULL << UUID_VARIANT_SHIFT)); // variant 11 - auto [valid, reason] = isUuid(uuid); + auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); - EXPECT_EQ(reason.value(), Reason::UNSUPPORTED_VARIANT); - EXPECT_THROW(getVariant(uuid), InvalidUuid); + EXPECT_EQ(reason.value(), validator::uuid::Reason::UNSUPPORTED_VARIANT); + EXPECT_THROW(validator::uuid::getVariant(uuid), validator::uuid::InvalidUuid); // NOLINT } // Test UUID from the future // Exception on getRemainingTime() -TEST_F(TestUuidValidator, FromTheFuture) { +TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT // Creating UUID with a timestamp in the future - auto future_time = std::chrono::system_clock::now() + 100s; - uint64_t future_timestamp = + auto future_time = std::chrono::system_clock::now() + HUNDRED_SECONDS; + auto future_timestamp = std::chrono::duration_cast( future_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(future_timestamp); - auto [valid, reason] = isUuid(uuid); + auto uuid = createFakeUuid(static_cast(future_timestamp)); + auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); - EXPECT_EQ(reason.value(), Reason::FROM_THE_FUTURE); - EXPECT_THROW(getRemainingTime(uuid, 60s), InvalidUuid); + EXPECT_EQ(reason.value(), validator::uuid::Reason::FROM_THE_FUTURE); + EXPECT_THROW(validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), validator::uuid::InvalidUuid); // NOLINT } // Test expired UUID -TEST_F(TestUuidValidator, ExpiredUuid) { +TEST_F(TestUuidValidator, ExpiredUuid) { // NOLINT // Creating a UUID with a past timestamp - auto past_time = std::chrono::system_clock::now() - 100s; - uint64_t past_timestamp = + auto past_time = std::chrono::system_clock::now() - HUNDRED_SECONDS; + auto past_timestamp = std::chrono::duration_cast( past_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(past_timestamp); - auto [valid, reason] = isExpired(uuid, 60s); // 60 seconds TTL + auto uuid = createFakeUuid(static_cast(past_timestamp)); + auto [valid, reason] = validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL EXPECT_TRUE(valid); - EXPECT_EQ(reason.value(), Reason::EXPIRED); + EXPECT_EQ(reason.value(), validator::uuid::Reason::EXPIRED); } // Test non-expired UUID -TEST_F(TestUuidValidator, NonExpiredUuid) { +TEST_F(TestUuidValidator, NonExpiredUuid) { // NOLINT // Creating a UUID with a recent timestamp - auto recent_time = std::chrono::system_clock::now() - 30s; - uint64_t recent_timestamp = + auto recent_time = std::chrono::system_clock::now() - THIRTY_SECONDS; + auto recent_timestamp = std::chrono::duration_cast( recent_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(recent_timestamp); - auto [valid, reason] = isExpired(uuid, 60s); // 60 seconds TTL + auto uuid = createFakeUuid(static_cast(recent_timestamp)); + auto [valid, reason] = validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL EXPECT_FALSE(valid); EXPECT_FALSE(reason.has_value()); } // Test retrieving version -TEST_F(TestUuidValidator, RetrieveVersion) { +TEST_F(TestUuidValidator, RetrieveVersion) { // NOLINT auto uuid = createFakeUuid(); - EXPECT_EQ(getVersion(uuid), UUID_VERSION_7); + EXPECT_EQ(validator::uuid::getVersion(uuid), UUID_VERSION_7); } // Test retrieving variant -TEST_F(TestUuidValidator, RetrieveVariant) { +TEST_F(TestUuidValidator, RetrieveVariant) { // NOLINT auto uuid = createFakeUuid(); - EXPECT_EQ(getVariant(uuid), UUID_VARIANT_RFC4122); + EXPECT_EQ(validator::uuid::getVariant(uuid), UUID_VARIANT_RFC4122); } -TEST_F(TestUuidValidator, RetrieveTimestamp) { +TEST_F(TestUuidValidator, RetrieveTimestamp) { // NOLINT auto time_now = std::chrono::system_clock::now(); auto time_now_ms = std::chrono::time_point_cast(time_now); - uint64_t timestamp = time_now_ms.time_since_epoch().count(); + uint64_t timestamp = static_cast(time_now_ms.time_since_epoch().count()); auto uuid = createFakeUuid(timestamp); - auto uuid_time = getTime(uuid); + auto uuid_time = validator::uuid::getTime(uuid); auto uuid_ms = std::chrono::time_point_cast(uuid_time); EXPECT_EQ(uuid_ms, time_now_ms); } // Test retrieving elapsed time -TEST_F(TestUuidValidator, RetrieveElapsedTime) { - auto past_time = std::chrono::system_clock::now() - 30s; - uint64_t timestamp = std::chrono::duration_cast( +TEST_F(TestUuidValidator, RetrieveElapsedTime) { // NOLINT + auto past_time = std::chrono::system_clock::now() - THIRTY_SECONDS; + auto timestamp = std::chrono::duration_cast( past_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(timestamp); - auto elapsed_time = getElapsedTime(uuid); + auto uuid = createFakeUuid(static_cast(timestamp)); + auto elapsed_time = validator::uuid::getElapsedTime(uuid); auto expected_elapsed_time = std::chrono::duration_cast( std::chrono::system_clock::now() - past_time); @@ -185,15 +190,15 @@ TEST_F(TestUuidValidator, RetrieveElapsedTime) { } // Test retrieving remaining time -TEST_F(TestUuidValidator, RetrieveRemainingTime) { - auto past_time = std::chrono::system_clock::now() - 30s; - uint64_t timestamp = std::chrono::duration_cast( +TEST_F(TestUuidValidator, RetrieveRemainingTime) { // NOLINT + auto past_time = std::chrono::system_clock::now() - THIRTY_SECONDS; + auto timestamp = std::chrono::duration_cast( past_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(timestamp); - auto ttl = 60s; - auto remaining_time = getRemainingTime(uuid, ttl); + auto uuid = createFakeUuid(static_cast(timestamp)); + auto ttl = SIXTY_SECONDS; + auto remaining_time = validator::uuid::getRemainingTime(uuid, ttl); auto expected_remaining_time = ttl - std::chrono::duration_cast( std::chrono::system_clock::now() - past_time); @@ -208,28 +213,28 @@ TEST_F(TestUuidValidator, RetrieveRemainingTime) { } // Test remaining time of 0ms -TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { - auto past_time = std::chrono::system_clock::now() - 100s; - uint64_t past_timestamp = +TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { // NOLINT + auto past_time = std::chrono::system_clock::now() - HUNDRED_SECONDS; + auto past_timestamp = std::chrono::duration_cast( past_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(past_timestamp); - auto remaining_time = getRemainingTime(uuid, 60s); - EXPECT_EQ(remaining_time, 0ms); + auto uuid = createFakeUuid(static_cast(past_timestamp)); + auto remaining_time = validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS); + EXPECT_EQ(remaining_time, std::chrono::milliseconds(0)); } // Future timestamp to test exception thrown on getElapsedTime() -TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { - auto future_time = std::chrono::system_clock::now() + 100s; - uint64_t future_timestamp = +TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { // NOLINT + auto future_time = std::chrono::system_clock::now() + HUNDRED_SECONDS; + auto future_timestamp = std::chrono::duration_cast( future_time.time_since_epoch()) .count(); - auto uuid = createFakeUuid(future_timestamp); - EXPECT_THROW(getElapsedTime(uuid), InvalidUuid); + auto uuid = createFakeUuid(static_cast(future_timestamp)); + EXPECT_THROW(validator::uuid::getElapsedTime(uuid), validator::uuid::InvalidUuid); // NOLINT } -} // namespace +} // namespace uprotocol::datamodel diff --git a/test/coverage/transport/UTransportTest.cpp b/test/coverage/transport/UTransportTest.cpp index 0757c1fe4..1622432e2 100644 --- a/test/coverage/transport/UTransportTest.cpp +++ b/test/coverage/transport/UTransportTest.cpp @@ -91,22 +91,22 @@ class TestUTransport : public testing::Test { } }; -TEST_F(TestUTransport, CreateTransport) { - EXPECT_NO_THROW(auto transport = makeTransport(getValidUri())); +TEST_F(TestUTransport, CreateTransport) { // NOLINT + EXPECT_NO_THROW(auto transport = makeTransport(getValidUri())); // NOLINT } using InvalidUUri = uprotocol::datamodel::validator::uri::InvalidUUri; -TEST_F(TestUTransport, CreateTransportInvalidUUri) { +TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT auto uri = getValidUri(); uri.set_authority_name("*"); - EXPECT_THROW({ auto transport = makeTransport(uri); }, InvalidUUri); + EXPECT_THROW({ auto transport = makeTransport(uri); }, InvalidUUri); // NOLINT } using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; using PayloadBuilder = uprotocol::datamodel::builder::Payload; -TEST_F(TestUTransport, SendOk) { +TEST_F(TestUTransport, SendOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -118,7 +118,7 @@ TEST_F(TestUTransport, SendOk) { UMessageBuilder::publish(std::move(topic)).build(std::move(payload)); decltype(transport->send(message)) result; - EXPECT_NO_THROW(result = transport->send(message)); + EXPECT_NO_THROW(result = transport->send(message)); // NOLINT EXPECT_EQ(result.code(), uprotocol::v1::UCode::OK); EXPECT_EQ(transport_mock->send_count_, 1); @@ -128,7 +128,7 @@ TEST_F(TestUTransport, SendOk) { using InvalidUMessge = uprotocol::datamodel::validator::message::InvalidUMessage; -TEST_F(TestUTransport, SendInvalidMessage) { +TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -139,11 +139,11 @@ TEST_F(TestUTransport, SendInvalidMessage) { uprotocol::v1::UMessageType::UMESSAGE_TYPE_REQUEST); decltype(transport->send(message)) result; - EXPECT_THROW({ result = transport->send(message); }, InvalidUMessge); + EXPECT_THROW({ result = transport->send(message); }, InvalidUMessge); // NOLINT EXPECT_EQ(transport_mock->send_count_, 0); } -TEST_F(TestUTransport, SendImplStatus) { +TEST_F(TestUTransport, SendImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -155,12 +155,12 @@ TEST_F(TestUTransport, SendImplStatus) { auto message = UMessageBuilder::publish(std::move(topic)).build(); decltype(transport->send(message)) result; - EXPECT_NO_THROW(result = transport->send(message)); + EXPECT_NO_THROW(result = transport->send(message)); // NOLINT EXPECT_EQ(result.code(), uprotocol::v1::UCode::PERMISSION_DENIED); } -TEST_F(TestUTransport, RegisterListenerOk) { +TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -169,7 +169,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { auto source_filter = getWildcardUri(); uprotocol::transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -195,7 +195,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { } } -TEST_F(TestUTransport, RegisterListenerInvalidSource) { +TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -204,7 +204,7 @@ TEST_F(TestUTransport, RegisterListenerInvalidSource) { auto source_filter = getWildcardUri(); source_filter.set_resource_id(1); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener(callback, source_filter); @@ -217,7 +217,7 @@ TEST_F(TestUTransport, RegisterListenerInvalidSource) { EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerImplStatus) { +TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -229,7 +229,7 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { auto source_filter = getWildcardUri(); uprotocol::v1::UStatus status; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -252,7 +252,7 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { } } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { +TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -263,7 +263,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { sink_filter.set_resource_id(0xFFFF); uprotocol::transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -293,7 +293,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { } } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { +TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -306,7 +306,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // Make source invalid source_filter.set_ue_version_major(0xFFFF); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener( callback, source_filter, sink_filter); @@ -319,7 +319,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { +TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -332,7 +332,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // Make sink invalid sink_filter.set_ue_version_major(0xFFFF); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener( callback, source_filter, sink_filter); @@ -345,7 +345,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { +TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -359,7 +359,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { sink_filter.set_resource_id(0xFFFF); uprotocol::v1::UStatus status; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -382,7 +382,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { } } -TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { +TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -391,7 +391,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { auto source_filter = getWildcardUri(); uprotocol::transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, 0xF00D); @@ -423,7 +423,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { } } -TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { +TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -434,7 +434,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // Make source invalid source_filter.set_ue_version_major(0xFFFF); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener(callback, source_filter, 0xABBA); @@ -450,7 +450,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOTE: it is not possible to produce an invalid sink filter with this method // since it constrains the sink resource parameter to uint16_t -TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { +TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -462,7 +462,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { auto source_filter = getWildcardUri(); uprotocol::v1::UStatus status; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, 0xFFFF); @@ -487,7 +487,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { } } -TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { +TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -496,7 +496,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { auto topic_source_filter = getWildcardUri(); uprotocol::transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT // When source_filter is omitted, sink_filter is treated as a publish // topic. auto maybe_handle = @@ -524,7 +524,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { } } -TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { +TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -535,7 +535,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { sink_filter.set_resource_id(0xFFFF); uprotocol::transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(sink_filter, callback, source_filter); From 1e4715e2f60a1a38fa682242951ff6bbf8cc843b Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 12:29:33 +0200 Subject: [PATCH 17/41] Add NOLINT behin ASSERT_THROW and ASSERT_NO_THROW --- lint/clang-tidy.sh | 2 +- .../datamodel/UMessageValidatorTest.cpp | 28 +- .../coverage/datamodel/UUriSerializerTest.cpp | 335 +++++++++--------- test/coverage/datamodel/UuidValidatorTest.cpp | 2 +- 4 files changed, 191 insertions(+), 176 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index e667c0e81..cc4a66cd9 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -59,7 +59,7 @@ if [ -z "$target_source" ]; then pushd "$PROJECT_ROOT" > /dev/null # for f in include/**/*.h src/**/*.cpp - for f in test/coverage/datamodel/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/datamodel/UMessageValidatorTest.cpp b/test/coverage/datamodel/UMessageValidatorTest.cpp index 29fc10338..17e36c255 100644 --- a/test/coverage/datamodel/UMessageValidatorTest.cpp +++ b/test/coverage/datamodel/UMessageValidatorTest.cpp @@ -581,8 +581,8 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT } TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT - constexpr uint32_t SOURCE_RESCOURCE_ID = 0x8000; - getSource().set_resource_id(SOURCE_RESCOURCE_ID); + constexpr uint32_t SOURCE_RESOURCE_ID = 0x8000; + getSource().set_resource_id(SOURCE_RESOURCE_ID); { // test common attributes for any message @@ -621,9 +621,9 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT { // invalid source - constexpr uint32_t SOURCE_RESCOURCE_ID_INVALID = 0x7FFF; + constexpr uint32_t SOURCE_RESOURCE_ID_INVALID = 0x7FFF; UUri source = getSource(); - source.set_resource_id(SOURCE_RESCOURCE_ID_INVALID); // should greater than 0x8000 + source.set_resource_id(SOURCE_RESOURCE_ID_INVALID); // should greater than 0x8000 auto attributes = fakePublish(source); auto umessage = build(attributes); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); @@ -684,8 +684,8 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT } TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT - constexpr uint32_t SOURCE_RESCOURCE_ID = 0x8001; - getSource().set_resource_id(SOURCE_RESCOURCE_ID); + constexpr uint32_t SOURCE_RESOURCE_ID = 0x8001; + getSource().set_resource_id(SOURCE_RESOURCE_ID); getSink().set_resource_id(0); { @@ -735,9 +735,9 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT { // invalid source - constexpr uint32_t LOCAL_SOURCE_RESCOURCE_ID = 0x7FFF; + constexpr uint32_t LOCAL_SOURCE_RESOURCE_ID = 0x7FFF; UUri local_source = getSource(); - local_source.set_resource_id(LOCAL_SOURCE_RESCOURCE_ID); // should be greater than 0x8000 + local_source.set_resource_id(LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 auto attributes = fakeNotification(local_source, getSink()); auto umessage = build(attributes); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); @@ -747,9 +747,9 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT { // invalid sink - constexpr uint32_t LOCAL_SOURCE_RESCOURCE_ID = 0x7FFF; + constexpr uint32_t LOCAL_SOURCE_RESOURCE_ID = 0x7FFF; UUri local_sink = getSink(); - local_sink.set_resource_id(LOCAL_SOURCE_RESCOURCE_ID); // should be greater than 0x8000 + local_sink.set_resource_id(LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 auto attributes = fakeNotification(getSource(), local_sink); auto umessage = build(attributes); auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); @@ -877,9 +877,9 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT { constexpr uint32_t ATTRIBUTES_INVALID_PRIORITY = 0xFFFF; // valid publish - constexpr uint32_t PUBLISH_SOURCE_RESCOURCE_ID = 0x8000; + constexpr uint32_t PUBLISH_SOURCE_RESOURCE_ID = 0x8000; auto source = getSource(); - source.set_resource_id(PUBLISH_SOURCE_RESCOURCE_ID); + source.set_resource_id(PUBLISH_SOURCE_RESOURCE_ID); auto attributes = fakePublish(source); auto umessage = build(attributes); @@ -899,10 +899,10 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT { // valid notification - constexpr uint32_t NOTIFICATION_SOURCE_RESCOURCE_ID = 0x8001; + constexpr uint32_t NOTIFICATION_SOURCE_RESOURCE_ID = 0x8001; auto source = getSource(); auto sink = getSink(); - source.set_resource_id(NOTIFICATION_SOURCE_RESCOURCE_ID); + source.set_resource_id(NOTIFICATION_SOURCE_RESOURCE_ID); sink.set_resource_id(0); auto attributes = fakeNotification(source, sink); diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index 787daf220..afb936a36 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -13,10 +13,11 @@ #include #include -namespace { -using namespace uprotocol::datamodel::serializer::uri; -using namespace uprotocol::datamodel::validator; -using namespace uprotocol; +constexpr uint32_t DEFAULT_RESOURCE_ID = 0x7500; +constexpr uint32_t DEFAULT_UE_ID = 0x10010001; +constexpr uint32_t DEFAULT_VERSION_MAJOR = 0xFE; + +namespace uprotocol::datamodel::serializer::uri{ class TestUUriSerializer : public testing::Test { protected: @@ -28,267 +29,281 @@ class TestUUriSerializer : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUUriSerializer() = default; - ~TestUUriSerializer() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestUUriSerializer() override = default; }; -v1::UUri buildValidTestURI(const std::string& authority = "192.168.1.10") { - v1::UUri uri; +uprotocol::v1::UUri buildValidTestURI(const std::string& authority = "192.168.1.10") { + uprotocol::v1::UUri uri; uri.set_authority_name(authority); - uri.set_ue_id(0x10010001); - uri.set_ue_version_major(0xFE); - uri.set_resource_id(0x7500); + uri.set_ue_id(DEFAULT_UE_ID); + uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + uri.set_resource_id(DEFAULT_RESOURCE_ID); return uri; } // Positive test case - test serialization of UUri to string TEST_F(TestUUriSerializer, SerializeUUriToString) { // NOLINT - auto testUUri = buildValidTestURI(); - const std::string expectedUUri = "//192.168.1.10/10010001/FE/7500"; - const std::string actualUUri = AsString::serialize(testUUri); - ASSERT_EQ(expectedUUri, actualUUri); + auto test_u_uri = buildValidTestURI(); + const std::string expected_u_uri = "//192.168.1.10/10010001/FE/7500"; + const std::string actual_u_uri = AsString::serialize(test_u_uri); + ASSERT_EQ(expected_u_uri, actual_u_uri); } // Positive test case - test serialization of UUri with no authority to string TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT - auto testUUri = buildValidTestURI(""); - const std::string expectedUUri = "/10010001/FE/7500"; - const std::string actualUUri = AsString::serialize(testUUri); - ASSERT_EQ(expectedUUri, actualUUri); + auto test_u_uri = buildValidTestURI(""); + const std::string expected_u_uri = "/10010001/FE/7500"; + const std::string actual_u_uri = AsString::serialize(test_u_uri); + ASSERT_EQ(expected_u_uri, actual_u_uri); } // Test authority name '*' to see if it serializes without an exception for // using wildcard TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { // NOLINT - v1::UUri testUUri; - testUUri.set_authority_name("*"); // Wildcard - testUUri.set_ue_id(0x1FFFE); - testUUri.set_ue_version_major(0xFE); - testUUri.set_resource_id(0x7500); + constexpr uint32_t WILDCARD = 0x1FFFE; + uprotocol::v1::UUri test_u_uri; + test_u_uri.set_authority_name("*"); // Wildcard + test_u_uri.set_ue_id(WILDCARD); + test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(testUUri)); + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//*/1FFFE/FE/7500"); } // Test Service ID in uEID field as a 0xFFFF to see if it serializes without // an exception for using wildcard TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { // NOLINT - v1::UUri testUUri; - testUUri.set_authority_name("testAuthority"); - testUUri.set_ue_id(0x1FFFF); // Wildcard - testUUri.set_ue_version_major(0xFE); - testUUri.set_resource_id(0x7500); + constexpr uint32_t WILDCARD = 0x1FFFF; + uprotocol::v1::UUri test_u_uri; + test_u_uri.set_authority_name("testAuthority"); + test_u_uri.set_ue_id(WILDCARD); // Wildcard + test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(testUUri)); + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/1FFFF/FE/7500"); } // Test Instance ID in uEID field as a 0x0 to see if it serializes without an // exception for using wildcard TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { // NOLINT - v1::UUri testUUri; - testUUri.set_authority_name("testAuthority"); - testUUri.set_ue_id(0x00001234); // Wildcard - testUUri.set_ue_version_major(0xFE); - testUUri.set_resource_id(0x7500); + constexpr uint32_t WILDCARD = 0x00001234; + uprotocol::v1::UUri test_u_uri; + test_u_uri.set_authority_name("testAuthority"); + test_u_uri.set_ue_id(WILDCARD); // Wildcard + test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(testUUri)); + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/1234/FE/7500"); } // Test major version as 0xFF to see if it serializes without an exception for // using wildcard TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { // NOLINT - v1::UUri testUUri; - testUUri.set_authority_name("testAuthority"); - testUUri.set_ue_id(0x12340000); - testUUri.set_ue_version_major(0xFF); // Wildcard - testUUri.set_resource_id(0x7500); + constexpr uint32_t TEST_UE_ID = 0x12340000; + constexpr uint32_t WILDCARD = 0xFF; + uprotocol::v1::UUri test_u_uri; + test_u_uri.set_authority_name("testAuthority"); + test_u_uri.set_ue_id(TEST_UE_ID); + test_u_uri.set_ue_version_major(WILDCARD); // Wildcard + test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(testUUri)); + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/12340000/FF/7500"); } // Test resource id as 0xFFFF to see if it thorws an exception for using // wildcard TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { // NOLINT - v1::UUri testUUri; - testUUri.set_authority_name("testAuthority"); - testUUri.set_ue_id(0x12340000); - testUUri.set_ue_version_major(0xFE); - testUUri.set_resource_id(0xFFFF); // Wildcard + constexpr uint32_t TEST_UE_ID = 0x12340000; + constexpr uint32_t WILDCARD = 0xFFFF; + uprotocol::v1::UUri test_u_uri; + test_u_uri.set_authority_name("testAuthority"); + test_u_uri.set_ue_id(TEST_UE_ID); + test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + test_u_uri.set_resource_id(WILDCARD); // Wildcard std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(testUUri)); + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/12340000/FE/FFFF"); } // Attempt to serialize invalid UUris and verify exceptions are thrown TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT - const v1::UUri baseUUri = []() { - v1::UUri uuri; + constexpr uint32_t TEST_UE_ID = 0x12340000; + constexpr uint32_t WILDCARD = 0xFFFE; + const uprotocol::v1::UUri base_u_uri = []() { + uprotocol::v1::UUri uuri; uuri.set_authority_name("testAuthority"); - uuri.set_ue_id(0x12340000); - uuri.set_ue_version_major(0xFE); - uuri.set_resource_id(0xFFFE); + uuri.set_ue_id(TEST_UE_ID); + uuri.set_ue_version_major(DEFAULT_VERSION_MAJOR); + uuri.set_resource_id(WILDCARD); return uuri; }(); std::string serialized; // Empty UUri - v1::UUri testUUri; - ASSERT_THROW(serialized = AsString::serialize(testUUri), uri::InvalidUUri); + uprotocol::v1::UUri test_u_uri; + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Authority name too long - testUUri = baseUUri; - testUUri.set_authority_name(std::string(129, 'b')); - ASSERT_THROW(serialized = AsString::serialize(testUUri), uri::InvalidUUri); + test_u_uri = base_u_uri; + test_u_uri.set_authority_name(std::string(129, 'b')); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Version out of uint8 range - testUUri = baseUUri; - testUUri.set_ue_version_major(0x100); - ASSERT_THROW(serialized = AsString::serialize(testUUri), uri::InvalidUUri); + test_u_uri = base_u_uri; + test_u_uri.set_ue_version_major(0x100); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Version reserved - testUUri = baseUUri; - testUUri.set_ue_version_major(0); - ASSERT_THROW(serialized = AsString::serialize(testUUri), uri::InvalidUUri); + test_u_uri = base_u_uri; + test_u_uri.set_ue_version_major(0); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Resource ID out of uint16 range - testUUri = baseUUri; - testUUri.set_ue_version_major(0x10000); - ASSERT_THROW(serialized = AsString::serialize(testUUri), uri::InvalidUUri); + test_u_uri = base_u_uri; + test_u_uri.set_resource_id(0x10000); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT } // Test deserialize by providing scheme "up:" which is allowed to have as per // spec TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT - const std::string uuriAsString = "up://192.168.1.10/10010001/FE/7500"; - const std::string expectedAuthority = "192.168.1.10"; - const uint32_t expectedUEID = 0x10010001; - const uint32_t expectedMajorVersion = 0xFE; - const uint32_t expectedResourceID = 0x7500; - - auto uri = AsString::deserialize(uuriAsString); - ASSERT_EQ(expectedAuthority, uri.authority_name()); - ASSERT_EQ(expectedUEID, uri.ue_id()); - ASSERT_EQ(expectedMajorVersion, uri.ue_version_major()); - ASSERT_EQ(expectedResourceID, uri.resource_id()); + const std::string uuri_as_string = "up://192.168.1.10/10010001/FE/7500"; + const std::string expected_authority = "192.168.1.10"; + const uint32_t expected_ue_id = DEFAULT_UE_ID; + const uint32_t expected_major_version = DEFAULT_VERSION_MAJOR; + const uint32_t expected_resource_id = DEFAULT_RESOURCE_ID; + + auto uri = AsString::deserialize(uuri_as_string); + ASSERT_EQ(expected_authority, uri.authority_name()); + ASSERT_EQ(expected_ue_id, uri.ue_id()); + ASSERT_EQ(expected_major_version, uri.ue_version_major()); + ASSERT_EQ(expected_resource_id, uri.resource_id()); } // Test deserialize by providing incorrect scheme "uprotocol:" TEST_F(TestUUriSerializer, DeSerializeUUriStringWithIncorrectScheme) { // NOLINT - const std::string uuriAsString = + const std::string uuri_as_string = "uprotocol://192.168.1.10/10010001/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT } // Test deserialize without providing scheme "up:" TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT - const std::string uuriAsString = "//192.168.1.10/10010001/FE/7500"; - const std::string expectedAuthority = "192.168.1.10"; - const uint32_t expectedUEID = 0x10010001; - const uint32_t expectedMajorVersion = 0xFE; - const uint32_t expectedResourceID = 0x7500; - - auto uri = AsString::deserialize(uuriAsString); - ASSERT_EQ(expectedAuthority, uri.authority_name()); - ASSERT_EQ(expectedUEID, uri.ue_id()); - ASSERT_EQ(expectedMajorVersion, uri.ue_version_major()); - ASSERT_EQ(expectedResourceID, uri.resource_id()); + const std::string uuri_as_string = "//192.168.1.10/10010001/FE/7500"; + const std::string expected_authority = "192.168.1.10"; + const uint32_t expected_ue_id = DEFAULT_UE_ID; + const uint32_t expected_major_version = DEFAULT_VERSION_MAJOR; + const uint32_t expected_resource_id = DEFAULT_RESOURCE_ID; + + auto uri = AsString::deserialize(uuri_as_string); + ASSERT_EQ(expected_authority, uri.authority_name()); + ASSERT_EQ(expected_ue_id, uri.ue_id()); + ASSERT_EQ(expected_major_version, uri.ue_version_major()); + ASSERT_EQ(expected_resource_id, uri.resource_id()); } // Test deserializing empty string to check if it thorws an exception TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT - const std::string uuriAsString = ""; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + const std::string uuri_as_string; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT } // Test deserializing string with no authority TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT - const std::string uuriAsString = "/10010001/FE/7500"; - const std::string expectedAuthority = ""; - const uint32_t expectedUEID = 0x10010001; - const uint32_t expectedMajorVersion = 0xFE; - const uint32_t expectedResourceID = 0x7500; - - auto uri = AsString::deserialize(uuriAsString); - ASSERT_EQ(expectedAuthority, uri.authority_name()); - ASSERT_EQ(expectedUEID, uri.ue_id()); - ASSERT_EQ(expectedMajorVersion, uri.ue_version_major()); - ASSERT_EQ(expectedResourceID, uri.resource_id()); + const std::string uuri_as_string = "/10010001/FE/7500"; + const std::string expected_authority; + const uint32_t expected_ue_id = DEFAULT_UE_ID; + const uint32_t expected_major_version = DEFAULT_VERSION_MAJOR; + const uint32_t expected_resource_id = DEFAULT_RESOURCE_ID; + + auto uri = AsString::deserialize(uuri_as_string); + ASSERT_EQ(expected_authority, uri.authority_name()); + ASSERT_EQ(expected_ue_id, uri.ue_id()); + ASSERT_EQ(expected_major_version, uri.ue_version_major()); + ASSERT_EQ(expected_resource_id, uri.resource_id()); } // Test deserializing string with invalid number of arguments TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidNumberOfArgument) { // NOLINT // Provided 5 arguments instead of 4 when authority exist - std::string uuriAsString = "//192.168.1.10/10010001/FE/FE/7500"; + std::string uuri_as_string = "//192.168.1.10/10010001/FE/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // UE ID is missing. Provided 3 arguments instead of 4 when authority exist. - uuriAsString = "//192.168.1.10/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Provided 4 arguments instead of 3 when authority does not exist. - uuriAsString = "/1102/FE/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "/1102/FE/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // UE ID is missing. Provided 2 arguments instead of 3 when authority does // not exist. - uuriAsString = "/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Valid Uri but no leading / - uuriAsString = "192.168.1.10/1102/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "192.168.1.10/1102/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Valid Uri but no leading / - uuriAsString = "1102/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "1102/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Valid Uri but leading /// . - uuriAsString = "///192.168.1.10/1102/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "///192.168.1.10/1102/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Valid Uri but additional trailing / - uuriAsString = "//192.168.1.10/1102/FE/7500/"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/1102/FE/7500/"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT } // Test deserializing string with invalid arguments TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidArgument) { // NOLINT // UE ID provided is invalid. It should be hex numeric - std::string uuriAsString = "//192.168.1.10/testUE/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + std::string uuri_as_string = "//192.168.1.10/testUE/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Major Version provided is invalid. It should be hex numeric - uuriAsString = "//192.168.1.10/10010001/^%/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/10010001/^%/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Resource ID provided is invalid. It should be hex numeric - uuriAsString = "//192.168.1.10/10010001/FE/xyz"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/10010001/FE/xyz"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // UE ID is outside the 32-bit int range - uuriAsString = "//192.168.1.10/110010001/FE/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/110010001/FE/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Major Version is outside the 8-bit int range - uuriAsString = "//192.168.1.10/10010001/100/7500"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/10010001/100/7500"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT // Resiource ID is outside the 16-bit int range - uuriAsString = "//192.168.1.10/10010001/FE/10000"; - ASSERT_THROW(AsString::deserialize(uuriAsString), std::invalid_argument); + uuri_as_string = "//192.168.1.10/10010001/FE/10000"; + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT } // Test deserializing string with wildcard arguments to see if throws exception TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLINT + constexpr uint32_t UE_SERVICE_ID_WILDCARD = 0x1FFFF; + constexpr uint32_t UE_INSTANCE_ID_WILDCARD = 0x1234; + constexpr uint32_t VERSION_MAJOR_WILDCARD = 0xFF; + constexpr uint32_t RESOURCE_ID_WILDCARD = 0xFFFF; uprotocol::v1::UUri uuri; auto check_uri = [&uuri](auto auth, uint32_t ueid, uint32_t mv, @@ -300,43 +315,43 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLIN }; // Authority name provided in ueID is wildcard as "*" - std::string uuriAsString = "//*/1FFFF/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuriAsString)); + std::string uuri_as_string = "//*/1FFFF/FE/7500"; + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Authority Name Wildcard"); - check_uri("*", 0x1FFFF, 0xFE, 0x7500); + check_uri("*", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); } // Service ID provided in ueID is wildcard as 0xFFFF - uuriAsString = "//192.168.1.10/1FFFF/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuriAsString)); + uuri_as_string = "//192.168.1.10/1FFFF/FE/7500"; + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Service ID Wildcard"); - check_uri("192.168.1.10", 0x1FFFF, 0xFE, 0x7500); + check_uri("192.168.1.10", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); } // Instance ID provided in ueID is wildcard as 0x0 - uuriAsString = "//192.168.1.10/00001234/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuriAsString)); + uuri_as_string = "//192.168.1.10/00001234/FE/7500"; + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Instance ID Wildcard"); - check_uri("192.168.1.10", 0x1234, 0xFE, 0x7500); + check_uri("192.168.1.10", UE_INSTANCE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); } // Major Version provided is wildcard as 0xFF - uuriAsString = "//192.168.1.10/10010001/FF/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuriAsString)); + uuri_as_string = "//192.168.1.10/10010001/FF/7500"; + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Major Version Wildcard"); - check_uri("192.168.1.10", 0x10010001, 0xFF, 0x7500); + check_uri("192.168.1.10", DEFAULT_UE_ID, VERSION_MAJOR_WILDCARD, DEFAULT_RESOURCE_ID); } // Resource ID provided is wildcard as 0xFFFF - uuriAsString = "//192.168.1.10/10010001/FE/FFFF"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuriAsString)); + uuri_as_string = "//192.168.1.10/10010001/FE/FFFF"; + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Resource ID Wildcard"); - check_uri("192.168.1.10", 0x10010001, 0xFE, 0xFFFF); + check_uri("192.168.1.10", DEFAULT_UE_ID, DEFAULT_VERSION_MAJOR, RESOURCE_ID_WILDCARD); } } @@ -346,30 +361,30 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT uprotocol::v1::UUri uuri; // Major Version reserved - std::string uuriAsString = "//192.168.1.10/1FFFE/0/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuriAsString), uri::InvalidUUri); + std::string uuri_as_string = "//192.168.1.10/1FFFE/0/7500"; + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Empty UUri - uuriAsString = "// /0/0/0"; - ASSERT_THROW(uuri = AsString::deserialize(uuriAsString), uri::InvalidUUri); + uuri_as_string = "// /0/0/0"; + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Major Version reserved - uuriAsString = "//"; - uuriAsString += std::string(129, 'a'); - uuriAsString += "/1FFFE/1/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuriAsString), uri::InvalidUUri); + uuri_as_string = "//"; + uuri_as_string += std::string(129, 'a'); + uuri_as_string += "/1FFFE/1/7500"; + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // NOTE These are also checked earlier against the std::invalid_argument // exception. They can be caught either way. These can be checked against // InvalidUUri since they are valid uint32 values, but *not* valid for UUri // Major Version outside the uint8 range - uuriAsString = "//192.168.1.10/1FFFE/FFFE/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuriAsString), uri::InvalidUUri); + uuri_as_string = "//192.168.1.10/1FFFE/FFFE/7500"; + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Resource ID outside the uint8 range - uuriAsString = "//192.168.1.10/1FFFE/FE/C0FFEEEE"; - ASSERT_THROW(uuri = AsString::deserialize(uuriAsString), uri::InvalidUUri); + uuri_as_string = "//192.168.1.10/1FFFE/FE/C0FFEEEE"; + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT } -} // namespace +} // namespace uprotocol::datamodel::serializer::uri diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 62f3a8554..23d3cacbc 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -17,7 +17,7 @@ #include "up-cpp/datamodel/constants/UuidConstants.h" constexpr std::chrono::seconds HUNDRED_SECONDS(100); constexpr std::chrono::seconds SIXTY_SECONDS(60); -constexpr std::chrono::seconds THIRTY_SECONDS(60); +constexpr std::chrono::seconds THIRTY_SECONDS(30); namespace uprotocol::datamodel{ From b88275660ac0c462cc1cd7bc830f0011c2528d90 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 13:07:24 +0200 Subject: [PATCH 18/41] Mostly finished datamodel/ --- .../coverage/datamodel/UUriSerializerTest.cpp | 12 +- test/coverage/datamodel/UUriValidatorTest.cpp | 241 ++++++++++-------- 2 files changed, 139 insertions(+), 114 deletions(-) diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index afb936a36..0e6f725cf 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -137,8 +137,11 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { // NOL // Attempt to serialize invalid UUris and verify exceptions are thrown TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT + constexpr uint32_t AUTHORITY_NAME_NUMBER = 129; constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFFFE; + constexpr uint32_t INVALID_VERSION_MAJOR = 0x100; + constexpr uint32_t INVALID_RESOURCE_ID = 0x10000; const uprotocol::v1::UUri base_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name("testAuthority"); @@ -156,12 +159,12 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT // Authority name too long test_u_uri = base_u_uri; - test_u_uri.set_authority_name(std::string(129, 'b')); + test_u_uri.set_authority_name(std::string(AUTHORITY_NAME_NUMBER, 'b')); ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Version out of uint8 range test_u_uri = base_u_uri; - test_u_uri.set_ue_version_major(0x100); + test_u_uri.set_ue_version_major(INVALID_VERSION_MAJOR); ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT // Version reserved @@ -171,7 +174,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT // Resource ID out of uint16 range test_u_uri = base_u_uri; - test_u_uri.set_resource_id(0x10000); + test_u_uri.set_resource_id(INVALID_RESOURCE_ID); ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT } @@ -358,6 +361,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLIN // Test deserializing string with invalid field values to verify exceptions are // thrown TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT + constexpr uint32_t UURI_NUMBER = 129; uprotocol::v1::UUri uuri; // Major Version reserved @@ -370,7 +374,7 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT // Major Version reserved uuri_as_string = "//"; - uuri_as_string += std::string(129, 'a'); + uuri_as_string += std::string(UURI_NUMBER, 'a'); uuri_as_string += "/1FFFE/1/7500"; ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT diff --git a/test/coverage/datamodel/UUriValidatorTest.cpp b/test/coverage/datamodel/UUriValidatorTest.cpp index ec0db58a5..cd3c1e2e9 100644 --- a/test/coverage/datamodel/UUriValidatorTest.cpp +++ b/test/coverage/datamodel/UUriValidatorTest.cpp @@ -12,9 +12,10 @@ #include #include -namespace { +constexpr uint32_t DEFAULT_UE_ID = 0x00010001; +constexpr uint32_t WILDCARD = 0xFFFF; -using namespace uprotocol::datamodel::validator::uri; +namespace uprotocol::datamodel::validator::uri{ constexpr const char* AUTHORITY_NAME = "test"; @@ -28,26 +29,27 @@ class TestUUriValidator : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUUriValidator() = default; - ~TestUUriValidator() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestUUriValidator() = default; }; TEST_F(TestUUriValidator, Valid) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); uuri.set_resource_id(1); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); @@ -55,7 +57,7 @@ TEST_F(TestUUriValidator, Valid) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(0); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); @@ -63,7 +65,7 @@ TEST_F(TestUUriValidator, Valid) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); @@ -71,32 +73,35 @@ TEST_F(TestUUriValidator, Valid) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0x7FFF); + constexpr uint32_t VALID_RESOURCE_ID = 0x7FFF; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); - uuri.set_resource_id(0x8000); + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFE); + constexpr uint32_t VALID_RESOURCE_ID = 0xFFFE; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); EXPECT_TRUE(uses_wildcards(uuri)); auto [valid, reason] = isValid(uuri); @@ -106,71 +111,74 @@ TEST_F(TestUUriValidator, Valid) { // NOLINT } TEST_F(TestUUriValidator, Wildcards) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); uuri.set_resource_id(1); return uuri; }; { // Check for no wildcards - auto uuri = getUuri(); + auto uuri = get_u_uri(); EXPECT_FALSE(uses_wildcards(uuri)); } { // Change Authority name to "hello*" (Any) - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name("hello*"); EXPECT_TRUE(uses_wildcards(uuri)); } { // Set Service ID to FFFF (Any) and Instance ID to 1 - auto uuri = getUuri(); - uuri.set_ue_id(0x0001FFFF); + constexpr uint32_t WILDCARD_SERVICE_UE_ID = 0x0001FFFF; + auto uuri = get_u_uri(); + uuri.set_ue_id(WILDCARD_SERVICE_UE_ID); EXPECT_TRUE(uses_wildcards(uuri)); } { // Set Service ID to 1 and Instance ID to FFFF (Any) + constexpr uint32_t WILDCARD_INSTANCE_UE_ID = 0xFFFF0001; // This changed in 581291f in up-spec - auto uuri = getUuri(); - uuri.set_ue_id(0xFFFF0001); + auto uuri = get_u_uri(); + uuri.set_ue_id(WILDCARD_INSTANCE_UE_ID); EXPECT_TRUE(uses_wildcards(uuri)); } { // Set major version to FF (Any) - auto uuri = getUuri(); - uuri.set_ue_version_major(0xFF); + constexpr uint32_t WILDCARD_VERSION_MAJOR = 0xFF; + auto uuri = get_u_uri(); + uuri.set_ue_version_major(WILDCARD_VERSION_MAJOR); EXPECT_TRUE(uses_wildcards(uuri)); } { // Set Resource ID to FFFF (any) - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); EXPECT_TRUE(uses_wildcards(uuri)); } } TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); uuri.set_resource_id(1); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidRpcMethod(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -178,7 +186,7 @@ TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidRpcMethod(uuri); EXPECT_TRUE(valid); @@ -186,16 +194,17 @@ TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidRpcMethod(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::DISALLOWED_WILDCARD); } { - auto uuri = getUuri(); - uuri.set_resource_id(0x8000); + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValidRpcMethod(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::BAD_RESOURCE_ID); @@ -203,24 +212,24 @@ TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT } TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); uuri.set_resource_id(0); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidRpcResponse(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -228,7 +237,7 @@ TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidRpcResponse(uuri); EXPECT_TRUE(valid); @@ -236,15 +245,15 @@ TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidRpcResponse(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::DISALLOWED_WILDCARD); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValidRpcResponse(uuri); EXPECT_FALSE(valid); @@ -253,24 +262,25 @@ TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT } TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT - auto getUuri = []() { + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); - uuri.set_resource_id(0x8000); + uuri.set_resource_id(VALID_RESOURCE_ID); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidPublishTopic(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -278,7 +288,7 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidPublishTopic(uuri); EXPECT_TRUE(valid); @@ -286,15 +296,15 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidPublishTopic(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::DISALLOWED_WILDCARD); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValidPublishTopic(uuri); EXPECT_FALSE(valid); @@ -302,8 +312,9 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0x10000); + constexpr uint32_t VALID_RESOURCE_ID = 0x10000; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValidPublishTopic(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::BAD_RESOURCE_ID); @@ -311,24 +322,25 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT } TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT - auto getUuri = []() { + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); - uuri.set_resource_id(0x8000); + uuri.set_resource_id(VALID_RESOURCE_ID); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidNotificationSource(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -336,7 +348,7 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidNotificationSource(uuri); EXPECT_TRUE(valid); @@ -344,15 +356,15 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidNotificationSource(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::DISALLOWED_WILDCARD); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValidNotificationSource(uuri); EXPECT_FALSE(valid); @@ -360,8 +372,9 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0x10000); + constexpr uint32_t VALID_RESOURCE_ID = 0x10000; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValidNotificationSource(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::BAD_RESOURCE_ID); @@ -369,24 +382,24 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT } TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); uuri.set_resource_id(0); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValid(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidNotificationSink(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -394,7 +407,7 @@ TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidNotificationSink(uuri); EXPECT_TRUE(valid); @@ -402,15 +415,15 @@ TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidNotificationSink(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::DISALLOWED_WILDCARD); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValidNotificationSink(uuri); EXPECT_FALSE(valid); @@ -419,17 +432,18 @@ TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT } TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT - auto getUuri = []() { + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); - uuri.set_resource_id(0x8000); + uuri.set_resource_id(VALID_RESOURCE_ID); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidSubscription(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -437,7 +451,7 @@ TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidSubscription(uuri); EXPECT_TRUE(valid); @@ -445,7 +459,7 @@ TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isValidSubscription(uuri); EXPECT_FALSE(valid); @@ -453,16 +467,17 @@ TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT } { - auto uuri = getUuri(); - uuri.set_resource_id(0x10000); + constexpr uint32_t VALID_RESOURCE_ID = 0x10000; + auto uuri = get_u_uri(); + uuri.set_resource_id(VALID_RESOURCE_ID); auto [valid, reason] = isValidSubscription(uuri); EXPECT_FALSE(valid); EXPECT_TRUE(reason == Reason::BAD_RESOURCE_ID); } { - auto uuri = getUuri(); - uuri.set_resource_id(0xFFFF); + auto uuri = get_u_uri(); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidSubscription(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -470,17 +485,18 @@ TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT } TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT - auto getUuri = []() { + constexpr uint32_t VALID_RESOURCE_ID = 0x8000; + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); - uuri.set_ue_id(0x00010001); + uuri.set_ue_id(DEFAULT_UE_ID); uuri.set_ue_version_major(1); - uuri.set_resource_id(0x8000); + uuri.set_resource_id(VALID_RESOURCE_ID); return uuri; }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(""); auto [valid, reason] = isValidDefaultSource(uuri); EXPECT_FALSE(valid); @@ -489,7 +505,7 @@ TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT } TEST_F(TestUUriValidator, Empty) { // NOLINT - auto getUuri = []() { + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(""); uuri.set_ue_id(0); @@ -499,14 +515,14 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT }; { - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isEmpty(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(" bad "); auto [valid, reason] = isEmpty(uuri); EXPECT_FALSE(valid); @@ -514,7 +530,7 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_authority_name(AUTHORITY_NAME); auto [valid, reason] = isEmpty(uuri); EXPECT_FALSE(valid); @@ -522,7 +538,7 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_ue_id(1); auto [valid, reason] = isEmpty(uuri); EXPECT_FALSE(valid); @@ -530,7 +546,7 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_ue_version_major(1); auto [valid, reason] = isEmpty(uuri); EXPECT_FALSE(valid); @@ -538,7 +554,7 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } { - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_resource_id(1); auto [valid, reason] = isEmpty(uuri); EXPECT_FALSE(valid); @@ -547,10 +563,11 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } TEST_F(TestUUriValidator, ValidFilter) { // NOLINT - auto getUuri = []() { + constexpr uint32_t VALID_UE_ID_FILTER = 10001; + auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name("ValidFilterTest"); - uuri.set_ue_id(10001); + uuri.set_ue_id(VALID_UE_ID_FILTER); uuri.set_ue_version_major(1); uuri.set_resource_id(1); return uuri; @@ -559,7 +576,7 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT ////// GOOD ////// { // Plain URI - auto uuri = getUuri(); + auto uuri = get_u_uri(); auto [valid, reason] = isValidFilter(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -567,11 +584,12 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT { // Wildcard URI + constexpr uint32_t WILDCARD_VERSION_MAJOR = 0xFF; uprotocol::v1::UUri uuri; uuri.set_authority_name("*"); - uuri.set_ue_id(0xFFFF); - uuri.set_ue_version_major(0xFF); - uuri.set_resource_id(0xFFFF); + uuri.set_ue_id(WILDCARD); + uuri.set_ue_version_major(WILDCARD_VERSION_MAJOR); + uuri.set_resource_id(WILDCARD); auto [valid, reason] = isValidFilter(uuri); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -588,7 +606,7 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT { // Reserved Version - auto uuri = getUuri(); + auto uuri = get_u_uri(); uuri.set_ue_version_major(0); auto [valid, reason] = isValidFilter(uuri); EXPECT_FALSE(valid); @@ -598,8 +616,9 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT { // Overflow Version - auto uuri = getUuri(); - uuri.set_ue_version_major(0x100); + constexpr uint32_t OVERFLOW_VERSION_MAJOR = 0x100; + auto uuri = get_u_uri(); + uuri.set_ue_version_major(OVERFLOW_VERSION_MAJOR); auto [valid, reason] = isValidFilter(uuri); EXPECT_FALSE(valid); EXPECT_EQ(reason.value_or(static_cast(-1)), @@ -608,8 +627,9 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT { // Overflow Resource - auto uuri = getUuri(); - uuri.set_resource_id(0x10000); + constexpr uint32_t OVERFLOW_RESOURCE_ID = 0x10000; + auto uuri = get_u_uri(); + uuri.set_resource_id(OVERFLOW_RESOURCE_ID); auto [valid, reason] = isValidFilter(uuri); EXPECT_FALSE(valid); EXPECT_EQ(reason.value_or(static_cast(-1)), @@ -618,8 +638,9 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT { // Long Authority - auto uuri = getUuri(); - uuri.set_authority_name(std::string(129, 'i')); + constexpr uint32_t AUTHORITY_NAME_NUMBER = 129; + auto uuri = get_u_uri(); + uuri.set_authority_name(std::string(AUTHORITY_NAME_NUMBER, 'i')); auto [valid, reason] = isValidFilter(uuri); EXPECT_FALSE(valid); EXPECT_EQ(reason.value_or(static_cast(-1)), @@ -687,4 +708,4 @@ TEST_F(TestUUriValidator, ReasonMessages) { // NOLINT } } -} // namespace +} // namespace uprotocol::datamodel::validator::uri From bad80aca00bbabed65c91fbbd090ffa78f5f2481 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 13:21:20 +0200 Subject: [PATCH 19/41] Finished transport/ --- test/coverage/transport/UTransportTest.cpp | 151 ++++++++++----------- 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/test/coverage/transport/UTransportTest.cpp b/test/coverage/transport/UTransportTest.cpp index 1622432e2..5ad281a7b 100644 --- a/test/coverage/transport/UTransportTest.cpp +++ b/test/coverage/transport/UTransportTest.cpp @@ -18,26 +18,20 @@ #include "UTransportMock.h" -namespace { +constexpr uint32_t WILDCARD = 0xFFFF; +constexpr uint32_t RESOURCE_ID_F00D = 0xF00D; -bool operator==(const uprotocol::v1::UUri& lhs, - const uprotocol::v1::UUri& rhs) { - using namespace google::protobuf::util; - return MessageDifferencer::Equals(lhs, rhs); -} +namespace uprotocol{ -bool operator==(const uprotocol::v1::UMessage& lhs, - const uprotocol::v1::UMessage& rhs) { - using namespace google::protobuf::util; - return MessageDifferencer::Equals(lhs, rhs); +bool operator==(const v1::UUri& lhs, + const v1::UUri& rhs) { + return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -#if 0 -bool operator==(const uprotocol::v1::UStatus& lhs, - const uprotocol::v1::UCode& rhs) { - return lhs.code() == rhs; +bool operator==(const v1::UMessage& lhs, + const v1::UMessage& rhs) { + return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -#endif class TestUTransport : public testing::Test { protected: @@ -50,52 +44,56 @@ class TestUTransport : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestUTransport() = default; - ~TestUTransport() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - static std::shared_ptr makeMockTransport( - const uprotocol::v1::UUri& uri) { - return std::make_shared(uri); + static std::shared_ptr makeMockTransport( + const v1::UUri& uri) { + return std::make_shared(uri); } - static std::shared_ptr makeTransport( - const uprotocol::v1::UUri& uri) { + static std::shared_ptr makeTransport( + const v1::UUri& uri) { return makeMockTransport(uri); } - static std::shared_ptr makeTransport( - std::shared_ptr mock) { + static std::shared_ptr makeTransport( + std::shared_ptr mock) { return mock; } - static uprotocol::v1::UUri getValidUri() { - uprotocol::v1::UUri uri; + static v1::UUri getValidUri() { + constexpr uint32_t RANDOM_UE_ID = 0xdeadbeef; + constexpr uint32_t RANDOM_VERSION_MAJOR = 16; + v1::UUri uri; uri.set_authority_name("UTransportTest"); - uri.set_ue_id(0xdeadbeef); - uri.set_ue_version_major(16); + uri.set_ue_id(RANDOM_UE_ID); + uri.set_ue_version_major(RANDOM_VERSION_MAJOR); uri.set_resource_id(0); return uri; } - static uprotocol::v1::UUri getWildcardUri() { - uprotocol::v1::UUri uri; + static v1::UUri getWildcardUri() { + constexpr uint32_t WILDCARD_VERSION_MAJOR = 0xFF; + v1::UUri uri; uri.set_authority_name("*"); - uri.set_ue_id(0xFFFF); - uri.set_ue_version_major(0xFF); - uri.set_resource_id(0xFFFF); + uri.set_ue_id(WILDCARD); + uri.set_ue_version_major(WILDCARD_VERSION_MAJOR); + uri.set_resource_id(WILDCARD); return uri; } +public: + ~TestUTransport() override = default; }; TEST_F(TestUTransport, CreateTransport) { // NOLINT EXPECT_NO_THROW(auto transport = makeTransport(getValidUri())); // NOLINT } -using InvalidUUri = uprotocol::datamodel::validator::uri::InvalidUUri; +using InvalidUUri = datamodel::validator::uri::InvalidUUri; TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT auto uri = getValidUri(); @@ -103,40 +101,41 @@ TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT EXPECT_THROW({ auto transport = makeTransport(uri); }, InvalidUUri); // NOLINT } -using UMessageBuilder = uprotocol::datamodel::builder::UMessageBuilder; -using PayloadBuilder = uprotocol::datamodel::builder::Payload; +using UMessageBuilder = datamodel::builder::UMessageBuilder; +using PayloadBuilder = datamodel::builder::Payload; TEST_F(TestUTransport, SendOk) { // NOLINT + constexpr uint32_t RANDOM_RESOURCE_ID = 0xABBA; auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); auto topic = getValidUri(); - topic.set_resource_id(0xABBA); - PayloadBuilder payload(std::string("[\"Arrival\", \"Waterloo\"]"), - uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + topic.set_resource_id(RANDOM_RESOURCE_ID); + PayloadBuilder payload(std::string(R"(["Arrival", "Waterloo"])"), + v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); auto message = UMessageBuilder::publish(std::move(topic)).build(std::move(payload)); decltype(transport->send(message)) result; EXPECT_NO_THROW(result = transport->send(message)); // NOLINT - EXPECT_EQ(result.code(), uprotocol::v1::UCode::OK); + EXPECT_EQ(result.code(), v1::UCode::OK); EXPECT_EQ(transport_mock->send_count_, 1); EXPECT_TRUE(transport_mock->message_ == message); } using InvalidUMessge = - uprotocol::datamodel::validator::message::InvalidUMessage; + datamodel::validator::message::InvalidUMessage; TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); message.mutable_attributes()->set_type( - uprotocol::v1::UMessageType::UMESSAGE_TYPE_REQUEST); + v1::UMessageType::UMESSAGE_TYPE_REQUEST); decltype(transport->send(message)) result; EXPECT_THROW({ result = transport->send(message); }, InvalidUMessge); // NOLINT @@ -148,16 +147,16 @@ TEST_F(TestUTransport, SendImplStatus) { // NOLINT auto transport = makeTransport(transport_mock); transport_mock->send_status_.set_code( - uprotocol::v1::UCode::PERMISSION_DENIED); + v1::UCode::PERMISSION_DENIED); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); decltype(transport->send(message)) result; EXPECT_NO_THROW(result = transport->send(message)); // NOLINT - EXPECT_EQ(result.code(), uprotocol::v1::UCode::PERMISSION_DENIED); + EXPECT_EQ(result.code(), v1::UCode::PERMISSION_DENIED); } TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT @@ -168,7 +167,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); - uprotocol::transport::UTransport::ListenHandle handle; + transport::UTransport::ListenHandle handle; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -188,7 +187,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(called); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_TRUE(called); @@ -222,13 +221,13 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT auto transport = makeTransport(transport_mock); transport_mock->registerListener_status_.set_code( - uprotocol::v1::UCode::INTERNAL); + v1::UCode::INTERNAL); bool called = false; auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); - uprotocol::v1::UStatus status; + v1::UStatus status; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -245,7 +244,7 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(callable); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_FALSE(called); @@ -260,9 +259,9 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xFFFF); + sink_filter.set_resource_id(WILDCARD); - uprotocol::transport::UTransport::ListenHandle handle; + transport::UTransport::ListenHandle handle; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -286,7 +285,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(called); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_TRUE(called); @@ -301,10 +300,10 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xFFFF); + sink_filter.set_resource_id(WILDCARD); // Make source invalid - source_filter.set_ue_version_major(0xFFFF); + source_filter.set_ue_version_major(WILDCARD); EXPECT_THROW( // NOLINT { @@ -327,10 +326,10 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xFFFF); + sink_filter.set_resource_id(WILDCARD); // Make sink invalid - sink_filter.set_ue_version_major(0xFFFF); + sink_filter.set_ue_version_major(WILDCARD); EXPECT_THROW( // NOLINT { @@ -350,15 +349,15 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT auto transport = makeTransport(transport_mock); transport_mock->registerListener_status_.set_code( - uprotocol::v1::UCode::NOT_FOUND); + v1::UCode::NOT_FOUND); bool called = false; auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xFFFF); + sink_filter.set_resource_id(WILDCARD); - uprotocol::v1::UStatus status; + v1::UStatus status; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -375,7 +374,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(callable); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_FALSE(called); @@ -390,10 +389,10 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); - uprotocol::transport::UTransport::ListenHandle handle; + transport::UTransport::ListenHandle handle; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = - transport->registerListener(callback, source_filter, 0xF00D); + transport->registerListener(callback, source_filter, RESOURCE_ID_F00D); EXPECT_TRUE(maybe_handle); if (maybe_handle) { @@ -406,7 +405,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT EXPECT_TRUE(transport_mock->sink_filter_); if (transport_mock->sink_filter_) { auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xF00D); + sink_filter.set_resource_id(RESOURCE_ID_F00D); EXPECT_TRUE(sink_filter == transport_mock->sink_filter_.value()); } @@ -416,7 +415,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(called); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_TRUE(called); @@ -432,7 +431,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLIN auto source_filter = getWildcardUri(); // Make source invalid - source_filter.set_ue_version_major(0xFFFF); + source_filter.set_ue_version_major(WILDCARD); EXPECT_THROW( // NOLINT { @@ -455,16 +454,16 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT auto transport = makeTransport(transport_mock); transport_mock->registerListener_status_.set_code( - uprotocol::v1::UCode::NOT_FOUND); + v1::UCode::NOT_FOUND); bool called = false; auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); - uprotocol::v1::UStatus status; + v1::UStatus status; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = - transport->registerListener(callback, source_filter, 0xFFFF); + transport->registerListener(callback, source_filter, WILDCARD); EXPECT_FALSE(maybe_handle); if (!maybe_handle) { @@ -480,7 +479,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT EXPECT_FALSE(callable); // ...but we're still going to try to call it anyway auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_FALSE(called); @@ -495,7 +494,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto topic_source_filter = getWildcardUri(); - uprotocol::transport::UTransport::ListenHandle handle; + transport::UTransport::ListenHandle handle; EXPECT_NO_THROW({ // NOLINT // When source_filter is omitted, sink_filter is treated as a publish // topic. @@ -517,7 +516,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(called); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_TRUE(called); @@ -532,9 +531,9 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); auto sink_filter = getValidUri(); - sink_filter.set_resource_id(0xFFFF); + sink_filter.set_resource_id(WILDCARD); - uprotocol::transport::UTransport::ListenHandle handle; + transport::UTransport::ListenHandle handle; EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(sink_filter, callback, source_filter); @@ -558,11 +557,11 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT auto callable = transport_mock->listener_.value(); EXPECT_FALSE(called); auto topic = getValidUri(); - topic.set_resource_id(0xF00D); + topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); callable(message); EXPECT_TRUE(called); } } -} // namespace +} // namespace uprotocol From 2640935349a21206ff23af17ae552da1dad9c8ec Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 13:38:09 +0200 Subject: [PATCH 20/41] Added NOLINT to rest of test files (TEST_F, EXPECT_THROW, EXPECT_NO_THROW, ASSERT_THROW, ASSERT_NO_THROW) --- .../coverage/utils/CallbackConnectionTest.cpp | 70 +++++++++---------- test/coverage/utils/CyclicQueueTest.cpp | 2 +- test/coverage/utils/ExpectedTest.cpp | 42 +++++------ test/coverage/utils/IpAddressTest.cpp | 2 +- test/coverage/utils/ThreadPoolTest.cpp | 2 +- test/coverage/utils/base64Test.cpp | 2 +- test/extra/NotificationTest.cpp | 2 +- test/extra/PublisherSubscriberTest.cpp | 2 +- test/extra/RpcClientServerTest.cpp | 2 +- test/extra/UTransportMockTest.cpp | 4 +- 10 files changed, 65 insertions(+), 65 deletions(-) diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index fd265b4ac..bff741f23 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -40,15 +40,15 @@ class CallbackTest : public testing::Test { /// It should be possible to establish a connection without an exception /// being thrown. Exceptions that can be thrown at this stage would be a result /// of a system-level failure, such as running out of memory. -TEST_F(CallbackTest, EstablishDoesNotThrow) { +TEST_F(CallbackTest, EstablishDoesNotThrow) { // NOLINT using namespace uprotocol::utils; - EXPECT_NO_THROW(callbacks::Connection::establish([]() {})); + EXPECT_NO_THROW(callbacks::Connection::establish([]() {})); // NOLINT } /// It should be possible to establish a connection and call the callback /// function via the CallerHandle (aka the callable). -TEST_F(CallbackTest, EstablishLinkedPair) { +TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT using namespace uprotocol::utils; int call_count{0}; @@ -62,7 +62,7 @@ TEST_F(CallbackTest, EstablishLinkedPair) { // It's the first time we're calling the callback - check that it doesn't // throw to stop the test here if something is wrong. - EXPECT_NO_THROW(callable()); + EXPECT_NO_THROW(callable()); // NOLINT EXPECT_TRUE(handle); EXPECT_TRUE(callable); @@ -78,7 +78,7 @@ TEST_F(CallbackTest, EstablishLinkedPair) { // When dropping a CalleeHandle or the last CallerHandle, the connection should // be broken. -TEST_F(CallbackTest, DroppedHandlesBreakConnection) { +TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT int call_count{0}; // Utility to produce connected pairs that have been validated as connected @@ -130,7 +130,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { EXPECT_FALSE(callable_outside); // Calling the callback after disconnect from the callee end should not // result in an exception. - EXPECT_NO_THROW(callable_outside()); + EXPECT_NO_THROW(callable_outside()); // NOLINT EXPECT_EQ(call_count, 0); } @@ -168,13 +168,13 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // CallerHandles cannot be used when default constructed or after reset is // called. Doing so will result in an exception being thrown. -TEST_F(CallbackTest, CallerHandleThrowsBadCall) { +TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT using namespace uprotocol::utils; // Default constructed CallerHandle cannot be called { callbacks::CallerHandle callable; - EXPECT_THROW(callable(), callbacks::BadCallerAccess); + EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT } // Freshly reset CallerHandle cannot be called @@ -182,14 +182,14 @@ TEST_F(CallbackTest, CallerHandleThrowsBadCall) { auto [handle, callable] = callbacks::Connection::establish([]() {}); callable.reset(); - EXPECT_THROW(callable(), callbacks::BadCallerAccess); + EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT } } // This connection system will be used for multiple connected callbacks // simultaneously. As such, it should be possible to have multiple handle pairs // in use and not have any unexpected interactions between them. -TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { +TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT using namespace uprotocol::utils; std::array call_count{0}; @@ -247,7 +247,7 @@ TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // Cleanup functions should be called when the connection is broken from the // callee end of the connection. -TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { +TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT using namespace uprotocol::utils; int cleanup_count{0}; @@ -262,7 +262,7 @@ TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // Cleanup functions should not be called when the connection is broken from // the caller end of the connection. -TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { +TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT using namespace uprotocol::utils; { @@ -295,7 +295,7 @@ TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // It is very likely that connections will be held in some sort of map. In // order to effectively make use of the cleanup function, it should be possible // to use the CallerHandle as a reverse-lookup key. -TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { +TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT using namespace uprotocol::utils; std::map::Callable, int> cleanup_count; @@ -331,7 +331,7 @@ TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // functions. However, this should be supported by the connection system. We // can verify the parameters are passed through by checking for the result of // known operations. -TEST_F(CallbackTest, CallablesCanTakeArguments) { +TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT using namespace uprotocol::utils; // Add a couple of numbers together, check the result @@ -366,7 +366,7 @@ TEST_F(CallbackTest, CallablesCanTakeArguments) { // Until this point, the callback has not returned a value. This should be // supported by the connection system. Building on passing parameters, we can // return the result of an operation performed by the callback function. -TEST_F(CallbackTest, CallablesCanReturnValues) { +TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT using namespace uprotocol::utils; // Multiply two numbers together, check the result @@ -404,7 +404,7 @@ TEST_F(CallbackTest, CallablesCanReturnValues) { // inadvertently introduce a copy. We can detect this by a) using a non- // copyable type as the return and b) checking container objects for changes // in their data pointers. -TEST_F(CallbackTest, ReturnValuesAreMoved) { +TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT using namespace uprotocol::utils; // Checking with a non-copyable object (in this case, std::unique_ptr) @@ -459,7 +459,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // still exist. It is safe to call - nothing will happen. However, when the // callback is a returning callback, an empty optional will be returned to // indicate that the connection is not active. -TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { +TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT using namespace uprotocol::utils; { @@ -496,7 +496,7 @@ TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // The typical use case for these callbacks is to pass asynchronous events. // It should work with the caller executing from a separate context. -TEST_F(CallbackTest, CanCallFromAnotherThread) { +TEST_F(CallbackTest, CanCallFromAnotherThread) { // NOLINT using namespace uprotocol::utils; std::atomic call_count{0}; @@ -562,7 +562,7 @@ struct SemaphoreLike { // threads all blocking to acquire resources (via semaphore-like object). These // blocks are released one-by-one to check that the connection states remain // valid and the callee remains blocked throughout the process. -TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { +TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT using namespace uprotocol::utils; using namespace std::chrono_literals; @@ -676,10 +676,10 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // construct a CallerHandle then initialize it later. Check this works, that // the default-constructed object reports as disconnected, and that no // exception is thrown. -TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { +TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT using namespace uprotocol::utils; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT callbacks::CallerHandle x; EXPECT_FALSE(x); }); @@ -689,10 +689,10 @@ TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // construct a CalleeHandle then initialize it later. Check this works, that // the default-constructed object reports as disconnected, and that no // exception is thrown. -TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { +TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT using namespace uprotocol::utils; - EXPECT_NO_THROW({ + EXPECT_NO_THROW({ // NOLINT callbacks::CalleeHandle x; EXPECT_FALSE(x); }); @@ -705,12 +705,12 @@ TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // function objects they receive // Tests invalid callback function objects -TEST_F(CallbackTest, EstablishWithNonCallableCallback) { +TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT using namespace uprotocol::utils; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish({}), + EXPECT_THROW(conn = callbacks::Connection::establish({}), // NOLINT callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -720,19 +720,19 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); - EXPECT_NO_THROW(callable.reset()); + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } // Tests invalid cleanup function objects -TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { +TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT using namespace uprotocol::utils; auto cb = []() -> bool { return true; }; callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish(cb, empty), + EXPECT_THROW(conn = callbacks::Connection::establish(cb, empty), // NOLINT callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -742,18 +742,18 @@ TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); - EXPECT_NO_THROW(callable.reset()); + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } // Tests both invalid cleanup and invalid callback function objects -TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { +TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT using namespace uprotocol::utils; callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish({}, empty), + EXPECT_THROW(conn = callbacks::Connection::establish({}, empty), // NOLINT callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -763,8 +763,8 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); - EXPECT_NO_THROW(callable.reset()); + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } } // namespace diff --git a/test/coverage/utils/CyclicQueueTest.cpp b/test/coverage/utils/CyclicQueueTest.cpp index 8160e8b33..46b2b4ccc 100644 --- a/test/coverage/utils/CyclicQueueTest.cpp +++ b/test/coverage/utils/CyclicQueueTest.cpp @@ -33,6 +33,6 @@ class TestFixture : public testing::Test { }; // TODO replace -TEST_F(TestFixture, SomeTestName) {} +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index 76f712854..b32137656 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -45,7 +45,7 @@ int get_rand() { return dist(mt); } -TEST_F(ExpectedTest, ExpectScalarScalar) { +TEST_F(ExpectedTest, ExpectScalarScalar) { // NOLINT auto sample = get_rand(); auto expected = Expected(sample); EXPECT_TRUE(bool(expected)); @@ -54,7 +54,7 @@ TEST_F(ExpectedTest, ExpectScalarScalar) { EXPECT_EQ(sample, *expected); } -TEST_F(ExpectedTest, UnexpectScalarScalar) { +TEST_F(ExpectedTest, UnexpectScalarScalar) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(sample)); EXPECT_FALSE(bool(expected)); @@ -62,7 +62,7 @@ TEST_F(ExpectedTest, UnexpectScalarScalar) { EXPECT_EQ(sample, expected.error()); } -TEST_F(ExpectedTest, ExpectScalar) { +TEST_F(ExpectedTest, ExpectScalar) { // NOLINT auto sample = get_rand(); auto expected = Expected(sample); EXPECT_TRUE(bool(expected)); @@ -71,7 +71,7 @@ TEST_F(ExpectedTest, ExpectScalar) { EXPECT_EQ(sample, *expected); } -TEST_F(ExpectedTest, UnexpectScalar) { +TEST_F(ExpectedTest, UnexpectScalar) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(sample)); EXPECT_FALSE(bool(expected)); @@ -79,7 +79,7 @@ TEST_F(ExpectedTest, UnexpectScalar) { EXPECT_EQ(sample, expected.error()); } -TEST_F(ExpectedTest, UnexpectValueOr) { +TEST_F(ExpectedTest, UnexpectValueOr) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(std::string("hello"))); @@ -95,7 +95,7 @@ struct Pair { Pair(int x, int y) : x(x), y(y) {} }; -TEST_F(ExpectedTest, ExpectUnique) { +TEST_F(ExpectedTest, ExpectUnique) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected, std::string>( @@ -107,7 +107,7 @@ TEST_F(ExpectedTest, ExpectUnique) { EXPECT_EQ(y, p->y); } -TEST_F(ExpectedTest, UnexpectUnique) { +TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected>( @@ -119,7 +119,7 @@ TEST_F(ExpectedTest, UnexpectUnique) { EXPECT_EQ(y, p->y); } -TEST_F(ExpectedTest, ExpectShared) { +TEST_F(ExpectedTest, ExpectShared) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected, std::string>( @@ -132,7 +132,7 @@ TEST_F(ExpectedTest, ExpectShared) { EXPECT_EQ(y, (*expected)->y); } -TEST_F(ExpectedTest, UnexpectShared) { +TEST_F(ExpectedTest, UnexpectShared) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected>( @@ -143,7 +143,7 @@ TEST_F(ExpectedTest, UnexpectShared) { EXPECT_EQ(y, expected.error()->y); } -TEST_F(ExpectedTest, ExpectStruct) { +TEST_F(ExpectedTest, ExpectStruct) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected(Pair(x, y)); @@ -155,7 +155,7 @@ TEST_F(ExpectedTest, ExpectStruct) { EXPECT_EQ(y, expected->y); } -TEST_F(ExpectedTest, UnexpectStruct) { +TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected(Unexpected(Pair(x, y))); @@ -179,7 +179,7 @@ struct PairDestruct { int PairDestruct::cd_count = 0; -TEST_F(ExpectedTest, ExpectStructDestruct) { +TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT PairDestruct::cd_count = 0; { auto x = get_rand(); @@ -196,7 +196,7 @@ TEST_F(ExpectedTest, ExpectStructDestruct) { EXPECT_EQ(0, PairDestruct::cd_count); } -TEST_F(ExpectedTest, UnexpectStructDestruct) { +TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT PairDestruct::cd_count = 0; { auto x = get_rand(); @@ -212,10 +212,10 @@ TEST_F(ExpectedTest, UnexpectStructDestruct) { EXPECT_EQ(0, PairDestruct::cd_count); } -TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { +TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); @@ -230,9 +230,9 @@ TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { +TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { // NOLINT auto expected = Expected(5); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { try { EXPECT_TRUE(bool(expected)); @@ -247,10 +247,10 @@ TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { +TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); @@ -266,10 +266,10 @@ TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) { +TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); diff --git a/test/coverage/utils/IpAddressTest.cpp b/test/coverage/utils/IpAddressTest.cpp index b243bd071..4a484e990 100644 --- a/test/coverage/utils/IpAddressTest.cpp +++ b/test/coverage/utils/IpAddressTest.cpp @@ -33,6 +33,6 @@ class TestFixture : public testing::Test { }; // TODO replace -TEST_F(TestFixture, SomeTestName) {} +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp index 22b1dfd6f..b601b2a1e 100644 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ b/test/coverage/utils/ThreadPoolTest.cpp @@ -33,6 +33,6 @@ class TestFixture : public testing::Test { }; // TODO replace -TEST_F(TestFixture, SomeTestName) {} +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp index 34fec4db0..91616799c 100644 --- a/test/coverage/utils/base64Test.cpp +++ b/test/coverage/utils/base64Test.cpp @@ -33,6 +33,6 @@ class TestFixture : public testing::Test { }; // TODO replace -TEST_F(TestFixture, SomeTestName) {} +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/extra/NotificationTest.cpp b/test/extra/NotificationTest.cpp index db4268160..9dee1011c 100644 --- a/test/extra/NotificationTest.cpp +++ b/test/extra/NotificationTest.cpp @@ -63,7 +63,7 @@ class NotificationTest : public testing::Test { return testTopic_; } -TEST_F(NotificationTest, NotificationSuccess) { +TEST_F(NotificationTest, NotificationSuccess) { // NOLINT // Initialize uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; diff --git a/test/extra/PublisherSubscriberTest.cpp b/test/extra/PublisherSubscriberTest.cpp index b29d0a17c..1eff56b9c 100644 --- a/test/extra/PublisherSubscriberTest.cpp +++ b/test/extra/PublisherSubscriberTest.cpp @@ -67,7 +67,7 @@ class TestPublisherSubscriber : public testing::Test { std::optional ttl_; }; -TEST_F(TestPublisherSubscriber, PubSubSuccess) { +TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT // sub auto transportSub = std::make_shared(source_); diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index eaf54ce9c..6f6295b9b 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -108,7 +108,7 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT UPriority::UPRIORITY_CS4, 1000ms); uprotocol::communication::RpcClient::InvokeHandle client_handle; // NOLINT - EXPECT_NO_THROW( + EXPECT_NO_THROW( // NOLINT client_handle = client.invokeMethod( std::move(client_request_payload), [this, &client_called, &client_capture](auto maybe_response) { diff --git a/test/extra/UTransportMockTest.cpp b/test/extra/UTransportMockTest.cpp index 349486193..ff5bcfd26 100644 --- a/test/extra/UTransportMockTest.cpp +++ b/test/extra/UTransportMockTest.cpp @@ -67,7 +67,7 @@ class TestMockUTransport : public testing::Test { static void TearDownTestSuite() {} }; -TEST_F(TestMockUTransport, Send) { +TEST_F(TestMockUTransport, Send) { // NOLINT using namespace std; uprotocol::v1::UUri def_src_uuri; @@ -117,7 +117,7 @@ TEST_F(TestMockUTransport, Send) { } } -TEST_F(TestMockUTransport, registerListener) { +TEST_F(TestMockUTransport, registerListener) { // NOLINT using namespace std; uprotocol::v1::UUri def_src_uuri; From b24249ff28b23d17835dd1f2ed1ce48ee5c3b2b1 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 14:56:13 +0200 Subject: [PATCH 21/41] Continue solving warnings --- .../coverage/utils/CallbackConnectionTest.cpp | 92 +++++++++---------- test/coverage/utils/CyclicQueueTest.cpp | 3 +- test/coverage/utils/ExpectedTest.cpp | 3 +- test/coverage/utils/IpAddressTest.cpp | 3 +- test/coverage/utils/ThreadPoolTest.cpp | 3 +- test/coverage/utils/base64Test.cpp | 3 +- 6 files changed, 54 insertions(+), 53 deletions(-) diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index bff741f23..73d329c7f 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -17,7 +17,7 @@ #include #include -namespace { +namespace uprotocol::utils{ class CallbackTest : public testing::Test { protected: @@ -29,27 +29,25 @@ class CallbackTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. CallbackTest() = default; - ~CallbackTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~CallbackTest() override = default; }; /// It should be possible to establish a connection without an exception /// being thrown. Exceptions that can be thrown at this stage would be a result /// of a system-level failure, such as running out of memory. TEST_F(CallbackTest, EstablishDoesNotThrow) { // NOLINT - using namespace uprotocol::utils; - EXPECT_NO_THROW(callbacks::Connection::establish([]() {})); // NOLINT } /// It should be possible to establish a connection and call the callback /// function via the CallerHandle (aka the callable). TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT - using namespace uprotocol::utils; int call_count{0}; @@ -82,8 +80,8 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT int call_count{0}; // Utility to produce connected pairs that have been validated as connected - auto getPair = ([&call_count]() { - using namespace uprotocol::utils; + auto get_pair = ([&call_count]() { + auto connected_pair = callbacks::Connection::establish( [&call_count]() { ++call_count; }); @@ -98,7 +96,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // Drop the handle end via reset() { - auto [handle, callable] = getPair(); + auto [handle, callable] = get_pair(); handle.reset(); EXPECT_FALSE(handle); EXPECT_FALSE(callable); @@ -108,7 +106,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // Drop the callable end via reset() { - auto [handle, callable] = getPair(); + auto [handle, callable] = get_pair(); callable.reset(); EXPECT_FALSE(handle); EXPECT_FALSE(callable); @@ -116,12 +114,12 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // Drop the handle end by letting it go out of scope { - using namespace uprotocol::utils; + callbacks::Connection::Callable callable_outside; static_assert(std::is_move_assignable_v); EXPECT_FALSE(callable_outside); { - auto [handle, callable] = getPair(); + auto [handle, callable] = get_pair(); callable_outside = std::move(callable); EXPECT_FALSE(callable); EXPECT_TRUE(callable_outside); @@ -136,12 +134,12 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // Drop the callable end by letting it go out of scope { - using namespace uprotocol::utils; + callbacks::Connection::Handle handle_outside; static_assert(std::is_move_assignable_v); EXPECT_FALSE(handle_outside); { - auto [handle, callable] = getPair(); + auto [handle, callable] = get_pair(); handle_outside = std::move(handle); EXPECT_FALSE(handle); EXPECT_TRUE(handle_outside); @@ -153,7 +151,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // If multiple copies of the callable end are held, dropping one doesn't // break the connection. { - auto [handle, callable] = getPair(); + auto [handle, callable] = get_pair(); auto other_callable = callable; EXPECT_TRUE(other_callable); callable(); @@ -169,7 +167,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // CallerHandles cannot be used when default constructed or after reset is // called. Doing so will result in an exception being thrown. TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT - using namespace uprotocol::utils; + // Default constructed CallerHandle cannot be called { @@ -190,7 +188,7 @@ TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT // simultaneously. As such, it should be possible to have multiple handle pairs // in use and not have any unexpected interactions between them. TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT - using namespace uprotocol::utils; + std::array call_count{0}; @@ -248,12 +246,12 @@ TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT // Cleanup functions should be called when the connection is broken from the // callee end of the connection. TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT - using namespace uprotocol::utils; + int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); EXPECT_EQ(cleanup_count, 0); handle.reset(); @@ -263,13 +261,13 @@ TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT // Cleanup functions should not be called when the connection is broken from // the caller end of the connection. TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT - using namespace uprotocol::utils; + { int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); EXPECT_EQ(cleanup_count, 0); callable.reset(); @@ -280,7 +278,7 @@ TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); auto callable_copy = callable; @@ -296,16 +294,15 @@ TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT // order to effectively make use of the cleanup function, it should be possible // to use the CallerHandle as a reverse-lookup key. TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT - using namespace uprotocol::utils; std::map::Callable, int> cleanup_count; auto [handle_a, callable_a] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count[c]; }); + []() {}, [&cleanup_count](const auto& c) { ++cleanup_count[c]; }); auto [handle_b, callable_b] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count[c]; }); + []() {}, [&cleanup_count](const auto& c) { ++cleanup_count[c]; }); auto [handle_c, callable_c] = callbacks::Connection::establish( - []() {}, [&cleanup_count](auto c) { ++cleanup_count[c]; }); + []() {}, [&cleanup_count](const auto& c) { ++cleanup_count[c]; }); EXPECT_EQ(cleanup_count[callable_a], 0); EXPECT_EQ(cleanup_count[callable_b], 0); @@ -332,7 +329,7 @@ TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT // can verify the parameters are passed through by checking for the result of // known operations. TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT - using namespace uprotocol::utils; + // Add a couple of numbers together, check the result { @@ -367,7 +364,7 @@ TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT // supported by the connection system. Building on passing parameters, we can // return the result of an operation performed by the callback function. TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT - using namespace uprotocol::utils; + // Multiply two numbers together, check the result { @@ -405,7 +402,7 @@ TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT // copyable type as the return and b) checking container objects for changes // in their data pointers. TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT - using namespace uprotocol::utils; + // Checking with a non-copyable object (in this case, std::unique_ptr) { @@ -427,7 +424,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT // Checking with a container object (in this case, std::string) { void* original_string_location{nullptr}; - constexpr size_t expected_capacity = 9000; + constexpr size_t EXPECTED_CAPACITY = 9000; std::string a_copy; auto [handle, callable] = @@ -437,7 +434,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT // to see if a copy or a move has occurred. Copies will // generally only reserve what is needed to hold the // current content of the original string. - s.reserve(expected_capacity); + s.reserve(EXPECTED_CAPACITY); original_string_location = s.data(); a_copy = s; return s; @@ -446,12 +443,12 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT auto result = callable(); EXPECT_TRUE(result); EXPECT_EQ(original_string_location, (*result).data()); - EXPECT_EQ(expected_capacity, (*result).capacity()); + EXPECT_EQ(EXPECTED_CAPACITY, (*result).capacity()); // Just to be safe, check our assumptions about copies vs moves. The // a_copy variable should hold a copy of the original string, this time // with a different pointer and capacity. EXPECT_NE(original_string_location, a_copy.data()); - EXPECT_NE(expected_capacity, a_copy.capacity()); + EXPECT_NE(EXPECTED_CAPACITY, a_copy.capacity()); } } @@ -460,11 +457,11 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT // callback is a returning callback, an empty optional will be returned to // indicate that the connection is not active. TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT - using namespace uprotocol::utils; + { auto [handle, callable] = - callbacks::Connection::establish([]() { return 1.0f; }); + callbacks::Connection::establish([]() { return 1.0F; }); static_assert( std::is_same_v, decltype(callable())>); @@ -497,18 +494,18 @@ TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT // The typical use case for these callbacks is to pass asynchronous events. // It should work with the caller executing from a separate context. TEST_F(CallbackTest, CanCallFromAnotherThread) { // NOLINT - using namespace uprotocol::utils; + std::atomic call_count{0}; auto [handle, callable] = callbacks::Connection::establish( [&call_count]() { ++call_count; }); - constexpr int expected = 21; + constexpr int EXPECTED = 21; // Note: C++20 could use jthread instead of std::thread std::thread other([c = std::move(callable)]() mutable { - for (int i = 0; i < expected; ++i) { + for (int i = 0; i < EXPECTED; ++i) { c(); } }); @@ -517,7 +514,7 @@ TEST_F(CallbackTest, CanCallFromAnotherThread) { // NOLINT EXPECT_FALSE(callable); other.join(); EXPECT_FALSE(handle); - EXPECT_EQ(call_count, expected); + EXPECT_EQ(call_count, EXPECTED); } //////////////////////////////////////////////////////////////////////////// @@ -538,15 +535,14 @@ struct SemaphoreLike { if (ctr_ > 0) { --ctr_; return true; - } else { - return cv_.wait_for(l, t, [this]() { + } return cv_.wait_for(l, t, [this]() { if (ctr_ > 0) { --ctr_; return true; } return false; }); - } + } private: @@ -563,7 +559,7 @@ struct SemaphoreLike { // blocks are released one-by-one to check that the connection states remain // valid and the callee remains blocked throughout the process. TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT - using namespace uprotocol::utils; + using namespace std::chrono_literals; std::atomic disconnect_done{false}; @@ -677,7 +673,7 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT // the default-constructed object reports as disconnected, and that no // exception is thrown. TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT - using namespace uprotocol::utils; + EXPECT_NO_THROW({ // NOLINT callbacks::CallerHandle x; @@ -690,7 +686,7 @@ TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT // the default-constructed object reports as disconnected, and that no // exception is thrown. TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT - using namespace uprotocol::utils; + EXPECT_NO_THROW({ // NOLINT callbacks::CalleeHandle x; @@ -706,7 +702,7 @@ TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT // Tests invalid callback function objects TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT - using namespace uprotocol::utils; + callbacks::Connection::ConnectedPair conn; @@ -726,7 +722,7 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT // Tests invalid cleanup function objects TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT - using namespace uprotocol::utils; + auto cb = []() -> bool { return true; }; callbacks::Connection::Cleanup empty; @@ -748,7 +744,7 @@ TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT // Tests both invalid cleanup and invalid callback function objects TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT - using namespace uprotocol::utils; + callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; @@ -767,4 +763,4 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT EXPECT_NO_THROW(callable.reset()); // NOLINT } -} // namespace +} // namespace uprotocol::utils diff --git a/test/coverage/utils/CyclicQueueTest.cpp b/test/coverage/utils/CyclicQueueTest.cpp index 46b2b4ccc..991992d94 100644 --- a/test/coverage/utils/CyclicQueueTest.cpp +++ b/test/coverage/utils/CyclicQueueTest.cpp @@ -24,12 +24,13 @@ class TestFixture : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestFixture() = default; - ~TestFixture() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestFixture() override = default; }; // TODO replace diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index b32137656..5019bdfce 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -30,12 +30,13 @@ class ExpectedTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. ExpectedTest() = default; - ~ExpectedTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~ExpectedTest() override = default; }; int get_rand() { diff --git a/test/coverage/utils/IpAddressTest.cpp b/test/coverage/utils/IpAddressTest.cpp index 4a484e990..e332a2be8 100644 --- a/test/coverage/utils/IpAddressTest.cpp +++ b/test/coverage/utils/IpAddressTest.cpp @@ -24,12 +24,13 @@ class TestFixture : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestFixture() = default; - ~TestFixture() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestFixture() override = default; }; // TODO replace diff --git a/test/coverage/utils/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp index b601b2a1e..59cff4ab2 100644 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ b/test/coverage/utils/ThreadPoolTest.cpp @@ -24,12 +24,13 @@ class TestFixture : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestFixture() = default; - ~TestFixture() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestFixture() override = default; }; // TODO replace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp index 91616799c..600287655 100644 --- a/test/coverage/utils/base64Test.cpp +++ b/test/coverage/utils/base64Test.cpp @@ -24,12 +24,13 @@ class TestFixture : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestFixture() = default; - ~TestFixture() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestFixture() override = default; }; // TODO replace From dc2759fe3e04a638568d99c2d7b43636196ac160 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Thu, 10 Apr 2025 16:57:40 +0200 Subject: [PATCH 22/41] Solved more linter warnings. Mostly finished. --- test/coverage/datamodel/UUriValidatorTest.cpp | 2 +- .../coverage/datamodel/UuidSerializerTest.cpp | 12 +-- .../coverage/utils/CallbackConnectionTest.cpp | 13 ++- test/coverage/utils/ExpectedTest.cpp | 22 ++-- test/extra/NotificationTest.cpp | 97 +++++++++-------- test/extra/PublisherSubscriberTest.cpp | 84 ++++++++------- test/extra/RpcClientServerTest.cpp | 102 +++++++++++------- test/extra/UTransportMockTest.cpp | 66 +++++++----- 8 files changed, 225 insertions(+), 173 deletions(-) diff --git a/test/coverage/datamodel/UUriValidatorTest.cpp b/test/coverage/datamodel/UUriValidatorTest.cpp index cd3c1e2e9..53bb04e90 100644 --- a/test/coverage/datamodel/UUriValidatorTest.cpp +++ b/test/coverage/datamodel/UUriValidatorTest.cpp @@ -35,7 +35,7 @@ class TestUUriValidator : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} public: - ~TestUUriValidator() = default; + ~TestUUriValidator() override = default; }; TEST_F(TestUUriValidator, Valid) { // NOLINT diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index 992da52bb..b4912b3d1 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -108,7 +108,7 @@ TEST_F(TestUuidSerializer, // NOLINT } // Test string deserialization -TEST(DeserializerTest, DeserializeUUID) { +TEST(DeserializerTest, DeserializeUUID) { // NOLINT // Define a UUID string in the traditional format std::string uuid_str = "12345678-9abc-def0-fedc-ba9876543210"; // Deserialize the UUID string @@ -133,7 +133,7 @@ TEST_F(TestUuidSerializer, // NOLINT } // Test invalid string deserialization -TEST(DeserializerTest, InvalidUUIDFormat) { +TEST(DeserializerTest, InvalidUUIDFormat) { // NOLINT // Define an invalid UUID string (missing dashes) std::string invalid_uuid_str = "123456789abcdef0123456789abcdef0"; // Assert that deserialization throws an invalid argument exception @@ -143,7 +143,7 @@ TEST(DeserializerTest, InvalidUUIDFormat) { } // Test deserialization with correct length but incorrect placement of dashes -TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { +TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { // NOLINT std::string invalid_uuid = "12345678-1234-5678-1234-56781234567"; // Missing one character EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT @@ -152,7 +152,7 @@ TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { } // Test deserialization with UUIDs that have an extra character -TEST(DeserializerTest, DeserializeWithExtraCharacter) { +TEST(DeserializerTest, DeserializeWithExtraCharacter) { // NOLINT std::string invalid_uuid1 = "12345678-1234-5678-1234-1234567890123"; // Extra character at the end EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT @@ -188,7 +188,7 @@ TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { } // Test deserialization with a zero-length string -TEST(DeserializerTest, DeserializeEmptyString) { +TEST(DeserializerTest, DeserializeEmptyString) { // NOLINT // Define an empty UUID string std::string empty_uuid_str; // Deserialize the empty UUID string @@ -198,7 +198,7 @@ TEST(DeserializerTest, DeserializeEmptyString) { } // Test deserialization with an invalid character in the UUID string -TEST(DeserializerTest, DeserializeInvalidCharacter) { +TEST(DeserializerTest, DeserializeInvalidCharacter) { // NOLINT // Define a UUID string with an invalid character ('x' instead of valid hex) std::string invalid_uuid_str = "1234567890ab-cdef-1234-5678-90abcdefxabc"; EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 73d329c7f..63da1a5ba 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -329,7 +329,10 @@ TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT // can verify the parameters are passed through by checking for the result of // known operations. TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT - + constexpr uint16_t RANDOM_NUMBER_1 = 5; + constexpr uint16_t RANDOM_NUMBER_2 = 9; + constexpr int16_t RANDOM_NUMBER_3 = -80; + constexpr uint16_t RANDOM_NUMBER_4 = 79; // Add a couple of numbers together, check the result { @@ -339,9 +342,9 @@ TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT callbacks::Connection::establish( [&sum](int x, int y) { sum = x + y; }); - callable(5, 9); + callable(RANDOM_NUMBER_1, RANDOM_NUMBER_2); EXPECT_EQ(sum, 14); - callable(-80, 79); + callable(RANDOM_NUMBER_3, RANDOM_NUMBER_4); EXPECT_EQ(sum, -1); } @@ -402,7 +405,7 @@ TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT // copyable type as the return and b) checking container objects for changes // in their data pointers. TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT - + constexpr size_t RANDOM_NUMBER = 71; // Checking with a non-copyable object (in this case, std::unique_ptr) { @@ -411,7 +414,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT auto [handle, callable] = callbacks::Connection>::establish( [&original_location]() { - auto p = std::make_unique(71); + auto p = std::make_unique(RANDOM_NUMBER); original_location = p.get(); return p; }); diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index 5019bdfce..ab86d1ec2 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -169,24 +169,24 @@ TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT struct PairDestruct { int x; int y; - static int cd_count; + static int cd_count_; - PairDestruct(int x, int y) : x(x), y(y) { cd_count++; } + PairDestruct(int x, int y) : x(x), y(y) { cd_count_++; } - PairDestruct(const PairDestruct& arg) : x(arg.x), y(arg.y) { cd_count++; } + PairDestruct(const PairDestruct& arg) : x(arg.x), y(arg.y) { cd_count_++; } - ~PairDestruct() { cd_count--; } + ~PairDestruct() { cd_count_--; } }; -int PairDestruct::cd_count = 0; +int PairDestruct::cd_count_ = 0; TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT - PairDestruct::cd_count = 0; + PairDestruct::cd_count_ = 0; { auto x = get_rand(); auto y = get_rand(); auto expected = Expected(PairDestruct(x, y)); - EXPECT_EQ(1, PairDestruct::cd_count); + EXPECT_EQ(1, PairDestruct::cd_count_); EXPECT_TRUE(bool(expected)); EXPECT_TRUE(expected.has_value()); EXPECT_EQ(x, expected.value().x); @@ -194,23 +194,23 @@ TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT EXPECT_EQ(x, expected->x); EXPECT_EQ(y, expected->y); } - EXPECT_EQ(0, PairDestruct::cd_count); + EXPECT_EQ(0, PairDestruct::cd_count_); } TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT - PairDestruct::cd_count = 0; + PairDestruct::cd_count_ = 0; { auto x = get_rand(); auto y = get_rand(); auto expected = Expected(Unexpected(PairDestruct(x, y))); - EXPECT_EQ(1, PairDestruct::cd_count); + EXPECT_EQ(1, PairDestruct::cd_count_); EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); EXPECT_EQ(x, expected.error().x); EXPECT_EQ(y, expected.error().y); } - EXPECT_EQ(0, PairDestruct::cd_count); + EXPECT_EQ(0, PairDestruct::cd_count_); } TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT diff --git a/test/extra/NotificationTest.cpp b/test/extra/NotificationTest.cpp index 9dee1011c..19b7643ae 100644 --- a/test/extra/NotificationTest.cpp +++ b/test/extra/NotificationTest.cpp @@ -17,10 +17,13 @@ #include "UTransportMock.h" #include "up-cpp/datamodel/serializer/UUri.h" -namespace { -using namespace uprotocol::communication; -using namespace uprotocol::datamodel::serializer::uri; -using MsgDiff = google::protobuf::util::MessageDifferencer; +constexpr uint32_t DEFAULT_UE_ID = 0x00011101; +constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8101; +constexpr uint32_t DEFAULT_SOURCE_UE_ID = 0x18000; +constexpr uint16_t DEFAULT_VERSION_MAJOR = 0xF8; +constexpr std::chrono::milliseconds THOUSAND_MILLISECONDS(1000); + +namespace uprotocol::datamodel::serializer::uri{ class NotificationTest : public testing::Test { protected: @@ -32,35 +35,36 @@ class NotificationTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. NotificationTest() = default; - ~NotificationTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - [[nodiscard]] uprotocol::v1::UUri buildValidTestTopic() const; - [[nodiscard]] uprotocol::v1::UUri buildValidDefaultSourceURI() const; + [[nodiscard]] static uprotocol::v1::UUri buildValidTestTopic() ; + [[nodiscard]] static uprotocol::v1::UUri buildValidDefaultSourceURI() ; +public: + ~NotificationTest() override = default; }; [[nodiscard]] uprotocol::v1::UUri NotificationTest::buildValidDefaultSourceURI() - const { - uprotocol::v1::UUri testDefaultSourceURI_; - testDefaultSourceURI_.set_authority_name("10.0.0.1"); - testDefaultSourceURI_.set_ue_id(0x18000); - testDefaultSourceURI_.set_ue_version_major(0x1); - testDefaultSourceURI_.set_resource_id(0x0); - return testDefaultSourceURI_; + { + uprotocol::v1::UUri test_default_source_uri; + test_default_source_uri.set_authority_name("10.0.0.1"); + test_default_source_uri.set_ue_id(DEFAULT_SOURCE_UE_ID); + test_default_source_uri.set_ue_version_major(0x1); + test_default_source_uri.set_resource_id(0x0); + return test_default_source_uri; } [[nodiscard]] uprotocol::v1::UUri NotificationTest::buildValidTestTopic() - const { - uprotocol::v1::UUri testTopic_; - testTopic_.set_authority_name("10.0.0.2"); - testTopic_.set_ue_id(0x00011101); - testTopic_.set_ue_version_major(0xF8); - testTopic_.set_resource_id(0x8101); - return testTopic_; + { + uprotocol::v1::UUri test_topic; + test_topic.set_authority_name("10.0.0.2"); + test_topic.set_ue_id(DEFAULT_UE_ID); + test_topic.set_ue_version_major(DEFAULT_VERSION_MAJOR); + test_topic.set_resource_id(DEFAULT_RESOURCE_ID); + return test_topic; } TEST_F(NotificationTest, NotificationSuccess) { // NOLINT @@ -70,56 +74,55 @@ TEST_F(NotificationTest, NotificationSuccess) { // NOLINT std::optional priority = uprotocol::v1::UPriority::UPRIORITY_CS1; - std::optional ttl = - std::chrono::milliseconds(1000); - uprotocol::v1::UUri testDefaultSourceURI = buildValidDefaultSourceURI(); - uprotocol::v1::UUri testTopic = buildValidTestTopic(); + std::optional ttl = THOUSAND_MILLISECONDS; + uprotocol::v1::UUri test_default_source_uri = buildValidDefaultSourceURI(); + uprotocol::v1::UUri test_topic = buildValidTestTopic(); // Notify Sink - auto transportMockNotificationSink = - std::make_shared(testDefaultSourceURI); + auto transport_mock_notification_sink = + std::make_shared(test_default_source_uri); uprotocol::v1::UMessage capture_msg; auto callback = [&capture_msg](const auto& message) { capture_msg = message; }; - auto result = NotificationSink::create(transportMockNotificationSink, - std::move(callback), testTopic); + auto result = uprotocol::communication::NotificationSink::create(transport_mock_notification_sink, + std::move(callback), test_topic); // Notify Source - std::string testPayloadStr = "test_payload"; - auto transportMockNotificationSource_ = - std::make_shared(testDefaultSourceURI); + std::string test_payload_str = "test_payload"; + auto transport_mock_notification_source = + std::make_shared(test_default_source_uri); - auto movableTopic = testTopic; + auto movable_topic = test_topic; - NotificationSource notificationSource( - transportMockNotificationSource_, std::move(movableTopic), - std::move(testDefaultSourceURI), format, priority, ttl); + uprotocol::communication::NotificationSource notification_source( + transport_mock_notification_source, std::move(movable_topic), + std::move(test_default_source_uri), format, priority, ttl); - uprotocol::datamodel::builder::Payload testPayload(testPayloadStr, format); - auto status = notificationSource.notify(std::move(testPayload)); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, format); + auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ( AsString::serialize( - transportMockNotificationSource_->message_.attributes().source()), - AsString::serialize(transportMockNotificationSink->source_filter_)); + transport_mock_notification_source->message_.attributes().source()), + AsString::serialize(transport_mock_notification_sink->source_filter_)); EXPECT_EQ( AsString::serialize( - transportMockNotificationSource_->message_.attributes().sink()), + transport_mock_notification_source->message_.attributes().sink()), AsString::serialize( - transportMockNotificationSink->sink_filter_.value())); + transport_mock_notification_sink->sink_filter_.value())); // Manually bridge the two transports - transportMockNotificationSink->mockMessage( - transportMockNotificationSource_->message_); + transport_mock_notification_sink->mockMessage( + transport_mock_notification_source->message_); // Test - EXPECT_TRUE(MsgDiff::Equals(transportMockNotificationSource_->message_, + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(transport_mock_notification_source->message_, capture_msg)); - EXPECT_EQ(testPayloadStr, capture_msg.payload()); + EXPECT_EQ(test_payload_str, capture_msg.payload()); } -} // namespace +} // namespace uprotocol::datamodel::serializer::uri diff --git a/test/extra/PublisherSubscriberTest.cpp b/test/extra/PublisherSubscriberTest.cpp index 1eff56b9c..061e53601 100644 --- a/test/extra/PublisherSubscriberTest.cpp +++ b/test/extra/PublisherSubscriberTest.cpp @@ -12,39 +12,56 @@ #include #include +#include + #include "UTransportMock.h" #include "up-cpp/communication/Publisher.h" #include "up-cpp/communication/Subscriber.h" #include "up-cpp/datamodel/serializer/UUri.h" -using namespace uprotocol::communication; -using namespace uprotocol::v1; -using namespace uprotocol::datamodel::serializer::uri; -using MsgDiff = google::protobuf::util::MessageDifferencer; +constexpr uint32_t DEFAULT_SOURCE_UE_ID = 0x00011101; +constexpr uint32_t DEFAULT_TOPIC_UE_ID = 0x10010001; +constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8101; +constexpr uint16_t DEFAULT_SOURCE_VERSION_MAJOR = 0xF1; +constexpr uint16_t DEFAULT_TOPIC_VERSION_MAJOR = 0xF8; +constexpr std::chrono::milliseconds THOUSAND_MILLISECONDS(1000); -namespace { -using namespace uprotocol::datamodel::builder; +namespace uprotocol::v1{ class TestPublisherSubscriber : public testing::Test { +private: + std::shared_ptr transportMock_; + UUri source_; + UUri topic_; + UPayloadFormat format_ = UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + std::optional priority_; + std::optional ttl_; protected: + std::shared_ptr getTransportMock() const { return transportMock_; } + UUri getSource() const { return source_; } + UUri getTopic() const { return topic_; } + UPayloadFormat getFormat() const { return format_; } + std::optional& getPriority() { return priority_; } + std::optional getTTL() const { return ttl_; } + // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(0x00011101); - source_.set_ue_version_major(0xF1); + source_.set_ue_id(DEFAULT_SOURCE_UE_ID); + source_.set_ue_version_major(DEFAULT_SOURCE_VERSION_MAJOR); source_.set_resource_id(0x0); topic_.set_authority_name("10.0.0.1"); - topic_.set_ue_id(0x10010001); - topic_.set_ue_version_major(0xF8); - topic_.set_resource_id(0x8101); + topic_.set_ue_id(DEFAULT_TOPIC_UE_ID); + topic_.set_ue_version_major(DEFAULT_TOPIC_VERSION_MAJOR); + topic_.set_resource_id(DEFAULT_RESOURCE_ID); transportMock_ = std::make_shared(source_); format_ = UPayloadFormat::UPAYLOAD_FORMAT_TEXT; priority_ = UPriority::UPRIORITY_CS2; - ttl_ = std::chrono::milliseconds(1000); + ttl_ = THOUSAND_MILLISECONDS; } void TearDown() override {} @@ -52,58 +69,53 @@ class TestPublisherSubscriber : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestPublisherSubscriber() = default; - ~TestPublisherSubscriber() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} - std::shared_ptr transportMock_; - UUri source_; - UUri topic_; - UPayloadFormat format_; - std::optional priority_; - std::optional ttl_; +public: + ~TestPublisherSubscriber() override = default; }; TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT // sub - auto transportSub = - std::make_shared(source_); + auto transport_sub = + std::make_shared(getSource()); uprotocol::v1::UMessage captured_message; auto callback = [&captured_message](auto message) { - captured_message = message; + captured_message = std::move(message); }; auto result = - Subscriber::subscribe(transportSub, topic_, std::move(callback)); + uprotocol::communication::Subscriber::subscribe(transport_sub, getTopic(), std::move(callback)); // pub - std::string testPayloadStr = "test_payload"; - auto movableTopic = topic_; - Publisher publisher(transportMock_, std::move(movableTopic), format_, - priority_, ttl_); + std::string test_payload_str = "test_payload"; + auto movable_topic = getTopic(); + uprotocol::communication::Publisher publisher(getTransportMock(), std::move(movable_topic), getFormat(), + getPriority(), getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - transportMock_->send_status_ = retval; + getTransportMock()->send_status_ = retval; - Payload testPayload(testPayloadStr, format_); - auto status = publisher.publish(std::move(testPayload)); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + auto status = publisher.publish(std::move(test_payload)); // Test EXPECT_EQ( - AsString::serialize(transportMock_->message_.attributes().source()), - AsString::serialize(transportSub->source_filter_)); + uprotocol::datamodel::serializer::uri::AsString::serialize(getTransportMock()->message_.attributes().source()), + uprotocol::datamodel::serializer::uri::AsString::serialize(transport_sub->source_filter_)); // Manually bridge the two transports - transportSub->mockMessage(transportMock_->message_); + transport_sub->mockMessage(getTransportMock()->message_); // Test - EXPECT_TRUE(MsgDiff::Equals(transportMock_->message_, captured_message)); - EXPECT_EQ(testPayloadStr, captured_message.payload()); + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(getTransportMock()->message_, captured_message)); + EXPECT_EQ(test_payload_str, captured_message.payload()); } -} // namespace \ No newline at end of file +} // namespace uprotocol::v1 diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index 6f6295b9b..c8c243c50 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -19,39 +19,60 @@ #include #include -#include - using namespace std::chrono_literals; -namespace { - -using namespace uprotocol::v1; -using uprotocol::communication::RpcClient; -using uprotocol::communication::RpcServer; -using uprotocol::test::UTransportMock; - -struct MyUUri { - std::string auth = ""; - uint32_t ue_id = 0x8000; - uint32_t ue_version_major = 1; - uint32_t resource_id = 1; - - operator uprotocol::v1::UUri() const { - UUri ret; - ret.set_authority_name(auth); - ret.set_ue_id(ue_id); - ret.set_ue_version_major(ue_version_major); - ret.set_resource_id(resource_id); - return ret; - } - - std::string to_string() const { - return std::string("<< ") + UUri(*this).ShortDebugString() + " >>"; - } -}; - -const MyUUri rpc_service_uuri{"me_authority", 65538, 1, 32600}; -const MyUUri ident{"me_authority", 65538, 1, 0}; +namespace uprotocol::v1{ + + struct UeDetails { + uint32_t ue_id; + uint32_t ue_version_major; + }; + + struct MyUUri { + static constexpr uint32_t DEFAULT_UE_ID = 0x8000; + + public: + MyUUri(std::string auth_val, UeDetails ue_details, uint32_t resource_id_val) + : auth(std::move(auth_val)), + ue_id(ue_details.ue_id), + ue_version_major(ue_details.ue_version_major), + resource_id(resource_id_val) {} + + void set_auth(const std::string& auth_val) { auth = auth_val; } + [[nodiscard]] const std::string& get_auth() const { return auth; } + + void set_ue_details(UeDetails ue_details) { + ue_id = ue_details.ue_id; + ue_version_major = ue_details.ue_version_major; + } + + [[nodiscard]] uint32_t get_ue_id() const { return ue_id; } + [[nodiscard]] uint32_t get_ue_version_major() const { + return ue_version_major; + } + + void set_resource_id(uint32_t resource) { resource_id = resource; } + [[nodiscard]] uint32_t get_resource_id() const { return resource_id; } + + explicit operator uprotocol::v1::UUri() const { + UUri ret; + ret.set_authority_name(auth); + ret.set_ue_id(ue_id); + ret.set_ue_version_major(ue_version_major); + ret.set_resource_id(resource_id); + return ret; + } + + [[nodiscard]] std::string to_string() const { + return std::string("<< ") + UUri(*this).ShortDebugString() + " >>"; + } + + private: + std::string auth; + uint32_t ue_id = DEFAULT_UE_ID; + uint32_t ue_version_major = 1; + uint32_t resource_id = 1; + }; class RpcClientServerTest : public testing::Test { protected: @@ -64,17 +85,20 @@ class RpcClientServerTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. RpcClientServerTest() = default; - ~RpcClientServerTest() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~RpcClientServerTest() override = default; }; TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT - auto server_transport = std::make_shared(ident); - auto client_transport = std::make_shared(ident); + const MyUUri ident{"me_authority",{ 65538, 1}, 0}; + const MyUUri rpc_service_uuri{"me_authority", {65538, 1}, 32600}; + auto server_transport = std::make_shared(static_cast(ident)); + auto client_transport = std::make_shared(static_cast(ident)); // if the client and server try to share the transport handle, this test no // longer works auto client_transport = server_transport; @@ -92,8 +116,8 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT server_response, UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto server_or_status = uprotocol::communication::RpcServer::create( - server_transport, rpc_service_uuri, - [this, &server_called, &server_capture, + server_transport, v1::UUri(rpc_service_uuri), + [&server_called, &server_capture, &server_response_payload](const UMessage& message) { server_called = true; server_capture = message; @@ -104,14 +128,14 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT ASSERT_NE(server_or_status.value(), nullptr); EXPECT_TRUE(server_transport->listener_); - auto client = RpcClient(client_transport, rpc_service_uuri, + auto client = uprotocol::communication::RpcClient(client_transport, v1::UUri(rpc_service_uuri), UPriority::UPRIORITY_CS4, 1000ms); uprotocol::communication::RpcClient::InvokeHandle client_handle; // NOLINT EXPECT_NO_THROW( // NOLINT client_handle = client.invokeMethod( std::move(client_request_payload), - [this, &client_called, &client_capture](auto maybe_response) { + [&client_called, &client_capture](auto maybe_response) { client_called = true; if (maybe_response.has_value()) { client_capture = maybe_response.value(); @@ -129,4 +153,4 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT EXPECT_EQ(server_response, client_capture.payload()); } -} // namespace +} // namespace uprotocol::v1 diff --git a/test/extra/UTransportMockTest.cpp b/test/extra/UTransportMockTest.cpp index ff5bcfd26..60ad11862 100644 --- a/test/extra/UTransportMockTest.cpp +++ b/test/extra/UTransportMockTest.cpp @@ -18,25 +18,33 @@ #include #include -#include -using MsgDiff = google::protobuf::util::MessageDifferencer; +constexpr uint16_t STR_MAX_LEN = 32; +constexpr uint16_t PAYLOAD_STR_MAX_LEN = 1400; +constexpr uint16_t RANDOM_INT_MAX = 100; +constexpr uint32_t DEFAULT_UE_ID = 0x00010001; +constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; +constexpr uint16_t ATTR_TTL = 1000; -static std::random_device random_dev; -static std::mt19937 random_gen(random_dev()); -static std::uniform_int_distribution char_dist('A', 'z'); +using MsgDiff = google::protobuf::util::MessageDifferencer; -std::string get_random_string(size_t max_len = 32) { +std::string get_random_string(size_t max_len = STR_MAX_LEN) { + std::random_device random_dev; + std::mt19937 random_gen(random_dev()); + std::uniform_int_distribution char_dist('A', 'z'); std::uniform_int_distribution len_dist(1, static_cast(max_len)); - size_t len = len_dist(random_gen); + auto len = static_cast(len_dist(random_gen)); std::string retval; retval.reserve(len); - for (size_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { retval += static_cast(char_dist(random_gen)); + } return retval; } -int get_random_int(int mn = 0, int mx = 100) { +int get_random_int(int mn = 0, int mx = RANDOM_INT_MAX) { + std::random_device random_dev; + std::mt19937 random_gen(random_dev()); std::uniform_int_distribution int_dist(mn, mx); return int_dist(random_gen); } @@ -59,20 +67,23 @@ class TestMockUTransport : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. TestMockUTransport() = default; - ~TestMockUTransport() = default; // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} +public: + ~TestMockUTransport() override = default; }; TEST_F(TestMockUTransport, Send) { // NOLINT - using namespace std; + constexpr uint32_t DEF_SRC_UE_ID = 0x18000; + constexpr uint16_t CODE_MAX = 15; + constexpr uint16_t CODE_MOD = 16; uprotocol::v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); - def_src_uuri.set_ue_id(0x18000); + def_src_uuri.set_ue_id(DEF_SRC_UE_ID); def_src_uuri.set_ue_version_major(1); def_src_uuri.set_resource_id(0); @@ -81,13 +92,13 @@ TEST_F(TestMockUTransport, Send) { // NOLINT EXPECT_NE(nullptr, transport); EXPECT_TRUE(MsgDiff::Equals(def_src_uuri, transport->getDefaultSource())); - const size_t max_count = 1000 * 100; + const size_t max_count = 100000; for (size_t i = 0; i < max_count; i++) { - auto src = new uprotocol::v1::UUri(); + auto *src = new uprotocol::v1::UUri(); src->set_authority_name("10.0.0.1"); - src->set_ue_id(0x00010001); + src->set_ue_id(DEFAULT_UE_ID); src->set_ue_version_major(1); - src->set_resource_id(0x8000); + src->set_resource_id(DEFAULT_RESOURCE_ID); // auto sink = new uprotocol::v1::UUri(); // sink->set_authority_name("10.0.0.2"); @@ -101,13 +112,13 @@ TEST_F(TestMockUTransport, Send) { // NOLINT attr->set_allocated_source(src); // attr->set_allocated_sink(sink); attr->set_payload_format(uprotocol::v1::UPAYLOAD_FORMAT_PROTOBUF); - attr->set_ttl(1000); + attr->set_ttl(ATTR_TTL); uprotocol::v1::UMessage msg; msg.set_allocated_attributes(attr); - msg.set_payload(get_random_string(1400)); + msg.set_payload(get_random_string(PAYLOAD_STR_MAX_LEN)); transport->send_status_.set_code( - static_cast(15 - (i % 16))); + static_cast(CODE_MAX - (i % CODE_MOD))); transport->send_status_.set_message(get_random_string()); auto result = transport->send(msg); @@ -118,11 +129,10 @@ TEST_F(TestMockUTransport, Send) { // NOLINT } TEST_F(TestMockUTransport, registerListener) { // NOLINT - using namespace std; - + constexpr uint32_t DEF_SRC_UE_ID = 0x18000; uprotocol::v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); - def_src_uuri.set_ue_id(0x18000); + def_src_uuri.set_ue_id(DEF_SRC_UE_ID); def_src_uuri.set_ue_version_major(1); def_src_uuri.set_resource_id(0); @@ -133,15 +143,15 @@ TEST_F(TestMockUTransport, registerListener) { // NOLINT uprotocol::v1::UUri sink_filter; sink_filter.set_authority_name(get_random_string()); - sink_filter.set_ue_id(0x00010001); + sink_filter.set_ue_id(DEFAULT_UE_ID); sink_filter.set_ue_version_major(1); - sink_filter.set_resource_id(0x8000); + sink_filter.set_resource_id(DEFAULT_RESOURCE_ID); uprotocol::v1::UUri source_filter; source_filter.set_authority_name(get_random_string()); - source_filter.set_ue_id(0x00010001); + source_filter.set_ue_id(DEFAULT_UE_ID); source_filter.set_ue_version_major(1); - source_filter.set_resource_id(0x8000); + source_filter.set_resource_id(DEFAULT_RESOURCE_ID); uprotocol::v1::UMessage capture_msg; size_t capture_count = 0; @@ -161,12 +171,12 @@ TEST_F(TestMockUTransport, registerListener) { // NOLINT EXPECT_TRUE(MsgDiff::Equals(sink_filter, *transport->sink_filter_)); EXPECT_TRUE(MsgDiff::Equals(source_filter, transport->source_filter_)); - const size_t max_count = 1000 * 100; + const size_t max_count = 100000; for (size_t i = 0; i < max_count; i++) { uprotocol::v1::UMessage msg; auto attr = new uprotocol::v1::UAttributes(); msg.set_allocated_attributes(attr); - msg.set_payload(get_random_string(1400)); + msg.set_payload(get_random_string(PAYLOAD_STR_MAX_LEN)); transport->mockMessage(msg); EXPECT_EQ(i + 1, capture_count); EXPECT_TRUE(MsgDiff::Equals(msg, capture_msg)); From 918bd11685dbac0abd2a73c6bd127a901d555d03 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 08:11:24 +0200 Subject: [PATCH 23/41] Solved more issues --- .../coverage/utils/CallbackConnectionTest.cpp | 3 +- test/coverage/utils/CyclicQueueTest.cpp | 2 +- test/coverage/utils/ExpectedTest.cpp | 86 +++++++++++-------- test/coverage/utils/IpAddressTest.cpp | 2 +- test/coverage/utils/ThreadPoolTest.cpp | 2 +- test/coverage/utils/base64Test.cpp | 2 +- test/include/UTransportMock.h | 6 +- 7 files changed, 56 insertions(+), 47 deletions(-) diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 63da1a5ba..b0ab1c34c 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -405,8 +405,6 @@ TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT // copyable type as the return and b) checking container objects for changes // in their data pointers. TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT - constexpr size_t RANDOM_NUMBER = 71; - // Checking with a non-copyable object (in this case, std::unique_ptr) { void* original_location{nullptr}; @@ -414,6 +412,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT auto [handle, callable] = callbacks::Connection>::establish( [&original_location]() { + constexpr int RANDOM_NUMBER = 71; auto p = std::make_unique(RANDOM_NUMBER); original_location = p.get(); return p; diff --git a/test/coverage/utils/CyclicQueueTest.cpp b/test/coverage/utils/CyclicQueueTest.cpp index 991992d94..f23fc8eb1 100644 --- a/test/coverage/utils/CyclicQueueTest.cpp +++ b/test/coverage/utils/CyclicQueueTest.cpp @@ -33,7 +33,7 @@ class TestFixture : public testing::Test { ~TestFixture() override = default; }; -// TODO replace +// TODO(unknown) TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index ab86d1ec2..06058ebf4 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -39,11 +39,13 @@ class ExpectedTest : public testing::Test { ~ExpectedTest() override = default; }; +constexpr int MAX_BIT_SHIFT = 30; + int get_rand() { - static std::random_device rd; - static std::mt19937 mt(rd()); - static std::uniform_int_distribution dist(0, 1 << 30); - return dist(mt); + static std::random_device rd; + static std::mt19937 mt(rd()); + static std::uniform_int_distribution dist(0, 1 << MAX_BIT_SHIFT); + return dist(mt); } TEST_F(ExpectedTest, ExpectScalarScalar) { // NOLINT @@ -90,11 +92,14 @@ TEST_F(ExpectedTest, UnexpectValueOr) { // NOLINT } struct Pair { - int x; - int y; - - Pair(int x, int y) : x(x), y(y) {} -}; + private: + int x; + int y; + public: + Pair(int x_value, int y_value) : x(x_value), y(y_value) {} + [[nodiscard]] int getX() const { return x; } + [[nodiscard]] int getY() const { return y; } + }; TEST_F(ExpectedTest, ExpectUnique) { // NOLINT auto x = get_rand(); @@ -104,8 +109,8 @@ TEST_F(ExpectedTest, ExpectUnique) { // NOLINT EXPECT_TRUE(bool(expected)); EXPECT_TRUE(expected.has_value()); auto p = std::move(expected).value(); - EXPECT_EQ(x, p->x); - EXPECT_EQ(y, p->y); + EXPECT_EQ(x, p->getX()); + EXPECT_EQ(y, p->getY()); } TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT @@ -116,8 +121,8 @@ TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); auto p = std::move(expected).error(); - EXPECT_EQ(x, p->x); - EXPECT_EQ(y, p->y); + EXPECT_EQ(x, p->getX()); + EXPECT_EQ(y, p->getY()); } TEST_F(ExpectedTest, ExpectShared) { // NOLINT @@ -127,10 +132,10 @@ TEST_F(ExpectedTest, ExpectShared) { // NOLINT std::make_shared(x, y)); EXPECT_TRUE(bool(expected)); EXPECT_TRUE(expected.has_value()); - EXPECT_EQ(x, expected.value()->x); - EXPECT_EQ(y, expected.value()->y); - EXPECT_EQ(x, (*expected)->x); - EXPECT_EQ(y, (*expected)->y); + EXPECT_EQ(x, expected.value()->getX()); + EXPECT_EQ(y, expected.value()->getY()); + EXPECT_EQ(x, (*expected)->getX()); + EXPECT_EQ(y, (*expected)->getY()); } TEST_F(ExpectedTest, UnexpectShared) { // NOLINT @@ -140,8 +145,8 @@ TEST_F(ExpectedTest, UnexpectShared) { // NOLINT Unexpected(std::make_shared(x, y))); EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); - EXPECT_EQ(x, expected.error()->x); - EXPECT_EQ(y, expected.error()->y); + EXPECT_EQ(x, expected.error()->getX()); + EXPECT_EQ(y, expected.error()->getY()); } TEST_F(ExpectedTest, ExpectStruct) { // NOLINT @@ -150,10 +155,10 @@ TEST_F(ExpectedTest, ExpectStruct) { // NOLINT auto expected = Expected(Pair(x, y)); EXPECT_TRUE(bool(expected)); EXPECT_TRUE(expected.has_value()); - EXPECT_EQ(x, expected.value().x); - EXPECT_EQ(y, expected.value().y); - EXPECT_EQ(x, expected->x); - EXPECT_EQ(y, expected->y); + EXPECT_EQ(x, expected.value().getX()); + EXPECT_EQ(y, expected.value().getY()); + EXPECT_EQ(x, expected->getX()); + EXPECT_EQ(y, expected->getY()); } TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT @@ -162,21 +167,25 @@ TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT auto expected = Expected(Unexpected(Pair(x, y))); EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); - EXPECT_EQ(x, expected.error().x); - EXPECT_EQ(y, expected.error().y); + EXPECT_EQ(x, expected.error().getX()); + EXPECT_EQ(y, expected.error().getY()); } struct PairDestruct { +private: int x; int y; + +public: static int cd_count_; - - PairDestruct(int x, int y) : x(x), y(y) { cd_count_++; } - - PairDestruct(const PairDestruct& arg) : x(arg.x), y(arg.y) { cd_count_++; } - + PairDestruct(int x_value, int y_value) : x(x_value), y(y_value) { cd_count_++; } + PairDestruct(const PairDestruct& arg) : x(arg.getX()), y(arg.getY()) { cd_count_++; } ~PairDestruct() { cd_count_--; } + + [[nodiscard]] int getX() const { return x; } + [[nodiscard]] int getY() const { return y; } }; + int PairDestruct::cd_count_ = 0; @@ -189,10 +198,10 @@ TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT EXPECT_EQ(1, PairDestruct::cd_count_); EXPECT_TRUE(bool(expected)); EXPECT_TRUE(expected.has_value()); - EXPECT_EQ(x, expected.value().x); - EXPECT_EQ(y, expected.value().y); - EXPECT_EQ(x, expected->x); - EXPECT_EQ(y, expected->y); + EXPECT_EQ(x, expected.value().getX()); + EXPECT_EQ(y, expected.value().getY()); + EXPECT_EQ(x, expected->getX()); + EXPECT_EQ(y, expected->getY()); } EXPECT_EQ(0, PairDestruct::cd_count_); } @@ -207,8 +216,8 @@ TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT EXPECT_EQ(1, PairDestruct::cd_count_); EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); - EXPECT_EQ(x, expected.error().x); - EXPECT_EQ(y, expected.error().y); + EXPECT_EQ(x, expected.error().getX()); + EXPECT_EQ(y, expected.error().getY()); } EXPECT_EQ(0, PairDestruct::cd_count_); } @@ -232,7 +241,8 @@ TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT } TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { // NOLINT - auto expected = Expected(5); + constexpr int DEFAULT_EXPECTED_VALUE = 5; + auto expected = Expected(DEFAULT_EXPECTED_VALUE); EXPECT_THROW( // NOLINT { try { @@ -275,7 +285,7 @@ TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) { // NOLINT try { EXPECT_FALSE(bool(expected)); EXPECT_FALSE(expected.has_value()); - static_cast(expected->x); + static_cast(expected->getX()); } catch (const BadExpectedAccess& ex) { EXPECT_STREQ( "Attempt to dereference expected pointer when unexpected.", diff --git a/test/coverage/utils/IpAddressTest.cpp b/test/coverage/utils/IpAddressTest.cpp index e332a2be8..a62c050e0 100644 --- a/test/coverage/utils/IpAddressTest.cpp +++ b/test/coverage/utils/IpAddressTest.cpp @@ -33,7 +33,7 @@ class TestFixture : public testing::Test { ~TestFixture() override = default; }; -// TODO replace +// TODO(unknown) TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp index 59cff4ab2..e06bb1113 100644 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ b/test/coverage/utils/ThreadPoolTest.cpp @@ -33,7 +33,7 @@ class TestFixture : public testing::Test { ~TestFixture() override = default; }; -// TODO replace +// TODO(unknown) TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp index 600287655..df5b40a6b 100644 --- a/test/coverage/utils/base64Test.cpp +++ b/test/coverage/utils/base64Test.cpp @@ -33,7 +33,7 @@ class TestFixture : public testing::Test { ~TestFixture() override = default; }; -// TODO replace +// TODO(unknown) TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/include/UTransportMock.h b/test/include/UTransportMock.h index 0121dac55..1ee15265a 100644 --- a/test/include/UTransportMock.h +++ b/test/include/UTransportMock.h @@ -9,8 +9,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#ifndef UP_CPP_TEST_UTRANSPORTMOCK_H -#define UP_CPP_TEST_UTRANSPORTMOCK_H +#ifndef UTRANSPORTMOCK_H +#define UTRANSPORTMOCK_H #include #include @@ -80,4 +80,4 @@ class UTransportMock : public uprotocol::transport::UTransport { }; // namespace uprotocol::test -#endif // UP_CPP_TEST_UTRANSPORTMOCK_H +#endif // UTRANSPORTMOCK_H From c9f1eb0f35ed8c032c076d4a2699f11facd44229 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 08:23:50 +0200 Subject: [PATCH 24/41] Before updating UTransportMock.h to private member variables --- test/include/UTransportMock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/include/UTransportMock.h b/test/include/UTransportMock.h index 1ee15265a..f67b1aa75 100644 --- a/test/include/UTransportMock.h +++ b/test/include/UTransportMock.h @@ -51,7 +51,7 @@ class UTransportMock : public uprotocol::transport::UTransport { v1::UMessage message_; std::mutex message_mtx_; - virtual ~UTransportMock() = default; + virtual ~UTransportMock() override = default; private: [[nodiscard]] v1::UStatus sendImpl(const v1::UMessage& message) override { From 941621d0fb410462903cf207d760131c5cfd7e34 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 08:58:25 +0200 Subject: [PATCH 25/41] Updated UTransportMock.h to private member. No compiling, nor test errors --- .../client/usubscription/v3/ConsumerTest.cpp | 10 +- .../communication/NotificationSinkTest.cpp | 8 +- .../communication/NotificationSourceTest.cpp | 26 ++-- test/coverage/communication/PublisherTest.cpp | 18 +-- test/coverage/communication/RpcClientTest.cpp | 134 +++++++++--------- test/coverage/communication/RpcServerTest.cpp | 52 +++---- .../coverage/communication/SubscriberTest.cpp | 8 +- test/coverage/transport/UTransportTest.cpp | 110 +++++++------- test/extra/NotificationTest.cpp | 12 +- test/extra/PublisherSubscriberTest.cpp | 10 +- test/extra/RpcClientServerTest.cpp | 10 +- test/extra/UTransportMockTest.cpp | 18 +-- test/include/UTransportMock.h | 35 +++-- 13 files changed, 235 insertions(+), 216 deletions(-) diff --git a/test/coverage/client/usubscription/v3/ConsumerTest.cpp b/test/coverage/client/usubscription/v3/ConsumerTest.cpp index 8d547ad4a..cebf168a2 100644 --- a/test/coverage/client/usubscription/v3/ConsumerTest.cpp +++ b/test/coverage/client/usubscription/v3/ConsumerTest.cpp @@ -176,8 +176,8 @@ TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT notification_source.notify(std::move(payload)); // Check send count - EXPECT_TRUE(getMockTransportServer()->send_count_ == 1); - EXPECT_TRUE(getMockTransportClient()->send_count_ == 1); + EXPECT_TRUE(getMockTransportServer()->getSendCount() == 1); + EXPECT_TRUE(getMockTransportClient()->getSendCount() == 1); } TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT @@ -223,12 +223,12 @@ TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT notification_source.notify(std::move(payload)); // Check send count - EXPECT_TRUE(getMockTransportServer()->send_count_ == 1); - EXPECT_TRUE(getMockTransportClient()->send_count_ == 1); + EXPECT_TRUE(getMockTransportServer()->getSendCount() == 1); + EXPECT_TRUE(getMockTransportClient()->getSendCount() == 1); consumer_ptr->unsubscribe(priority, subscribe_request_ttl); - EXPECT_TRUE(getMockTransportClient()->send_count_ == 2); + EXPECT_TRUE(getMockTransportClient()->getSendCount() == 2); } } // namespace diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index ac6fe02f9..91d145b73 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -173,14 +173,14 @@ TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT auto result = NotificationSink::create(transport, transport->getEntityUri(), std::move(callback), getTestTopicUUri()); - EXPECT_TRUE(transport->listener_); + EXPECT_TRUE(transport->getListener()); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->source_filter_)); + EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); EXPECT_TRUE( - MsgDiff::Equals(transport->getEntityUri(), *transport->sink_filter_)); + MsgDiff::Equals(transport->getEntityUri(), *transport->getSinkFilter())); const size_t max_count = 100; for (size_t i = 0; i < max_count; i++) { @@ -205,7 +205,7 @@ TEST_F(NotificationSinkTest, FailWithErrorCode) { // NOLINT uprotocol::v1::UStatus expected_status; expected_status.set_code(uprotocol::v1::UCode::ABORTED); - transport->registerListener_status_ = expected_status; + transport->getRegisterListenerStatus() = expected_status; auto result = NotificationSink::create(transport, transport->getEntityUri(), std::move(callback), getTestTopicUUri()); diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index 09a9bcc79..f0f65492a 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -95,7 +95,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -103,7 +103,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); } @@ -115,7 +115,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -123,10 +123,10 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); - EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); } TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOLINT @@ -138,7 +138,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOL uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -146,10 +146,10 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOL auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); - EXPECT_EQ(getTransportMock()->message_.attributes().priority(), + EXPECT_EQ(getTransportMock()->getMessage().attributes().priority(), uprotocol::v1::UPriority::UPRIORITY_CS1); } @@ -162,7 +162,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(std::move(test_payload)); @@ -175,14 +175,14 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(); EXPECT_EQ(status.code(), retval.code()); - EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); - EXPECT_EQ(getTransportMock()->message_.attributes().priority(), + EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->getMessage().attributes().priority(), uprotocol::v1::UPriority::UPRIORITY_CS1); } @@ -192,7 +192,7 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; auto status = notification_source.notify(); diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index ab4400d42..3d126de36 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -94,7 +94,7 @@ TEST_F(TestPublisher, PublisherSuccess) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); @@ -103,7 +103,7 @@ TEST_F(TestPublisher, PublisherSuccess) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); } @@ -114,7 +114,7 @@ TEST_F(TestPublisher, PublishFailure) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); @@ -128,7 +128,7 @@ TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); @@ -137,10 +137,10 @@ TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); - EXPECT_EQ(getTransportMock()->message_.attributes().ttl(), 0); + EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); } TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT @@ -151,7 +151,7 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); @@ -160,10 +160,10 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish( - getTransportMock()->message_); + getTransportMock()->getMessage()); EXPECT_EQ(valid, true); - EXPECT_EQ(getTransportMock()->message_.attributes().priority(), + EXPECT_EQ(getTransportMock()->getMessage().attributes().priority(), v1::UPriority::UPRIORITY_CS1); } diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 420b72794..0f0a843c3 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -99,23 +99,23 @@ class RpcClientTest : public testing::Test { } void validateTransportProperties() const { - EXPECT_TRUE(transport_->listener_); + EXPECT_TRUE(transport_->getListener()); } void validateFilters() const { - EXPECT_TRUE(transport_->source_filter_ == methodUri()); - EXPECT_TRUE(transport_->sink_filter_); - if (transport_->sink_filter_) { - EXPECT_TRUE(*(transport_->sink_filter_) == defaultSourceUri()); + EXPECT_TRUE(transport_->getSourceFilter() == methodUri()); + EXPECT_TRUE(transport_->getSinkFilter()); + if (transport_->getSinkFilter()) { + EXPECT_TRUE(*(transport_->getSinkFilter()) == defaultSourceUri()); } } void validateSendCount(size_t expected_send_count) const { - EXPECT_EQ(transport_->send_count_, expected_send_count); + EXPECT_EQ(transport_->getSendCount(), expected_send_count); } void validateMessage() const { - auto [valid_request, _] = datamodel::validator::message::isValidRpcRequest(transport_->message_); + auto [valid_request, _] = datamodel::validator::message::isValidRpcRequest(transport_->getMessage()); EXPECT_TRUE(valid_request); } @@ -214,10 +214,10 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); - EXPECT_TRUE(getTransport()->message_.payload().empty()); + EXPECT_TRUE(getTransport()->getMessage().payload().empty()); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -240,8 +240,8 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT auto invoke_future = client.invokeMethod(), datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(getTransport()->send_count_, 0); - EXPECT_FALSE(getTransport()->listener_); + EXPECT_EQ(getTransport()->getSendCount(), 0); + EXPECT_FALSE(getTransport()->getListener()); } TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT @@ -271,13 +271,13 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->registerListener_status_.set_code( + getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT - EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -293,7 +293,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->send_status_.set_code( + getTransport()->getSendStatus().set_code( v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; @@ -340,7 +340,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -371,13 +371,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); using PayloadField = datamodel::builder::Payload::PayloadType; - EXPECT_EQ(getTransport()->message_.payload(), + EXPECT_EQ(getTransport()->getMessage().payload(), std::get(payload_content)); - EXPECT_EQ(getTransport()->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->getMessage().attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -405,13 +405,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); using PayloadField = datamodel::builder::Payload::PayloadType; - EXPECT_EQ(getTransport()->message_.payload(), + EXPECT_EQ(getTransport()->getMessage().payload(), std::get(payload_content)); - EXPECT_EQ(getTransport()->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->getMessage().attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -434,8 +434,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT auto invoke_future = client.invokeMethod(fakePayload()), datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(getTransport()->send_count_, 0); - EXPECT_FALSE(getTransport()->listener_); + EXPECT_EQ(getTransport()->getSendCount(), 0); + EXPECT_FALSE(getTransport()->getListener()); } TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT @@ -465,13 +465,13 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->registerListener_status_.set_code( + getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT - EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -487,7 +487,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->send_status_.set_code( + getTransport()->getSendStatus().set_code( v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; @@ -533,7 +533,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -568,10 +568,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT })); validateLastRequest(1); - EXPECT_TRUE(getTransport()->message_.payload().empty()); + EXPECT_TRUE(getTransport()->getMessage().payload().empty()); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -589,8 +589,8 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT handle = client.invokeMethod([](auto) {}), datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(getTransport()->send_count_, 0); - EXPECT_FALSE(getTransport()->listener_); + EXPECT_EQ(getTransport()->getSendCount(), 0); + EXPECT_FALSE(getTransport()->getListener()); } TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT @@ -627,7 +627,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->registerListener_status_.set_code( + getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; @@ -640,7 +640,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT v1::UCode::RESOURCE_EXHAUSTED); })); - EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(callback_called); } @@ -648,7 +648,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->send_status_.set_code( + getTransport()->getSendStatus().set_code( v1::UCode::FAILED_PRECONDITION); bool callback_called = false; @@ -700,7 +700,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT })); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -732,13 +732,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT validateLastRequest(1); using PayloadField = datamodel::builder::Payload::PayloadType; - EXPECT_EQ(getTransport()->message_.payload(), + EXPECT_EQ(getTransport()->getMessage().payload(), std::get(payload_content)); - EXPECT_EQ(getTransport()->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->getMessage().attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -769,13 +769,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT validateLastRequest(1); using PayloadField = datamodel::builder::Payload::PayloadType; - EXPECT_EQ(getTransport()->message_.payload(), + EXPECT_EQ(getTransport()->getMessage().payload(), std::get(payload_content)); - EXPECT_EQ(getTransport()->message_.attributes().payload_format(), + EXPECT_EQ(getTransport()->getMessage().attributes().payload_format(), std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -793,8 +793,8 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT handle = client.invokeMethod(fakePayload(), [](auto) {}), datamodel::builder::UMessageBuilder::UnexpectedFormat); - EXPECT_EQ(getTransport()->send_count_, 0); - EXPECT_FALSE(getTransport()->listener_); + EXPECT_EQ(getTransport()->getSendCount(), 0); + EXPECT_FALSE(getTransport()->getListener()); } TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT @@ -832,7 +832,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->registerListener_status_.set_code( + getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); bool callback_called = false; @@ -846,7 +846,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT v1::UCode::RESOURCE_EXHAUSTED); })); - EXPECT_EQ(getTransport()->send_count_, 0); + EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(callback_called); } @@ -854,7 +854,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - getTransport()->send_status_.set_code( + getTransport()->getSendStatus().set_code( v1::UCode::FAILED_PRECONDITION); bool callback_called = false; @@ -910,7 +910,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT })); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->message_); + auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT @@ -927,24 +927,24 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT TWO_HUNDRED_FIFTY_MILLISECONDS); std::list futures; - std::listlistener_.value())>> callables; + std::listgetListener().value())>> callables; std::list requests; futures.push_back(client.invokeMethod()); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); futures.push_back(client.invokeMethod(fakePayload())); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); futures.push_back(client.invokeMethod()); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); futures.push_back(client.invokeMethod(fakePayload())); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); std::vector handles; @@ -952,20 +952,20 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT auto callback = [&callback_count](const auto&) { ++callback_count; }; handles.push_back(client.invokeMethod(callback)); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); handles.push_back(client.invokeMethod(fakePayload(), callback)); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); handles.push_back(client.invokeMethod(callback)); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); handles.push_back(client.invokeMethod(fakePayload(), callback)); - callables.push_back(getTransport()->listener_.value()); - requests.push_back(getTransport()->message_); + callables.push_back(getTransport()->getListener().value()); + requests.push_back(getTransport()->getMessage()); auto ready_futures = [&futures]() { size_t ready = 0; @@ -1173,7 +1173,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT // Reply to some for (auto& transport : transports) { - auto reply = datamodel::builder::UMessageBuilder::response(transport->message_).build(); + auto reply = datamodel::builder::UMessageBuilder::response(transport->getMessage()).build(); transport->mockMessage(reply); } size_t num_ready = 0; @@ -1399,9 +1399,9 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT // Attempting this without a request having ever been sent results // in an InvalidUUri exception thrown from a thread. gtest can't // guard for that, so we avoid generating the exception. - if (transport->send_count_ > 0) { + if (transport->getSendCount() > 0) { auto response = - datamodel::builder::UMessageBuilder::response(transport->message_).build(); + datamodel::builder::UMessageBuilder::response(transport->getMessage()).build(); transport->mockMessage(response); } } diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index e971a9ee2..b0c8b1717 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -289,7 +289,7 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { // NOLINT EXPECT_NE(handle, nullptr); // Verify that the register listener uri mataches with input method uri - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); } // Test case to verify RPC request handling with return payload and TTL @@ -309,7 +309,7 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); // Create request umessage auto builder = datamodel::builder::UMessageBuilder::request( @@ -320,10 +320,10 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT // Ignore the return value auto _ = getMockTransport()->send(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 1); - EXPECT_TRUE(getMockTransport()->listener_); + EXPECT_TRUE(getMockTransport()->getSendCount() == 1); + EXPECT_TRUE(getMockTransport()->getListener()); getMockTransport()->mockMessage(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 2); + EXPECT_TRUE(getMockTransport()->getSendCount() == 2); // Compare expected reposen message with actual response message auto expected_response_msg = @@ -334,20 +334,20 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT EXPECT_TRUE( MsgDiff::Equals(expected_response_msg.attributes().source(), - getMockTransport()->message_.attributes().source())); + getMockTransport()->getMessage().attributes().source())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - getMockTransport()->message_.attributes().sink())); + getMockTransport()->getMessage().attributes().sink())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - getMockTransport()->message_.attributes().reqid())); + getMockTransport()->getMessage().attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(getMockTransport()->message_.attributes().type())); + static_cast(getMockTransport()->getMessage().attributes().type())); EXPECT_EQ(static_cast(expected_response_msg.attributes().ttl()), - static_cast(getMockTransport()->message_.attributes().ttl())); + static_cast(getMockTransport()->getMessage().attributes().ttl())); EXPECT_EQ( static_cast(expected_response_msg.attributes().priority()), - static_cast(getMockTransport()->message_.attributes().priority())); - EXPECT_EQ(getMockTransport()->message_.payload().data(), + static_cast(getMockTransport()->getMessage().attributes().priority())); + EXPECT_EQ(getMockTransport()->getMessage().payload().data(), expected_response_payload); } @@ -365,7 +365,7 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->sink_filter_)); + EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); // Create request umessage auto builder = datamodel::builder::UMessageBuilder::request( @@ -376,10 +376,10 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT // Ignore the return value auto _ = getMockTransport()->send(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 1); - EXPECT_TRUE(getMockTransport()->listener_); + EXPECT_TRUE(getMockTransport()->getSendCount() == 1); + EXPECT_TRUE(getMockTransport()->getListener()); getMockTransport()->mockMessage(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 2); + EXPECT_TRUE(getMockTransport()->getSendCount() == 2); // Compare expected reposen message with actual response message auto expected_response_msg = @@ -387,18 +387,18 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT EXPECT_TRUE( MsgDiff::Equals(expected_response_msg.attributes().source(), - getMockTransport()->message_.attributes().source())); + getMockTransport()->getMessage().attributes().source())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - getMockTransport()->message_.attributes().sink())); + getMockTransport()->getMessage().attributes().sink())); EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - getMockTransport()->message_.attributes().reqid())); + getMockTransport()->getMessage().attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(getMockTransport()->message_.attributes().type())); + static_cast(getMockTransport()->getMessage().attributes().type())); EXPECT_EQ( static_cast(expected_response_msg.attributes().priority()), - static_cast(getMockTransport()->message_.attributes().priority())); - EXPECT_FALSE(getMockTransport()->message_.has_payload()); + static_cast(getMockTransport()->getMessage().attributes().priority())); + EXPECT_FALSE(getMockTransport()->getMessage().has_payload()); } // Test case to verify RPC request handling with invalid request @@ -427,9 +427,9 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT msg.mutable_attributes()->mutable_sink()->set_resource_id(0); // Check results when invalid request is received - EXPECT_TRUE(getMockTransport()->listener_); + EXPECT_TRUE(getMockTransport()->getListener()); getMockTransport()->mockMessage(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 0); + EXPECT_TRUE(getMockTransport()->getSendCount() == 0); } // Test case to verify RPC sever resets the listener when the server is @@ -457,10 +457,10 @@ TEST_F(TestRpcServer, RestRPCServerHandle) { // NOLINT // Ignore the return value auto _ = getMockTransport()->send(msg); - EXPECT_TRUE(getMockTransport()->send_count_ == 1); + EXPECT_TRUE(getMockTransport()->getSendCount() == 1); getMockTransport()->mockMessage(msg); // Check if the listener is reset - EXPECT_FALSE(getMockTransport()->send_count_ == 2); + EXPECT_FALSE(getMockTransport()->getSendCount() == 2); } } // namespace uprotocol diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index 3e1c7c5a6..dadd090ce 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -138,12 +138,12 @@ TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); - EXPECT_TRUE(transport->listener_); + EXPECT_TRUE(transport->getListener()); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->source_filter_)); - EXPECT_FALSE(transport->sink_filter_); + EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); + EXPECT_FALSE(transport->getSinkFilter()); const size_t max_count = 100; for (size_t i = 0; i < max_count; i++) { @@ -183,7 +183,7 @@ TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { // NOLINT uprotocol::v1::UStatus expected_status; expected_status.set_code(uprotocol::v1::UCode::ABORTED); - transport->registerListener_status_ = expected_status; + transport->getRegisterListenerStatus() = expected_status; auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); diff --git a/test/coverage/transport/UTransportTest.cpp b/test/coverage/transport/UTransportTest.cpp index 5ad281a7b..689a24c18 100644 --- a/test/coverage/transport/UTransportTest.cpp +++ b/test/coverage/transport/UTransportTest.cpp @@ -120,8 +120,8 @@ TEST_F(TestUTransport, SendOk) { // NOLINT EXPECT_NO_THROW(result = transport->send(message)); // NOLINT EXPECT_EQ(result.code(), v1::UCode::OK); - EXPECT_EQ(transport_mock->send_count_, 1); - EXPECT_TRUE(transport_mock->message_ == message); + EXPECT_EQ(transport_mock->getSendCount(), 1); + EXPECT_TRUE(transport_mock->getMessage() == message); } using InvalidUMessge = @@ -139,14 +139,14 @@ TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT decltype(transport->send(message)) result; EXPECT_THROW({ result = transport->send(message); }, InvalidUMessge); // NOLINT - EXPECT_EQ(transport_mock->send_count_, 0); + EXPECT_EQ(transport_mock->getSendCount(), 0); } TEST_F(TestUTransport, SendImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->send_status_.set_code( + transport_mock->getSendStatus().set_code( v1::UCode::PERMISSION_DENIED); auto topic = getValidUri(); @@ -180,11 +180,11 @@ TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT EXPECT_TRUE(handle); - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_TRUE(source_filter == transport_mock->source_filter_); - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_TRUE(source_filter == transport_mock->getSourceFilter()); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(called); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -211,8 +211,8 @@ TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT InvalidUUri); // Did not attempt to register a callback - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_FALSE(transport_mock->listener_); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_FALSE(transport_mock->getListener()); EXPECT_FALSE(called); } @@ -220,7 +220,7 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->registerListener_status_.set_code( + transport_mock->getRegisterListenerStatus().set_code( v1::UCode::INTERNAL); bool called = false; @@ -239,9 +239,9 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT }); // The listener that was sent to the impl is not connected - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(callable); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -274,15 +274,15 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT EXPECT_TRUE(handle); - EXPECT_TRUE(transport_mock->sink_filter_); - if (transport_mock->sink_filter_) { - EXPECT_TRUE(sink_filter == transport_mock->sink_filter_.value()); + EXPECT_TRUE(transport_mock->getSinkFilter()); + if (transport_mock->getSinkFilter()) { + EXPECT_TRUE(sink_filter == transport_mock->getSinkFilter().value()); } - EXPECT_TRUE(source_filter == transport_mock->source_filter_); - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(source_filter == transport_mock->getSourceFilter()); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(called); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -313,8 +313,8 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT InvalidUUri); // Did not attempt to register a callback - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_FALSE(transport_mock->listener_); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_FALSE(transport_mock->getListener()); EXPECT_FALSE(called); } @@ -339,8 +339,8 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT InvalidUUri); // Did not attempt to register a callback - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_FALSE(transport_mock->listener_); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_FALSE(transport_mock->getListener()); EXPECT_FALSE(called); } @@ -348,7 +348,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->registerListener_status_.set_code( + transport_mock->getRegisterListenerStatus().set_code( v1::UCode::NOT_FOUND); bool called = false; @@ -369,9 +369,9 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT }); // The listener that was sent to the impl is not connected - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(callable); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -402,17 +402,17 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT EXPECT_TRUE(handle); - EXPECT_TRUE(transport_mock->sink_filter_); - if (transport_mock->sink_filter_) { + EXPECT_TRUE(transport_mock->getSinkFilter()); + if (transport_mock->getSinkFilter()) { auto sink_filter = getValidUri(); sink_filter.set_resource_id(RESOURCE_ID_F00D); - EXPECT_TRUE(sink_filter == transport_mock->sink_filter_.value()); + EXPECT_TRUE(sink_filter == transport_mock->getSinkFilter().value()); } - EXPECT_TRUE(source_filter == transport_mock->source_filter_); - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(source_filter == transport_mock->getSourceFilter()); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(called); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -441,8 +441,8 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLIN InvalidUUri); // Did not attempt to register a callback - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_FALSE(transport_mock->listener_); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_FALSE(transport_mock->getListener()); EXPECT_FALSE(called); } @@ -453,7 +453,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->registerListener_status_.set_code( + transport_mock->getRegisterListenerStatus().set_code( v1::UCode::NOT_FOUND); bool called = false; @@ -472,9 +472,9 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT }); // The listener that was sent to the impl is not connected - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); // The callback isn't connected... EXPECT_FALSE(callable); // ...but we're still going to try to call it anyway @@ -509,11 +509,11 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT EXPECT_TRUE(handle); - EXPECT_FALSE(transport_mock->sink_filter_); - EXPECT_TRUE(topic_source_filter == transport_mock->source_filter_); - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_FALSE(transport_mock->getSinkFilter()); + EXPECT_TRUE(topic_source_filter == transport_mock->getSourceFilter()); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(called); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); @@ -546,15 +546,15 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT EXPECT_TRUE(handle); - EXPECT_TRUE(transport_mock->sink_filter_); - if (transport_mock->sink_filter_) { - EXPECT_TRUE(sink_filter == transport_mock->sink_filter_.value()); + EXPECT_TRUE(transport_mock->getSinkFilter()); + if (transport_mock->getSinkFilter()) { + EXPECT_TRUE(sink_filter == transport_mock->getSinkFilter().value()); } - EXPECT_TRUE(source_filter == transport_mock->source_filter_); - EXPECT_TRUE(transport_mock->listener_); - if (transport_mock->listener_) { - auto callable = transport_mock->listener_.value(); + EXPECT_TRUE(source_filter == transport_mock->getSourceFilter()); + EXPECT_TRUE(transport_mock->getListener()); + if (transport_mock->getListener()) { + auto callable = transport_mock->getListener().value(); EXPECT_FALSE(called); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); diff --git a/test/extra/NotificationTest.cpp b/test/extra/NotificationTest.cpp index 19b7643ae..f2fe9178e 100644 --- a/test/extra/NotificationTest.cpp +++ b/test/extra/NotificationTest.cpp @@ -106,21 +106,21 @@ TEST_F(NotificationTest, NotificationSuccess) { // NOLINT EXPECT_EQ( AsString::serialize( - transport_mock_notification_source->message_.attributes().source()), - AsString::serialize(transport_mock_notification_sink->source_filter_)); + transport_mock_notification_source->getMessage().attributes().source()), + AsString::serialize(transport_mock_notification_sink->getSourceFilter())); EXPECT_EQ( AsString::serialize( - transport_mock_notification_source->message_.attributes().sink()), + transport_mock_notification_source->getMessage().attributes().sink()), AsString::serialize( - transport_mock_notification_sink->sink_filter_.value())); + transport_mock_notification_sink->getSinkFilter().value())); // Manually bridge the two transports transport_mock_notification_sink->mockMessage( - transport_mock_notification_source->message_); + transport_mock_notification_source->getMessage()); // Test - EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(transport_mock_notification_source->message_, + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(transport_mock_notification_source->getMessage(), capture_msg)); EXPECT_EQ(test_payload_str, capture_msg.payload()); } diff --git a/test/extra/PublisherSubscriberTest.cpp b/test/extra/PublisherSubscriberTest.cpp index 061e53601..6553420aa 100644 --- a/test/extra/PublisherSubscriberTest.cpp +++ b/test/extra/PublisherSubscriberTest.cpp @@ -100,21 +100,21 @@ TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); - getTransportMock()->send_status_ = retval; + getTransportMock()->getSendStatus() = retval; uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); auto status = publisher.publish(std::move(test_payload)); // Test EXPECT_EQ( - uprotocol::datamodel::serializer::uri::AsString::serialize(getTransportMock()->message_.attributes().source()), - uprotocol::datamodel::serializer::uri::AsString::serialize(transport_sub->source_filter_)); + uprotocol::datamodel::serializer::uri::AsString::serialize(getTransportMock()->getMessage().attributes().source()), + uprotocol::datamodel::serializer::uri::AsString::serialize(transport_sub->getSourceFilter())); // Manually bridge the two transports - transport_sub->mockMessage(getTransportMock()->message_); + transport_sub->mockMessage(getTransportMock()->getMessage()); // Test - EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(getTransportMock()->message_, captured_message)); + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(getTransportMock()->getMessage(), captured_message)); EXPECT_EQ(test_payload_str, captured_message.payload()); } diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index c8c243c50..fb9edc91d 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -126,7 +126,7 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT UPayloadFormat::UPAYLOAD_FORMAT_TEXT); ASSERT_TRUE(server_or_status.has_value()); ASSERT_NE(server_or_status.value(), nullptr); - EXPECT_TRUE(server_transport->listener_); + EXPECT_TRUE(server_transport->getListener()); auto client = uprotocol::communication::RpcClient(client_transport, v1::UUri(rpc_service_uuri), UPriority::UPRIORITY_CS4, 1000ms); @@ -141,14 +141,14 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT client_capture = maybe_response.value(); } })); - EXPECT_TRUE(client_transport->send_count_ == 1); - EXPECT_TRUE(client_transport->listener_); + EXPECT_TRUE(client_transport->getSendCount() == 1); + EXPECT_TRUE(client_transport->getListener()); - (*server_transport->listener_)(client_transport->message_); + (*server_transport->getListener())(client_transport->getMessage()); EXPECT_TRUE(server_called); EXPECT_EQ(client_request, server_capture.payload()); - client_transport->mockMessage(server_transport->message_); + client_transport->mockMessage(server_transport->getMessage()); EXPECT_TRUE(client_called); EXPECT_EQ(server_response, client_capture.payload()); } diff --git a/test/extra/UTransportMockTest.cpp b/test/extra/UTransportMockTest.cpp index 60ad11862..f621142f8 100644 --- a/test/extra/UTransportMockTest.cpp +++ b/test/extra/UTransportMockTest.cpp @@ -117,14 +117,14 @@ TEST_F(TestMockUTransport, Send) { // NOLINT uprotocol::v1::UMessage msg; msg.set_allocated_attributes(attr); msg.set_payload(get_random_string(PAYLOAD_STR_MAX_LEN)); - transport->send_status_.set_code( + transport->getSendStatus().set_code( static_cast(CODE_MAX - (i % CODE_MOD))); - transport->send_status_.set_message(get_random_string()); + transport->getSendStatus().set_message(get_random_string()); auto result = transport->send(msg); - EXPECT_EQ(i + 1, transport->send_count_); - EXPECT_TRUE(MsgDiff::Equals(result, transport->send_status_)); - EXPECT_TRUE(MsgDiff::Equals(msg, transport->message_)); + EXPECT_EQ(i + 1, transport->getSendCount()); + EXPECT_TRUE(MsgDiff::Equals(result, transport->getSendStatus())); + EXPECT_TRUE(MsgDiff::Equals(msg, transport->getMessage())); } } @@ -161,15 +161,15 @@ TEST_F(TestMockUTransport, registerListener) { // NOLINT }; auto lhandle = transport->registerListener(sink_filter, action, source_filter); - EXPECT_TRUE(transport->listener_); + EXPECT_TRUE(transport->getListener()); // EXPECT_EQ(*mock_info.listener, action); // need exposed target_type() to // make comparable. EXPECT_TRUE(lhandle.has_value()); auto handle = std::move(lhandle).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(transport->sink_filter_); - EXPECT_TRUE(MsgDiff::Equals(sink_filter, *transport->sink_filter_)); - EXPECT_TRUE(MsgDiff::Equals(source_filter, transport->source_filter_)); + EXPECT_TRUE(transport->getSinkFilter()); + EXPECT_TRUE(MsgDiff::Equals(sink_filter, *transport->getSinkFilter())); + EXPECT_TRUE(MsgDiff::Equals(source_filter, transport->getSourceFilter())); const size_t max_count = 100000; for (size_t i = 0; i < max_count; i++) { diff --git a/test/include/UTransportMock.h b/test/include/UTransportMock.h index f67b1aa75..f83fc0c2e 100644 --- a/test/include/UTransportMock.h +++ b/test/include/UTransportMock.h @@ -33,27 +33,46 @@ class UTransportMock : public uprotocol::transport::UTransport { (*listener_)(msg); } + size_t getSendCount() const { return send_count_.load(); } + + uprotocol::v1::UStatus& getSendStatus() { return send_status_; } + + uprotocol::v1::UStatus& getRegisterListenerStatus() { return registerListener_status_; } + + std::optional> getListener() const { return listener_; } + + std::optional> getCleanupListener() const { return cleanup_listener_; } + + std::optional getSinkFilter() const { return sink_filter_; } + + v1::UUri getSourceFilter() const { return source_filter_; } + + std::mutex& getRegisterMtx() { return register_mtx_; } + + v1::UMessage getMessage() const { return message_; } + + std::mutex& getMessageMtx() { return message_mtx_; } + + ~UTransportMock() override = default; + +private: std::atomic send_count_; uprotocol::v1::UStatus send_status_; uprotocol::v1::UStatus registerListener_status_; std::optional> - listener_; + void, uprotocol::v1::UMessage const&>> + listener_; std::optional> - cleanup_listener_; + void, uprotocol::v1::UMessage const&>> + cleanup_listener_; std::optional sink_filter_; v1::UUri source_filter_; std::mutex register_mtx_; v1::UMessage message_; std::mutex message_mtx_; - - virtual ~UTransportMock() override = default; - -private: [[nodiscard]] v1::UStatus sendImpl(const v1::UMessage& message) override { { std::lock_guard lock(message_mtx_); From 87dabfec3c32bc486a4faf71c2a6762c18eff16f Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 10:25:54 +0200 Subject: [PATCH 26/41] 12 warnings missing --- test/coverage/communication/RpcClientTest.cpp | 2 +- test/coverage/datamodel/UMessageBuilderTest.cpp | 6 +++--- test/coverage/datamodel/UuidSerializerTest.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 0f0a843c3..ceb90c6e1 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1281,7 +1281,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array, workers.size()> handles; - auto *worker_handles = handles.begin(); + auto* worker_handles = handles.begin(); for (auto& worker : workers) { worker = std::thread([&call_count, &client, diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index f52c73622..e1d2f33b5 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -90,14 +90,14 @@ class TestUMessageBuilder : public testing::Test { method_.set_ue_version_major(METHOD_UE_VERSION_MAJOR); method_.set_resource_id(METHOD_RESOURCE_ID); - req_id_ = datamodel::builder::UuidBuilder::getBuilder().build(); + req_id_ = datamodel::builder::UuidBuilder::getBuilder().build(); } static void TearDownTestSuite() {} static v1::UUri source_; static v1::UUri sink_; static v1::UUri method_; - static v1::UUID req_id_; + static v1::UUID req_id_; public: ~TestUMessageBuilder() override = default; }; @@ -105,7 +105,7 @@ class TestUMessageBuilder : public testing::Test { v1::UUri TestUMessageBuilder::source_; v1::UUri TestUMessageBuilder::sink_; v1::UUri TestUMessageBuilder::method_; -v1::UUID TestUMessageBuilder:: req_id_; +v1::UUID TestUMessageBuilder::req_id_; /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index b4912b3d1..ce606ebe2 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -160,7 +160,7 @@ TEST(DeserializerTest, DeserializeWithExtraCharacter) { // NOLINT std::invalid_argument); } -TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { +TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { //NOLINT std::string invalid_uuid1 = "123456781-2345-6781-2345-67812345678"; // First Dash placement From 0756b6390483c7a11e1ff6e71a70a58d6742560b Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 12:35:15 +0200 Subject: [PATCH 27/41] Before .clang-format --- test/coverage/communication/RpcClientTest.cpp | 3 ++- test/coverage/utils/CallbackConnectionTest.cpp | 4 ++-- test/extra/UTransportMockTest.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index ceb90c6e1..47721a12b 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1281,7 +1281,8 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array, workers.size()> handles; - auto* worker_handles = handles.begin(); + // size_t handle_counter = 0; + auto worker_handles = handles.begin(); for (auto& worker : workers) { worker = std::thread([&call_count, &client, diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index b0ab1c34c..d8d49bcb8 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -121,7 +121,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT { auto [handle, callable] = get_pair(); callable_outside = std::move(callable); - EXPECT_FALSE(callable); + EXPECT_FALSE(callable); // NOLINT EXPECT_TRUE(callable_outside); // Handle dropped here } @@ -141,7 +141,7 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT { auto [handle, callable] = get_pair(); handle_outside = std::move(handle); - EXPECT_FALSE(handle); + EXPECT_FALSE(handle); // NOLINT EXPECT_TRUE(handle_outside); // Callable dropped here } diff --git a/test/extra/UTransportMockTest.cpp b/test/extra/UTransportMockTest.cpp index f621142f8..8cbd66a21 100644 --- a/test/extra/UTransportMockTest.cpp +++ b/test/extra/UTransportMockTest.cpp @@ -94,7 +94,7 @@ TEST_F(TestMockUTransport, Send) { // NOLINT const size_t max_count = 100000; for (size_t i = 0; i < max_count; i++) { - auto *src = new uprotocol::v1::UUri(); + auto src = std::make_unique(); src->set_authority_name("10.0.0.1"); src->set_ue_id(DEFAULT_UE_ID); src->set_ue_version_major(1); @@ -106,16 +106,16 @@ TEST_F(TestMockUTransport, Send) { // NOLINT // sink->set_ue_version_major(2); // sink->set_resource_id(2); - auto attr = new uprotocol::v1::UAttributes(); + auto attr = std::make_unique(); attr->set_type(uprotocol::v1::UMESSAGE_TYPE_PUBLISH); *attr->mutable_id() = make_uuid(); - attr->set_allocated_source(src); + attr->set_allocated_source(src.release()); // attr->set_allocated_sink(sink); attr->set_payload_format(uprotocol::v1::UPAYLOAD_FORMAT_PROTOBUF); attr->set_ttl(ATTR_TTL); uprotocol::v1::UMessage msg; - msg.set_allocated_attributes(attr); + msg.set_allocated_attributes(attr.release()); msg.set_payload(get_random_string(PAYLOAD_STR_MAX_LEN)); transport->getSendStatus().set_code( static_cast(CODE_MAX - (i % CODE_MOD))); @@ -174,8 +174,8 @@ TEST_F(TestMockUTransport, registerListener) { // NOLINT const size_t max_count = 100000; for (size_t i = 0; i < max_count; i++) { uprotocol::v1::UMessage msg; - auto attr = new uprotocol::v1::UAttributes(); - msg.set_allocated_attributes(attr); + auto attr = std::make_unique(); + msg.set_allocated_attributes(attr.release()); msg.set_payload(get_random_string(PAYLOAD_STR_MAX_LEN)); transport->mockMessage(msg); EXPECT_EQ(i + 1, capture_count); From 4c7b78114d5b80213c970fa03e73d8ec5e2a13e3 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 13:08:53 +0200 Subject: [PATCH 28/41] Adapted NOLINT Comments to formated code --- .../client/usubscription/v3/ConsumerTest.cpp | 64 +- .../communication/NotificationSinkTest.cpp | 102 ++- .../communication/NotificationSourceTest.cpp | 94 ++- test/coverage/communication/PublisherTest.cpp | 57 +- test/coverage/communication/RpcClientTest.cpp | 683 +++++++++--------- test/coverage/communication/RpcServerTest.cpp | 186 ++--- .../coverage/communication/SubscriberTest.cpp | 90 ++- .../coverage/datamodel/PayloadBuilderTest.cpp | 162 +++-- .../datamodel/UMessageBuilderTest.cpp | 316 ++++---- .../datamodel/UMessageValidatorTest.cpp | 565 ++++++++++----- .../coverage/datamodel/UUriSerializerTest.cpp | 162 +++-- test/coverage/datamodel/UUriValidatorTest.cpp | 27 +- test/coverage/datamodel/UuidBuilderTest.cpp | 24 +- .../coverage/datamodel/UuidSerializerTest.cpp | 135 ++-- test/coverage/datamodel/UuidValidatorTest.cpp | 82 ++- test/coverage/transport/UTransportTest.cpp | 100 ++- .../coverage/utils/CallbackConnectionTest.cpp | 125 ++-- test/coverage/utils/CyclicQueueTest.cpp | 3 +- test/coverage/utils/ExpectedTest.cpp | 81 ++- test/coverage/utils/IpAddressTest.cpp | 3 +- test/coverage/utils/ThreadPoolTest.cpp | 3 +- test/coverage/utils/base64Test.cpp | 3 +- test/extra/NotificationTest.cpp | 44 +- test/extra/PublisherSubscriberTest.cpp | 31 +- test/extra/RpcClientServerTest.cpp | 120 +-- test/extra/UTransportMockTest.cpp | 5 +- test/include/UTransportMock.h | 42 +- 27 files changed, 1882 insertions(+), 1427 deletions(-) diff --git a/test/coverage/client/usubscription/v3/ConsumerTest.cpp b/test/coverage/client/usubscription/v3/ConsumerTest.cpp index cebf168a2..58dc5e7c5 100644 --- a/test/coverage/client/usubscription/v3/ConsumerTest.cpp +++ b/test/coverage/client/usubscription/v3/ConsumerTest.cpp @@ -33,33 +33,37 @@ class ConsumerTest : public testing::Test { uprotocol::v1::UUri client_uuri; uprotocol::v1::UUri server_uuri; uprotocol::v1::UUri subcription_uuri; + protected: // Run once per TEST_F. // Used to set up clean environments per test. - - std::shared_ptr getMockTransportClient() const { return mockTransportClient_; } - std::shared_ptr getMockTransportServer() const { return mockTransportServer_; } - uprotocol::v1::UUri& getClientUUri() { - return client_uuri; - } - const uprotocol::v1::UUri& getServerUUri() const { - return server_uuri; - } + + std::shared_ptr getMockTransportClient() + const { + return mockTransportClient_; + } + std::shared_ptr getMockTransportServer() + const { + return mockTransportServer_; + } + uprotocol::v1::UUri& getClientUUri() { return client_uuri; } + const uprotocol::v1::UUri& getServerUUri() const { return server_uuri; } const uprotocol::v1::UUri& getSubcriptionUUri() const { - return subcription_uuri; - } - void setMockTransportClient(const std::shared_ptr& client) { mockTransportClient_ = client; } - void setMockTransportServer(const std::shared_ptr& server) { mockTransportClient_ = server; } - void setClientUUri(const uprotocol::v1::UUri& uuri) { - client_uuri = uuri; - } - void setServerUUri(const uprotocol::v1::UUri& uuri) { - server_uuri = uuri; - } + return subcription_uuri; + } + void setMockTransportClient( + const std::shared_ptr& client) { + mockTransportClient_ = client; + } + void setMockTransportServer( + const std::shared_ptr& server) { + mockTransportClient_ = server; + } + void setClientUUri(const uprotocol::v1::UUri& uuri) { client_uuri = uuri; } + void setServerUUri(const uprotocol::v1::UUri& uuri) { server_uuri = uuri; } void setSubcriptionUUri(const uprotocol::v1::UUri& uuri) { - subcription_uuri = uuri; - } - + subcription_uuri = uuri; + } void SetUp() override { constexpr uint32_t TEST_UE_ID = 0x18000; @@ -103,12 +107,13 @@ class ConsumerTest : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~ConsumerTest() override = default; }; // Negative test case with no source filter -TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT +TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT constexpr int REQUEST_TTL_TIME = 0x8000; auto subcription_callback = someCallBack; auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); @@ -119,8 +124,7 @@ TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, - subscribe_request_ttl, options); + subcription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); @@ -133,7 +137,7 @@ TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT ASSERT_NE(consumer_ptr, nullptr); } -TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT +TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; constexpr int REQUEST_TTL_TIME = 0x8000; auto subcription_callback = someCallBack; @@ -145,8 +149,7 @@ TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, - subscribe_request_ttl, options); + subcription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); @@ -180,7 +183,7 @@ TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT EXPECT_TRUE(getMockTransportClient()->getSendCount() == 1); } -TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT +TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; constexpr int REQUEST_TTL_TIME = 0x8000; auto subcription_callback = someCallBack; @@ -192,8 +195,7 @@ TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, - subscribe_request_ttl, options); + subcription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index 91d145b73..9b8f4ad55 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -13,14 +13,14 @@ #include #include -#include #include +#include #include "UTransportMock.h" #include "up-cpp/datamodel/validator/UUri.h" using MsgDiff = google::protobuf::util::MessageDifferencer; -namespace uprotocol::communication{ +namespace uprotocol::communication { namespace UriValidator = uprotocol::datamodel::validator::uri; class NotificationSinkTest : public testing::Test { @@ -30,6 +30,7 @@ class NotificationSinkTest : public testing::Test { uprotocol::v1::UUri testDefaultSourceUUri_; size_t capture_count_ = 0; uprotocol::v1::UMessage capture_msg_; + protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -49,21 +50,37 @@ class NotificationSinkTest : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - void setTestTopicUUri(const uprotocol::v1::UUri& uuri) { testTopicUUri_ = uuri; } - void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uuri) { testInvalidTopicUUri_ = uuri; } - void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uuri) { testDefaultSourceUUri_ = uuri; } - void setCaptureCount(size_t count) { capture_count_ = count; } - void setCaptureMsg(const uprotocol::v1::UMessage& msg) { capture_msg_ = msg; } + void setTestTopicUUri(const uprotocol::v1::UUri& uuri) { + testTopicUUri_ = uuri; + } + void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uuri) { + testInvalidTopicUUri_ = uuri; + } + void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uuri) { + testDefaultSourceUUri_ = uuri; + } + void setCaptureCount(size_t count) { capture_count_ = count; } + void setCaptureMsg(const uprotocol::v1::UMessage& msg) { + capture_msg_ = msg; + } - const uprotocol::v1::UUri& getTestTopicUUri() const { return testTopicUUri_; } - const uprotocol::v1::UUri& getTestInvalidTopicUUri() const { return testInvalidTopicUUri_; } - const uprotocol::v1::UUri& getTestDefaultSourceUUri() const { return testDefaultSourceUUri_; } - size_t getCaptureCount() const { return capture_count_; } - const uprotocol::v1::UMessage& getCaptureMsg() const { return capture_msg_; } + const uprotocol::v1::UUri& getTestTopicUUri() const { + return testTopicUUri_; + } + const uprotocol::v1::UUri& getTestInvalidTopicUUri() const { + return testInvalidTopicUUri_; + } + const uprotocol::v1::UUri& getTestDefaultSourceUUri() const { + return testDefaultSourceUUri_; + } + size_t getCaptureCount() const { return capture_count_; } + const uprotocol::v1::UMessage& getCaptureMsg() const { + return capture_msg_; + } public: void handleCallbackMessage(const uprotocol::v1::UMessage& message); - ~ NotificationSinkTest() override = default; + ~NotificationSinkTest() override = default; }; void NotificationSinkTest::SetUp() { @@ -108,10 +125,11 @@ void NotificationSinkTest::handleCallbackMessage( std::string get_random_string(size_t length) { auto randchar = []() -> char { constexpr std::array CHARSET = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' - }; + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', + 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> distr(0, CHARSET.size() - 1); @@ -123,7 +141,7 @@ std::string get_random_string(size_t length) { } // Negative test case with no source filter -TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { // NOLINT +TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -133,17 +151,17 @@ TEST_F(NotificationSinkTest, FailWithoutSourceFilter) { // NOLINT std::optional source_filter; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - auto result = NotificationSink::create(transport, getTestTopicUUri(), - std::move(callback), - std::move(source_filter)); + auto result = NotificationSink::create( + transport, getTestTopicUUri(), std::move(callback), + std::move(source_filter)); }, UriValidator::InvalidUUri); } // Negative test case with invalid notification resource ID -TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // NOLINT +TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -154,14 +172,14 @@ TEST_F(NotificationSinkTest, FailWithInvalidResourceID) { // NOLINT std::optional source_filter; // Notification to invalid UUri topic with resource ID not in correct range - EXPECT_THROW(auto result = NotificationSink::create( // NOLINT + EXPECT_THROW(auto result = NotificationSink::create( // NOLINT transport, getTestInvalidTopicUUri(), std::move(callback), std::move(source_filter)), UriValidator::InvalidUUri); } // Positive test case with source filter -TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT +TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT constexpr uint16_t RANDOM_STRING_LENGTH = 1400; auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -170,17 +188,19 @@ TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT return this->handleCallbackMessage(arg); }; - auto result = NotificationSink::create(transport, transport->getEntityUri(), - std::move(callback), getTestTopicUUri()); + auto result = + NotificationSink::create(transport, transport->getEntityUri(), + std::move(callback), getTestTopicUUri()); EXPECT_TRUE(transport->getListener()); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); EXPECT_TRUE( - MsgDiff::Equals(transport->getEntityUri(), *transport->getSinkFilter())); + MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); + EXPECT_TRUE(MsgDiff::Equals(transport->getEntityUri(), + *transport->getSinkFilter())); const size_t max_count = 100; for (size_t i = 0; i < max_count; i++) { @@ -195,7 +215,7 @@ TEST_F(NotificationSinkTest, SuccessWithSourceFilter) { // NOLINT } // Simulate Error code from transport mock -TEST_F(NotificationSinkTest, FailWithErrorCode) { // NOLINT +TEST_F(NotificationSinkTest, FailWithErrorCode) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -207,15 +227,16 @@ TEST_F(NotificationSinkTest, FailWithErrorCode) { // NOLINT expected_status.set_code(uprotocol::v1::UCode::ABORTED); transport->getRegisterListenerStatus() = expected_status; - auto result = NotificationSink::create(transport, transport->getEntityUri(), - std::move(callback), getTestTopicUUri()); + auto result = + NotificationSink::create(transport, transport->getEntityUri(), + std::move(callback), getTestTopicUUri()); auto actual_status = std::move(result).error(); EXPECT_EQ(actual_status.code(), expected_status.code()); } // Notification sink with null transport -TEST_F(NotificationSinkTest, NullTransport) { // NOLINT +TEST_F(NotificationSinkTest, NullTransport) { // NOLINT // set transport to null auto transport = nullptr; std::optional source_filter; @@ -224,25 +245,25 @@ TEST_F(NotificationSinkTest, NullTransport) { // NOLINT return this->handleCallbackMessage(arg); }; - EXPECT_THROW(auto result = NotificationSink::create( // NOLINT + EXPECT_THROW(auto result = NotificationSink::create( // NOLINT transport, getTestDefaultSourceUUri(), std::move(callback), getTestTopicUUri()), uprotocol::transport::NullTransport); } // notification sink with null callback -TEST_F(NotificationSinkTest, NullCallback) { // NOLINT +TEST_F(NotificationSinkTest, NullCallback) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); // bind to null callback auto test_create_nullptr = [transport, this]() { - std::ignore = - NotificationSink::create(transport, transport->getEntityUri(), - nullptr, getTestTopicUUri()); + std::ignore = NotificationSink::create( + transport, transport->getEntityUri(), nullptr, getTestTopicUUri()); }; - EXPECT_THROW(test_create_nullptr(), utils::callbacks::EmptyFunctionObject); // NOLINT + EXPECT_THROW(test_create_nullptr(), // NOLINT + utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_create_empty = [transport, this]() { @@ -250,7 +271,8 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT transport, transport->getEntityUri(), {}, getTestTopicUUri()); }; - EXPECT_THROW(test_create_empty(), utils::callbacks::EmptyFunctionObject); // NOLINT + EXPECT_THROW(test_create_empty(), + utils::callbacks::EmptyFunctionObject); // NOLINT } } // namespace uprotocol::communication diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index f0f65492a..a667bb261 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -19,14 +19,15 @@ #include "up-cpp/datamodel/validator/UMessage.h" #include "up-cpp/transport/UTransport.h" -namespace uprotocol::communication{ +namespace uprotocol::communication { class TestNotificationSource : public testing::Test { private: std::shared_ptr transportMock_; uprotocol::v1::UUri source_; uprotocol::v1::UUri sink_; - uprotocol::v1::UPayloadFormat format_ = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + uprotocol::v1::UPayloadFormat format_ = + uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; std::optional priority_; std::optional ttl_; @@ -68,30 +69,43 @@ class TestNotificationSource : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - std::shared_ptr getTransportMock() const { return transportMock_; } + std::shared_ptr getTransportMock() const { + return transportMock_; + } uprotocol::v1::UUri getSource() const { return source_; } - uprotocol::v1::UUri getSink() const { return sink_; } - uprotocol::v1::UPayloadFormat getFormat() const { return format_; } - std::optional& getPriority() { return priority_; } - std::optional getTTL() const { return ttl_; } - - void setTransportMock(const std::shared_ptr& transport_mock) { transportMock_ = transport_mock; } - void setSource(const uprotocol::v1::UUri& source) { source_ = source; } - void setSink(const uprotocol::v1::UUri& sink) { sink_ = sink; } - void setFormat(const uprotocol::v1::UPayloadFormat& format) { format_ = format; } - void setPriority(const std::optional& priority) { priority_ = priority; } - void setTTL(const std::optional& ttl) { ttl_ = ttl; } + uprotocol::v1::UUri getSink() const { return sink_; } + uprotocol::v1::UPayloadFormat getFormat() const { return format_; } + std::optional& getPriority() { return priority_; } + std::optional getTTL() const { return ttl_; } + + void setTransportMock( + const std::shared_ptr& + transport_mock) { + transportMock_ = transport_mock; + } + void setSource(const uprotocol::v1::UUri& source) { source_ = source; } + void setSink(const uprotocol::v1::UUri& sink) { sink_ = sink; } + void setFormat(const uprotocol::v1::UPayloadFormat& format) { + format_ = format; + } + void setPriority(const std::optional& priority) { + priority_ = priority; + } + void setTTL(const std::optional& ttl) { + ttl_ = ttl; + } public: ~TestNotificationSource() override = default; }; -TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT +TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT std::string test_payload_str = "test_payload"; NotificationSource notification_source(getTransportMock(), getSource(), - getSink(), getFormat(), getPriority(), - getTTL()); - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + getSink(), getFormat(), + getPriority(), getTTL()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -107,11 +121,12 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccess) { // NOLINT EXPECT_EQ(valid, true); } -TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT +TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT std::string test_payload_str = "test_payload"; - NotificationSource notification_source(getTransportMock(), getSource(), - getSink(), getFormat(), getPriority()); - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + NotificationSource notification_source( + getTransportMock(), getSource(), getSink(), getFormat(), getPriority()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -129,12 +144,14 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); } -TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOLINT +TEST_F(TestNotificationSource, // NOLINT + NotifyWithPayloadSuccessWithoutPriority) { std::string test_payload_str = "test_payload"; getPriority().reset(); - NotificationSource notification_source(getTransportMock(), getSource(), - getSink(), getFormat(), getPriority()); - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + NotificationSource notification_source( + getTransportMock(), getSource(), getSink(), getFormat(), getPriority()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -150,15 +167,16 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutPriority) { // NOL EXPECT_EQ(valid, true); EXPECT_EQ(getTransportMock()->getMessage().attributes().priority(), - uprotocol::v1::UPriority::UPRIORITY_CS1); + uprotocol::v1::UPriority::UPRIORITY_CS1); } -TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT +TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT std::string test_payload_str = "test_payload"; NotificationSource notification_source(getTransportMock(), getSource(), - getSink(), getFormat(), getPriority(), - getTTL()); - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + getSink(), getFormat(), + getPriority(), getTTL()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + getFormat()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); @@ -169,9 +187,9 @@ TEST_F(TestNotificationSource, NotifyWithPayloadFailure) { // NOLINT EXPECT_EQ(status.code(), retval.code()); } -TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT +TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT NotificationSource notification_source(getTransportMock(), getSource(), - getSink()); + getSink()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -183,12 +201,12 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadSuccess) { // NOLINT EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); EXPECT_EQ(getTransportMock()->getMessage().attributes().priority(), - uprotocol::v1::UPriority::UPRIORITY_CS1); + uprotocol::v1::UPriority::UPRIORITY_CS1); } -TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT +TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT NotificationSource notification_source(getTransportMock(), getSource(), - getSink()); + getSink()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); @@ -200,10 +218,10 @@ TEST_F(TestNotificationSource, NotifyWithoutPayloadFailure) { // NOLINT } // Test with Null transport -TEST_F(TestNotificationSource, NullTransport) { // NOLINT +TEST_F(TestNotificationSource, NullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(NotificationSource notification_source( // NOLINT + EXPECT_THROW(NotificationSource notification_source( // NOLINT transport, getSource(), getSink(), getFormat(), getPriority(), getTTL()), uprotocol::transport::NullTransport); diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 3d126de36..c8e7c4add 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -16,7 +16,7 @@ #include "UTransportMock.h" -namespace uprotocol{ +namespace uprotocol { // namespace { // using namespace uprotocol::datamodel::builder; @@ -30,8 +30,11 @@ class TestPublisher : public testing::Test { std::optional priority_; std::optional ttl_; uprotocol::v1::UMessage capture_msg_; + protected: - std::shared_ptr getTransportMock() const { return transportMock_; } + std::shared_ptr getTransportMock() const { + return transportMock_; + } v1::UUri getSource() const { return source_; } v1::UUri getTopic() const { return topic_; } v1::UPayloadFormat getFormat() const { return format_; } @@ -39,13 +42,23 @@ class TestPublisher : public testing::Test { std::optional getTTL() const { return ttl_; } uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } - void setTransportMock(const std::shared_ptr& transport_mock) { transportMock_ = transport_mock; } + void setTransportMock( + const std::shared_ptr& + transport_mock) { + transportMock_ = transport_mock; + } void setSource(const v1::UUri& source) { source_ = source; } void setTopic(const v1::UUri& topic) { topic_ = topic; } void setFormat(const v1::UPayloadFormat& format) { format_ = format; } - void setPriority(const std::optional& priority) { priority_ = priority; } - void setTTL(const std::optional& ttl) { ttl_ = ttl; } - void setCaptureMsg(const uprotocol::v1::UMessage& capture_msg) { capture_msg_ = capture_msg; } + void setPriority(const std::optional& priority) { + priority_ = priority; + } + void setTTL(const std::optional& ttl) { + ttl_ = ttl; + } + void setCaptureMsg(const uprotocol::v1::UMessage& capture_msg) { + capture_msg_ = capture_msg; + } // Run once per TEST_F. // Used to set up clean environments per test. @@ -70,7 +83,6 @@ class TestPublisher : public testing::Test { priority_ = v1::UPriority::UPRIORITY_CS2; ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); - } void TearDown() override {} @@ -83,14 +95,15 @@ class TestPublisher : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestPublisher() override = default; }; -TEST_F(TestPublisher, PublisherSuccess) { // NOLINT +TEST_F(TestPublisher, PublisherSuccess) { // NOLINT std::string test_payload_str = "test_payload"; - communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), - getTTL()); + communication::Publisher publisher(getTransportMock(), getTopic(), + getFormat(), getPriority(), getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -107,10 +120,10 @@ TEST_F(TestPublisher, PublisherSuccess) { // NOLINT EXPECT_EQ(valid, true); } -TEST_F(TestPublisher, PublishFailure) { // NOLINT +TEST_F(TestPublisher, PublishFailure) { // NOLINT std::string test_payload_str = "test_payload"; - communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), - getTTL()); + communication::Publisher publisher(getTransportMock(), getTopic(), + getFormat(), getPriority(), getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::DATA_LOSS); @@ -122,9 +135,10 @@ TEST_F(TestPublisher, PublishFailure) { // NOLINT EXPECT_EQ(status.code(), retval.code()); } -TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT +TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT std::string test_payload_str = "test_payload"; - communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority()); + communication::Publisher publisher(getTransportMock(), getTopic(), + getFormat(), getPriority()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -143,11 +157,11 @@ TEST_F(TestPublisher, PublishSuccessWithoutTTL) { // NOLINT EXPECT_EQ(getTransportMock()->getMessage().attributes().ttl(), 0); } -TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT +TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT std::string test_payload_str = "test_payload"; getPriority().reset(); - communication::Publisher publisher(getTransportMock(), getTopic(), getFormat(), getPriority(), - getTTL()); + communication::Publisher publisher(getTransportMock(), getTopic(), + getFormat(), getPriority(), getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); @@ -168,10 +182,11 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT } // publisher with null transport -TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT +TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(communication::Publisher publisher(transport, getTopic(), getFormat(), // NOLINT - getPriority(), getTTL()), + EXPECT_THROW(communication::Publisher publisher(transport, getTopic(), // NOLINT + getFormat(), + getPriority(), getTTL()), uprotocol::transport::NullTransport); } diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 47721a12b..fcda36dc0 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -27,32 +27,29 @@ constexpr std::chrono::milliseconds TEN_MILLISECONDS(10); constexpr std::chrono::milliseconds ONE_HUNDRED_FIFTY_MILLISECONDS(150); constexpr uint32_t SHIFT_AMOUNT = 16; -namespace uprotocol{ +namespace uprotocol { -bool operator==(const v1::UUri& lhs, - const v1::UUri& rhs) { +bool operator==(const v1::UUri& lhs, const v1::UUri& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -bool operator==(const v1::UMessage& lhs, - const v1::UMessage& rhs) { +bool operator==(const v1::UMessage& lhs, const v1::UMessage& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -bool operator==(const v1::UStatus& lhs, - const v1::UCode& rhs) { +bool operator==(const v1::UStatus& lhs, const v1::UCode& rhs) { return lhs.code() == rhs; } class RpcClientTest : public testing::Test { private: std::shared_ptr transport_; + protected: // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { - transport_ = std::make_shared( - defaultSourceUri()); + transport_ = std::make_shared(defaultSourceUri()); } void TearDown() override {} @@ -70,12 +67,12 @@ class RpcClientTest : public testing::Test { // when the application exits. google::protobuf::ShutdownProtobufLibrary(); } - + static v1::UUri methodUri(const std::string& auth = "TestAuth", - uint16_t ue_id = 0x8000, - uint16_t ue_instance = 1, // NOLINT - uint16_t ue_version_major = 1, - uint16_t resource_id = 1) { + uint16_t ue_id = 0x8000, + uint16_t ue_instance = 1, // NOLINT + uint16_t ue_version_major = 1, + uint16_t resource_id = 1) { v1::UUri uri; uri.set_authority_name(auth); uri.set_ue_id(static_cast(ue_instance) << SHIFT_AMOUNT | @@ -97,11 +94,11 @@ class RpcClientTest : public testing::Test { validateSendCount(expected_send_count); validateMessage(); } - + void validateTransportProperties() const { EXPECT_TRUE(transport_->getListener()); } - + void validateFilters() const { EXPECT_TRUE(transport_->getSourceFilter() == methodUri()); EXPECT_TRUE(transport_->getSinkFilter()); @@ -109,22 +106,24 @@ class RpcClientTest : public testing::Test { EXPECT_TRUE(*(transport_->getSinkFilter()) == defaultSourceUri()); } } - + void validateSendCount(size_t expected_send_count) const { EXPECT_EQ(transport_->getSendCount(), expected_send_count); } - + void validateMessage() const { - auto [valid_request, _] = datamodel::validator::message::isValidRpcRequest(transport_->getMessage()); + auto [valid_request, _] = + datamodel::validator::message::isValidRpcRequest( + transport_->getMessage()); EXPECT_TRUE(valid_request); } [[nodiscard]] std::shared_ptr getTransport() const { - return transport_; - } + return transport_; + } void setTransport(const std::shared_ptr& transport) { - transport_ = transport; - } + transport_ = transport; + } public: ~RpcClientTest() override = default; @@ -142,61 +141,63 @@ void checkErrorResponse( } datamodel::builder::Payload fakePayload() { - auto uuid = datamodel::builder::UuidBuilder::getBuilder(); - auto uuid_str = datamodel::serializer::uuid::AsString::serialize(uuid.build()); + auto uuid_str = + datamodel::serializer::uuid::AsString::serialize(uuid.build()); - return { std::move(uuid_str), v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT }; + return {std::move(uuid_str), v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT}; } /////////////////////////////////////////////////////////////////////////////// // Construction -TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT +TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT // Base parameters - EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS);); // Optional format - EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON);); // Optional permission level - EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), - v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, 9);); + v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, + 9);); // Optional permission level - EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT + EXPECT_NO_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, {}, {}, "Some token");); } -TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLINT +TEST_F(RpcClientTest, // NOLINT + ExceptionThrownWithInvalidConstructorArguments) { // Bad method URI - EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); // NOLINT + EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); // NOLINT auto client = communication::RpcClient( getTransport(), std::move(uri), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); , datamodel::validator::uri::InvalidUUri); // Bad priority - EXPECT_THROW(auto client = communication::RpcClient( // NOLINT - getTransport(), methodUri(), - v1::UPriority::UPRIORITY_CS3, TEN_MILLISECONDS); + EXPECT_THROW(auto client = communication::RpcClient( // NOLINT + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS3, + TEN_MILLISECONDS); , std::out_of_range); // Bad ttl - EXPECT_THROW(auto client = communication::RpcClient( // NOLINT - getTransport(), methodUri(), - v1::UPriority::UPRIORITY_CS4, std::chrono::milliseconds(0)); + EXPECT_THROW(auto client = communication::RpcClient( // NOLINT + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + std::chrono::milliseconds(0)); , std::out_of_range); // Bad payload format - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT auto client = communication::RpcClient( getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, static_cast(-1)); @@ -205,21 +206,23 @@ TEST_F(RpcClientTest, ExceptionThrownWithInvalidConstructorArguments) { // NOLIN /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod() -TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); EXPECT_TRUE(getTransport()->getMessage().payload().empty()); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -231,12 +234,12 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(), datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -244,13 +247,14 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadAndFormatSet) { // NOLINT EXPECT_FALSE(getTransport()->getListener()); } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(ONE_HUNDRED_FIFTY_MILLISECONDS); @@ -262,20 +266,20 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadTimeout) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::DEADLINE_EXCEEDED); + checkErrorResponse(maybe_response, v1::UCode::DEADLINE_EXCEEDED); } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); @@ -284,20 +288,19 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::RESOURCE_EXHAUSTED); + checkErrorResponse(maybe_response, v1::UCode::RESOURCE_EXHAUSTED); } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - getTransport()->getSendStatus().set_code( - v1::UCode::FAILED_PRECONDITION); + getTransport()->getSendStatus().set_code(v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -305,20 +308,19 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::FAILED_PRECONDITION); + checkErrorResponse(maybe_response, v1::UCode::FAILED_PRECONDITION); } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT communication::RpcClient::InvokeFuture invoke_future; { - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT } EXPECT_TRUE(invoke_future.valid()); @@ -326,24 +328,26 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { - EXPECT_NO_THROW(auto maybe_response = invoke_future.get(); // NOLINT - checkErrorResponse(maybe_response, - v1::UCode::CANCELLED);); + EXPECT_NO_THROW( + auto maybe_response = invoke_future.get(); // NOLINT + checkErrorResponse(maybe_response, v1::UCode::CANCELLED);); } } -TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT + EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -351,22 +355,23 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::PERMISSION_DENIED); + checkErrorResponse(maybe_response, v1::UCode::PERMISSION_DENIED); } } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload) -TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(std::move(payload))); EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -377,9 +382,10 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -391,16 +397,17 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(std::move(payload))); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(std::move(payload))); EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -411,9 +418,10 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -425,12 +433,12 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT auto invoke_future = client.invokeMethod(fakePayload()), datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -438,13 +446,15 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndWrongFormatSet) { // NOLINT EXPECT_FALSE(getTransport()->getListener()); } -TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(ONE_HUNDRED_FIFTY_MILLISECONDS); @@ -456,20 +466,21 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::DEADLINE_EXCEEDED); + checkErrorResponse(maybe_response, v1::UCode::DEADLINE_EXCEEDED); } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); @@ -478,20 +489,20 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::RESOURCE_EXHAUSTED); + checkErrorResponse(maybe_response, v1::UCode::RESOURCE_EXHAUSTED); } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - getTransport()->getSendStatus().set_code( - v1::UCode::FAILED_PRECONDITION); + getTransport()->getSendStatus().set_code(v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -499,20 +510,20 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::FAILED_PRECONDITION); + checkErrorResponse(maybe_response, v1::UCode::FAILED_PRECONDITION); } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT +TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT communication::RpcClient::InvokeFuture invoke_future; { - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); } EXPECT_TRUE(invoke_future.valid()); @@ -525,18 +536,21 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT } } -TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = client.invokeMethod(fakePayload())); // NOLINT + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -544,22 +558,22 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { auto maybe_response = invoke_future.get(); - checkErrorResponse(maybe_response, - v1::UCode::PERMISSION_DENIED); + checkErrorResponse(maybe_response, v1::UCode::PERMISSION_DENIED); } } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Callback) -TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); bool callback_called = false; v1::UMessage received_response; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( [&callback_called, &received_response](auto maybe_response) { callback_called = true; @@ -571,21 +585,22 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayload) { // NOLINT EXPECT_TRUE(getTransport()->getMessage().payload().empty()); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_SOMEIP); communication::RpcClient::InvokeHandle handle; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT handle = client.invokeMethod([](auto) {}), datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -593,28 +608,29 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadAndFormatSet) { // NOLINT EXPECT_FALSE(getTransport()->getListener()); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; auto when_requested = std::chrono::steady_clock::now(); communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod( - [&callback_called, &callback_event](const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::DEADLINE_EXCEEDED); - callback_event.notify_all(); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod([&callback_called, &callback_event]( + const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::DEADLINE_EXCEEDED); + callback_event.notify_all(); + })); std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, ONE_HUNDRED_FIFTY_MILLISECONDS, [&callback_called]() { return callback_called; }); + lock, ONE_HUNDRED_FIFTY_MILLISECONDS, + [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); @@ -623,9 +639,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadTimeout) { // NOLINT EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); @@ -633,86 +650,90 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::RESOURCE_EXHAUSTED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod([&callback_called]( + const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::RESOURCE_EXHAUSTED); + })); EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - getTransport()->getSendStatus().set_code( - v1::UCode::FAILED_PRECONDITION); + getTransport()->getSendStatus().set_code(v1::UCode::FAILED_PRECONDITION); bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::FAILED_PRECONDITION); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod([&callback_called]( + const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::FAILED_PRECONDITION); + })); EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; communication::RpcClient::InvokeHandle handle; { - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, v1::UCode::CANCELLED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod([&callback_called]( + const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); + })); } EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW(handle = client.invokeMethod([&callback_called]( // NOLINT - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::PERMISSION_DENIED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod([&callback_called]( + const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::PERMISSION_DENIED); + })); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); } /////////////////////////////////////////////////////////////////////////////// // RpcClient::invokeMethod(Payload, Callback) -TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -721,7 +742,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT v1::UMessage received_response; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), [&callback_called, &received_response](auto maybe_response) { @@ -738,18 +759,19 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayload) { // NOLINT std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto payload = fakePayload(); auto payload_content = payload.buildCopy(); @@ -758,7 +780,7 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT v1::UMessage received_response; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( std::move(payload), [&callback_called, &received_response](auto maybe_response) { @@ -775,21 +797,22 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndFormatSet) { // NOLINT std::get(payload_content)); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); EXPECT_TRUE(response == received_response); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT +TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS, - v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS, v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); communication::RpcClient::InvokeHandle handle; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT handle = client.invokeMethod(fakePayload(), [](auto) {}), datamodel::builder::UMessageBuilder::UnexpectedFormat); @@ -797,16 +820,17 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadAndWrongFormatSet) { // NOLINT EXPECT_FALSE(getTransport()->getListener()); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); bool callback_called = false; std::condition_variable callback_event; communication::RpcClient::InvokeHandle handle; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called, &callback_event](auto maybe_response) { @@ -819,7 +843,8 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT std::mutex mtx; std::unique_lock lock(mtx); callback_called = callback_event.wait_for( - lock, ONE_HUNDRED_FIFTY_MILLISECONDS, [&callback_called]() { return callback_called; }); + lock, ONE_HUNDRED_FIFTY_MILLISECONDS, + [&callback_called]() { return callback_called; }); auto when_expired = std::chrono::steady_clock::now(); EXPECT_GE((when_expired - when_requested), TEN_MILLISECONDS); @@ -828,9 +853,10 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadTimeout) { // NOLINT EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); getTransport()->getRegisterListenerStatus().set_code( v1::UCode::RESOURCE_EXHAUSTED); @@ -838,96 +864,95 @@ TEST_F(RpcClientTest, InvokeCallbackWithPayloadListenFail) { // NOLINT bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod( - fakePayload(), [&callback_called](auto maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::RESOURCE_EXHAUSTED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod(fakePayload(), [&callback_called]( + auto maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::RESOURCE_EXHAUSTED); + })); EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithPayloadSendFail) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - getTransport()->getSendStatus().set_code( - v1::UCode::FAILED_PRECONDITION); + getTransport()->getSendStatus().set_code(v1::UCode::FAILED_PRECONDITION); bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod( - fakePayload(), [&callback_called](auto maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::FAILED_PRECONDITION); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod(fakePayload(), [&callback_called]( + auto maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::FAILED_PRECONDITION); + })); EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT +TEST_F(RpcClientTest, InvokeCallbackWithPayloadClientDestroyed) { // NOLINT communication::RpcClient::InvokeFuture invoke_future; bool callback_called = false; communication::RpcClient::InvokeHandle handle; { - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT handle = client.invokeMethod( fakePayload(), [&callback_called](auto maybe_response) { callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::CANCELLED); + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); })); } EXPECT_TRUE(callback_called); } -TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); +TEST_F(RpcClientTest, InvokeCallbackWithPayloadCommstatus) { // NOLINT + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod( - fakePayload(), [&callback_called](auto maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, - v1::UCode::PERMISSION_DENIED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod(fakePayload(), [&callback_called]( + auto maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::PERMISSION_DENIED); + })); using UMessageBuilder = datamodel::builder::UMessageBuilder; - auto response_builder = UMessageBuilder::response(getTransport()->getMessage()); + auto response_builder = + UMessageBuilder::response(getTransport()->getMessage()); response_builder.withCommStatus(v1::UCode::PERMISSION_DENIED); auto response = response_builder.build(); - EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT + EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(callback_called); } /////////////////////////////////////////////////////////////////////////////// // Usecases -TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT +TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT constexpr std::chrono::milliseconds TWO_HUNDRED_FIFTY_MILLISECONDS(250); - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - TWO_HUNDRED_FIFTY_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TWO_HUNDRED_FIFTY_MILLISECONDS); std::list futures; - std::listgetListener().value())>> callables; + std::listgetListener().value())>> + callables; std::list requests; futures.push_back(client.invokeMethod()); @@ -994,7 +1019,8 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT EXPECT_EQ(callback_count, 1); EXPECT_EQ(ready_futures(), 1); - EXPECT_EQ(futures.front().wait_for(std::chrono::milliseconds(0)), std::future_status::ready); + EXPECT_EQ(futures.front().wait_for(std::chrono::milliseconds(0)), + std::future_status::ready); requests.pop_front(); requests.pop_back(); @@ -1012,11 +1038,10 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT // Intentionally leaving a couple pending requests to discard } -TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT +TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT constexpr std::chrono::milliseconds TWO_HUNDRED_MILLISECONDS(200); constexpr size_t NUM_CLIENTS = 10; - std::vector> - clients; + std::vector> clients; std::mutex expire_mtx; std::vector expire_order; @@ -1029,14 +1054,13 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT for (size_t client_id = 0; client_id < NUM_CLIENTS; ++client_id, client_ttl += PER_CLIENT_TTL_INCREMENT) { - auto transport = std::make_shared( - defaultSourceUri()); + auto transport = + std::make_shared(defaultSourceUri()); clients.emplace_back(std::make_tuple( - client_id, - communication::RpcClient( - transport, methodUri(), v1::UPriority::UPRIORITY_CS4, - client_ttl))); + client_id, communication::RpcClient(transport, methodUri(), + v1::UPriority::UPRIORITY_CS4, + client_ttl))); expected_order.push_back(client_id); } @@ -1052,8 +1076,7 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT &expire_signal](const auto& maybe_response) { if (!maybe_response) { const auto& some_status = maybe_response.error(); - if (some_status.code() != - v1::UCode::DEADLINE_EXCEEDED) { + if (some_status.code() != v1::UCode::DEADLINE_EXCEEDED) { return; } std::lock_guard lock(expire_mtx); @@ -1082,7 +1105,7 @@ TEST_F(RpcClientTest, PendingRequestsExpireInOrder) { // NOLINT // the top. This results in the second request not expiring until after the // first request's expiration time (even though the expirations will be called // in order). -TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT +TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT constexpr std::chrono::seconds TEN_SECONDS(10); constexpr std::chrono::milliseconds TWENTY_FIVE_MILLISECONDS(25); constexpr std::chrono::milliseconds ONE_HUNDRED_MILLISECONDS(100); @@ -1097,8 +1120,9 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT auto slow_ready = slow_future.wait_for(ONE_HUNDRED_MILLISECONDS); EXPECT_EQ(slow_ready, std::future_status::timeout); - auto fast_client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TWENTY_FIVE_MILLISECONDS); + auto fast_client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TWENTY_FIVE_MILLISECONDS); auto fast_future = fast_client.invokeMethod(); @@ -1115,7 +1139,7 @@ TEST_F(RpcClientTest, ExpireWorkerWakesForRightPendingRequest) { // NOLINT // NOTE: for some reason, when the above test fails, the _next_ test also // fails. I do not know how this is possible. -TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT +TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT constexpr size_t NUM_CLIENTS = 20; using UTransportMock = test::UTransportMock; @@ -1131,9 +1155,12 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT } std::array timeouts{}; - constexpr std::chrono::milliseconds TIMEOUT_STEP = std::chrono::milliseconds(7); - constexpr std::chrono::milliseconds TIMEOUT_MIN = std::chrono::milliseconds(200); - constexpr std::chrono::milliseconds TIMEOUT_MAX = TIMEOUT_MIN + std::chrono::milliseconds(40); + constexpr std::chrono::milliseconds TIMEOUT_STEP = + std::chrono::milliseconds(7); + constexpr std::chrono::milliseconds TIMEOUT_MIN = + std::chrono::milliseconds(200); + constexpr std::chrono::milliseconds TIMEOUT_MAX = + TIMEOUT_MIN + std::chrono::milliseconds(40); std::chrono::milliseconds next_timeout = TIMEOUT_MIN; for (auto& timeout : timeouts) { timeout = next_timeout; @@ -1151,9 +1178,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT remaining > 0; --remaining, ++transport, ++timeout) { auto method_uri = (*transport)->getDefaultSource(); method_uri.set_resource_id(methodUri().resource_id()); - communication::RpcClient client( - *transport, std::move(method_uri), - v1::UPriority::UPRIORITY_CS4, *timeout); + communication::RpcClient client(*transport, std::move(method_uri), + v1::UPriority::UPRIORITY_CS4, *timeout); clients.push_back(std::move(client)); } @@ -1167,19 +1193,23 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT for (size_t remaining = NUM_INVOCATIONS; remaining > 0; --remaining) { const size_t client_index = remaining % NUM_CLIENTS; ++client_invoke_count.at(client_index); - pending.emplace_back(std::chrono::steady_clock::now() + timeouts.at(client_index), - clients[client_index].invokeMethod()); + pending.emplace_back( + std::chrono::steady_clock::now() + timeouts.at(client_index), + clients[client_index].invokeMethod()); } // Reply to some for (auto& transport : transports) { - auto reply = datamodel::builder::UMessageBuilder::response(transport->getMessage()).build(); + auto reply = datamodel::builder::UMessageBuilder::response( + transport->getMessage()) + .build(); transport->mockMessage(reply); } size_t num_ready = 0; for (auto& request : pending) { auto& future = std::get<1>(request); - const bool is_ready = future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; + const bool is_ready = future.wait_for(std::chrono::milliseconds(0)) == + std::future_status::ready; if (is_ready) { ++num_ready; auto maybe_response = future.get(); @@ -1199,8 +1229,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT for (auto& request : pending) { auto& future = std::get<1>(request); // Ignoring the futures we have already used - if (future.valid() && - (future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)) { + if (future.valid() && (future.wait_for(std::chrono::milliseconds(0)) == + std::future_status::ready)) { auto maybe_response = future.get(); checkErrorResponse(maybe_response, v1::UCode::CANCELLED); ++num_cancelled; @@ -1248,9 +1278,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT std::future_status::ready) { ++ready_futures; auto maybe_message = future.get(); - if (!maybe_message && - (maybe_message.error().code() == - v1::UCode::DEADLINE_EXCEEDED)) { + if (!maybe_message && (maybe_message.error().code() == + v1::UCode::DEADLINE_EXCEEDED)) { ++expired_futures; checkErrorResponse(maybe_message, v1::UCode::DEADLINE_EXCEEDED); @@ -1266,15 +1295,16 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT // Discard the rest } -TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT +TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT constexpr size_t NUM_REQUESTS_PER_WORKER = 10; constexpr std::chrono::milliseconds TWENTY_MILLISECONDS(20); std::array workers; - auto client = communication::RpcClient( - getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); + auto client = communication::RpcClient(getTransport(), methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); std::atomic call_count = 0; @@ -1285,22 +1315,22 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT auto worker_handles = handles.begin(); for (auto& worker : workers) { - worker = std::thread([&call_count, &client, - &handles = *(worker_handles++)]() { - for (auto remaining = NUM_REQUESTS_PER_WORKER; remaining > 0; - --remaining) { - handles.emplace_back( - client.invokeMethod([&call_count](const auto&) { ++call_count; })); - } - }); + worker = std::thread( + [&call_count, &client, &handles = *(worker_handles++)]() { + for (auto remaining = NUM_REQUESTS_PER_WORKER; remaining > 0; + --remaining) { + handles.emplace_back(client.invokeMethod( + [&call_count](const auto&) { ++call_count; })); + } + }); } for (auto& worker : workers) { worker.join(); } - for (int remaining_attempts = NUM_REQUESTS_PER_WORKER; remaining_attempts > 0; - --remaining_attempts) { + for (int remaining_attempts = NUM_REQUESTS_PER_WORKER; + remaining_attempts > 0; --remaining_attempts) { std::this_thread::sleep_for(TWENTY_MILLISECONDS); if (call_count == NUM_REQUESTS_PER_WORKER * workers.size()) { break; @@ -1309,17 +1339,17 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT EXPECT_EQ(call_count, NUM_REQUESTS_PER_WORKER * workers.size()); } -TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT +TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::vector workers; constexpr size_t NUM_REQUESTS_PER_WORKER = 1500; auto get_client = []() { - auto transport = std::make_shared( - defaultSourceUri()); - return communication::RpcClient( - transport, methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto transport = + std::make_shared(defaultSourceUri()); + return communication::RpcClient(transport, methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); }; // Repeatedly creates a client, makes a request, then discards the client @@ -1345,8 +1375,8 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { auto future = client.invokeMethod(); - if (future.valid() && - (future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)) { + if (future.valid() && (future.wait_for(std::chrono::milliseconds( + 0)) == std::future_status::ready)) { ++abandon_calls; } } @@ -1388,21 +1418,22 @@ TEST_F(RpcClientTest, ParallelAccessMultipleClients) { // NOLINT std::atomic self_calls = 0; auto self_responder = [&self_calls]() { - auto transport = std::make_shared( - defaultSourceUri()); - auto client = communication::RpcClient( - transport, methodUri(), v1::UPriority::UPRIORITY_CS4, - TEN_MILLISECONDS); + auto transport = + std::make_shared(defaultSourceUri()); + auto client = communication::RpcClient(transport, methodUri(), + v1::UPriority::UPRIORITY_CS4, + TEN_MILLISECONDS); for (auto remaining_requests = NUM_REQUESTS_PER_WORKER; remaining_requests > 0; --remaining_requests) { - auto handle = - client.invokeMethod([&self_calls](const auto&) { ++self_calls; }); + auto handle = client.invokeMethod( + [&self_calls](const auto&) { ++self_calls; }); // Attempting this without a request having ever been sent results // in an InvalidUUri exception thrown from a thread. gtest can't // guard for that, so we avoid generating the exception. if (transport->getSendCount() > 0) { - auto response = - datamodel::builder::UMessageBuilder::response(transport->getMessage()).build(); + auto response = datamodel::builder::UMessageBuilder::response( + transport->getMessage()) + .build(); transport->mockMessage(response); } } diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index b0c8b1717..066ce8ac0 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -20,7 +20,7 @@ constexpr size_t MAX_LEN_RANDOM_STRING = 32; -namespace uprotocol{ +namespace uprotocol { using MsgDiff = google::protobuf::util::MessageDifferencer; @@ -35,19 +35,18 @@ std::string get_random_string(size_t max_len = MAX_LEN_RANDOM_STRING) { retval.reserve(len); for (size_t i = 0; i < len; i++) { retval += static_cast(char_dist(random_gen)); -} + } return retval; } std::optional RpcCallbackNoReturn( - const v1::UMessage& /*message*/) { + const v1::UMessage& /*message*/) { return std::nullopt; } std::optional RpcCallbackWithReturn( - const v1::UMessage& /*message*/) { - v1::UPayloadFormat format = - v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; + const v1::UMessage& /*message*/) { + v1::UPayloadFormat format = v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; std::string response_data = "RPC Response"; datamodel::builder::Payload payload(response_data, format); @@ -61,24 +60,39 @@ class TestRpcServer : public testing::Test { std::shared_ptr mockTransport_; std::shared_ptr method_uri_; std::shared_ptr request_uri_; - std::chrono::milliseconds ttl_ = std::chrono::milliseconds(DEFAULT_TTL_TIME); + std::chrono::milliseconds ttl_ = + std::chrono::milliseconds(DEFAULT_TTL_TIME); v1::UPayloadFormat format = v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; protected: // Run once per TEST_F. // Used to set up clean environments per test. - [[nodiscard]] std::shared_ptr getMockTransport() const { return mockTransport_; } - [[nodiscard]] std::shared_ptr getMethodUri() const { return method_uri_; } - [[nodiscard]] std::shared_ptr getRequestUri() const { return request_uri_; } - [[nodiscard]] std::chrono::milliseconds getTTL() const { return ttl_; } - [[nodiscard]] v1::UPayloadFormat getFormat() const { return format; } + [[nodiscard]] std::shared_ptr getMockTransport() + const { + return mockTransport_; + } + [[nodiscard]] std::shared_ptr getMethodUri() const { + return method_uri_; + } + [[nodiscard]] std::shared_ptr getRequestUri() const { + return request_uri_; + } + [[nodiscard]] std::chrono::milliseconds getTTL() const { return ttl_; } + [[nodiscard]] v1::UPayloadFormat getFormat() const { return format; } - void setMockTransport(const std::shared_ptr& mock_transport) { mockTransport_ = mock_transport; } - void setMethodUri(const std::shared_ptr& method_uri) { method_uri_ = method_uri; } - void setRequestUri(const std::shared_ptr& request_uri) { request_uri_ = request_uri; } - void setTTL(const std::chrono::milliseconds& ttl) { ttl_ = ttl; } - void setFormat(v1::UPayloadFormat format) { this->format = format; } + void setMockTransport( + const std::shared_ptr& mock_transport) { + mockTransport_ = mock_transport; + } + void setMethodUri(const std::shared_ptr& method_uri) { + method_uri_ = method_uri; + } + void setRequestUri(const std::shared_ptr& request_uri) { + request_uri_ = request_uri; + } + void setTTL(const std::chrono::milliseconds& ttl) { ttl_ = ttl; } + void setFormat(v1::UPayloadFormat format) { this->format = format; } void SetUp() override { constexpr uint32_t DEF_UE_ID = 0x18000; @@ -93,8 +107,7 @@ class TestRpcServer : public testing::Test { def_src_uuri.set_resource_id(0); // Set up a transport - mockTransport_ = - std::make_shared(def_src_uuri); + mockTransport_ = std::make_shared(def_src_uuri); // Set up a method URI method_uri_ = std::make_shared(); @@ -131,10 +144,9 @@ class TestRpcServer : public testing::Test { // Test to ensure RpcServer constructor initializes correctly with valid // parameters -TEST_F(TestRpcServer, ConstructorValidParams) { // NOLINT +TEST_F(TestRpcServer, ConstructorValidParams) { // NOLINT // Define a callback function to be used with the RpcServer - communication::RpcServer::RpcCallback callback = - RpcCallbackNoReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with valid parameters auto server_or_status = communication::RpcServer::create( @@ -152,24 +164,22 @@ TEST_F(TestRpcServer, ConstructorValidParams) { // NOLINT } // Null transport -TEST_F(TestRpcServer, CreateWithNullTransport) { // NOLINT +TEST_F(TestRpcServer, CreateWithNullTransport) { // NOLINT // Define a callback function to be used with the RpcServer - communication::RpcServer::RpcCallback callback = - RpcCallbackNoReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; auto transport = nullptr; // Attempt to create an RpcServer instance with valid parameters - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT auto server_or_status = communication::RpcServer::create( transport, *getMethodUri(), std::move(callback)), transport::NullTransport); } // Test to verify RpcServer construction with a specific payload format -TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // NOLINT +TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // NOLINT // Define a callback that returns a specific value, simulating a response - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with the provided callback and a // specific format @@ -190,16 +200,16 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormat) { // NOLINT // Test to ensure RpcServer can be constructed with both a specific payload // format and TTL -TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // NOLINT +TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // NOLINT // Define a callback that returns a specific value, simulating a server // response - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with additional parameters: // payload format and TTL auto server_or_status = communication::RpcServer::create( - getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), + getTTL()); // Verify that the server creation was successful and a valid instance was // returned @@ -214,7 +224,7 @@ TEST_F(TestRpcServer, ConstructorWithPayloadFormatAndTTL) { // NOLINT } // Test to verify RpcServer construction fails with invalid URI -TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // NOLINT +TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // NOLINT // Create an invalid URI object to simulate invalid input parameters v1::UUri invalid_uri; @@ -222,8 +232,7 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // NOLINT const std::string error_message = "Invalid rpc URI"; // Define a callback function to be used with the RpcServer, even though // it's expected to fail - communication::RpcServer::RpcCallback callback = - RpcCallbackNoReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with the invalid URI and verify // creation fails @@ -240,24 +249,25 @@ TEST_F(TestRpcServer, ConstructorWithInvalidURI) { // NOLINT } // Test to verify RpcServer construction fails with invalid PaylodFormat -TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // NOLINT +TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // NOLINT constexpr uint16_t INVALID_PAYLOADFORMAT = 9999; // Create an invalid PaylodFormat to simulate invalid input parameters - auto invalid_format = static_cast(INVALID_PAYLOADFORMAT); + auto invalid_format = + static_cast(INVALID_PAYLOADFORMAT); // Expecte error message const std::string error_message = "Invalid payload format"; // Define a callback function to be used with the RpcServer, even though // it's expected to fail - communication::RpcServer::RpcCallback callback = - RpcCallbackNoReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Attempt to create an RpcServer instance with the invalid PaylodFormat and // verify creation fails - auto server_or_status = communication::RpcServer::create( - getMockTransport(), *getMethodUri(), std::move(callback), invalid_format); + auto server_or_status = + communication::RpcServer::create(getMockTransport(), *getMethodUri(), + std::move(callback), invalid_format); // Define the expected error code for this operation v1::UCode expected_code = v1::UCode::OUT_OF_RANGE; @@ -269,10 +279,9 @@ TEST_F(TestRpcServer, ConstructorWithInvalidPaylodFormat) { // NOLINT } // Test case to verify successful connection with a valid handle -TEST_F(TestRpcServer, ConnectwithValidHandle) { // NOLINT +TEST_F(TestRpcServer, ConnectwithValidHandle) { // NOLINT // Define a callback function that simulates a server response - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Attempt to create an RpcServer instance with mockTransport_ auto server_or_status = communication::RpcServer::create( @@ -289,27 +298,29 @@ TEST_F(TestRpcServer, ConnectwithValidHandle) { // NOLINT EXPECT_NE(handle, nullptr); // Verify that the register listener uri mataches with input method uri - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); + EXPECT_TRUE( + MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); } // Test case to verify RPC request handling with return payload and TTL -TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT +TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT // Expected response by RPC method std::string expected_response_payload = "RPC Response"; // Create a callback to be called when request is received - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Create a server to offer the RPC method auto server_or_status = communication::RpcServer::create( - getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), + getTTL()); // Check if the server was created successfully const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); + EXPECT_TRUE( + MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); // Create request umessage auto builder = datamodel::builder::UMessageBuilder::request( @@ -332,30 +343,33 @@ TEST_F(TestRpcServer, RPCRequestWithReturnPayloadAndTTL) { // NOLINT .withPayloadFormat(getFormat()) .build({expected_response_payload, getFormat()}); + EXPECT_TRUE(MsgDiff::Equals( + expected_response_msg.attributes().source(), + getMockTransport()->getMessage().attributes().source())); EXPECT_TRUE( - MsgDiff::Equals(expected_response_msg.attributes().source(), - getMockTransport()->getMessage().attributes().source())); - EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - getMockTransport()->getMessage().attributes().sink())); - EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - getMockTransport()->getMessage().attributes().reqid())); + MsgDiff::Equals(expected_response_msg.attributes().sink(), + getMockTransport()->getMessage().attributes().sink())); + EXPECT_TRUE( + MsgDiff::Equals(expected_response_msg.attributes().reqid(), + getMockTransport()->getMessage().attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(getMockTransport()->getMessage().attributes().type())); - EXPECT_EQ(static_cast(expected_response_msg.attributes().ttl()), - static_cast(getMockTransport()->getMessage().attributes().ttl())); + static_cast( + getMockTransport()->getMessage().attributes().type())); EXPECT_EQ( - static_cast(expected_response_msg.attributes().priority()), - static_cast(getMockTransport()->getMessage().attributes().priority())); + static_cast(expected_response_msg.attributes().ttl()), + static_cast(getMockTransport()->getMessage().attributes().ttl())); + EXPECT_EQ(static_cast(expected_response_msg.attributes().priority()), + static_cast( + getMockTransport()->getMessage().attributes().priority())); EXPECT_EQ(getMockTransport()->getMessage().payload().data(), expected_response_payload); } // Test case to verify RPC request handling without return payload -TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT +TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT // Create a callback to be called when request is received - communication::RpcServer::RpcCallback callback = - RpcCallbackNoReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackNoReturn; // Create a server to offer the RPC method auto server_or_status = communication::RpcServer::create( @@ -365,7 +379,8 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT const auto& handle = server_or_status.value(); EXPECT_NE(handle, nullptr); - EXPECT_TRUE(MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); + EXPECT_TRUE( + MsgDiff::Equals(*getMethodUri(), *getMockTransport()->getSinkFilter())); // Create request umessage auto builder = datamodel::builder::UMessageBuilder::request( @@ -385,31 +400,34 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT auto expected_response_msg = datamodel::builder::UMessageBuilder::response(msg).build(); + EXPECT_TRUE(MsgDiff::Equals( + expected_response_msg.attributes().source(), + getMockTransport()->getMessage().attributes().source())); EXPECT_TRUE( - MsgDiff::Equals(expected_response_msg.attributes().source(), - getMockTransport()->getMessage().attributes().source())); - EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().sink(), - getMockTransport()->getMessage().attributes().sink())); - EXPECT_TRUE(MsgDiff::Equals(expected_response_msg.attributes().reqid(), - getMockTransport()->getMessage().attributes().reqid())); + MsgDiff::Equals(expected_response_msg.attributes().sink(), + getMockTransport()->getMessage().attributes().sink())); + EXPECT_TRUE( + MsgDiff::Equals(expected_response_msg.attributes().reqid(), + getMockTransport()->getMessage().attributes().reqid())); EXPECT_EQ(static_cast(expected_response_msg.attributes().type()), - static_cast(getMockTransport()->getMessage().attributes().type())); - EXPECT_EQ( - static_cast(expected_response_msg.attributes().priority()), - static_cast(getMockTransport()->getMessage().attributes().priority())); + static_cast( + getMockTransport()->getMessage().attributes().type())); + EXPECT_EQ(static_cast(expected_response_msg.attributes().priority()), + static_cast( + getMockTransport()->getMessage().attributes().priority())); EXPECT_FALSE(getMockTransport()->getMessage().has_payload()); } // Test case to verify RPC request handling with invalid request -TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT +TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT // Create a callback to be called when request is received - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; // Create a server to offer the RPC method auto server_or_status = communication::RpcServer::create( - getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), getTTL()); + getMockTransport(), *getMethodUri(), std::move(callback), getFormat(), + getTTL()); // Check if the server was created successfully const auto& handle = server_or_status.value(); @@ -434,13 +452,13 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT // Test case to verify RPC sever resets the listener when the server is // destroyed -TEST_F(TestRpcServer, RestRPCServerHandle) { // NOLINT - communication::RpcServer::RpcCallback callback = - RpcCallbackWithReturn; +TEST_F(TestRpcServer, RestRPCServerHandle) { // NOLINT + communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; { auto server_or_status = communication::RpcServer::create( - getMockTransport(), *getMethodUri(), std::move(callback), getFormat()); + getMockTransport(), *getMethodUri(), std::move(callback), + getFormat()); EXPECT_TRUE(server_or_status.has_value()); diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index dadd090ce..09aa704b5 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -19,7 +19,7 @@ #include "UTransportMock.h" #include "up-cpp/datamodel/validator/UUri.h" -namespace uprotocol{ +namespace uprotocol { using MsgDiff = google::protobuf::util::MessageDifferencer; class SubscriberTest : public testing::Test { @@ -50,16 +50,28 @@ class SubscriberTest : public testing::Test { void buildDefaultSourceURI(); uprotocol::v1::UUri getTestTopicUUri() const { return testTopicUUri_; } - uprotocol::v1::UUri getTestInvalidTopicUUri() const { return testInvalidTopicUUri_; } - uprotocol::v1::UUri getTestDefaultSourceUUri() const { return testDefaultSourceUUri_; } - size_t getCaptureCount() const { return capture_count_; } - uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } + uprotocol::v1::UUri getTestInvalidTopicUUri() const { + return testInvalidTopicUUri_; + } + uprotocol::v1::UUri getTestDefaultSourceUUri() const { + return testDefaultSourceUUri_; + } + size_t getCaptureCount() const { return capture_count_; } + uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } - void setTestTopicUUri(const uprotocol::v1::UUri& uri) { testTopicUUri_ = uri; } - void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uri) { testInvalidTopicUUri_ = uri; } - void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uri) { testDefaultSourceUUri_ = uri; } - void setCaptureCount(size_t count) { capture_count_ = count; } - void setCaptureMsg(const uprotocol::v1::UMessage& msg) { capture_msg_ = msg; } + void setTestTopicUUri(const uprotocol::v1::UUri& uri) { + testTopicUUri_ = uri; + } + void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uri) { + testInvalidTopicUUri_ = uri; + } + void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uri) { + testDefaultSourceUUri_ = uri; + } + void setCaptureCount(size_t count) { capture_count_ = count; } + void setCaptureMsg(const uprotocol::v1::UMessage& msg) { + capture_msg_ = msg; + } public: void handleCallbackMessage(const uprotocol::v1::UMessage& message); @@ -75,7 +87,7 @@ void SubscriberTest::SetUp() { void SubscriberTest::buildValidSubscribeURI() { constexpr uint32_t VALID_UE_ID = 0x00011101; constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8001; - + testTopicUUri_.set_authority_name("192.168.1.10"); testTopicUUri_.set_ue_id(VALID_UE_ID); testTopicUUri_.set_ue_version_major(0x1); @@ -86,7 +98,7 @@ void SubscriberTest::buildInValidSubscribeURI() { constexpr uint32_t VALID_UE_ID = 0x00011101; // Resource ID should be in the range of 0x8000 to 0xFFFF constexpr uint32_t INVALID_RESOURCE_ID = 0x1200; - + testInvalidTopicUUri_.set_authority_name("192.168.1.10"); testInvalidTopicUUri_.set_ue_id(VALID_UE_ID); testInvalidTopicUUri_.set_ue_version_major(0x1); @@ -95,7 +107,7 @@ void SubscriberTest::buildInValidSubscribeURI() { void SubscriberTest::buildDefaultSourceURI() { constexpr uint32_t DEFAULT_UE_ID = 0x00011102; - + testDefaultSourceUUri_.set_authority_name("192.168.1.10"); testDefaultSourceUUri_.set_ue_id(DEFAULT_UE_ID); testDefaultSourceUUri_.set_ue_version_major(0x1); @@ -104,10 +116,11 @@ void SubscriberTest::buildDefaultSourceURI() { std::string get_random_string(size_t length) { auto randchar = []() -> char { constexpr std::array CHARSET = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' - }; + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', + 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> distr(0, CHARSET.size() - 1); @@ -125,7 +138,7 @@ void SubscriberTest::handleCallbackMessage( } // Positive test case to subscribe to a valid topic -TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT +TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT constexpr uint16_t RANDOM_STRING_LENGTH = 1400; auto transport = std::make_shared( @@ -135,14 +148,15 @@ TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT return this->handleCallbackMessage(arg1); }; - auto result = - communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); + auto result = communication::Subscriber::subscribe( + transport, getTestTopicUUri(), std::move(callback)); EXPECT_TRUE(transport->getListener()); EXPECT_TRUE(result.has_value()); auto handle = std::move(result).value(); EXPECT_TRUE(handle); - EXPECT_TRUE(MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); + EXPECT_TRUE( + MsgDiff::Equals(getTestTopicUUri(), transport->getSourceFilter())); EXPECT_FALSE(transport->getSinkFilter()); const size_t max_count = 100; @@ -158,7 +172,7 @@ TEST_F(SubscriberTest, SubscribeSuccess) { // NOLINT } // Negative test case to subscribe to a invalid topic -TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { // NOLINT +TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -167,13 +181,13 @@ TEST_F(SubscriberTest, SubscribeFailWithInvalidTopic) { // NOLINT }; // Subscribe to invalid UUri topic with resource ID not in correct range - EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT + EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT transport, getTestInvalidTopicUUri(), std::move(callback)), - datamodel::validator::uri::InvalidUUri); + datamodel::validator::uri::InvalidUUri); } // Negative test case to subscribe to a topic with registerListener failure -TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { // NOLINT +TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); @@ -185,43 +199,47 @@ TEST_F(SubscriberTest, SubscribeFailWithErrorCode) { // NOLINT expected_status.set_code(uprotocol::v1::UCode::ABORTED); transport->getRegisterListenerStatus() = expected_status; - auto result = - communication::Subscriber::subscribe(transport, getTestTopicUUri(), std::move(callback)); + auto result = communication::Subscriber::subscribe( + transport, getTestTopicUUri(), std::move(callback)); auto actual_status = std::move(result).error(); EXPECT_EQ(actual_status.code(), expected_status.code()); } // subscribe to a topic with null transport -TEST_F(SubscriberTest, SubscribeNullTransport) { // NOLINT +TEST_F(SubscriberTest, SubscribeNullTransport) { // NOLINT // set transport to null auto transport = nullptr; auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; - EXPECT_THROW(auto result = communication::Subscriber::subscribe(transport, getTestTopicUUri(), // NOLINT - std::move(callback)), + EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT + transport, getTestTopicUUri(), + std::move(callback)), std::invalid_argument); } // subscribe to a topic with null callback -TEST_F(SubscriberTest, SubscribeNullCallback) { // NOLINT +TEST_F(SubscriberTest, SubscribeNullCallback) { // NOLINT auto transport = std::make_shared( getTestDefaultSourceUUri()); // bind to null callback auto test_subscribe_nullptr = [transport, this]() { - std::ignore = communication::Subscriber::subscribe(transport, getTestTopicUUri(), - nullptr); + std::ignore = communication::Subscriber::subscribe( + transport, getTestTopicUUri(), nullptr); }; - EXPECT_THROW(test_subscribe_nullptr(), utils::callbacks::EmptyFunctionObject); // NOLINT + EXPECT_THROW(test_subscribe_nullptr(), // NOLINT + utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_subscribe_empty = [transport, this]() { - std::ignore = communication::Subscriber::subscribe(transport, getTestTopicUUri(), {}); + std::ignore = communication::Subscriber::subscribe( + transport, getTestTopicUUri(), {}); }; - EXPECT_THROW(test_subscribe_empty(), utils::callbacks::EmptyFunctionObject); // NOLINT + EXPECT_THROW(test_subscribe_empty(), // NOLINT + utils::callbacks::EmptyFunctionObject); } } // namespace uprotocol diff --git a/test/coverage/datamodel/PayloadBuilderTest.cpp b/test/coverage/datamodel/PayloadBuilderTest.cpp index fcea10a77..9508e20a4 100644 --- a/test/coverage/datamodel/PayloadBuilderTest.cpp +++ b/test/coverage/datamodel/PayloadBuilderTest.cpp @@ -14,7 +14,7 @@ #include -namespace uprotocol::datamodel::builder{ +namespace uprotocol::datamodel::builder { struct TimeAsPayloadSerializer { static Payload::Serialized serialize(std::chrono::milliseconds t) { @@ -35,9 +35,11 @@ class PayloadTest : public testing::Test { private: // Note : Need to make the std::string version longer to avoid SSO (small // string optimization) as it will interfere with the move tests - const std::string testStringPayload_ = "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; + const std::string testStringPayload_ = + "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; const std::vector testBytesPayload_{'T', 'e', 's', 't', '0', '1', '2', '3'}; + protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -53,8 +55,12 @@ class PayloadTest : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - [[nodiscard]] std::string getTestStringPayload() const { return testStringPayload_; } - [[nodiscard]] std::vector getTestBytesPayload() const { return testBytesPayload_; } + [[nodiscard]] std::string getTestStringPayload() const { + return testStringPayload_; + } + [[nodiscard]] std::vector getTestBytesPayload() const { + return testBytesPayload_; + } public: ~PayloadTest() override = default; @@ -63,7 +69,7 @@ class PayloadTest : public testing::Test { /////////////////Serialized Protobuf Tests///////////////////////// // Create serialized protobuf payload and verify build payload -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndBuildTest) { // NOLINT +TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndBuildTest) { // NOLINT // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(getTestStringPayload()); @@ -80,7 +86,7 @@ TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndBuildTest) { // NOLINT } // Create serialized protobuf payload with empty message -TEST_F(PayloadTest, CreateEmptySerializedProtobufPayloadTest) { // NOLINT +TEST_F(PayloadTest, CreateEmptySerializedProtobufPayloadTest) { // NOLINT // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(""); @@ -96,7 +102,7 @@ TEST_F(PayloadTest, CreateEmptySerializedProtobufPayloadTest) { // NOLINT } // Create serialized protobuf payload and verify moved payload -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { // NOLINT +TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { // NOLINT // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(getTestStringPayload()); @@ -113,12 +119,14 @@ TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { // NOLINT uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); EXPECT_EQ(payloadData, expected_payload_data); - EXPECT_THROW(static_cast(payload.buildCopy()), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(static_cast(payload.buildCopy()), // NOLINT + Payload::PayloadMoved); EXPECT_EQ(original_address, payloadData.data()); } // Create serialized protobuf payload. Verify exception for move paylod twice -TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { // NOLINT +TEST_F(PayloadTest, // NOLINT + CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(getTestStringPayload()); @@ -133,13 +141,13 @@ TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); EXPECT_EQ(payloadData, uri_object.SerializeAsString()); - EXPECT_THROW({ auto _ = std::move(payload).buildMove(); }, // NOLINT + EXPECT_THROW({ auto _ = std::move(payload).buildMove(); }, // NOLINT Payload::PayloadMoved); } // Create serialized protobuf payload. Call build after move. -TEST_F(PayloadTest, // NOLINT - CreateSerializedProtobufPayloadAndCallBuildAfterMoveExceptionTest) { +TEST_F(PayloadTest, // NOLINT + CreateSerializedProtobufPayloadAndCallBuildAfterMoveExceptionTest) { // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(getTestStringPayload()); @@ -156,21 +164,23 @@ TEST_F(PayloadTest, // NOLINT EXPECT_EQ(payloadData, uri_object.SerializeAsString()); // Call build on payload after move - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } /////////////Serializer Payload Protobuf Tests///////////////// // Create a serializer payload and verify build payload -TEST_F(PayloadTest, CreateSerializerPayloadAndBuildTest) { // NOLINT +TEST_F(PayloadTest, CreateSerializerPayloadAndBuildTest) { // NOLINT constexpr uint16_t RANDOM_TIME = 1234; // Arrange std::chrono::milliseconds t(RANDOM_TIME); TimeAsPayloadSerializer time_serializer; uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat( uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW); - auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( - std::chrono::duration_cast(t)); + auto expected_serialized_object = + uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( + std::chrono::duration_cast(t)); // Act Payload payload(time_serializer, t); @@ -179,40 +189,45 @@ TEST_F(PayloadTest, CreateSerializerPayloadAndBuildTest) { // NOLINT auto [payloadData, payloadFormat] = payload.buildCopy(); EXPECT_EQ(payloadData, std::get(expected_serialized_object)); - EXPECT_EQ(payloadFormat, - std::get(expected_serialized_object)); + EXPECT_EQ(payloadFormat, std::get( + expected_serialized_object)); } // Create a serializer payload with invalid format -TEST_F(PayloadTest, CreateSerializerPayloadWithInvalidFormat) { // NOLINT +TEST_F(PayloadTest, CreateSerializerPayloadWithInvalidFormat) { // NOLINT constexpr uint16_t RANDOM_TIME = 1234; constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; // Arrange std::chrono::milliseconds t(RANDOM_TIME); TimeAsPayloadSerializer time_serializer; - auto invalid_format = static_cast(INVALID_PAYLOAD_FORMAT); + auto invalid_format = + static_cast(INVALID_PAYLOAD_FORMAT); // Ovreide the format with invalid value - uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat(invalid_format); + uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat( + invalid_format); - auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( - std::chrono::duration_cast(t)); + auto expected_serialized_object = + uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( + std::chrono::duration_cast(t)); // Act - EXPECT_THROW(Payload payload(time_serializer, t), std::out_of_range); // NOLINT + EXPECT_THROW(Payload payload(time_serializer, t), // NOLINT + std::out_of_range); } // Create a serializer payload and verify moved payload -TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { // NOLINT +TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { // NOLINT constexpr uint16_t RANDOM_TIME = 12345; - + // Arrange std::chrono::milliseconds t(RANDOM_TIME); TimeAsPayloadSerializer time_serializer; uprotocol::datamodel::builder::TimeAsPayloadSerializer::setFormat( uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW); - auto expected_serialized_object = uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( - std::chrono::duration_cast(t)); + auto expected_serialized_object = + uprotocol::datamodel::builder::TimeAsPayloadSerializer::serialize( + std::chrono::duration_cast(t)); // Act Payload payload(time_serializer, t); @@ -221,16 +236,17 @@ TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { // NOLINT auto [payloadData, payloadFormat] = std::move(payload).buildMove(); EXPECT_EQ(payloadData, std::get(expected_serialized_object)); - EXPECT_EQ(payloadFormat, - std::get(expected_serialized_object)); + EXPECT_EQ(payloadFormat, std::get( + expected_serialized_object)); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } ////////////////////////Byte Array Payload Tests//////////////////////// // Create payload of Byte array and check if the payload is created correctly -TEST_F(PayloadTest, ByteArrayPayloadTest) { // NOLINT +TEST_F(PayloadTest, ByteArrayPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; @@ -247,20 +263,22 @@ TEST_F(PayloadTest, ByteArrayPayloadTest) { // NOLINT // Create payload of Byte array with invalid format and check if it throws // exception -TEST_F(PayloadTest, ConstructorInvalidFormatForByteArrayPayloadTest) { // NOLINT +TEST_F(PayloadTest, // NOLINT + ConstructorInvalidFormatForByteArrayPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; - + // Arrange auto invalid_format = static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(getTestBytesPayload(), invalid_format), // NOLINT - std::out_of_range); + EXPECT_THROW( // NOLINT + Payload payload(getTestBytesPayload(), invalid_format), + std::out_of_range); } // Create empty byte array payload -TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { // NOLINT +TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { // NOLINT // Arrange std::vector value_bytes = {}; uprotocol::v1::UPayloadFormat format = @@ -277,7 +295,7 @@ TEST_F(PayloadTest, EmptyByteArrayPayloadTest) { // NOLINT } // Create byte array payload and call buildMove() -TEST_F(PayloadTest, MoveByteArrayPayloadTest) { // NOLINT +TEST_F(PayloadTest, MoveByteArrayPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; @@ -289,13 +307,14 @@ TEST_F(PayloadTest, MoveByteArrayPayloadTest) { // NOLINT // Assert EXPECT_EQ(serialized_data, "Test0123"); EXPECT_EQ(payloadFormat, format); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } //////////////String Payload Tests////////////// // Create payload of std::string and check if the payload is created -TEST_F(PayloadTest, StringPayloadTest) { // NOLINT +TEST_F(PayloadTest, StringPayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -310,20 +329,21 @@ TEST_F(PayloadTest, StringPayloadTest) { // NOLINT } // Create payload of std::string with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForStringPayloadTest) { // NOLINT +TEST_F(PayloadTest, ConstructorInvalidFormatForStringPayloadTest) { // NOLINT constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; - + // Arrange auto invalid_format = static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(getTestStringPayload(), invalid_format), // NOLINT - std::out_of_range); + EXPECT_THROW( // NOLINT + Payload payload(getTestStringPayload(), invalid_format), + std::out_of_range); } // Create empty string payload -TEST_F(PayloadTest, EmptyStringPayloadTest) { // NOLINT +TEST_F(PayloadTest, EmptyStringPayloadTest) { // NOLINT // Arrange std::string value_string; uprotocol::v1::UPayloadFormat format = @@ -339,7 +359,7 @@ TEST_F(PayloadTest, EmptyStringPayloadTest) { // NOLINT } // Create std::string payload and call move on payload object test -TEST_F(PayloadTest, StringMovePayloadTest) { // NOLINT +TEST_F(PayloadTest, StringMovePayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -351,7 +371,8 @@ TEST_F(PayloadTest, StringMovePayloadTest) { // NOLINT // Assert EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } // Create Any and move payload object test @@ -382,7 +403,7 @@ TEST_F(PayloadTest, AnyMovePayloadTest) { // NOLINT /////////////////////RValue String Payload Tests///////////////////// // Create RValue String Payload -TEST_F(PayloadTest, RValueStringPayloadTest) { // NOLINT +TEST_F(PayloadTest, RValueStringPayloadTest) { // NOLINT // Arrange std::string value_string = getTestStringPayload(); uprotocol::v1::UPayloadFormat format = @@ -400,21 +421,23 @@ TEST_F(PayloadTest, RValueStringPayloadTest) { // NOLINT } // Create payload of RValue String with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForRValueStringPayloadTest) { // NOLINT +TEST_F(PayloadTest, // NOLINT + ConstructorInvalidFormatForRValueStringPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; - + // Arrange std::string value_string = getTestStringPayload(); auto invalid_format = static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW(Payload payload(std::move(value_string), invalid_format), // NOLINT - std::out_of_range); + EXPECT_THROW( // NOLINT + Payload payload(std::move(value_string), invalid_format), + std::out_of_range); } // Create empty RValue String payload -TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { // NOLINT +TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { // NOLINT // Arrange std::string value_string; uprotocol::v1::UPayloadFormat format = @@ -430,7 +453,7 @@ TEST_F(PayloadTest, EmptyRValueStringPayloadTest) { // NOLINT } // Create RValue String and move payload object test -TEST_F(PayloadTest, RValueStringMovePayloadTest) { // NOLINT +TEST_F(PayloadTest, RValueStringMovePayloadTest) { // NOLINT // Arrange std::string value_string = getTestStringPayload(); const void* original_address = value_string.data(); @@ -447,13 +470,14 @@ TEST_F(PayloadTest, RValueStringMovePayloadTest) { // NOLINT EXPECT_EQ(payloadFormat, format); EXPECT_EQ(original_address, moved_address); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } ///////////////////////RValue Serialized Payload Tests////////////////////// // Create RValue Serialized payload -TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // NOLINT +TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; @@ -473,9 +497,10 @@ TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // NOLINT } // Create payload of RValue Serialized with invalid format -TEST_F(PayloadTest, ConstructorInvalidFormatForRValueSerializedPayloadTest) { // NOLINT +TEST_F(PayloadTest, // NOLINT + ConstructorInvalidFormatForRValueSerializedPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; - + // Arrange auto format = static_cast(INVALID_PAYLOAD_FORMAT); @@ -483,11 +508,12 @@ TEST_F(PayloadTest, ConstructorInvalidFormatForRValueSerializedPayloadTest) { // std::make_tuple(getTestStringPayload(), format); // Act - EXPECT_THROW(Payload payload(std::move(serialized));, std::out_of_range); // NOLINT + EXPECT_THROW(Payload payload(std::move(serialized)); // NOLINT + , std::out_of_range); } // Create empty RValue Serialized payload and build. -TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { // NOLINT +TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { // NOLINT // Arrange std::string serialized_data; uprotocol::v1::UPayloadFormat format = @@ -504,7 +530,7 @@ TEST_F(PayloadTest, EmptyRValueSerializedPayloadTest) { // NOLINT } // Create RValue Serialized and move payload object test -TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { // NOLINT +TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_RAW; @@ -524,13 +550,14 @@ TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { // NOLINT EXPECT_EQ(payloadFormat, format); EXPECT_EQ(original_address, moved_address); - EXPECT_THROW(auto _ = payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } //////////////////////Other Constructor Tests/////////////////////// // Move Constructor Test -TEST_F(PayloadTest, MoveConstructorTest) { // NOLINT +TEST_F(PayloadTest, MoveConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -544,11 +571,12 @@ TEST_F(PayloadTest, MoveConstructorTest) { // NOLINT EXPECT_EQ(movedData, getTestStringPayload()); EXPECT_EQ(movedFormat, format); - EXPECT_THROW(auto _ = original_payload.buildCopy(), Payload::PayloadMoved); // NOLINT + EXPECT_THROW(auto _ = original_payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } // Cppy Constructor Test -TEST_F(PayloadTest, CopyConstructorTest) { // NOLINT +TEST_F(PayloadTest, CopyConstructorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -565,7 +593,7 @@ TEST_F(PayloadTest, CopyConstructorTest) { // NOLINT } // Move Assignment Operator Test -TEST_F(PayloadTest, MoveAssignmentOperatorTest) { // NOLINT +TEST_F(PayloadTest, MoveAssignmentOperatorTest) { // NOLINT // Arrange uprotocol::v1::UUri uri_object1; uri_object1.set_authority_name("test1"); @@ -586,7 +614,7 @@ TEST_F(PayloadTest, MoveAssignmentOperatorTest) { // NOLINT } // Copy Assignment Operator Test -TEST_F(PayloadTest, CopyAssignmentOperatorTest) { // NOLINT +TEST_F(PayloadTest, CopyAssignmentOperatorTest) { // NOLINT // Arrange uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index e1d2f33b5..cc623e37a 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -19,7 +19,7 @@ constexpr uint16_t TTL_TIME = 5000; constexpr uint32_t UI_ID_INVALID_TEST = 0xFFFF0000; -namespace uprotocol{ +namespace uprotocol { class TestUMessageBuilder : public testing::Test { protected: @@ -34,22 +34,22 @@ class TestUMessageBuilder : public testing::Test { v1::UUri method = method_; v1::UUri source = sink_; - return datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), - priority, ttl); + return datamodel::builder::UMessageBuilder::request( + std::move(method), std::move(source), priority, ttl); } static datamodel::builder::UMessageBuilder createFakeResponse() { v1::UUri sink = sink_; v1::UUri method = method_; - v1::UUID request_id = req_id_; + v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - return datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), - priority, std::move(method)); + return datamodel::builder::UMessageBuilder::response( + std::move(sink), std::move(request_id), priority, + std::move(method)); } - static bool urisAreEqual(const v1::UUri& uri1, - const v1::UUri& uri2) { + static bool urisAreEqual(const v1::UUri& uri1, const v1::UUri& uri2) { return uri1.authority_name() == uri2.authority_name() && uri1.ue_id() == uri2.ue_id() && uri1.ue_version_major() == uri2.ue_version_major() && @@ -98,6 +98,7 @@ class TestUMessageBuilder : public testing::Test { static v1::UUri sink_; static v1::UUri method_; static v1::UUID req_id_; + public: ~TestUMessageBuilder() override = default; }; @@ -108,210 +109,238 @@ v1::UUri TestUMessageBuilder::method_; v1::UUID TestUMessageBuilder::req_id_; /// @brief Test the publish function of the UMessageBuilder -TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT v1::UUri topic = source_; - EXPECT_NO_THROW({ // NOLINT - auto builder = datamodel::builder::UMessageBuilder::publish(std::move(topic)); + EXPECT_NO_THROW({ // NOLINT + auto builder = + datamodel::builder::UMessageBuilder::publish(std::move(topic)); const v1::UAttributes& attr = builder.attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_PUBLISH); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(source_)); + EXPECT_EQ( + datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(source_)); }); } -TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { // NOLINT v1::UUri topic; - EXPECT_THROW({ datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, datamodel::validator::uri::InvalidUUri); // NOLINT + EXPECT_THROW( // NOLINT + { datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, + datamodel::validator::uri::InvalidUUri); } /// @brief Test the notification function of the UMessageBuilder -TEST_F(TestUMessageBuilder, NotificationTest) { // NOLINT +TEST_F(TestUMessageBuilder, NotificationTest) { // NOLINT // Call the notification function v1::UUri source = source_; v1::UUri sink = sink_; - EXPECT_NO_THROW({ // NOLINT - auto builder = - datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); + EXPECT_NO_THROW({ // NOLINT + auto builder = datamodel::builder::UMessageBuilder::notification( + std::move(source), std::move(sink)); // Verify the result const v1::UAttributes& attr = builder.attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_NOTIFICATION); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(source_)); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), datamodel::serializer::uri::AsString::serialize(sink_)); + EXPECT_EQ( + datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(source_)); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), + datamodel::serializer::uri::AsString::serialize(sink_)); }); } -TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); v1::UUri sink = sink_; - EXPECT_THROW( // NOLINT - { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, + EXPECT_THROW( // NOLINT + { + datamodel::builder::UMessageBuilder::notification(std::move(source), + std::move(sink)); + }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { // NOLINT v1::UUri source = source_; v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); - EXPECT_THROW( // NOLINT - { datamodel::builder::UMessageBuilder::notification(std::move(source), std::move(sink)); }, + EXPECT_THROW( // NOLINT + { + datamodel::builder::UMessageBuilder::notification(std::move(source), + std::move(sink)); + }, datamodel::validator::uri::InvalidUUri); } /// @brief Test the request function of the UMessageBuilder -TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); v1::UUri method = method_; v1::UUri source = sink_; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::request( std::move(method), std::move(source), priority, ttl); auto attr = builder.build().attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_REQUEST); EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), datamodel::serializer::uri::AsString::serialize(method_)); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(sink_)); + EXPECT_EQ( + datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(sink_)); EXPECT_EQ(attr.priority(), priority); EXPECT_EQ(attr.ttl(), TTL_TIME); }); } -TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { // NOLINT v1::UUri method; v1::UUri source = source_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), - priority, ttl); + datamodel::builder::UMessageBuilder::request( + std::move(method), std::move(source), priority, ttl); }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); v1::UUri method = method_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), - priority, ttl); + datamodel::builder::UMessageBuilder::request( + std::move(method), std::move(source), priority, ttl); }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { // NOLINT +TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { // NOLINT v1::UUri method = method_; v1::UUri source = sink_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(-1); // Invalid TTL - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::request(std::move(method), std::move(source), - priority, ttl); + datamodel::builder::UMessageBuilder::request( + std::move(method), std::move(source), priority, ttl); }, std::out_of_range); } /// @brief Test the response function of the UMessageBuilder -TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { // NOLINT v1::UUri sink = sink_; v1::UUri method = method_; - v1::UUID request_id = req_id_; + v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_NO_THROW({ // NOLINT - auto builder = - datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), - priority, std::move(method)); + EXPECT_NO_THROW({ // NOLINT + auto builder = datamodel::builder::UMessageBuilder::response( + std::move(sink), std::move(request_id), priority, + std::move(method)); const v1::UAttributes& attr = builder.attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_RESPONSE); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), datamodel::serializer::uri::AsString::serialize(sink_)); - EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(method_)); + EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), + datamodel::serializer::uri::AsString::serialize(sink_)); + EXPECT_EQ( + datamodel::serializer::uri::AsString::serialize(attr.source()), + datamodel::serializer::uri::AsString::serialize(method_)); // EXPECT_EQ(attr.reqid(), req_id_); EXPECT_EQ(attr.priority(), priority); }); } -TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { // NOLINT v1::UUri sink = sink_; v1::UUri method; - v1::UUID request_id = req_id_; + v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), - priority, std::move(method)); + datamodel::builder::UMessageBuilder::response( + std::move(sink), std::move(request_id), priority, + std::move(method)); }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { // NOLINT +TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { // NOLINT v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); v1::UUri method = method_; - v1::UUID request_id = req_id_; + v1::UUID request_id = req_id_; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), - priority, std::move(method)); + datamodel::builder::UMessageBuilder::response( + std::move(sink), std::move(request_id), priority, + std::move(method)); }, datamodel::validator::uri::InvalidUUri); } -TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { // NOLINT +TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { // NOLINT v1::UUri sink = sink_; v1::UUri method = method_; v1::UUID request_id; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; - EXPECT_THROW(// NOLINT + EXPECT_THROW( // NOLINT { - datamodel::builder::UMessageBuilder::response(std::move(sink), std::move(request_id), - priority, std::move(method)); + datamodel::builder::UMessageBuilder::response( + std::move(sink), std::move(request_id), priority, + std::move(method)); }, datamodel::validator::uuid::InvalidUuid); } /// @brief withPriority test -TEST_F(TestUMessageBuilder, WithPriorityValidForRequestOrResponseSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + WithPriorityValidForRequestOrResponseSuccess) { auto builder = createFakeRequest(); - - EXPECT_NO_THROW({ builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); // NOLINT + + EXPECT_NO_THROW( // NOLINT + { builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); auto builder2 = createFakeResponse(); - EXPECT_NO_THROW({ builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); // NOLINT + EXPECT_NO_THROW( // NOLINT + { builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); } -TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW( // NOLINT - { builder.withPriority(static_cast(v1::UPriority_MIN - 1)); }, + EXPECT_THROW( // NOLINT + { + builder.withPriority( + static_cast(v1::UPriority_MIN - 1)); + }, std::out_of_range); - EXPECT_THROW( // NOLINT - { builder.withPriority(static_cast(v1::UPriority_MAX + 1)); }, + EXPECT_THROW( // NOLINT + { + builder.withPriority( + static_cast(v1::UPriority_MAX + 1)); + }, std::out_of_range); } -TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + WithPriorityLessThanCS4ForRequestOrResponseThrows) { auto builder = createFakeRequest(); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { builder.withPriority( static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); @@ -320,7 +349,7 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { auto builder2 = createFakeResponse(); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { builder2.withPriority( static_cast(v1::UPriority::UPRIORITY_CS4 - 1)); @@ -329,22 +358,23 @@ TEST_F(TestUMessageBuilder, WithPriorityLessThanCS4ForRequestOrResponseThrows) { } ///@brief withTtl() tests -TEST_F(TestUMessageBuilder, WithTtlValidSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithTtlValidSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withTtl(std::chrono::milliseconds(1)); }); // NOLINT - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW( // NOLINT + { builder.withTtl(std::chrono::milliseconds(1)); }); + EXPECT_NO_THROW({ // NOLINT builder.withTtl( std::chrono::milliseconds(std::numeric_limits::max())); }); } -TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(-1)); }, // NOLINT + EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(-1)); }, // NOLINT std::out_of_range); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { builder.withTtl(std::chrono::milliseconds( static_cast(std::numeric_limits::max()) + @@ -353,83 +383,91 @@ TEST_F(TestUMessageBuilder, WithTtlOutOfRangeThrows) { // NOLINT std::out_of_range); } -TEST_F(TestUMessageBuilder, WithTtlZeroThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithTtlZeroThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(0)); }, // NOLINT + EXPECT_THROW({ builder.withTtl(std::chrono::milliseconds(0)); }, // NOLINT std::out_of_range); } /// @brief withToken tests -TEST_F(TestUMessageBuilder, WithTokenEmptyStringSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithTokenEmptyStringSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withToken(""); }); // NOLINT + EXPECT_NO_THROW({ builder.withToken(""); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithTokenOnNonRequestThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithTokenOnNonRequestThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withToken("token"); }, std::domain_error); // NOLINT + EXPECT_THROW({ builder.withToken("token"); }, std::domain_error); // NOLINT } -TEST_F(TestUMessageBuilder, WithTokenOnRequestSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithTokenOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withToken("token"); }); // NOLINT + EXPECT_NO_THROW({ builder.withToken("token"); }); // NOLINT } /// @brief withPermissionLevel tests -TEST_F(TestUMessageBuilder, WithPermissionLevelOnRequestSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithPermissionLevelOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPermissionLevel(1); }); // NOLINT + EXPECT_NO_THROW({ builder.withPermissionLevel(1); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithPermissionLevelOnNonRequestThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithPermissionLevelOnNonRequestThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withPermissionLevel(1); }, std::domain_error); // NOLINT + EXPECT_THROW({ builder.withPermissionLevel(1); }, // NOLINT + std::domain_error); } -TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ builder.withPermissionLevel(0); }); // NOLINT + EXPECT_NO_THROW({ builder.withPermissionLevel(0); }); // NOLINT } /// @brief withCommStatus tests -TEST_F(TestUMessageBuilder, WithCommStatusOnResponseSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithCommStatusOnResponseSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT + EXPECT_NO_THROW({ builder.withCommStatus(v1::UCode::OK); }); // NOLINT } -TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, std::domain_error); // NOLINT + EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, // NOLINT + std::domain_error); } -TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { // NOLINT +TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withCommStatus(static_cast(-1)); }, // NOLINT - std::out_of_range); + EXPECT_THROW( // NOLINT + { builder.withCommStatus(static_cast(-1)); }, + std::out_of_range); } /// @brief withPayloadFormat tests -TEST_F(TestUMessageBuilder, WithPayloadFormatOnRequestSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithPayloadFormatOnRequestSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW( // NOLINT - { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); + EXPECT_NO_THROW( // NOLINT + { + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + }); } -TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { // NOLINT auto builder = createFakeResponse(); - EXPECT_NO_THROW( // NOLINT - { builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); }); + EXPECT_NO_THROW( // NOLINT + { + builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); + }); } -TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + WithPayloadFormatInvalidValueLessThanMinThrows) { auto builder = createFakeRequest(); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { builder.withPayloadFormat( static_cast(v1::UPayloadFormat_MIN - 1)); @@ -437,9 +475,10 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueLessThanMinThrows) { std::out_of_range); } -TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + WithPayloadFormatInvalidValueMoreThanMaxThrows) { auto builder = createFakeRequest(); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { builder.withPayloadFormat( static_cast(v1::UPayloadFormat_MAX + 1)); @@ -448,12 +487,12 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatInvalidValueMoreThanMaxThrows) { } /// @brief build() tests -TEST_F(TestUMessageBuilder, BuildWithPayloadFormatSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, BuildWithPayloadFormatSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW({ auto message = builder.build(); }); // NOLINT + EXPECT_NO_THROW({ auto message = builder.build(); }); // NOLINT } -TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { // NOLINT +TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { // NOLINT auto builder = createFakeRequest(); auto message = builder.build(); EXPECT_TRUE(typeid(message) == typeid(v1::UMessage)); @@ -466,36 +505,43 @@ TEST_F(TestUMessageBuilder, BuildReturnsUMessage) { // NOLINT urisAreEqual(builder.attributes().sink(), message.attributes().sink())); } -TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { // NOLINT +TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto message = builder.build(); }, datamodel::builder::UMessageBuilder::UnexpectedFormat); } -TEST_F(TestUMessageBuilder, BuildWithPayloadWithPayloadFormatSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadWithPayloadFormatSuccess) { auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; - datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload( + data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); // NOLINT + EXPECT_NO_THROW( // NOLINT + { auto message = builder.build(std::move(payload)); }); } -TEST_F(TestUMessageBuilder, BuildWithPayloadWithoutPayloadFormatSuccess) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadWithoutPayloadFormatSuccess) { auto builder = createFakeRequest(); std::string data = "test-data"; - datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload( + data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW({ auto message = builder.build(std::move(payload)); }); // NOLINT + EXPECT_NO_THROW( // NOLINT + { auto message = builder.build(std::move(payload)); }); } -TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT +TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; - datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload( + data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); auto message = builder.build(std::move(payload)); EXPECT_TRUE(typeid(message) == typeid(v1::UMessage)); @@ -510,13 +556,15 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT EXPECT_TRUE(message.payload() == data); } -TEST_F(TestUMessageBuilder, BuildWithPayloadMismatchedPayloadFormatThrows) { // NOLINT +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadMismatchedPayloadFormatThrows) { auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); std::string data = "test-data"; - datamodel::builder::Payload payload(data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); + datamodel::builder::Payload payload( + data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto message = builder.build(std::move(payload)); }, datamodel::builder::UMessageBuilder::UnexpectedFormat); } diff --git a/test/coverage/datamodel/UMessageValidatorTest.cpp b/test/coverage/datamodel/UMessageValidatorTest.cpp index 17e36c255..185143292 100644 --- a/test/coverage/datamodel/UMessageValidatorTest.cpp +++ b/test/coverage/datamodel/UMessageValidatorTest.cpp @@ -15,7 +15,7 @@ #include #include -namespace uprotocol::v1{ +namespace uprotocol::v1 { class TestUMessageValidator : public testing::Test { private: @@ -23,6 +23,7 @@ class TestUMessageValidator : public testing::Test { UUri sink_; // Note: this is used when intentionally setting an unexpected request ID UUID reqId_; + protected: // Run once per TEST_F. // Used to set up clean environments per test. @@ -58,8 +59,8 @@ class TestUMessageValidator : public testing::Test { static void TearDownTestSuite() {} UUri& getSource() { return source_; } - UUri& getSink() { return sink_;} - const UUID& getReqId() const { return reqId_;} + UUri& getSink() { return sink_; } + const UUID& getReqId() const { return reqId_; } public: ~TestUMessageValidator() override = default; @@ -67,7 +68,7 @@ class TestUMessageValidator : public testing::Test { UAttributes fakeRequest(const UUri& source, const UUri& sink) { constexpr uint16_t DEFAULT_TTL = 1000; - + UAttributes attributes; static auto uuid_builder = @@ -103,7 +104,7 @@ UAttributes fakeResponse(const UUri& sink, const UUri& source) { UAttributes fakePublish(const UUri& source) { constexpr uint16_t DEFAULT_TTL = 1000; - + UAttributes attributes; static auto uuid_builder = @@ -140,88 +141,106 @@ UMessage build(UAttributes& attributes) { } void testValidWithTTL(UAttributes& attributes_in) { - auto attributes = UAttributes(attributes_in); - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_TRUE(valid); - EXPECT_FALSE(reason.has_value()); + auto attributes = UAttributes(attributes_in); + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_TRUE(valid); + EXPECT_FALSE(reason.has_value()); } void testValidWithoutTTL(UAttributes& attributes_in) { - auto attributes = UAttributes(attributes_in); - attributes.clear_ttl(); - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_TRUE(valid); - EXPECT_FALSE(reason.has_value()); + auto attributes = UAttributes(attributes_in); + attributes.clear_ttl(); + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_TRUE(valid); + EXPECT_FALSE(reason.has_value()); } void testMissingId(UAttributes& attributes_in) { - auto attributes = UAttributes(attributes_in); - attributes.clear_id(); - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); + auto attributes = UAttributes(attributes_in); + attributes.clear_id(); + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); } void testInvalidId(UAttributes& attributes_in) { - auto attributes = UAttributes(attributes_in); - UUID local_id(attributes.id()); - local_id.set_lsb(0); - *attributes.mutable_id() = local_id; - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); + auto attributes = UAttributes(attributes_in); + UUID local_id(attributes.id()); + local_id.set_lsb(0); + *attributes.mutable_id() = local_id; + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_ID); } void testExpiredTTL(UAttributes& attributes_in) { - constexpr uint16_t SLEEP_TIME = 20000; - constexpr uint16_t DEFAULT_TTL = 10; - - auto attributes = UAttributes(attributes_in); - attributes.set_ttl(DEFAULT_TTL); - usleep(SLEEP_TIME); // sleep (id should be expired by now) - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); + constexpr uint16_t SLEEP_TIME = 20000; + constexpr uint16_t DEFAULT_TTL = 10; + + auto attributes = UAttributes(attributes_in); + attributes.set_ttl(DEFAULT_TTL); + usleep(SLEEP_TIME); // sleep (id should be expired by now) + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, + uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); } void testOutOfRangePriority(UAttributes& attributes_in) { - constexpr uint16_t DEFAULT_TTL = 10; - - auto attributes = UAttributes(attributes_in); - attributes.set_priority(UPriority(UPriority_MAX + DEFAULT_TTL)); - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); + constexpr uint16_t DEFAULT_TTL = 10; + + auto attributes = UAttributes(attributes_in); + attributes.set_priority(UPriority(UPriority_MAX + DEFAULT_TTL)); + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + PRIORITY_OUT_OF_RANGE); } void testOutOfRangePayloadFormat(UAttributes& attributes_in) { - constexpr uint16_t DEFAULT_TTL = 10; - - auto attributes = UAttributes(attributes_in); - attributes.set_payload_format(UPayloadFormat(UPayloadFormat_MAX + DEFAULT_TTL)); - auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::areCommonAttributesValid(umessage); - EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PAYLOAD_FORMAT_OUT_OF_RANGE); + constexpr uint16_t DEFAULT_TTL = 10; + + auto attributes = UAttributes(attributes_in); + attributes.set_payload_format( + UPayloadFormat(UPayloadFormat_MAX + DEFAULT_TTL)); + auto umessage = build(attributes); + auto [valid, reason] = + uprotocol::datamodel::validator::message::areCommonAttributesValid( + umessage); + EXPECT_FALSE(valid); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + PAYLOAD_FORMAT_OUT_OF_RANGE); } void testCommonAttributes(UAttributes& attributes_in) { - testValidWithTTL(attributes_in); - testValidWithoutTTL(attributes_in); - testMissingId(attributes_in); - testInvalidId(attributes_in); - testExpiredTTL(attributes_in); - testOutOfRangePriority(attributes_in); - testOutOfRangePayloadFormat(attributes_in); + testValidWithTTL(attributes_in); + testValidWithoutTTL(attributes_in); + testMissingId(attributes_in); + testInvalidId(attributes_in); + testExpiredTTL(attributes_in); + testOutOfRangePriority(attributes_in); + testOutOfRangePayloadFormat(attributes_in); } -TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT +TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT getSource().set_resource_id(0); // must be 0 for valid requests { @@ -234,7 +253,9 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT // valid auto attributes = fakeRequest(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -244,9 +265,12 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_RESPONSE); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + WRONG_MESSAGE_TYPE); } { @@ -254,9 +278,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -264,9 +292,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { @@ -275,9 +307,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT source.set_resource_id(1); // should be zero auto attributes = fakeRequest(source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -286,9 +322,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT sink.set_resource_id(0); // should NOT be zero auto attributes = fakeRequest(getSource(), sink); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { @@ -296,9 +336,12 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.set_priority(UPRIORITY_CS3); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + PRIORITY_OUT_OF_RANGE); } { @@ -306,9 +349,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.clear_ttl(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } { @@ -316,9 +363,13 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.set_ttl(0); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } { @@ -326,9 +377,12 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -336,13 +390,16 @@ TEST_F(TestUMessageValidator, ValidRpcRequest) { // NOLINT auto attributes = fakeRequest(getSource(), getSink()); *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcRequest(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcRequest( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT +TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT getSource().set_resource_id(0); { @@ -355,7 +412,9 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT // valid auto attributes = fakeResponse(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Only for debugging a test - should only happen if test is already @@ -370,9 +429,12 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + WRONG_MESSAGE_TYPE); } { @@ -380,9 +442,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -390,9 +456,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { @@ -401,9 +471,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT source.set_resource_id(1); // should be zero auto attributes = fakeResponse(source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { @@ -412,9 +486,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT sink.set_resource_id(0); // should NOT be zero auto attributes = fakeResponse(getSource(), sink); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -423,9 +501,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_reqid(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { @@ -436,9 +518,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); *attributes.mutable_reqid() = local_id; auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { @@ -446,7 +532,9 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.clear_ttl(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -458,9 +546,12 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT attributes.set_ttl(1); usleep(SLEEP_TIME); // sleep (id should be expired by now) auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); + EXPECT_EQ(reason, + uprotocol::datamodel::validator::message::Reason::ID_EXPIRED); } { @@ -468,9 +559,12 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.set_priority(UPRIORITY_CS3); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + PRIORITY_OUT_OF_RANGE); } { @@ -479,9 +573,12 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -489,13 +586,16 @@ TEST_F(TestUMessageValidator, ValidRpcResponse) { // NOLINT auto attributes = fakeResponse(getSource(), getSink()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponse(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponse( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT +TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT getSource().set_resource_id(0); { @@ -505,7 +605,9 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT *res_attr.mutable_reqid() = req_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Only for debugging test - shows reason when test is already failing @@ -521,9 +623,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT res_attr.clear_reqid(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { @@ -533,9 +639,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT *res_attr.mutable_reqid() = res_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::REQID_MISMATCH); } { @@ -546,9 +656,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT res_attr.sink().ue_version_major() + 1); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); } { @@ -559,9 +673,13 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT res_attr.source().ue_version_major() + 1); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::URI_MISMATCH); } { @@ -572,16 +690,21 @@ TEST_F(TestUMessageValidator, ValidRpcResponseFor) { // NOLINT *res_attr.mutable_reqid() = req_attr.id(); auto request = build(req_attr); auto response = build(res_attr); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidRpcResponseFor(request, response); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidRpcResponseFor( + request, response); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::PRIORITY_MISMATCH); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + PRIORITY_MISMATCH); // Test debugging - EXPECT_EQ(message(*reason), message(uprotocol::datamodel::validator::message::Reason::PRIORITY_MISMATCH)); + EXPECT_EQ(message(*reason), + message(uprotocol::datamodel::validator::message::Reason:: + PRIORITY_MISMATCH)); } } -TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT - constexpr uint32_t SOURCE_RESOURCE_ID = 0x8000; +TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT + constexpr uint32_t SOURCE_RESOURCE_ID = 0x8000; getSource().set_resource_id(SOURCE_RESOURCE_ID); { @@ -594,7 +717,8 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT // valid auto attributes = fakePublish(getSource()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -604,9 +728,11 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + WRONG_MESSAGE_TYPE); } { @@ -614,21 +740,28 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // invalid source - constexpr uint32_t SOURCE_RESOURCE_ID_INVALID = 0x7FFF; + constexpr uint32_t SOURCE_RESOURCE_ID_INVALID = 0x7FFF; UUri source = getSource(); - source.set_resource_id(SOURCE_RESOURCE_ID_INVALID); // should greater than 0x8000 + source.set_resource_id( + SOURCE_RESOURCE_ID_INVALID); // should greater than 0x8000 auto attributes = fakePublish(source); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -636,9 +769,11 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); *attributes.mutable_sink() = getSink(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -646,9 +781,11 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -656,9 +793,11 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -667,9 +806,11 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -677,13 +818,15 @@ TEST_F(TestUMessageValidator, ValidPublish) { // NOLINT auto attributes = fakePublish(getSource()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidPublish(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidPublish(umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT +TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT constexpr uint32_t SOURCE_RESOURCE_ID = 0x8001; getSource().set_resource_id(SOURCE_RESOURCE_ID); getSink().set_resource_id(0); @@ -698,7 +841,9 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT // valid auto attributes = fakeNotification(getSource(), getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -708,9 +853,12 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.set_type(UMESSAGE_TYPE_REQUEST); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::WRONG_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + WRONG_MESSAGE_TYPE); } { @@ -718,9 +866,13 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.clear_source(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -728,33 +880,47 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.clear_sink(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { // invalid source constexpr uint32_t LOCAL_SOURCE_RESOURCE_ID = 0x7FFF; UUri local_source = getSource(); - local_source.set_resource_id(LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 + local_source.set_resource_id( + LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 auto attributes = fakeNotification(local_source, getSink()); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { // invalid sink constexpr uint32_t LOCAL_SOURCE_RESOURCE_ID = 0x7FFF; UUri local_sink = getSink(); - local_sink.set_resource_id(LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 + local_sink.set_resource_id( + LOCAL_SOURCE_RESOURCE_ID); // should be greater than 0x8000 auto attributes = fakeNotification(getSource(), local_sink); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::BAD_SINK_URI); } { @@ -762,9 +928,12 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.set_commstatus(OK); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -772,9 +941,12 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); *attributes.mutable_reqid() = getReqId(); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -783,9 +955,12 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.set_permission_level(ATTRIBUTES_PERMISSION_LEVEL); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } { @@ -793,13 +968,16 @@ TEST_F(TestUMessageValidator, ValidNotification) { // NOLINT auto attributes = fakeNotification(getSource(), getSink()); attributes.set_token("token"); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValidNotification(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValidNotification( + umessage); EXPECT_FALSE(valid); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } } -TEST_F(TestUMessageValidator, IsValid) { // NOLINT +TEST_F(TestUMessageValidator, IsValid) { // NOLINT { // valid request auto source = getSource(); @@ -809,7 +987,8 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT auto attributes = fakeRequest(source, sink); auto umessage = build(attributes); { - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); } @@ -820,10 +999,12 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT uprotocol::v1::UMessageType::UMESSAGE_TYPE_UNSPECIFIED); umessage = build(attributes); { - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::UNSPECIFIED_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + UNSPECIFIED_MESSAGE_TYPE); } // Check with an invalid type @@ -832,10 +1013,12 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT static_cast(max_type + 1)); umessage = build(attributes); { - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_MESSAGE_TYPE); + EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason:: + INVALID_MESSAGE_TYPE); } // Restore the message type to finish out the test @@ -845,10 +1028,13 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT attributes.set_ttl(0); umessage = build(attributes); { - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid); EXPECT_TRUE(reason.has_value()); - EXPECT_EQ(reason, uprotocol::datamodel::validator::message::Reason::INVALID_TTL); + EXPECT_EQ( + reason, + uprotocol::datamodel::validator::message::Reason::INVALID_TTL); } } @@ -860,7 +1046,8 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT auto attributes = fakeResponse(source, sink); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -868,10 +1055,13 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT attributes = fakeResponse(sink, source); umessage = build(attributes); - auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid2, reason2] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); + EXPECT_EQ( + reason2, + uprotocol::datamodel::validator::message::Reason::BAD_SOURCE_URI); } { @@ -883,18 +1073,22 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT auto attributes = fakePublish(source); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); // Make the request invalid by making one change - attributes.set_priority(static_cast(ATTRIBUTES_INVALID_PRIORITY)); + attributes.set_priority( + static_cast(ATTRIBUTES_INVALID_PRIORITY)); umessage = build(attributes); - auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid2, reason2] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::PRIORITY_OUT_OF_RANGE); + EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason:: + PRIORITY_OUT_OF_RANGE); } { @@ -907,7 +1101,8 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT auto attributes = fakeNotification(source, sink); auto umessage = build(attributes); - auto [valid, reason] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid, reason] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_TRUE(valid); EXPECT_FALSE(reason.has_value()); @@ -915,10 +1110,12 @@ TEST_F(TestUMessageValidator, IsValid) { // NOLINT *(attributes.mutable_reqid()) = attributes.id(); umessage = build(attributes); - auto [valid2, reason2] = uprotocol::datamodel::validator::message::isValid(umessage); + auto [valid2, reason2] = + uprotocol::datamodel::validator::message::isValid(umessage); EXPECT_FALSE(valid2); EXPECT_TRUE(reason2.has_value()); - EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason::DISALLOWED_FIELD_SET); + EXPECT_EQ(reason2, uprotocol::datamodel::validator::message::Reason:: + DISALLOWED_FIELD_SET); } } diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index 0e6f725cf..5cd90a84e 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -17,7 +17,7 @@ constexpr uint32_t DEFAULT_RESOURCE_ID = 0x7500; constexpr uint32_t DEFAULT_UE_ID = 0x10010001; constexpr uint32_t DEFAULT_VERSION_MAJOR = 0xFE; -namespace uprotocol::datamodel::serializer::uri{ +namespace uprotocol::datamodel::serializer::uri { class TestUUriSerializer : public testing::Test { protected: @@ -34,11 +34,13 @@ class TestUUriSerializer : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestUUriSerializer() override = default; }; -uprotocol::v1::UUri buildValidTestURI(const std::string& authority = "192.168.1.10") { +uprotocol::v1::UUri buildValidTestURI( + const std::string& authority = "192.168.1.10") { uprotocol::v1::UUri uri; uri.set_authority_name(authority); uri.set_ue_id(DEFAULT_UE_ID); @@ -48,7 +50,7 @@ uprotocol::v1::UUri buildValidTestURI(const std::string& authority = "192.168.1. } // Positive test case - test serialization of UUri to string -TEST_F(TestUUriSerializer, SerializeUUriToString) { // NOLINT +TEST_F(TestUUriSerializer, SerializeUUriToString) { // NOLINT auto test_u_uri = buildValidTestURI(); const std::string expected_u_uri = "//192.168.1.10/10010001/FE/7500"; const std::string actual_u_uri = AsString::serialize(test_u_uri); @@ -56,7 +58,7 @@ TEST_F(TestUUriSerializer, SerializeUUriToString) { // NOLINT } // Positive test case - test serialization of UUri with no authority to string -TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT +TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT auto test_u_uri = buildValidTestURI(""); const std::string expected_u_uri = "/10010001/FE/7500"; const std::string actual_u_uri = AsString::serialize(test_u_uri); @@ -65,7 +67,8 @@ TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT // Test authority name '*' to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithAuthorityWildCard) { constexpr uint32_t WILDCARD = 0x1FFFE; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("*"); // Wildcard @@ -73,13 +76,14 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithAuthorityWildCard) { // NOLI test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//*/1FFFE/FE/7500"); } // Test Service ID in uEID field as a 0xFFFF to see if it serializes without // an exception for using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithServiceIDWildCard) { constexpr uint32_t WILDCARD = 0x1FFFF; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("testAuthority"); @@ -87,13 +91,14 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithServiceIDWildCard) { // NOLI test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/1FFFF/FE/7500"); } // Test Instance ID in uEID field as a 0x0 to see if it serializes without an // exception for using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithInstanceIDWildCard) { constexpr uint32_t WILDCARD = 0x00001234; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("testAuthority"); @@ -101,13 +106,14 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInstanceIDWildCard) { // NOL test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/1234/FE/7500"); } // Test major version as 0xFF to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithMajorVersionWildCard) { constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFF; uprotocol::v1::UUri test_u_uri; @@ -116,13 +122,14 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithMajorVersionWildCard) { // N test_u_uri.set_ue_version_major(WILDCARD); // Wildcard test_u_uri.set_resource_id(DEFAULT_RESOURCE_ID); std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/12340000/FF/7500"); } // Test resource id as 0xFFFF to see if it thorws an exception for using // wildcard -TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithResourceIDWildCard) { constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFFFF; uprotocol::v1::UUri test_u_uri; @@ -131,12 +138,12 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithResourceIDWildCard) { // NOL test_u_uri.set_ue_version_major(DEFAULT_VERSION_MAJOR); test_u_uri.set_resource_id(WILDCARD); // Wildcard std::string serialized; - ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT + ASSERT_NO_THROW(serialized = AsString::serialize(test_u_uri)); // NOLINT ASSERT_EQ(serialized, "//testAuthority/12340000/FE/FFFF"); } // Attempt to serialize invalid UUris and verify exceptions are thrown -TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT +TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT constexpr uint32_t AUTHORITY_NAME_NUMBER = 129; constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFFFE; @@ -155,32 +162,37 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT // Empty UUri uprotocol::v1::UUri test_u_uri; - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Authority name too long test_u_uri = base_u_uri; test_u_uri.set_authority_name(std::string(AUTHORITY_NAME_NUMBER, 'b')); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Version out of uint8 range test_u_uri = base_u_uri; test_u_uri.set_ue_version_major(INVALID_VERSION_MAJOR); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Version reserved test_u_uri = base_u_uri; test_u_uri.set_ue_version_major(0); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Resource ID out of uint16 range test_u_uri = base_u_uri; test_u_uri.set_resource_id(INVALID_RESOURCE_ID); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); } // Test deserialize by providing scheme "up:" which is allowed to have as per // spec -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT const std::string uuri_as_string = "up://192.168.1.10/10010001/FE/7500"; const std::string expected_authority = "192.168.1.10"; const uint32_t expected_ue_id = DEFAULT_UE_ID; @@ -195,14 +207,16 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT } // Test deserialize by providing incorrect scheme "uprotocol:" -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithIncorrectScheme) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithIncorrectScheme) { const std::string uuri_as_string = "uprotocol://192.168.1.10/10010001/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); } // Test deserialize without providing scheme "up:" -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT const std::string uuri_as_string = "//192.168.1.10/10010001/FE/7500"; const std::string expected_authority = "192.168.1.10"; const uint32_t expected_ue_id = DEFAULT_UE_ID; @@ -217,13 +231,14 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT } // Test deserializing empty string to check if it thorws an exception -TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT +TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT const std::string uuri_as_string; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); } // Test deserializing string with no authority -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT const std::string uuri_as_string = "/10010001/FE/7500"; const std::string expected_authority; const uint32_t expected_ue_id = DEFAULT_UE_ID; @@ -238,71 +253,88 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT } // Test deserializing string with invalid number of arguments -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidNumberOfArgument) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithInvalidNumberOfArgument) { // Provided 5 arguments instead of 4 when authority exist std::string uuri_as_string = "//192.168.1.10/10010001/FE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // UE ID is missing. Provided 3 arguments instead of 4 when authority exist. uuri_as_string = "//192.168.1.10/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Provided 4 arguments instead of 3 when authority does not exist. uuri_as_string = "/1102/FE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // UE ID is missing. Provided 2 arguments instead of 3 when authority does // not exist. uuri_as_string = "/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "192.168.1.10/1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Valid Uri but leading /// . uuri_as_string = "///192.168.1.10/1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Valid Uri but additional trailing / uuri_as_string = "//192.168.1.10/1102/FE/7500/"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); } // Test deserializing string with invalid arguments -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidArgument) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithInvalidArgument) { // UE ID provided is invalid. It should be hex numeric std::string uuri_as_string = "//192.168.1.10/testUE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Major Version provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/^%/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Resource ID provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/FE/xyz"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // UE ID is outside the 32-bit int range uuri_as_string = "//192.168.1.10/110010001/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Major Version is outside the 8-bit int range uuri_as_string = "//192.168.1.10/10010001/100/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); // Resiource ID is outside the 16-bit int range uuri_as_string = "//192.168.1.10/10010001/FE/10000"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // NOLINT + ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT + std::invalid_argument); } // Test deserializing string with wildcard arguments to see if throws exception -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLINT +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithWildcardArgument) { constexpr uint32_t UE_SERVICE_ID_WILDCARD = 0x1FFFF; constexpr uint32_t UE_INSTANCE_ID_WILDCARD = 0x1234; constexpr uint32_t VERSION_MAJOR_WILDCARD = 0xFF; @@ -319,64 +351,72 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithWildcardArgument) { // NOLIN // Authority name provided in ueID is wildcard as "*" std::string uuri_as_string = "//*/1FFFF/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Authority Name Wildcard"); - check_uri("*", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); + check_uri("*", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, + DEFAULT_RESOURCE_ID); } // Service ID provided in ueID is wildcard as 0xFFFF uuri_as_string = "//192.168.1.10/1FFFF/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Service ID Wildcard"); - check_uri("192.168.1.10", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); + check_uri("192.168.1.10", UE_SERVICE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, + DEFAULT_RESOURCE_ID); } // Instance ID provided in ueID is wildcard as 0x0 uuri_as_string = "//192.168.1.10/00001234/FE/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Instance ID Wildcard"); - check_uri("192.168.1.10", UE_INSTANCE_ID_WILDCARD, DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); + check_uri("192.168.1.10", UE_INSTANCE_ID_WILDCARD, + DEFAULT_VERSION_MAJOR, DEFAULT_RESOURCE_ID); } // Major Version provided is wildcard as 0xFF uuri_as_string = "//192.168.1.10/10010001/FF/7500"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Major Version Wildcard"); - check_uri("192.168.1.10", DEFAULT_UE_ID, VERSION_MAJOR_WILDCARD, DEFAULT_RESOURCE_ID); + check_uri("192.168.1.10", DEFAULT_UE_ID, VERSION_MAJOR_WILDCARD, + DEFAULT_RESOURCE_ID); } // Resource ID provided is wildcard as 0xFFFF uuri_as_string = "//192.168.1.10/10010001/FE/FFFF"; - ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT + ASSERT_NO_THROW(uuri = AsString::deserialize(uuri_as_string)); // NOLINT { SCOPED_TRACE("uE Resource ID Wildcard"); - check_uri("192.168.1.10", DEFAULT_UE_ID, DEFAULT_VERSION_MAJOR, RESOURCE_ID_WILDCARD); + check_uri("192.168.1.10", DEFAULT_UE_ID, DEFAULT_VERSION_MAJOR, + RESOURCE_ID_WILDCARD); } } // Test deserializing string with invalid field values to verify exceptions are // thrown -TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT +TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT constexpr uint32_t UURI_NUMBER = 129; uprotocol::v1::UUri uuri; // Major Version reserved std::string uuri_as_string = "//192.168.1.10/1FFFE/0/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Empty UUri uuri_as_string = "// /0/0/0"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Major Version reserved uuri_as_string = "//"; uuri_as_string += std::string(UURI_NUMBER, 'a'); uuri_as_string += "/1FFFE/1/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // NOTE These are also checked earlier against the std::invalid_argument // exception. They can be caught either way. These can be checked against @@ -384,11 +424,13 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT // Major Version outside the uint8 range uuri_as_string = "//192.168.1.10/1FFFE/FFFE/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Resource ID outside the uint8 range uuri_as_string = "//192.168.1.10/1FFFE/FE/C0FFEEEE"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), uprotocol::datamodel::validator::uri::InvalidUUri); // NOLINT + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); } } // namespace uprotocol::datamodel::serializer::uri diff --git a/test/coverage/datamodel/UUriValidatorTest.cpp b/test/coverage/datamodel/UUriValidatorTest.cpp index 53bb04e90..a1ffbb89f 100644 --- a/test/coverage/datamodel/UUriValidatorTest.cpp +++ b/test/coverage/datamodel/UUriValidatorTest.cpp @@ -15,7 +15,7 @@ constexpr uint32_t DEFAULT_UE_ID = 0x00010001; constexpr uint32_t WILDCARD = 0xFFFF; -namespace uprotocol::datamodel::validator::uri{ +namespace uprotocol::datamodel::validator::uri { constexpr const char* AUTHORITY_NAME = "test"; @@ -34,11 +34,12 @@ class TestUUriValidator : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestUUriValidator() override = default; }; -TEST_F(TestUUriValidator, Valid) { // NOLINT +TEST_F(TestUUriValidator, Valid) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -110,7 +111,7 @@ TEST_F(TestUUriValidator, Valid) { // NOLINT } } -TEST_F(TestUUriValidator, Wildcards) { // NOLINT +TEST_F(TestUUriValidator, Wildcards) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -160,7 +161,7 @@ TEST_F(TestUUriValidator, Wildcards) { // NOLINT } } -TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT +TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -211,7 +212,7 @@ TEST_F(TestUUriValidator, ValidRpcMethod) { // NOLINT } } -TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT +TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -261,7 +262,7 @@ TEST_F(TestUUriValidator, ValidRpcResponse) { // NOLINT } } -TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT +TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT constexpr uint32_t VALID_RESOURCE_ID = 0x8000; auto get_u_uri = []() { uprotocol::v1::UUri uuri; @@ -321,7 +322,7 @@ TEST_F(TestUUriValidator, ValidPublishTopic) { // NOLINT } } -TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT +TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT constexpr uint32_t VALID_RESOURCE_ID = 0x8000; auto get_u_uri = []() { uprotocol::v1::UUri uuri; @@ -381,7 +382,7 @@ TEST_F(TestUUriValidator, ValidNotificationSource) { // NOLINT } } -TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT +TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(AUTHORITY_NAME); @@ -431,7 +432,7 @@ TEST_F(TestUUriValidator, ValidNotificationSink) { // NOLINT } } -TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT +TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT constexpr uint32_t VALID_RESOURCE_ID = 0x8000; auto get_u_uri = []() { uprotocol::v1::UUri uuri; @@ -484,7 +485,7 @@ TEST_F(TestUUriValidator, ValidSubscription) { // NOLINT } } -TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT +TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT constexpr uint32_t VALID_RESOURCE_ID = 0x8000; auto get_u_uri = []() { uprotocol::v1::UUri uuri; @@ -504,7 +505,7 @@ TEST_F(TestUUriValidator, ValidDefaultSource) { // NOLINT } } -TEST_F(TestUUriValidator, Empty) { // NOLINT +TEST_F(TestUUriValidator, Empty) { // NOLINT auto get_u_uri = []() { uprotocol::v1::UUri uuri; uuri.set_authority_name(""); @@ -562,7 +563,7 @@ TEST_F(TestUUriValidator, Empty) { // NOLINT } } -TEST_F(TestUUriValidator, ValidFilter) { // NOLINT +TEST_F(TestUUriValidator, ValidFilter) { // NOLINT constexpr uint32_t VALID_UE_ID_FILTER = 10001; auto get_u_uri = []() { uprotocol::v1::UUri uuri; @@ -648,7 +649,7 @@ TEST_F(TestUUriValidator, ValidFilter) { // NOLINT } } -TEST_F(TestUUriValidator, ReasonMessages) { // NOLINT +TEST_F(TestUUriValidator, ReasonMessages) { // NOLINT std::array all_reasons{Reason::EMPTY, Reason::RESERVED_VERSION, Reason::RESERVED_RESOURCE, diff --git a/test/coverage/datamodel/UuidBuilderTest.cpp b/test/coverage/datamodel/UuidBuilderTest.cpp index f770f59b0..8207f3cee 100644 --- a/test/coverage/datamodel/UuidBuilderTest.cpp +++ b/test/coverage/datamodel/UuidBuilderTest.cpp @@ -15,7 +15,7 @@ #include "up-cpp/datamodel/constants/UuidConstants.h" // using namespace uprotocol::datamodel::builder::; -namespace uprotocol::datamodel{ +namespace uprotocol::datamodel { class TestUuidBuilder : public testing::Test { protected: @@ -26,12 +26,13 @@ class TestUuidBuilder : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestUuidBuilder() override = default; }; // Test getBuilder -TEST(UuidBuilderTest, GetBuilder) { // NOLINT +TEST(UuidBuilderTest, GetBuilder) { // NOLINT auto builder = builder::UuidBuilder::getBuilder(); auto uuid = builder.build(); @@ -40,7 +41,7 @@ TEST(UuidBuilderTest, GetBuilder) { // NOLINT } // Test GetTestBuilder -TEST(UuidBuilderTest, GetTestBuilder) { // NOLINT +TEST(UuidBuilderTest, GetTestBuilder) { // NOLINT auto builder = builder::UuidBuilder::getTestBuilder(); auto uuid = builder.build(); @@ -49,7 +50,7 @@ TEST(UuidBuilderTest, GetTestBuilder) { // NOLINT } // Test TestBuilder with time source -TEST(UuidBuilderTest, WithTimeSource) { // NOLINT +TEST(UuidBuilderTest, WithTimeSource) { // NOLINT constexpr std::time_t FIXED_TIME_T = 1234567890; auto fixed_time = std::chrono::system_clock::from_time_t(FIXED_TIME_T); auto fixed_time_ms = @@ -63,7 +64,7 @@ TEST(UuidBuilderTest, WithTimeSource) { // NOLINT } // Test RandomSource -TEST(UuidBuilderTest, WithRandomSource) { // NOLINT +TEST(UuidBuilderTest, WithRandomSource) { // NOLINT constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; uint64_t fixed_random = FIXED_RANDOM_T; auto builder = builder::UuidBuilder::getTestBuilder().withRandomSource( @@ -77,7 +78,7 @@ TEST(UuidBuilderTest, WithRandomSource) { // NOLINT } // Test independent state -TEST(UuidBuilderTest, Unguessability) { // NOLINT +TEST(UuidBuilderTest, Unguessability) { // NOLINT auto builder1 = builder::UuidBuilder::getBuilder(); auto builder2 = builder::UuidBuilder::getBuilder(); @@ -105,18 +106,19 @@ TEST(UuidBuilderTest, Unguessability) { // NOLINT } // Test exception thrown -TEST(UuidBuilderTest, TestModeOnly) { // NOLINT +TEST(UuidBuilderTest, TestModeOnly) { // NOLINT auto builder = builder::UuidBuilder::getBuilder(); - EXPECT_THROW(builder.withTimeSource( // NOLINT + EXPECT_THROW(builder.withTimeSource( // NOLINT []() { return std::chrono::system_clock::now(); }), std::domain_error); - EXPECT_THROW(builder.withRandomSource([]() { return 0x1234567890ABCDEF; }), // NOLINT + EXPECT_THROW(builder.withRandomSource( // NOLINT + []() { return 0x1234567890ABCDEF; }), std::domain_error); } // Test version and variant -TEST_F(TestUuidBuilder, CheckVersionAndVariant) { // NOLINT +TEST_F(TestUuidBuilder, CheckVersionAndVariant) { // NOLINT auto builder = builder::UuidBuilder::getBuilder(); auto uuid = builder.build(); @@ -127,7 +129,7 @@ TEST_F(TestUuidBuilder, CheckVersionAndVariant) { // NOLINT } // Test custom time and random source with builder -TEST(UuidBuilderTest, CustomTimeAndRandomSource) { // NOLINT +TEST(UuidBuilderTest, CustomTimeAndRandomSource) { // NOLINT constexpr std::time_t FIXED_TIME_T = 1623456789; constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; // Create a custom time source that returns a fixed timestamp diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index ce606ebe2..fa19a4647 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -15,7 +15,7 @@ #include -namespace uprotocol::datamodel::serializer::uuid{ +namespace uprotocol::datamodel::serializer::uuid { class TestUuidSerializer : public testing::Test { protected: @@ -32,68 +32,66 @@ class TestUuidSerializer : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestUuidSerializer() override = default; }; // Test string serialization -TEST_F(TestUuidSerializer, SerializeToString) { // NOLINT +TEST_F(TestUuidSerializer, SerializeToString) { // NOLINT constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; uprotocol::v1::UUID uuid; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string serialized_uuid = - AsString::serialize(uuid); + std::string serialized_uuid = AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "12345678-90ab-cdef-fedc-ba0987654321"); } // Test serialization with leading zeros in each segment -TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { // NOLINT +TEST_F(TestUuidSerializer, SerializeWithLeadingZeros) { // NOLINT constexpr uint64_t UUID_MSB = 0x00001234007800AB; constexpr uint64_t UUID_LSB = 0x00FE00BA09876543; uprotocol::v1::UUID uuid; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string serialized_uuid = - AsString::serialize(uuid); + std::string serialized_uuid = AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-0078-00ab-00fe-00ba09876543"); } // Test serialization with mixed case letters -TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { // NOLINT +TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { // NOLINT constexpr uint64_t UUID_MSB = 0x1234567890ABcDEF; constexpr uint64_t UUID_LSB = 0x00dcbA0987654321; uprotocol::v1::UUID uuid; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string serialized_uuid = - AsString::serialize(uuid); + std::string serialized_uuid = AsString::serialize(uuid); // Assert the serialized UUID matches the expected value in lowercase EXPECT_EQ(serialized_uuid, "12345678-90ab-cdef-00dc-ba0987654321"); } // Test serialization with leading zeros and mixed case letters -TEST_F(TestUuidSerializer, SerializeWithLeadingZerosAndMixedCaseLetters) { // NOLINT +TEST_F(TestUuidSerializer, // NOLINT + SerializeWithLeadingZerosAndMixedCaseLetters) { constexpr uint64_t UUID_MSB = 0x00001234567890AB; constexpr uint64_t UUID_LSB = 0xFedcba0987654982; uprotocol::v1::UUID uuid; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string serialized_uuid = - AsString::serialize(uuid); + std::string serialized_uuid = AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-5678-90ab-fedc-ba0987654982"); } // Test serialization with leading/trailing zeros and mixed case letters -TEST_F(TestUuidSerializer, // NOLINT +TEST_F(TestUuidSerializer, // NOLINT SerializeWithLeadingZerosAndTrailingZerosAndMixedCaseLetters) { constexpr uint64_t UUID_MSB = 0x00001234567890AB; constexpr uint64_t UUID_LSB = 0xFedcba0987600000; @@ -101,31 +99,28 @@ TEST_F(TestUuidSerializer, // NOLINT uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string serialized_uuid = - AsString::serialize(uuid); + std::string serialized_uuid = AsString::serialize(uuid); // Assert the serialized UUID matches the expected value EXPECT_EQ(serialized_uuid, "00001234-5678-90ab-fedc-ba0987600000"); } // Test string deserialization -TEST(DeserializerTest, DeserializeUUID) { // NOLINT +TEST(DeserializerTest, DeserializeUUID) { // NOLINT // Define a UUID string in the traditional format std::string uuid_str = "12345678-9abc-def0-fedc-ba9876543210"; // Deserialize the UUID string - uprotocol::v1::UUID deserialized_uuid = - AsString::deserialize(uuid_str); + uprotocol::v1::UUID deserialized_uuid = AsString::deserialize(uuid_str); // Assert the deserialized UUID matches the expected values EXPECT_EQ(deserialized_uuid.msb(), 0x123456789ABCDEF0); EXPECT_EQ(deserialized_uuid.lsb(), 0xFEDCBA9876543210); } // Test deserialization with leading/trailing zeros and mixed case letters -TEST_F(TestUuidSerializer, // NOLINT +TEST_F(TestUuidSerializer, // NOLINT DeserializeWithLeadingZerosAndTrailingZerosAndMixedCaseLetters) { std::string uuid_str = "00001234-5678-90ab-feDc-ba0987600000"; - uprotocol::v1::UUID deserialized_uuid = - AsString::deserialize(uuid_str); + uprotocol::v1::UUID deserialized_uuid = AsString::deserialize(uuid_str); // Assert the deserialized UUID matches the expected values EXPECT_EQ(deserialized_uuid.msb(), 0x00001234567890aB); @@ -133,153 +128,146 @@ TEST_F(TestUuidSerializer, // NOLINT } // Test invalid string deserialization -TEST(DeserializerTest, InvalidUUIDFormat) { // NOLINT +TEST(DeserializerTest, InvalidUUIDFormat) { // NOLINT // Define an invalid UUID string (missing dashes) std::string invalid_uuid_str = "123456789abcdef0123456789abcdef0"; // Assert that deserialization throws an invalid argument exception - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid_str)), std::invalid_argument); } // Test deserialization with correct length but incorrect placement of dashes -TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { // NOLINT +TEST(DeserializerTest, DeserializeWithMissingOneCharacter) { // NOLINT std::string invalid_uuid = "12345678-1234-5678-1234-56781234567"; // Missing one character - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid)), std::invalid_argument); } // Test deserialization with UUIDs that have an extra character -TEST(DeserializerTest, DeserializeWithExtraCharacter) { // NOLINT +TEST(DeserializerTest, DeserializeWithExtraCharacter) { // NOLINT std::string invalid_uuid1 = "12345678-1234-5678-1234-1234567890123"; // Extra character at the end - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid1)), std::invalid_argument); } -TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { //NOLINT +TEST(DeserializerTest, DeserializeWithIncorrectDashPlacement) { // NOLINT std::string invalid_uuid1 = "123456781-2345-6781-2345-67812345678"; // First Dash placement - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid1)), std::invalid_argument); std::string invalid_uuid2 = "12345678-12345-6781-2345-67812345678"; // Second Dash placement - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid2)), std::invalid_argument); std::string invalid_uuid3 = "12345678-1234-56781-2345-67812345678"; // Third Dash placement - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid3)), std::invalid_argument); std::string invalid_uuid4 = "12345678-1234-5678-12345-67812345678"; // Fourth Dash placement - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid4)), std::invalid_argument); } // Test deserialization with a zero-length string -TEST(DeserializerTest, DeserializeEmptyString) { // NOLINT +TEST(DeserializerTest, DeserializeEmptyString) { // NOLINT // Define an empty UUID string std::string empty_uuid_str; // Deserialize the empty UUID string - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT empty_uuid_str)), std::invalid_argument); } // Test deserialization with an invalid character in the UUID string -TEST(DeserializerTest, DeserializeInvalidCharacter) { // NOLINT +TEST(DeserializerTest, DeserializeInvalidCharacter) { // NOLINT // Define a UUID string with an invalid character ('x' instead of valid hex) std::string invalid_uuid_str = "1234567890ab-cdef-1234-5678-90abcdefxabc"; - EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT + EXPECT_THROW(static_cast(AsString::deserialize( // NOLINT invalid_uuid_str)), std::invalid_argument); } // Test byte serialization -TEST_F(TestUuidSerializer, SerializeToBytes) { // NOLINT +TEST_F(TestUuidSerializer, SerializeToBytes) { // NOLINT uprotocol::v1::UUID uuid; constexpr uint64_t UUID_MSB = 0x1234567890ABCDEF; constexpr uint64_t UUID_LSB = 0xFEDCBA0987654321; constexpr std::array EXPECTED_BYTES_ARRAY = { - 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, - 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 - }; + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21}; uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::vector uuid_bytes = - AsBytes::serialize(uuid); - std::vector expected_bytes(EXPECTED_BYTES_ARRAY.begin(), EXPECTED_BYTES_ARRAY.end()); + std::vector uuid_bytes = AsBytes::serialize(uuid); + std::vector expected_bytes(EXPECTED_BYTES_ARRAY.begin(), + EXPECTED_BYTES_ARRAY.end()); EXPECT_EQ(uuid_bytes, expected_bytes); } // Test byte deserialization -TEST_F(TestUuidSerializer, DeserializeFromBytes) { // NOLINT +TEST_F(TestUuidSerializer, DeserializeFromBytes) { // NOLINT constexpr std::array UUID_BYTES_ARRAY = { - 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, - 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21 - }; - std::vector uuid_bytes(UUID_BYTES_ARRAY.begin(), UUID_BYTES_ARRAY.end()); - uprotocol::v1::UUID uuid = - AsBytes::deserialize( - uuid_bytes); + 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, + 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21}; + std::vector uuid_bytes(UUID_BYTES_ARRAY.begin(), + UUID_BYTES_ARRAY.end()); + uprotocol::v1::UUID uuid = AsBytes::deserialize(uuid_bytes); EXPECT_EQ(uuid.msb(), 0x1234567890ABCDEF); EXPECT_EQ(uuid.lsb(), 0xFEDCBA0987654321); } // Test invalid byte deserialization -TEST_F(TestUuidSerializer, DeserializeInvalidBytes) { // NOLINT +TEST_F(TestUuidSerializer, DeserializeInvalidBytes) { // NOLINT constexpr std::array INVALID_BYTES_ARRAY = {0x12, 0x34, 0x56}; - std::vector invalid_bytes(INVALID_BYTES_ARRAY.begin(), INVALID_BYTES_ARRAY.end()); - EXPECT_THROW(static_cast(AsBytes::deserialize( // NOLINT + std::vector invalid_bytes(INVALID_BYTES_ARRAY.begin(), + INVALID_BYTES_ARRAY.end()); + EXPECT_THROW(static_cast(AsBytes::deserialize( // NOLINT invalid_bytes)), std::invalid_argument); } // Test edge case: minimum values for msb and lsb -TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { // NOLINT +TEST_F(TestUuidSerializer, SerializeDeserializeMinValues) { // NOLINT constexpr uint16_t NUM_BYTES = 16; uprotocol::v1::UUID uuid; uuid.set_msb(0x0000000000000000); uuid.set_lsb(0x0000000000000000); - std::string uuid_str = - AsString::serialize(uuid); + std::string uuid_str = AsString::serialize(uuid); EXPECT_EQ(uuid_str, "00000000-0000-0000-0000-000000000000"); - uprotocol::v1::UUID deserialized_uuid = - AsString::deserialize(uuid_str); + uprotocol::v1::UUID deserialized_uuid = AsString::deserialize(uuid_str); EXPECT_EQ(deserialized_uuid.msb(), 0x0000000000000000); EXPECT_EQ(deserialized_uuid.lsb(), 0x0000000000000000); - std::vector uuid_bytes = - AsBytes::serialize(uuid); - + std::vector uuid_bytes = AsBytes::serialize(uuid); + std::vector expected_bytes(NUM_BYTES, 0x00); EXPECT_EQ(uuid_bytes, expected_bytes); - deserialized_uuid = - AsBytes::deserialize( - uuid_bytes); + deserialized_uuid = AsBytes::deserialize(uuid_bytes); EXPECT_EQ(deserialized_uuid.msb(), 0x0000000000000000); EXPECT_EQ(deserialized_uuid.lsb(), 0x0000000000000000); } // Test edge case: maximum values for msb and lsb -TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { // NOLINT +TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { // NOLINT constexpr uint16_t NUM_BYTES = 16; constexpr uint16_t VAL_BYTES = 0xFF; uprotocol::v1::UUID uuid; @@ -288,23 +276,18 @@ TEST_F(TestUuidSerializer, SerializeDeserializeMaxValues) { // NOLINT uuid.set_msb(UUID_MSB); uuid.set_lsb(UUID_LSB); - std::string uuid_str = - AsString::serialize(uuid); + std::string uuid_str = AsString::serialize(uuid); EXPECT_EQ(uuid_str, "ffffffff-ffff-ffff-ffff-ffffffffffff"); - uprotocol::v1::UUID deserialized_uuid = - AsString::deserialize(uuid_str); + uprotocol::v1::UUID deserialized_uuid = AsString::deserialize(uuid_str); EXPECT_EQ(deserialized_uuid.msb(), 0xFFFFFFFFFFFFFFFF); EXPECT_EQ(deserialized_uuid.lsb(), 0xFFFFFFFFFFFFFFFF); - std::vector uuid_bytes = - AsBytes::serialize(uuid); + std::vector uuid_bytes = AsBytes::serialize(uuid); std::vector expected_bytes(NUM_BYTES, VAL_BYTES); EXPECT_EQ(uuid_bytes, expected_bytes); - deserialized_uuid = - AsBytes::deserialize( - uuid_bytes); + deserialized_uuid = AsBytes::deserialize(uuid_bytes); EXPECT_EQ(deserialized_uuid.msb(), 0xFFFFFFFFFFFFFFFF); EXPECT_EQ(deserialized_uuid.lsb(), 0xFFFFFFFFFFFFFFFF); } diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 23d3cacbc..46a753a38 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -19,8 +19,7 @@ constexpr std::chrono::seconds HUNDRED_SECONDS(100); constexpr std::chrono::seconds SIXTY_SECONDS(60); constexpr std::chrono::seconds THIRTY_SECONDS(30); - -namespace uprotocol::datamodel{ +namespace uprotocol::datamodel { // using namespace uprotocol::datamodel::validator::uuid::; class TestUuidValidator : public testing::Test { @@ -38,6 +37,7 @@ class TestUuidValidator : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestUuidValidator() override = default; }; @@ -55,13 +55,12 @@ uprotocol::v1::UUID createFakeUuid(uint64_t timestamp = 0) { // random value = 0xFFFFFFFFFFFF uuid.set_msb((timestamp << UUID_TIMESTAMP_SHIFT) | (UUID_VERSION_7 << UUID_VERSION_SHIFT) | (UUID_MSB)); - uuid.set_lsb((UUID_VARIANT_RFC4122 << UUID_VARIANT_SHIFT) | - (UUID_LSB)); + uuid.set_lsb((UUID_VARIANT_RFC4122 << UUID_VARIANT_SHIFT) | (UUID_LSB)); return uuid; } // Test valid UUID v7 -TEST_F(TestUuidValidator, ValidUuid) { // NOLINT +TEST_F(TestUuidValidator, ValidUuid) { // NOLINT // Create a valid UUID with version 7 and correct variant (10) auto uuid = createFakeUuid(); auto [valid, reason] = validator::uuid::isUuid(uuid); @@ -70,21 +69,23 @@ TEST_F(TestUuidValidator, ValidUuid) { // NOLINT } // Test UUID with wrong version -TEST_F(TestUuidValidator, WrongVersion) { // NOLINT +TEST_F(TestUuidValidator, WrongVersion) { // NOLINT // Creating a UUID with wrong version (!7) constexpr uint64_t UUID_MSB_VERSION8 = 8ULL; constexpr uint64_t UUID_MSB = 0x123ULL; auto uuid = createFakeUuid(); - uuid.set_msb((UUID_MSB_VERSION8 << UUID_VERSION_SHIFT) | (UUID_MSB)); // version 8 + uuid.set_msb((UUID_MSB_VERSION8 << UUID_VERSION_SHIFT) | + (UUID_MSB)); // version 8 auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::WRONG_VERSION); - EXPECT_THROW(validator::uuid::getVersion(uuid), validator::uuid::InvalidUuid); // NOLINT + EXPECT_THROW(validator::uuid::getVersion(uuid), // NOLINT + validator::uuid::InvalidUuid); } // Test UUID with unsupported variant -TEST_F(TestUuidValidator, UnsupportedVariant) { // NOLINT +TEST_F(TestUuidValidator, UnsupportedVariant) { // NOLINT // Creating UUID with unsupported variant.(!10) auto uuid = createFakeUuid(); uuid.set_lsb(uuid.lsb() | (3ULL << UUID_VARIANT_SHIFT)); // variant 11 @@ -92,12 +93,13 @@ TEST_F(TestUuidValidator, UnsupportedVariant) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::UNSUPPORTED_VARIANT); - EXPECT_THROW(validator::uuid::getVariant(uuid), validator::uuid::InvalidUuid); // NOLINT + EXPECT_THROW(validator::uuid::getVariant(uuid), // NOLINT + validator::uuid::InvalidUuid); } // Test UUID from the future // Exception on getRemainingTime() -TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT +TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT // Creating UUID with a timestamp in the future auto future_time = std::chrono::system_clock::now() + HUNDRED_SECONDS; auto future_timestamp = @@ -109,26 +111,27 @@ TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::FROM_THE_FUTURE); - EXPECT_THROW(validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), validator::uuid::InvalidUuid); // NOLINT + EXPECT_THROW(validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), // NOLINT + validator::uuid::InvalidUuid); } // Test expired UUID -TEST_F(TestUuidValidator, ExpiredUuid) { // NOLINT +TEST_F(TestUuidValidator, ExpiredUuid) { // NOLINT // Creating a UUID with a past timestamp auto past_time = std::chrono::system_clock::now() - HUNDRED_SECONDS; - auto past_timestamp = - std::chrono::duration_cast( - past_time.time_since_epoch()) - .count(); + auto past_timestamp = std::chrono::duration_cast( + past_time.time_since_epoch()) + .count(); auto uuid = createFakeUuid(static_cast(past_timestamp)); - auto [valid, reason] = validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL + auto [valid, reason] = + validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL EXPECT_TRUE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::EXPIRED); } // Test non-expired UUID -TEST_F(TestUuidValidator, NonExpiredUuid) { // NOLINT +TEST_F(TestUuidValidator, NonExpiredUuid) { // NOLINT // Creating a UUID with a recent timestamp auto recent_time = std::chrono::system_clock::now() - THIRTY_SECONDS; auto recent_timestamp = @@ -137,28 +140,30 @@ TEST_F(TestUuidValidator, NonExpiredUuid) { // NOLINT .count(); auto uuid = createFakeUuid(static_cast(recent_timestamp)); - auto [valid, reason] = validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL + auto [valid, reason] = + validator::uuid::isExpired(uuid, SIXTY_SECONDS); // 60 seconds TTL EXPECT_FALSE(valid); EXPECT_FALSE(reason.has_value()); } // Test retrieving version -TEST_F(TestUuidValidator, RetrieveVersion) { // NOLINT +TEST_F(TestUuidValidator, RetrieveVersion) { // NOLINT auto uuid = createFakeUuid(); EXPECT_EQ(validator::uuid::getVersion(uuid), UUID_VERSION_7); } // Test retrieving variant -TEST_F(TestUuidValidator, RetrieveVariant) { // NOLINT +TEST_F(TestUuidValidator, RetrieveVariant) { // NOLINT auto uuid = createFakeUuid(); EXPECT_EQ(validator::uuid::getVariant(uuid), UUID_VARIANT_RFC4122); } -TEST_F(TestUuidValidator, RetrieveTimestamp) { // NOLINT +TEST_F(TestUuidValidator, RetrieveTimestamp) { // NOLINT auto time_now = std::chrono::system_clock::now(); auto time_now_ms = std::chrono::time_point_cast(time_now); - uint64_t timestamp = static_cast(time_now_ms.time_since_epoch().count()); + uint64_t timestamp = + static_cast(time_now_ms.time_since_epoch().count()); auto uuid = createFakeUuid(timestamp); auto uuid_time = validator::uuid::getTime(uuid); @@ -168,11 +173,11 @@ TEST_F(TestUuidValidator, RetrieveTimestamp) { // NOLINT } // Test retrieving elapsed time -TEST_F(TestUuidValidator, RetrieveElapsedTime) { // NOLINT +TEST_F(TestUuidValidator, RetrieveElapsedTime) { // NOLINT auto past_time = std::chrono::system_clock::now() - THIRTY_SECONDS; auto timestamp = std::chrono::duration_cast( - past_time.time_since_epoch()) - .count(); + past_time.time_since_epoch()) + .count(); auto uuid = createFakeUuid(static_cast(timestamp)); auto elapsed_time = validator::uuid::getElapsedTime(uuid); @@ -190,11 +195,11 @@ TEST_F(TestUuidValidator, RetrieveElapsedTime) { // NOLINT } // Test retrieving remaining time -TEST_F(TestUuidValidator, RetrieveRemainingTime) { // NOLINT +TEST_F(TestUuidValidator, RetrieveRemainingTime) { // NOLINT auto past_time = std::chrono::system_clock::now() - THIRTY_SECONDS; auto timestamp = std::chrono::duration_cast( - past_time.time_since_epoch()) - .count(); + past_time.time_since_epoch()) + .count(); auto uuid = createFakeUuid(static_cast(timestamp)); auto ttl = SIXTY_SECONDS; @@ -213,20 +218,20 @@ TEST_F(TestUuidValidator, RetrieveRemainingTime) { // NOLINT } // Test remaining time of 0ms -TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { // NOLINT +TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { // NOLINT auto past_time = std::chrono::system_clock::now() - HUNDRED_SECONDS; - auto past_timestamp = - std::chrono::duration_cast( - past_time.time_since_epoch()) - .count(); + auto past_timestamp = std::chrono::duration_cast( + past_time.time_since_epoch()) + .count(); auto uuid = createFakeUuid(static_cast(past_timestamp)); - auto remaining_time = validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS); + auto remaining_time = + validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS); EXPECT_EQ(remaining_time, std::chrono::milliseconds(0)); } // Future timestamp to test exception thrown on getElapsedTime() -TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { // NOLINT +TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { // NOLINT auto future_time = std::chrono::system_clock::now() + HUNDRED_SECONDS; auto future_timestamp = std::chrono::duration_cast( @@ -234,7 +239,8 @@ TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { // NOLINT .count(); auto uuid = createFakeUuid(static_cast(future_timestamp)); - EXPECT_THROW(validator::uuid::getElapsedTime(uuid), validator::uuid::InvalidUuid); // NOLINT + EXPECT_THROW(validator::uuid::getElapsedTime(uuid), // NOLINT + validator::uuid::InvalidUuid); } } // namespace uprotocol::datamodel diff --git a/test/coverage/transport/UTransportTest.cpp b/test/coverage/transport/UTransportTest.cpp index 689a24c18..ee6a9fe9c 100644 --- a/test/coverage/transport/UTransportTest.cpp +++ b/test/coverage/transport/UTransportTest.cpp @@ -21,15 +21,13 @@ constexpr uint32_t WILDCARD = 0xFFFF; constexpr uint32_t RESOURCE_ID_F00D = 0xF00D; -namespace uprotocol{ +namespace uprotocol { -bool operator==(const v1::UUri& lhs, - const v1::UUri& rhs) { +bool operator==(const v1::UUri& lhs, const v1::UUri& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } -bool operator==(const v1::UMessage& lhs, - const v1::UMessage& rhs) { +bool operator==(const v1::UMessage& lhs, const v1::UMessage& rhs) { return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); } @@ -85,26 +83,28 @@ class TestUTransport : public testing::Test { uri.set_resource_id(WILDCARD); return uri; } + public: ~TestUTransport() override = default; }; -TEST_F(TestUTransport, CreateTransport) { // NOLINT - EXPECT_NO_THROW(auto transport = makeTransport(getValidUri())); // NOLINT +TEST_F(TestUTransport, CreateTransport) { // NOLINT + EXPECT_NO_THROW(auto transport = makeTransport(getValidUri())); // NOLINT } using InvalidUUri = datamodel::validator::uri::InvalidUUri; -TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT +TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT auto uri = getValidUri(); uri.set_authority_name("*"); - EXPECT_THROW({ auto transport = makeTransport(uri); }, InvalidUUri); // NOLINT + EXPECT_THROW({ auto transport = makeTransport(uri); }, // NOLINT + InvalidUUri); } using UMessageBuilder = datamodel::builder::UMessageBuilder; using PayloadBuilder = datamodel::builder::Payload; -TEST_F(TestUTransport, SendOk) { // NOLINT +TEST_F(TestUTransport, SendOk) { // NOLINT constexpr uint32_t RANDOM_RESOURCE_ID = 0xABBA; auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -117,17 +117,16 @@ TEST_F(TestUTransport, SendOk) { // NOLINT UMessageBuilder::publish(std::move(topic)).build(std::move(payload)); decltype(transport->send(message)) result; - EXPECT_NO_THROW(result = transport->send(message)); // NOLINT + EXPECT_NO_THROW(result = transport->send(message)); // NOLINT EXPECT_EQ(result.code(), v1::UCode::OK); EXPECT_EQ(transport_mock->getSendCount(), 1); EXPECT_TRUE(transport_mock->getMessage() == message); } -using InvalidUMessge = - datamodel::validator::message::InvalidUMessage; +using InvalidUMessge = datamodel::validator::message::InvalidUMessage; -TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT +TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -138,28 +137,28 @@ TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT v1::UMessageType::UMESSAGE_TYPE_REQUEST); decltype(transport->send(message)) result; - EXPECT_THROW({ result = transport->send(message); }, InvalidUMessge); // NOLINT + EXPECT_THROW({ result = transport->send(message); }, // NOLINT + InvalidUMessge); EXPECT_EQ(transport_mock->getSendCount(), 0); } -TEST_F(TestUTransport, SendImplStatus) { // NOLINT +TEST_F(TestUTransport, SendImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->getSendStatus().set_code( - v1::UCode::PERMISSION_DENIED); + transport_mock->getSendStatus().set_code(v1::UCode::PERMISSION_DENIED); auto topic = getValidUri(); topic.set_resource_id(RESOURCE_ID_F00D); auto message = UMessageBuilder::publish(std::move(topic)).build(); decltype(transport->send(message)) result; - EXPECT_NO_THROW(result = transport->send(message)); // NOLINT + EXPECT_NO_THROW(result = transport->send(message)); // NOLINT EXPECT_EQ(result.code(), v1::UCode::PERMISSION_DENIED); } -TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT +TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -168,7 +167,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT auto source_filter = getWildcardUri(); transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -194,7 +193,7 @@ TEST_F(TestUTransport, RegisterListenerOk) { // NOLINT } } -TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT +TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -203,7 +202,7 @@ TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT auto source_filter = getWildcardUri(); source_filter.set_resource_id(1); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener(callback, source_filter); @@ -216,19 +215,18 @@ TEST_F(TestUTransport, RegisterListenerInvalidSource) { // NOLINT EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT +TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->getRegisterListenerStatus().set_code( - v1::UCode::INTERNAL); + transport_mock->getRegisterListenerStatus().set_code(v1::UCode::INTERNAL); bool called = false; auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); v1::UStatus status; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter); @@ -251,7 +249,7 @@ TEST_F(TestUTransport, RegisterListenerImplStatus) { // NOLINT } } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -262,7 +260,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT sink_filter.set_resource_id(WILDCARD); transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -292,7 +290,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterOk) { // NOLINT } } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -305,7 +303,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT // Make source invalid source_filter.set_ue_version_major(WILDCARD); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener( callback, source_filter, sink_filter); @@ -318,7 +316,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSource) { // NOLINT EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -331,7 +329,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT // Make sink invalid sink_filter.set_ue_version_major(WILDCARD); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener( callback, source_filter, sink_filter); @@ -344,12 +342,11 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterInvalidSink) { // NOLINT EXPECT_FALSE(called); } -TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->getRegisterListenerStatus().set_code( - v1::UCode::NOT_FOUND); + transport_mock->getRegisterListenerStatus().set_code(v1::UCode::NOT_FOUND); bool called = false; auto callback = [&called](const auto&) { called = true; }; @@ -358,7 +355,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT sink_filter.set_resource_id(WILDCARD); v1::UStatus status; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, sink_filter); @@ -381,7 +378,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkFilterImplStatus) { // NOLINT } } -TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -390,9 +387,9 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT auto source_filter = getWildcardUri(); transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ // NOLINT - auto maybe_handle = - transport->registerListener(callback, source_filter, RESOURCE_ID_F00D); + EXPECT_NO_THROW({ // NOLINT + auto maybe_handle = transport->registerListener(callback, source_filter, + RESOURCE_ID_F00D); EXPECT_TRUE(maybe_handle); if (maybe_handle) { @@ -422,7 +419,8 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT } } -TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLINT +TEST_F(TestUTransport, // NOLINT + RegisterListenerWithSinkResourceInvalidSource) { auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -433,7 +431,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLIN // Make source invalid source_filter.set_ue_version_major(WILDCARD); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { auto maybe_handle = transport->registerListener(callback, source_filter, 0xABBA); @@ -449,19 +447,18 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceInvalidSource) { // NOLIN // NOTE: it is not possible to produce an invalid sink filter with this method // since it constrains the sink resource parameter to uint16_t -TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT +TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); - transport_mock->getRegisterListenerStatus().set_code( - v1::UCode::NOT_FOUND); + transport_mock->getRegisterListenerStatus().set_code(v1::UCode::NOT_FOUND); bool called = false; auto callback = [&called](const auto&) { called = true; }; auto source_filter = getWildcardUri(); v1::UStatus status; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(callback, source_filter, WILDCARD); @@ -486,7 +483,7 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceImplStatus) { // NOLINT } } -TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT +TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -495,7 +492,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT auto topic_source_filter = getWildcardUri(); transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT // When source_filter is omitted, sink_filter is treated as a publish // topic. auto maybe_handle = @@ -523,7 +520,8 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT } } -TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT +TEST_F(TestUTransport, // NOLINT + DeprecatedRegisterListenerWithSourceFilterOk) { auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -534,7 +532,7 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerWithSourceFilterOk) { // NOLINT sink_filter.set_resource_id(WILDCARD); transport::UTransport::ListenHandle handle; - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT auto maybe_handle = transport->registerListener(sink_filter, callback, source_filter); diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index d8d49bcb8..44dc58794 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -17,7 +17,7 @@ #include #include -namespace uprotocol::utils{ +namespace uprotocol::utils { class CallbackTest : public testing::Test { protected: @@ -34,6 +34,7 @@ class CallbackTest : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~CallbackTest() override = default; }; @@ -41,13 +42,13 @@ class CallbackTest : public testing::Test { /// It should be possible to establish a connection without an exception /// being thrown. Exceptions that can be thrown at this stage would be a result /// of a system-level failure, such as running out of memory. -TEST_F(CallbackTest, EstablishDoesNotThrow) { // NOLINT - EXPECT_NO_THROW(callbacks::Connection::establish([]() {})); // NOLINT +TEST_F(CallbackTest, EstablishDoesNotThrow) { // NOLINT + EXPECT_NO_THROW(callbacks::Connection::establish([]() {})); // NOLINT } /// It should be possible to establish a connection and call the callback /// function via the CallerHandle (aka the callable). -TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT +TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT int call_count{0}; @@ -60,7 +61,7 @@ TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT // It's the first time we're calling the callback - check that it doesn't // throw to stop the test here if something is wrong. - EXPECT_NO_THROW(callable()); // NOLINT + EXPECT_NO_THROW(callable()); // NOLINT EXPECT_TRUE(handle); EXPECT_TRUE(callable); @@ -76,13 +77,11 @@ TEST_F(CallbackTest, EstablishLinkedPair) { // NOLINT // When dropping a CalleeHandle or the last CallerHandle, the connection should // be broken. -TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT +TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT int call_count{0}; // Utility to produce connected pairs that have been validated as connected auto get_pair = ([&call_count]() { - - auto connected_pair = callbacks::Connection::establish( [&call_count]() { ++call_count; }); @@ -114,34 +113,32 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // Drop the handle end by letting it go out of scope { - callbacks::Connection::Callable callable_outside; static_assert(std::is_move_assignable_v); EXPECT_FALSE(callable_outside); { auto [handle, callable] = get_pair(); callable_outside = std::move(callable); - EXPECT_FALSE(callable); // NOLINT + EXPECT_FALSE(callable); // NOLINT EXPECT_TRUE(callable_outside); // Handle dropped here } EXPECT_FALSE(callable_outside); // Calling the callback after disconnect from the callee end should not // result in an exception. - EXPECT_NO_THROW(callable_outside()); // NOLINT + EXPECT_NO_THROW(callable_outside()); // NOLINT EXPECT_EQ(call_count, 0); } // Drop the callable end by letting it go out of scope { - callbacks::Connection::Handle handle_outside; static_assert(std::is_move_assignable_v); EXPECT_FALSE(handle_outside); { auto [handle, callable] = get_pair(); handle_outside = std::move(handle); - EXPECT_FALSE(handle); // NOLINT + EXPECT_FALSE(handle); // NOLINT EXPECT_TRUE(handle_outside); // Callable dropped here } @@ -166,13 +163,12 @@ TEST_F(CallbackTest, DroppedHandlesBreakConnection) { // NOLINT // CallerHandles cannot be used when default constructed or after reset is // called. Doing so will result in an exception being thrown. -TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT - +TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT // Default constructed CallerHandle cannot be called { callbacks::CallerHandle callable; - EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT + EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT } // Freshly reset CallerHandle cannot be called @@ -180,15 +176,14 @@ TEST_F(CallbackTest, CallerHandleThrowsBadCall) { // NOLINT auto [handle, callable] = callbacks::Connection::establish([]() {}); callable.reset(); - EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT + EXPECT_THROW(callable(), callbacks::BadCallerAccess); // NOLINT } } // This connection system will be used for multiple connected callbacks // simultaneously. As such, it should be possible to have multiple handle pairs // in use and not have any unexpected interactions between them. -TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT - +TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT std::array call_count{0}; @@ -245,13 +240,12 @@ TEST_F(CallbackTest, MultipleConnectionsCanCoexist) { // NOLINT // Cleanup functions should be called when the connection is broken from the // callee end of the connection. -TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT - +TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); EXPECT_EQ(cleanup_count, 0); handle.reset(); @@ -260,14 +254,13 @@ TEST_F(CallbackTest, CleanupCalledWhenCalleeHandleDropped) { // NOLINT // Cleanup functions should not be called when the connection is broken from // the caller end of the connection. -TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT - +TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT { int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); EXPECT_EQ(cleanup_count, 0); callable.reset(); @@ -278,7 +271,7 @@ TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT int cleanup_count{0}; auto [handle, callable] = callbacks::Connection::establish( - []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); + []() {}, [&cleanup_count](const auto& /*c*/) { ++cleanup_count; }); auto callable_copy = callable; @@ -293,7 +286,7 @@ TEST_F(CallbackTest, CleanupNotCalledWhenCallerHandleDropped) { // NOLINT // It is very likely that connections will be held in some sort of map. In // order to effectively make use of the cleanup function, it should be possible // to use the CallerHandle as a reverse-lookup key. -TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT +TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT std::map::Callable, int> cleanup_count; @@ -328,7 +321,7 @@ TEST_F(CallbackTest, CleanupParameterCanLookUpCallable) { // NOLINT // functions. However, this should be supported by the connection system. We // can verify the parameters are passed through by checking for the result of // known operations. -TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT +TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT constexpr uint16_t RANDOM_NUMBER_1 = 5; constexpr uint16_t RANDOM_NUMBER_2 = 9; constexpr int16_t RANDOM_NUMBER_3 = -80; @@ -366,8 +359,7 @@ TEST_F(CallbackTest, CallablesCanTakeArguments) { // NOLINT // Until this point, the callback has not returned a value. This should be // supported by the connection system. Building on passing parameters, we can // return the result of an operation performed by the callback function. -TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT - +TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT // Multiply two numbers together, check the result { @@ -404,7 +396,7 @@ TEST_F(CallbackTest, CallablesCanReturnValues) { // NOLINT // inadvertently introduce a copy. We can detect this by a) using a non- // copyable type as the return and b) checking container objects for changes // in their data pointers. -TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT +TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT // Checking with a non-copyable object (in this case, std::unique_ptr) { void* original_location{nullptr}; @@ -412,7 +404,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT auto [handle, callable] = callbacks::Connection>::establish( [&original_location]() { - constexpr int RANDOM_NUMBER = 71; + constexpr int RANDOM_NUMBER = 71; auto p = std::make_unique(RANDOM_NUMBER); original_location = p.get(); return p; @@ -458,8 +450,7 @@ TEST_F(CallbackTest, ReturnValuesAreMoved) { // NOLINT // still exist. It is safe to call - nothing will happen. However, when the // callback is a returning callback, an empty optional will be returned to // indicate that the connection is not active. -TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT - +TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT { auto [handle, callable] = @@ -495,8 +486,7 @@ TEST_F(CallbackTest, DisconnectedCallablesReturnNothing) { // NOLINT // The typical use case for these callbacks is to pass asynchronous events. // It should work with the caller executing from a separate context. -TEST_F(CallbackTest, CanCallFromAnotherThread) { // NOLINT - +TEST_F(CallbackTest, CanCallFromAnotherThread) { // NOLINT std::atomic call_count{0}; @@ -537,14 +527,14 @@ struct SemaphoreLike { if (ctr_ > 0) { --ctr_; return true; - } return cv_.wait_for(l, t, [this]() { - if (ctr_ > 0) { - --ctr_; - return true; - } - return false; - }); - + } + return cv_.wait_for(l, t, [this]() { + if (ctr_ > 0) { + --ctr_; + return true; + } + return false; + }); } private: @@ -560,8 +550,8 @@ struct SemaphoreLike { // threads all blocking to acquire resources (via semaphore-like object). These // blocks are released one-by-one to check that the connection states remain // valid and the callee remains blocked throughout the process. -TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT - +TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT + using namespace std::chrono_literals; std::atomic disconnect_done{false}; @@ -674,10 +664,9 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT // construct a CallerHandle then initialize it later. Check this works, that // the default-constructed object reports as disconnected, and that no // exception is thrown. -TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT - +TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT callbacks::CallerHandle x; EXPECT_FALSE(x); }); @@ -687,10 +676,9 @@ TEST_F(CallbackTest, CallerHandleCanDefaultConstruct) { // NOLINT // construct a CalleeHandle then initialize it later. Check this works, that // the default-constructed object reports as disconnected, and that no // exception is thrown. -TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT - +TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW({ // NOLINT callbacks::CalleeHandle x; EXPECT_FALSE(x); }); @@ -703,12 +691,11 @@ TEST_F(CallbackTest, CalleeHandleCanDefaultConstruct) { // NOLINT // function objects they receive // Tests invalid callback function objects -TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT - +TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish({}), // NOLINT + EXPECT_THROW(conn = callbacks::Connection::establish({}), // NOLINT callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -718,20 +705,20 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallback) { // NOLINT // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); // NOLINT - EXPECT_NO_THROW(callable.reset()); // NOLINT + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } // Tests invalid cleanup function objects -TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT - +TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT auto cb = []() -> bool { return true; }; callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish(cb, empty), // NOLINT - callbacks::EmptyFunctionObject); + EXPECT_THROW( // NOLINT + conn = callbacks::Connection::establish(cb, empty), + callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -740,19 +727,19 @@ TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); // NOLINT - EXPECT_NO_THROW(callable.reset()); // NOLINT + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } // Tests both invalid cleanup and invalid callback function objects -TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT - +TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW(conn = callbacks::Connection::establish({}, empty), // NOLINT - callbacks::EmptyFunctionObject); + EXPECT_THROW( // NOLINT + conn = callbacks::Connection::establish({}, empty), + callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -761,8 +748,8 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT // is broken. When that happens, the destructor will try to reset again. // By resetting the callable second, there is no need to try the cleanup // funciton again, so the destructor won't throw. - EXPECT_NO_THROW(handle.reset()); // NOLINT - EXPECT_NO_THROW(callable.reset()); // NOLINT + EXPECT_NO_THROW(handle.reset()); // NOLINT + EXPECT_NO_THROW(callable.reset()); // NOLINT } } // namespace uprotocol::utils diff --git a/test/coverage/utils/CyclicQueueTest.cpp b/test/coverage/utils/CyclicQueueTest.cpp index f23fc8eb1..2aa6d018b 100644 --- a/test/coverage/utils/CyclicQueueTest.cpp +++ b/test/coverage/utils/CyclicQueueTest.cpp @@ -29,11 +29,12 @@ class TestFixture : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestFixture() override = default; }; // TODO(unknown) -TEST_F(TestFixture, SomeTestName) {} // NOLINT +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index 06058ebf4..997b12236 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -35,6 +35,7 @@ class ExpectedTest : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~ExpectedTest() override = default; }; @@ -42,13 +43,13 @@ class ExpectedTest : public testing::Test { constexpr int MAX_BIT_SHIFT = 30; int get_rand() { - static std::random_device rd; - static std::mt19937 mt(rd()); - static std::uniform_int_distribution dist(0, 1 << MAX_BIT_SHIFT); - return dist(mt); + static std::random_device rd; + static std::mt19937 mt(rd()); + static std::uniform_int_distribution dist(0, 1 << MAX_BIT_SHIFT); + return dist(mt); } -TEST_F(ExpectedTest, ExpectScalarScalar) { // NOLINT +TEST_F(ExpectedTest, ExpectScalarScalar) { // NOLINT auto sample = get_rand(); auto expected = Expected(sample); EXPECT_TRUE(bool(expected)); @@ -57,7 +58,7 @@ TEST_F(ExpectedTest, ExpectScalarScalar) { // NOLINT EXPECT_EQ(sample, *expected); } -TEST_F(ExpectedTest, UnexpectScalarScalar) { // NOLINT +TEST_F(ExpectedTest, UnexpectScalarScalar) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(sample)); EXPECT_FALSE(bool(expected)); @@ -65,7 +66,7 @@ TEST_F(ExpectedTest, UnexpectScalarScalar) { // NOLINT EXPECT_EQ(sample, expected.error()); } -TEST_F(ExpectedTest, ExpectScalar) { // NOLINT +TEST_F(ExpectedTest, ExpectScalar) { // NOLINT auto sample = get_rand(); auto expected = Expected(sample); EXPECT_TRUE(bool(expected)); @@ -74,7 +75,7 @@ TEST_F(ExpectedTest, ExpectScalar) { // NOLINT EXPECT_EQ(sample, *expected); } -TEST_F(ExpectedTest, UnexpectScalar) { // NOLINT +TEST_F(ExpectedTest, UnexpectScalar) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(sample)); EXPECT_FALSE(bool(expected)); @@ -82,7 +83,7 @@ TEST_F(ExpectedTest, UnexpectScalar) { // NOLINT EXPECT_EQ(sample, expected.error()); } -TEST_F(ExpectedTest, UnexpectValueOr) { // NOLINT +TEST_F(ExpectedTest, UnexpectValueOr) { // NOLINT int sample = get_rand(); auto expected = Expected(Unexpected(std::string("hello"))); @@ -92,16 +93,17 @@ TEST_F(ExpectedTest, UnexpectValueOr) { // NOLINT } struct Pair { - private: - int x; - int y; - public: - Pair(int x_value, int y_value) : x(x_value), y(y_value) {} - [[nodiscard]] int getX() const { return x; } - [[nodiscard]] int getY() const { return y; } - }; - -TEST_F(ExpectedTest, ExpectUnique) { // NOLINT +private: + int x; + int y; + +public: + Pair(int x_value, int y_value) : x(x_value), y(y_value) {} + [[nodiscard]] int getX() const { return x; } + [[nodiscard]] int getY() const { return y; } +}; + +TEST_F(ExpectedTest, ExpectUnique) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected, std::string>( @@ -113,7 +115,7 @@ TEST_F(ExpectedTest, ExpectUnique) { // NOLINT EXPECT_EQ(y, p->getY()); } -TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT +TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected>( @@ -125,7 +127,7 @@ TEST_F(ExpectedTest, UnexpectUnique) { // NOLINT EXPECT_EQ(y, p->getY()); } -TEST_F(ExpectedTest, ExpectShared) { // NOLINT +TEST_F(ExpectedTest, ExpectShared) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected, std::string>( @@ -138,7 +140,7 @@ TEST_F(ExpectedTest, ExpectShared) { // NOLINT EXPECT_EQ(y, (*expected)->getY()); } -TEST_F(ExpectedTest, UnexpectShared) { // NOLINT +TEST_F(ExpectedTest, UnexpectShared) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected>( @@ -149,7 +151,7 @@ TEST_F(ExpectedTest, UnexpectShared) { // NOLINT EXPECT_EQ(y, expected.error()->getY()); } -TEST_F(ExpectedTest, ExpectStruct) { // NOLINT +TEST_F(ExpectedTest, ExpectStruct) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected(Pair(x, y)); @@ -161,7 +163,7 @@ TEST_F(ExpectedTest, ExpectStruct) { // NOLINT EXPECT_EQ(y, expected->getY()); } -TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT +TEST_F(ExpectedTest, UnexpectStruct) { // NOLINT auto x = get_rand(); auto y = get_rand(); auto expected = Expected(Unexpected(Pair(x, y))); @@ -175,21 +177,24 @@ struct PairDestruct { private: int x; int y; - + public: static int cd_count_; - PairDestruct(int x_value, int y_value) : x(x_value), y(y_value) { cd_count_++; } - PairDestruct(const PairDestruct& arg) : x(arg.getX()), y(arg.getY()) { cd_count_++; } + PairDestruct(int x_value, int y_value) : x(x_value), y(y_value) { + cd_count_++; + } + PairDestruct(const PairDestruct& arg) : x(arg.getX()), y(arg.getY()) { + cd_count_++; + } ~PairDestruct() { cd_count_--; } [[nodiscard]] int getX() const { return x; } [[nodiscard]] int getY() const { return y; } }; - int PairDestruct::cd_count_ = 0; -TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT +TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT PairDestruct::cd_count_ = 0; { auto x = get_rand(); @@ -206,7 +211,7 @@ TEST_F(ExpectedTest, ExpectStructDestruct) { // NOLINT EXPECT_EQ(0, PairDestruct::cd_count_); } -TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT +TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT PairDestruct::cd_count_ = 0; { auto x = get_rand(); @@ -222,10 +227,10 @@ TEST_F(ExpectedTest, UnexpectStructDestruct) { // NOLINT EXPECT_EQ(0, PairDestruct::cd_count_); } -TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT +TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); @@ -240,10 +245,10 @@ TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) { // NOLINT BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { // NOLINT +TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { // NOLINT constexpr int DEFAULT_EXPECTED_VALUE = 5; auto expected = Expected(DEFAULT_EXPECTED_VALUE); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { try { EXPECT_TRUE(bool(expected)); @@ -258,10 +263,10 @@ TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) { // NOLINT BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { // NOLINT +TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); @@ -277,10 +282,10 @@ TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) { // NOLINT BadExpectedAccess); } -TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) { // NOLINT +TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) { // NOLINT auto expected = Expected(Unexpected(std::string("hello"))); - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { try { EXPECT_FALSE(bool(expected)); diff --git a/test/coverage/utils/IpAddressTest.cpp b/test/coverage/utils/IpAddressTest.cpp index a62c050e0..12ca42a84 100644 --- a/test/coverage/utils/IpAddressTest.cpp +++ b/test/coverage/utils/IpAddressTest.cpp @@ -29,11 +29,12 @@ class TestFixture : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestFixture() override = default; }; // TODO(unknown) -TEST_F(TestFixture, SomeTestName) {} // NOLINT +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp index e06bb1113..042c46371 100644 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ b/test/coverage/utils/ThreadPoolTest.cpp @@ -29,11 +29,12 @@ class TestFixture : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestFixture() override = default; }; // TODO(unknown) -TEST_F(TestFixture, SomeTestName) {} // NOLINT +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp index df5b40a6b..181eedaf6 100644 --- a/test/coverage/utils/base64Test.cpp +++ b/test/coverage/utils/base64Test.cpp @@ -29,11 +29,12 @@ class TestFixture : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestFixture() override = default; }; // TODO(unknown) -TEST_F(TestFixture, SomeTestName) {} // NOLINT +TEST_F(TestFixture, SomeTestName) {} // NOLINT } // namespace diff --git a/test/extra/NotificationTest.cpp b/test/extra/NotificationTest.cpp index f2fe9178e..5134b8ea2 100644 --- a/test/extra/NotificationTest.cpp +++ b/test/extra/NotificationTest.cpp @@ -23,7 +23,7 @@ constexpr uint32_t DEFAULT_SOURCE_UE_ID = 0x18000; constexpr uint16_t DEFAULT_VERSION_MAJOR = 0xF8; constexpr std::chrono::milliseconds THOUSAND_MILLISECONDS(1000); -namespace uprotocol::datamodel::serializer::uri{ +namespace uprotocol::datamodel::serializer::uri { class NotificationTest : public testing::Test { protected: @@ -41,14 +41,15 @@ class NotificationTest : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - [[nodiscard]] static uprotocol::v1::UUri buildValidTestTopic() ; - [[nodiscard]] static uprotocol::v1::UUri buildValidDefaultSourceURI() ; + [[nodiscard]] static uprotocol::v1::UUri buildValidTestTopic(); + [[nodiscard]] static uprotocol::v1::UUri buildValidDefaultSourceURI(); + public: ~NotificationTest() override = default; }; -[[nodiscard]] uprotocol::v1::UUri NotificationTest::buildValidDefaultSourceURI() - { +[[nodiscard]] uprotocol::v1::UUri +NotificationTest::buildValidDefaultSourceURI() { uprotocol::v1::UUri test_default_source_uri; test_default_source_uri.set_authority_name("10.0.0.1"); test_default_source_uri.set_ue_id(DEFAULT_SOURCE_UE_ID); @@ -57,8 +58,7 @@ class NotificationTest : public testing::Test { return test_default_source_uri; } -[[nodiscard]] uprotocol::v1::UUri NotificationTest::buildValidTestTopic() - { +[[nodiscard]] uprotocol::v1::UUri NotificationTest::buildValidTestTopic() { uprotocol::v1::UUri test_topic; test_topic.set_authority_name("10.0.0.2"); test_topic.set_ue_id(DEFAULT_UE_ID); @@ -67,7 +67,7 @@ class NotificationTest : public testing::Test { return test_topic; } -TEST_F(NotificationTest, NotificationSuccess) { // NOLINT +TEST_F(NotificationTest, NotificationSuccess) { // NOLINT // Initialize uprotocol::v1::UPayloadFormat format = uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT; @@ -80,20 +80,22 @@ TEST_F(NotificationTest, NotificationSuccess) { // NOLINT // Notify Sink auto transport_mock_notification_sink = - std::make_shared(test_default_source_uri); + std::make_shared( + test_default_source_uri); uprotocol::v1::UMessage capture_msg; auto callback = [&capture_msg](const auto& message) { capture_msg = message; }; - auto result = uprotocol::communication::NotificationSink::create(transport_mock_notification_sink, - std::move(callback), test_topic); + auto result = uprotocol::communication::NotificationSink::create( + transport_mock_notification_sink, std::move(callback), test_topic); // Notify Source std::string test_payload_str = "test_payload"; auto transport_mock_notification_source = - std::make_shared(test_default_source_uri); + std::make_shared( + test_default_source_uri); auto movable_topic = test_topic; @@ -101,17 +103,21 @@ TEST_F(NotificationTest, NotificationSuccess) { // NOLINT transport_mock_notification_source, std::move(movable_topic), std::move(test_default_source_uri), format, priority, ttl); - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, format); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + format); auto status = notification_source.notify(std::move(test_payload)); EXPECT_EQ( + AsString::serialize(transport_mock_notification_source->getMessage() + .attributes() + .source()), AsString::serialize( - transport_mock_notification_source->getMessage().attributes().source()), - AsString::serialize(transport_mock_notification_sink->getSourceFilter())); + transport_mock_notification_sink->getSourceFilter())); EXPECT_EQ( - AsString::serialize( - transport_mock_notification_source->getMessage().attributes().sink()), + AsString::serialize(transport_mock_notification_source->getMessage() + .attributes() + .sink()), AsString::serialize( transport_mock_notification_sink->getSinkFilter().value())); @@ -120,8 +126,8 @@ TEST_F(NotificationTest, NotificationSuccess) { // NOLINT transport_mock_notification_source->getMessage()); // Test - EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(transport_mock_notification_source->getMessage(), - capture_msg)); + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals( + transport_mock_notification_source->getMessage(), capture_msg)); EXPECT_EQ(test_payload_str, capture_msg.payload()); } diff --git a/test/extra/PublisherSubscriberTest.cpp b/test/extra/PublisherSubscriberTest.cpp index 6553420aa..a14f346f8 100644 --- a/test/extra/PublisherSubscriberTest.cpp +++ b/test/extra/PublisherSubscriberTest.cpp @@ -26,7 +26,7 @@ constexpr uint16_t DEFAULT_SOURCE_VERSION_MAJOR = 0xF1; constexpr uint16_t DEFAULT_TOPIC_VERSION_MAJOR = 0xF8; constexpr std::chrono::milliseconds THOUSAND_MILLISECONDS(1000); -namespace uprotocol::v1{ +namespace uprotocol::v1 { class TestPublisherSubscriber : public testing::Test { private: @@ -36,8 +36,11 @@ class TestPublisherSubscriber : public testing::Test { UPayloadFormat format_ = UPayloadFormat::UPAYLOAD_FORMAT_TEXT; std::optional priority_; std::optional ttl_; + protected: - std::shared_ptr getTransportMock() const { return transportMock_; } + std::shared_ptr getTransportMock() const { + return transportMock_; + } UUri getSource() const { return source_; } UUri getTopic() const { return topic_; } UPayloadFormat getFormat() const { return format_; } @@ -79,7 +82,7 @@ class TestPublisherSubscriber : public testing::Test { ~TestPublisherSubscriber() override = default; }; -TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT +TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT // sub auto transport_sub = std::make_shared(getSource()); @@ -89,32 +92,36 @@ TEST_F(TestPublisherSubscriber, PubSubSuccess) { // NOLINT captured_message = std::move(message); }; - auto result = - uprotocol::communication::Subscriber::subscribe(transport_sub, getTopic(), std::move(callback)); + auto result = uprotocol::communication::Subscriber::subscribe( + transport_sub, getTopic(), std::move(callback)); // pub std::string test_payload_str = "test_payload"; auto movable_topic = getTopic(); - uprotocol::communication::Publisher publisher(getTransportMock(), std::move(movable_topic), getFormat(), - getPriority(), getTTL()); + uprotocol::communication::Publisher publisher( + getTransportMock(), std::move(movable_topic), getFormat(), + getPriority(), getTTL()); uprotocol::v1::UStatus retval; retval.set_code(uprotocol::v1::UCode::OK); getTransportMock()->getSendStatus() = retval; - uprotocol::datamodel::builder::Payload test_payload(test_payload_str, getFormat()); + uprotocol::datamodel::builder::Payload test_payload(test_payload_str, + getFormat()); auto status = publisher.publish(std::move(test_payload)); // Test - EXPECT_EQ( - uprotocol::datamodel::serializer::uri::AsString::serialize(getTransportMock()->getMessage().attributes().source()), - uprotocol::datamodel::serializer::uri::AsString::serialize(transport_sub->getSourceFilter())); + EXPECT_EQ(uprotocol::datamodel::serializer::uri::AsString::serialize( + getTransportMock()->getMessage().attributes().source()), + uprotocol::datamodel::serializer::uri::AsString::serialize( + transport_sub->getSourceFilter())); // Manually bridge the two transports transport_sub->mockMessage(getTransportMock()->getMessage()); // Test - EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(getTransportMock()->getMessage(), captured_message)); + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals( + getTransportMock()->getMessage(), captured_message)); EXPECT_EQ(test_payload_str, captured_message.payload()); } diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index fb9edc91d..636bb8299 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -21,58 +21,58 @@ using namespace std::chrono_literals; -namespace uprotocol::v1{ - - struct UeDetails { - uint32_t ue_id; - uint32_t ue_version_major; - }; - - struct MyUUri { - static constexpr uint32_t DEFAULT_UE_ID = 0x8000; - - public: - MyUUri(std::string auth_val, UeDetails ue_details, uint32_t resource_id_val) - : auth(std::move(auth_val)), - ue_id(ue_details.ue_id), - ue_version_major(ue_details.ue_version_major), - resource_id(resource_id_val) {} - - void set_auth(const std::string& auth_val) { auth = auth_val; } - [[nodiscard]] const std::string& get_auth() const { return auth; } - - void set_ue_details(UeDetails ue_details) { - ue_id = ue_details.ue_id; - ue_version_major = ue_details.ue_version_major; - } - - [[nodiscard]] uint32_t get_ue_id() const { return ue_id; } - [[nodiscard]] uint32_t get_ue_version_major() const { - return ue_version_major; - } - - void set_resource_id(uint32_t resource) { resource_id = resource; } - [[nodiscard]] uint32_t get_resource_id() const { return resource_id; } - - explicit operator uprotocol::v1::UUri() const { - UUri ret; - ret.set_authority_name(auth); - ret.set_ue_id(ue_id); - ret.set_ue_version_major(ue_version_major); - ret.set_resource_id(resource_id); - return ret; - } - - [[nodiscard]] std::string to_string() const { - return std::string("<< ") + UUri(*this).ShortDebugString() + " >>"; - } - - private: - std::string auth; - uint32_t ue_id = DEFAULT_UE_ID; - uint32_t ue_version_major = 1; - uint32_t resource_id = 1; - }; +namespace uprotocol::v1 { + +struct UeDetails { + uint32_t ue_id; + uint32_t ue_version_major; +}; + +struct MyUUri { + static constexpr uint32_t DEFAULT_UE_ID = 0x8000; + +public: + MyUUri(std::string auth_val, UeDetails ue_details, uint32_t resource_id_val) + : auth(std::move(auth_val)), + ue_id(ue_details.ue_id), + ue_version_major(ue_details.ue_version_major), + resource_id(resource_id_val) {} + + void set_auth(const std::string& auth_val) { auth = auth_val; } + [[nodiscard]] const std::string& get_auth() const { return auth; } + + void set_ue_details(UeDetails ue_details) { + ue_id = ue_details.ue_id; + ue_version_major = ue_details.ue_version_major; + } + + [[nodiscard]] uint32_t get_ue_id() const { return ue_id; } + [[nodiscard]] uint32_t get_ue_version_major() const { + return ue_version_major; + } + + void set_resource_id(uint32_t resource) { resource_id = resource; } + [[nodiscard]] uint32_t get_resource_id() const { return resource_id; } + + explicit operator uprotocol::v1::UUri() const { + UUri ret; + ret.set_authority_name(auth); + ret.set_ue_id(ue_id); + ret.set_ue_version_major(ue_version_major); + ret.set_resource_id(resource_id); + return ret; + } + + [[nodiscard]] std::string to_string() const { + return std::string("<< ") + UUri(*this).ShortDebugString() + " >>"; + } + +private: + std::string auth; + uint32_t ue_id = DEFAULT_UE_ID; + uint32_t ue_version_major = 1; + uint32_t resource_id = 1; +}; class RpcClientServerTest : public testing::Test { protected: @@ -90,15 +90,18 @@ class RpcClientServerTest : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~RpcClientServerTest() override = default; }; TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT - const MyUUri ident{"me_authority",{ 65538, 1}, 0}; + const MyUUri ident{"me_authority", {65538, 1}, 0}; const MyUUri rpc_service_uuri{"me_authority", {65538, 1}, 32600}; - auto server_transport = std::make_shared(static_cast(ident)); - auto client_transport = std::make_shared(static_cast(ident)); + auto server_transport = std::make_shared( + static_cast(ident)); + auto client_transport = std::make_shared( + static_cast(ident)); // if the client and server try to share the transport handle, this test no // longer works auto client_transport = server_transport; @@ -128,11 +131,12 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT ASSERT_NE(server_or_status.value(), nullptr); EXPECT_TRUE(server_transport->getListener()); - auto client = uprotocol::communication::RpcClient(client_transport, v1::UUri(rpc_service_uuri), - UPriority::UPRIORITY_CS4, 1000ms); + auto client = uprotocol::communication::RpcClient( + client_transport, v1::UUri(rpc_service_uuri), UPriority::UPRIORITY_CS4, + 1000ms); uprotocol::communication::RpcClient::InvokeHandle client_handle; // NOLINT - EXPECT_NO_THROW( // NOLINT + EXPECT_NO_THROW( // NOLINT client_handle = client.invokeMethod( std::move(client_request_payload), [&client_called, &client_capture](auto maybe_response) { diff --git a/test/extra/UTransportMockTest.cpp b/test/extra/UTransportMockTest.cpp index 8cbd66a21..e0249978c 100644 --- a/test/extra/UTransportMockTest.cpp +++ b/test/extra/UTransportMockTest.cpp @@ -72,11 +72,12 @@ class TestMockUTransport : public testing::Test { // Used only for global setup outside of tests. static void SetUpTestSuite() {} static void TearDownTestSuite() {} + public: ~TestMockUTransport() override = default; }; -TEST_F(TestMockUTransport, Send) { // NOLINT +TEST_F(TestMockUTransport, Send) { // NOLINT constexpr uint32_t DEF_SRC_UE_ID = 0x18000; constexpr uint16_t CODE_MAX = 15; constexpr uint16_t CODE_MOD = 16; @@ -128,7 +129,7 @@ TEST_F(TestMockUTransport, Send) { // NOLINT } } -TEST_F(TestMockUTransport, registerListener) { // NOLINT +TEST_F(TestMockUTransport, registerListener) { // NOLINT constexpr uint32_t DEF_SRC_UE_ID = 0x18000; uprotocol::v1::UUri def_src_uuri; def_src_uuri.set_authority_name(get_random_string()); diff --git a/test/include/UTransportMock.h b/test/include/UTransportMock.h index f83fc0c2e..f14af0fca 100644 --- a/test/include/UTransportMock.h +++ b/test/include/UTransportMock.h @@ -33,27 +33,39 @@ class UTransportMock : public uprotocol::transport::UTransport { (*listener_)(msg); } - size_t getSendCount() const { return send_count_.load(); } + size_t getSendCount() const { return send_count_.load(); } - uprotocol::v1::UStatus& getSendStatus() { return send_status_; } + uprotocol::v1::UStatus& getSendStatus() { return send_status_; } - uprotocol::v1::UStatus& getRegisterListenerStatus() { return registerListener_status_; } + uprotocol::v1::UStatus& getRegisterListenerStatus() { + return registerListener_status_; + } - std::optional> getListener() const { return listener_; } + std::optional> + getListener() const { + return listener_; + } - std::optional> getCleanupListener() const { return cleanup_listener_; } + std::optional> + getCleanupListener() const { + return cleanup_listener_; + } - std::optional getSinkFilter() const { return sink_filter_; } + std::optional getSinkFilter() const { + return sink_filter_; + } - v1::UUri getSourceFilter() const { return source_filter_; } + v1::UUri getSourceFilter() const { return source_filter_; } - std::mutex& getRegisterMtx() { return register_mtx_; } + std::mutex& getRegisterMtx() { return register_mtx_; } - v1::UMessage getMessage() const { return message_; } + v1::UMessage getMessage() const { return message_; } - std::mutex& getMessageMtx() { return message_mtx_; } + std::mutex& getMessageMtx() { return message_mtx_; } - ~UTransportMock() override = default; + ~UTransportMock() override = default; private: std::atomic send_count_; @@ -62,11 +74,11 @@ class UTransportMock : public uprotocol::transport::UTransport { uprotocol::v1::UStatus registerListener_status_; std::optional> - listener_; + void, uprotocol::v1::UMessage const&>> + listener_; std::optional> - cleanup_listener_; + void, uprotocol::v1::UMessage const&>> + cleanup_listener_; std::optional sink_filter_; v1::UUri source_filter_; std::mutex register_mtx_; From 6e335509c627eb6850854fe531dc349f288c58f1 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 13:14:26 +0200 Subject: [PATCH 29/41] Adapted NOLINT Comments to formated code. Part 2 --- .../communication/NotificationSinkTest.cpp | 8 +- .../communication/NotificationSourceTest.cpp | 2 +- test/coverage/communication/PublisherTest.cpp | 6 +- test/coverage/communication/RpcClientTest.cpp | 87 +++++----- .../coverage/communication/SubscriberTest.cpp | 13 +- .../coverage/datamodel/PayloadBuilderTest.cpp | 64 ++++---- .../datamodel/UMessageBuilderTest.cpp | 64 ++++---- .../coverage/datamodel/UUriSerializerTest.cpp | 154 ++++++++++-------- test/coverage/datamodel/UuidBuilderTest.cpp | 4 +- .../coverage/datamodel/UuidSerializerTest.cpp | 4 +- test/coverage/datamodel/UuidValidatorTest.cpp | 15 +- test/coverage/transport/UTransportTest.cpp | 16 +- .../coverage/utils/CallbackConnectionTest.cpp | 8 +- 13 files changed, 232 insertions(+), 213 deletions(-) diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index 9b8f4ad55..60c6dfe02 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -262,8 +262,8 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT transport, transport->getEntityUri(), nullptr, getTestTopicUUri()); }; - EXPECT_THROW(test_create_nullptr(), // NOLINT - utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_nullptr(), // NOLINT + utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_create_empty = [transport, this]() { @@ -271,8 +271,8 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT transport, transport->getEntityUri(), {}, getTestTopicUUri()); }; - EXPECT_THROW(test_create_empty(), - utils::callbacks::EmptyFunctionObject); // NOLINT + EXPECT_THROW(test_create_empty(), // NOLINT + utils::callbacks::EmptyFunctionObject); } } // namespace uprotocol::communication diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index a667bb261..e3a88105a 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -145,7 +145,7 @@ TEST_F(TestNotificationSource, NotifyWithPayloadSuccessWithoutTTL) { // NOLINT } TEST_F(TestNotificationSource, // NOLINT - NotifyWithPayloadSuccessWithoutPriority) { + NotifyWithPayloadSuccessWithoutPriority) { std::string test_payload_str = "test_payload"; getPriority().reset(); NotificationSource notification_source( diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index c8e7c4add..498711bcb 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -184,9 +184,9 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT // publisher with null transport TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(communication::Publisher publisher(transport, getTopic(), // NOLINT - getFormat(), - getPriority(), getTTL()), + EXPECT_THROW(communication::Publisher publisher( // NOLINT + transport, getTopic(), + getFormat(), getPriority(), getTTL()), uprotocol::transport::NullTransport); } diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index fcda36dc0..19e7aedb4 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -175,8 +175,8 @@ TEST_F(RpcClientTest, CanConstructWithoutExceptions) { // NOLINT "Some token");); } -TEST_F(RpcClientTest, // NOLINT - ExceptionThrownWithInvalidConstructorArguments) { +TEST_F(RpcClientTest, // NOLINT + ExceptionThrownWithInvalidConstructorArguments) { // Bad method URI EXPECT_THROW(auto uri = methodUri(); uri.set_resource_id(0); // NOLINT auto client = communication::RpcClient( @@ -328,8 +328,8 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { - EXPECT_NO_THROW( - auto maybe_response = invoke_future.get(); // NOLINT + EXPECT_NO_THROW( // NOLINT + auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, v1::UCode::CANCELLED);); } } @@ -370,8 +370,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(std::move(payload))); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(std::move(payload))); EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -406,8 +406,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto payload_content = payload.buildCopy(); decltype(client.invokeMethod(std::move(payload))) invoke_future; - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(std::move(payload))); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(std::move(payload))); EXPECT_TRUE(invoke_future.valid()); validateLastRequest(1); @@ -453,8 +453,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadTimeout) { // NOLINT decltype(client.invokeMethod()) invoke_future; auto when_requested = std::chrono::steady_clock::now(); - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(ONE_HUNDRED_FIFTY_MILLISECONDS); @@ -479,8 +479,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT v1::UCode::RESOURCE_EXHAUSTED); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); @@ -501,8 +501,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT getTransport()->getSendStatus().set_code(v1::UCode::FAILED_PRECONDITION); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); @@ -522,8 +522,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); } EXPECT_TRUE(invoke_future.valid()); @@ -542,8 +542,8 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT TEN_MILLISECONDS); decltype(client.invokeMethod()) invoke_future; - EXPECT_NO_THROW(invoke_future = // NOLINT - client.invokeMethod(fakePayload())); + EXPECT_NO_THROW(invoke_future = // NOLINT + client.invokeMethod(fakePayload())); using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = @@ -650,12 +650,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadListenFail) { // NOLINT bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod([&callback_called]( - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, v1::UCode::RESOURCE_EXHAUSTED); - })); + EXPECT_NO_THROW( // NOLINT + handle = + client.invokeMethod([&callback_called](const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, + v1::UCode::RESOURCE_EXHAUSTED); + })); EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(callback_called); @@ -671,12 +672,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadSendFail) { // NOLINT bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod([&callback_called]( - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, v1::UCode::FAILED_PRECONDITION); - })); + EXPECT_NO_THROW( // NOLINT + handle = + client.invokeMethod([&callback_called](const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, + v1::UCode::FAILED_PRECONDITION); + })); EXPECT_TRUE(callback_called); } @@ -692,12 +694,12 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadClientDestroyed) { // NOLINT v1::UPriority::UPRIORITY_CS4, TEN_MILLISECONDS); - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod([&callback_called]( - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, v1::UCode::CANCELLED); - })); + EXPECT_NO_THROW( // NOLINT + handle = client.invokeMethod( + [&callback_called](const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, v1::UCode::CANCELLED); + })); } EXPECT_TRUE(callback_called); @@ -711,12 +713,13 @@ TEST_F(RpcClientTest, InvokeCallbackWithoutPayloadCommstatus) { // NOLINT bool callback_called = false; communication::RpcClient::InvokeHandle handle; - EXPECT_NO_THROW( // NOLINT - handle = client.invokeMethod([&callback_called]( - const auto& maybe_response) { - callback_called = true; - checkErrorResponse(maybe_response, v1::UCode::PERMISSION_DENIED); - })); + EXPECT_NO_THROW( // NOLINT + handle = + client.invokeMethod([&callback_called](const auto& maybe_response) { + callback_called = true; + checkErrorResponse(maybe_response, + v1::UCode::PERMISSION_DENIED); + })); using UMessageBuilder = datamodel::builder::UMessageBuilder; auto response_builder = diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index 09aa704b5..39f01165e 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -213,9 +213,8 @@ TEST_F(SubscriberTest, SubscribeNullTransport) { // NOLINT auto callback = [this](const auto& arg1) { return this->handleCallbackMessage(arg1); }; - EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT - transport, getTestTopicUUri(), - std::move(callback)), + EXPECT_THROW(auto result = communication::Subscriber::subscribe( // NOLINT + transport, getTestTopicUUri(), std::move(callback)), std::invalid_argument); } // subscribe to a topic with null callback @@ -229,8 +228,8 @@ TEST_F(SubscriberTest, SubscribeNullCallback) { // NOLINT transport, getTestTopicUUri(), nullptr); }; - EXPECT_THROW(test_subscribe_nullptr(), // NOLINT - utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_nullptr(), // NOLINT + utils::callbacks::EmptyFunctionObject); // Default construct a function object auto test_subscribe_empty = [transport, this]() { @@ -238,8 +237,8 @@ TEST_F(SubscriberTest, SubscribeNullCallback) { // NOLINT transport, getTestTopicUUri(), {}); }; - EXPECT_THROW(test_subscribe_empty(), // NOLINT - utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_subscribe_empty(), // NOLINT + utils::callbacks::EmptyFunctionObject); } } // namespace uprotocol diff --git a/test/coverage/datamodel/PayloadBuilderTest.cpp b/test/coverage/datamodel/PayloadBuilderTest.cpp index 9508e20a4..26e837df0 100644 --- a/test/coverage/datamodel/PayloadBuilderTest.cpp +++ b/test/coverage/datamodel/PayloadBuilderTest.cpp @@ -119,14 +119,14 @@ TEST_F(PayloadTest, CreateSerializedProtobufPayloadAndMoveTest) { // NOLINT uprotocol::v1::UPayloadFormat::UPAYLOAD_FORMAT_PROTOBUF); EXPECT_EQ(payloadData, expected_payload_data); - EXPECT_THROW(static_cast(payload.buildCopy()), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(static_cast(payload.buildCopy()), // NOLINT + Payload::PayloadMoved); EXPECT_EQ(original_address, payloadData.data()); } // Create serialized protobuf payload. Verify exception for move paylod twice -TEST_F(PayloadTest, // NOLINT - CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { +TEST_F(PayloadTest, // NOLINT + CreateSerializedProtobufPayloadAndMoveTwiceExceptionTest) { // Arrange uprotocol::v1::UUri uri_object; uri_object.set_authority_name(getTestStringPayload()); @@ -164,8 +164,8 @@ TEST_F(PayloadTest, // NOLINT EXPECT_EQ(payloadData, uri_object.SerializeAsString()); // Call build on payload after move - EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } /////////////Serializer Payload Protobuf Tests///////////////// @@ -212,8 +212,8 @@ TEST_F(PayloadTest, CreateSerializerPayloadWithInvalidFormat) { // NOLINT std::chrono::duration_cast(t)); // Act - EXPECT_THROW(Payload payload(time_serializer, t), // NOLINT - std::out_of_range); + EXPECT_THROW(Payload payload(time_serializer, t), // NOLINT + std::out_of_range); } // Create a serializer payload and verify moved payload @@ -239,8 +239,8 @@ TEST_F(PayloadTest, CreateSerializerPayloadAndMoveTest) { // NOLINT EXPECT_EQ(payloadFormat, std::get( expected_serialized_object)); - EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } ////////////////////////Byte Array Payload Tests//////////////////////// @@ -264,7 +264,7 @@ TEST_F(PayloadTest, ByteArrayPayloadTest) { // NOLINT // Create payload of Byte array with invalid format and check if it throws // exception TEST_F(PayloadTest, // NOLINT - ConstructorInvalidFormatForByteArrayPayloadTest) { + ConstructorInvalidFormatForByteArrayPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; // Arrange @@ -272,8 +272,8 @@ TEST_F(PayloadTest, // NOLINT static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW( // NOLINT - Payload payload(getTestBytesPayload(), invalid_format), + EXPECT_THROW( // NOLINT + Payload payload(getTestBytesPayload(), invalid_format), std::out_of_range); } @@ -307,8 +307,8 @@ TEST_F(PayloadTest, MoveByteArrayPayloadTest) { // NOLINT // Assert EXPECT_EQ(serialized_data, "Test0123"); EXPECT_EQ(payloadFormat, format); - EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } //////////////String Payload Tests////////////// @@ -337,8 +337,8 @@ TEST_F(PayloadTest, ConstructorInvalidFormatForStringPayloadTest) { // NOLINT static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW( // NOLINT - Payload payload(getTestStringPayload(), invalid_format), + EXPECT_THROW( // NOLINT + Payload payload(getTestStringPayload(), invalid_format), std::out_of_range); } @@ -372,7 +372,7 @@ TEST_F(PayloadTest, StringMovePayloadTest) { // NOLINT EXPECT_EQ(serialized_data, getTestStringPayload()); EXPECT_EQ(payloadFormat, format); EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + Payload::PayloadMoved); } // Create Any and move payload object test @@ -421,8 +421,8 @@ TEST_F(PayloadTest, RValueStringPayloadTest) { // NOLINT } // Create payload of RValue String with invalid format -TEST_F(PayloadTest, // NOLINT - ConstructorInvalidFormatForRValueStringPayloadTest) { +TEST_F(PayloadTest, // NOLINT + ConstructorInvalidFormatForRValueStringPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; // Arrange @@ -431,8 +431,8 @@ TEST_F(PayloadTest, // NOLINT static_cast(INVALID_PAYLOAD_FORMAT); // Act and Assert - EXPECT_THROW( // NOLINT - Payload payload(std::move(value_string), invalid_format), + EXPECT_THROW( // NOLINT + Payload payload(std::move(value_string), invalid_format), std::out_of_range); } @@ -470,8 +470,8 @@ TEST_F(PayloadTest, RValueStringMovePayloadTest) { // NOLINT EXPECT_EQ(payloadFormat, format); EXPECT_EQ(original_address, moved_address); - EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } ///////////////////////RValue Serialized Payload Tests////////////////////// @@ -497,8 +497,8 @@ TEST_F(PayloadTest, RvalueSerializedConstructorTest) { // NOLINT } // Create payload of RValue Serialized with invalid format -TEST_F(PayloadTest, // NOLINT - ConstructorInvalidFormatForRValueSerializedPayloadTest) { +TEST_F(PayloadTest, // NOLINT + ConstructorInvalidFormatForRValueSerializedPayloadTest) { constexpr uint16_t INVALID_PAYLOAD_FORMAT = 9999; // Arrange @@ -508,8 +508,8 @@ TEST_F(PayloadTest, // NOLINT std::make_tuple(getTestStringPayload(), format); // Act - EXPECT_THROW(Payload payload(std::move(serialized)); // NOLINT - , std::out_of_range); + EXPECT_THROW(Payload payload(std::move(serialized)); // NOLINT + , std::out_of_range); } // Create empty RValue Serialized payload and build. @@ -550,8 +550,8 @@ TEST_F(PayloadTest, RValueSerializedMovePayloadTest) { // NOLINT EXPECT_EQ(payloadFormat, format); EXPECT_EQ(original_address, moved_address); - EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } //////////////////////Other Constructor Tests/////////////////////// @@ -571,8 +571,8 @@ TEST_F(PayloadTest, MoveConstructorTest) { // NOLINT EXPECT_EQ(movedData, getTestStringPayload()); EXPECT_EQ(movedFormat, format); - EXPECT_THROW(auto _ = original_payload.buildCopy(), // NOLINT - Payload::PayloadMoved); + EXPECT_THROW(auto _ = original_payload.buildCopy(), // NOLINT + Payload::PayloadMoved); } // Cppy Constructor Test diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index cc623e37a..7cac00530 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -124,9 +124,9 @@ TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { // NOLINT v1::UUri topic; - EXPECT_THROW( // NOLINT + EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::publish(std::move(topic)); }, - datamodel::validator::uri::InvalidUUri); + datamodel::validator::uri::InvalidUUri); } /// @brief Test the notification function of the UMessageBuilder @@ -306,17 +306,17 @@ TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { // NOLINT } /// @brief withPriority test -TEST_F(TestUMessageBuilder, // NOLINT - WithPriorityValidForRequestOrResponseSuccess) { +TEST_F(TestUMessageBuilder, // NOLINT + WithPriorityValidForRequestOrResponseSuccess) { auto builder = createFakeRequest(); - + EXPECT_NO_THROW( // NOLINT - { builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); + { builder.withPriority(v1::UPriority::UPRIORITY_CS4); }); auto builder2 = createFakeResponse(); - EXPECT_NO_THROW( // NOLINT - { builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); + EXPECT_NO_THROW( // NOLINT + { builder2.withPriority(v1::UPriority::UPRIORITY_CS4); }); } TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { // NOLINT @@ -336,8 +336,8 @@ TEST_F(TestUMessageBuilder, WithPriorityOutOfRangeThrows) { // NOLINT std::out_of_range); } -TEST_F(TestUMessageBuilder, // NOLINT - WithPriorityLessThanCS4ForRequestOrResponseThrows) { +TEST_F(TestUMessageBuilder, // NOLINT + WithPriorityLessThanCS4ForRequestOrResponseThrows) { auto builder = createFakeRequest(); EXPECT_THROW( // NOLINT @@ -361,9 +361,9 @@ TEST_F(TestUMessageBuilder, // NOLINT TEST_F(TestUMessageBuilder, WithTtlValidSuccess) { // NOLINT auto builder = createFakeRequest(); - EXPECT_NO_THROW( // NOLINT - { builder.withTtl(std::chrono::milliseconds(1)); }); - EXPECT_NO_THROW({ // NOLINT + EXPECT_NO_THROW( // NOLINT + { builder.withTtl(std::chrono::milliseconds(1)); }); + EXPECT_NO_THROW({ // NOLINT builder.withTtl( std::chrono::milliseconds(std::numeric_limits::max())); }); @@ -414,8 +414,8 @@ TEST_F(TestUMessageBuilder, WithPermissionLevelOnRequestSuccess) { // NOLINT TEST_F(TestUMessageBuilder, WithPermissionLevelOnNonRequestThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW({ builder.withPermissionLevel(1); }, // NOLINT - std::domain_error); + EXPECT_THROW({ builder.withPermissionLevel(1); }, // NOLINT + std::domain_error); } TEST_F(TestUMessageBuilder, WithPermissionLevelZeroSuccess) { // NOLINT @@ -436,14 +436,14 @@ TEST_F(TestUMessageBuilder, WithCommStatusValidValueSuccess) { // NOLINT TEST_F(TestUMessageBuilder, WithCommStatusOnNonResponseThrows) { // NOLINT auto builder = createFakeRequest(); - EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, // NOLINT - std::domain_error); + EXPECT_THROW({ builder.withCommStatus(v1::UCode::OK); }, // NOLINT + std::domain_error); } TEST_F(TestUMessageBuilder, WithCommStatusInvalidValueThrows) { // NOLINT auto builder = createFakeResponse(); - EXPECT_THROW( // NOLINT - { builder.withCommStatus(static_cast(-1)); }, + EXPECT_THROW( // NOLINT + { builder.withCommStatus(static_cast(-1)); }, std::out_of_range); } @@ -464,8 +464,8 @@ TEST_F(TestUMessageBuilder, WithPayloadFormatOnResponseSuccess) { // NOLINT }); } -TEST_F(TestUMessageBuilder, // NOLINT - WithPayloadFormatInvalidValueLessThanMinThrows) { +TEST_F(TestUMessageBuilder, // NOLINT + WithPayloadFormatInvalidValueLessThanMinThrows) { auto builder = createFakeRequest(); EXPECT_THROW( // NOLINT { @@ -476,7 +476,7 @@ TEST_F(TestUMessageBuilder, // NOLINT } TEST_F(TestUMessageBuilder, // NOLINT - WithPayloadFormatInvalidValueMoreThanMaxThrows) { + WithPayloadFormatInvalidValueMoreThanMaxThrows) { auto builder = createFakeRequest(); EXPECT_THROW( // NOLINT { @@ -513,27 +513,27 @@ TEST_F(TestUMessageBuilder, BuildWithoutPayloadFormatThrows) { // NOLINT datamodel::builder::UMessageBuilder::UnexpectedFormat); } -TEST_F(TestUMessageBuilder, // NOLINT - BuildWithPayloadWithPayloadFormatSuccess) { +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadWithPayloadFormatSuccess) { auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); std::string data = "test-data"; datamodel::builder::Payload payload( data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW( // NOLINT - { auto message = builder.build(std::move(payload)); }); + EXPECT_NO_THROW( // NOLINT + { auto message = builder.build(std::move(payload)); }); } -TEST_F(TestUMessageBuilder, // NOLINT - BuildWithPayloadWithoutPayloadFormatSuccess) { +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadWithoutPayloadFormatSuccess) { auto builder = createFakeRequest(); std::string data = "test-data"; datamodel::builder::Payload payload( data, v1::UPayloadFormat::UPAYLOAD_FORMAT_TEXT); - EXPECT_NO_THROW( // NOLINT - { auto message = builder.build(std::move(payload)); }); + EXPECT_NO_THROW( // NOLINT + { auto message = builder.build(std::move(payload)); }); } TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT @@ -556,8 +556,8 @@ TEST_F(TestUMessageBuilder, BuildWithPayloadReturnsUMessage) { // NOLINT EXPECT_TRUE(message.payload() == data); } -TEST_F(TestUMessageBuilder, // NOLINT - BuildWithPayloadMismatchedPayloadFormatThrows) { +TEST_F(TestUMessageBuilder, // NOLINT + BuildWithPayloadMismatchedPayloadFormatThrows) { auto builder = createFakeRequest(); builder.withPayloadFormat(v1::UPayloadFormat::UPAYLOAD_FORMAT_JSON); std::string data = "test-data"; diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index 5cd90a84e..78d0d2a43 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -67,8 +67,8 @@ TEST_F(TestUUriSerializer, SerializeUUriWithNoAuthorityToString) { // NOLINT // Test authority name '*' to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, // NOLINT - SerializeUUriToStringWithAuthorityWildCard) { +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithAuthorityWildCard) { constexpr uint32_t WILDCARD = 0x1FFFE; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("*"); // Wildcard @@ -82,8 +82,8 @@ TEST_F(TestUUriSerializer, // NOLINT // Test Service ID in uEID field as a 0xFFFF to see if it serializes without // an exception for using wildcard -TEST_F(TestUUriSerializer, // NOLINT - SerializeUUriToStringWithServiceIDWildCard) { +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithServiceIDWildCard) { constexpr uint32_t WILDCARD = 0x1FFFF; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("testAuthority"); @@ -97,8 +97,8 @@ TEST_F(TestUUriSerializer, // NOLINT // Test Instance ID in uEID field as a 0x0 to see if it serializes without an // exception for using wildcard -TEST_F(TestUUriSerializer, // NOLINT - SerializeUUriToStringWithInstanceIDWildCard) { +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithInstanceIDWildCard) { constexpr uint32_t WILDCARD = 0x00001234; uprotocol::v1::UUri test_u_uri; test_u_uri.set_authority_name("testAuthority"); @@ -112,8 +112,8 @@ TEST_F(TestUUriSerializer, // NOLINT // Test major version as 0xFF to see if it serializes without an exception for // using wildcard -TEST_F(TestUUriSerializer, // NOLINT - SerializeUUriToStringWithMajorVersionWildCard) { +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithMajorVersionWildCard) { constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFF; uprotocol::v1::UUri test_u_uri; @@ -128,8 +128,8 @@ TEST_F(TestUUriSerializer, // NOLINT // Test resource id as 0xFFFF to see if it thorws an exception for using // wildcard -TEST_F(TestUUriSerializer, // NOLINT - SerializeUUriToStringWithResourceIDWildCard) { +TEST_F(TestUUriSerializer, // NOLINT + SerializeUUriToStringWithResourceIDWildCard) { constexpr uint32_t TEST_UE_ID = 0x12340000; constexpr uint32_t WILDCARD = 0xFFFF; uprotocol::v1::UUri test_u_uri; @@ -162,32 +162,32 @@ TEST_F(TestUUriSerializer, SerializeUUriToStringWithInvalidUUri) { // NOLINT // Empty UUri uprotocol::v1::UUri test_u_uri; - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Authority name too long test_u_uri = base_u_uri; test_u_uri.set_authority_name(std::string(AUTHORITY_NAME_NUMBER, 'b')); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Version out of uint8 range test_u_uri = base_u_uri; test_u_uri.set_ue_version_major(INVALID_VERSION_MAJOR); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Version reserved test_u_uri = base_u_uri; test_u_uri.set_ue_version_major(0); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Resource ID out of uint16 range test_u_uri = base_u_uri; test_u_uri.set_resource_id(INVALID_RESOURCE_ID); - ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(serialized = AsString::serialize(test_u_uri), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); } // Test deserialize by providing scheme "up:" which is allowed to have as per @@ -207,12 +207,13 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithScheme) { // NOLINT } // Test deserialize by providing incorrect scheme "uprotocol:" -TEST_F(TestUUriSerializer, // NOLINT - DeSerializeUUriStringWithIncorrectScheme) { +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithIncorrectScheme) { const std::string uuri_as_string = "uprotocol://192.168.1.10/10010001/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); } // Test deserialize without providing scheme "up:" @@ -233,8 +234,9 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT // Test deserializing empty string to check if it thorws an exception TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT const std::string uuri_as_string; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); } // Test deserializing string with no authority @@ -253,88 +255,102 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithNoAuthority) { // NOLINT } // Test deserializing string with invalid number of arguments -TEST_F(TestUUriSerializer, // NOLINT - DeSerializeUUriStringWithInvalidNumberOfArgument) { +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithInvalidNumberOfArgument) { // Provided 5 arguments instead of 4 when authority exist std::string uuri_as_string = "//192.168.1.10/10010001/FE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // UE ID is missing. Provided 3 arguments instead of 4 when authority exist. uuri_as_string = "//192.168.1.10/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Provided 4 arguments instead of 3 when authority does not exist. uuri_as_string = "/1102/FE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // UE ID is missing. Provided 2 arguments instead of 3 when authority does // not exist. uuri_as_string = "/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "192.168.1.10/1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Valid Uri but leading /// . uuri_as_string = "///192.168.1.10/1102/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Valid Uri but additional trailing / uuri_as_string = "//192.168.1.10/1102/FE/7500/"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); } // Test deserializing string with invalid arguments -TEST_F(TestUUriSerializer, // NOLINT - DeSerializeUUriStringWithInvalidArgument) { +TEST_F(TestUUriSerializer, // NOLINT + DeSerializeUUriStringWithInvalidArgument) { // UE ID provided is invalid. It should be hex numeric std::string uuri_as_string = "//192.168.1.10/testUE/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Major Version provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/^%/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Resource ID provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/FE/xyz"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // UE ID is outside the 32-bit int range uuri_as_string = "//192.168.1.10/110010001/FE/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Major Version is outside the 8-bit int range uuri_as_string = "//192.168.1.10/10010001/100/7500"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); // Resiource ID is outside the 16-bit int range uuri_as_string = "//192.168.1.10/10010001/FE/10000"; - ASSERT_THROW(static_cast(AsString::deserialize(uuri_as_string)), // NOLINT - std::invalid_argument); + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), + std::invalid_argument); } // Test deserializing string with wildcard arguments to see if throws exception TEST_F(TestUUriSerializer, // NOLINT - DeSerializeUUriStringWithWildcardArgument) { + DeSerializeUUriStringWithWildcardArgument) { constexpr uint32_t UE_SERVICE_ID_WILDCARD = 0x1FFFF; constexpr uint32_t UE_INSTANCE_ID_WILDCARD = 0x1234; constexpr uint32_t VERSION_MAJOR_WILDCARD = 0xFF; @@ -403,20 +419,20 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT // Major Version reserved std::string uuri_as_string = "//192.168.1.10/1FFFE/0/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Empty UUri uuri_as_string = "// /0/0/0"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Major Version reserved uuri_as_string = "//"; uuri_as_string += std::string(UURI_NUMBER, 'a'); uuri_as_string += "/1FFFE/1/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // NOTE These are also checked earlier against the std::invalid_argument // exception. They can be caught either way. These can be checked against @@ -424,13 +440,13 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithInvalidUUri) { // NOLINT // Major Version outside the uint8 range uuri_as_string = "//192.168.1.10/1FFFE/FFFE/7500"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); // Resource ID outside the uint8 range uuri_as_string = "//192.168.1.10/1FFFE/FE/C0FFEEEE"; - ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT - uprotocol::datamodel::validator::uri::InvalidUUri); + ASSERT_THROW(uuri = AsString::deserialize(uuri_as_string), // NOLINT + uprotocol::datamodel::validator::uri::InvalidUUri); } } // namespace uprotocol::datamodel::serializer::uri diff --git a/test/coverage/datamodel/UuidBuilderTest.cpp b/test/coverage/datamodel/UuidBuilderTest.cpp index 8207f3cee..0ee7d3fb3 100644 --- a/test/coverage/datamodel/UuidBuilderTest.cpp +++ b/test/coverage/datamodel/UuidBuilderTest.cpp @@ -112,8 +112,8 @@ TEST(UuidBuilderTest, TestModeOnly) { // NOLINT EXPECT_THROW(builder.withTimeSource( // NOLINT []() { return std::chrono::system_clock::now(); }), std::domain_error); - EXPECT_THROW(builder.withRandomSource( // NOLINT - []() { return 0x1234567890ABCDEF; }), + EXPECT_THROW(builder.withRandomSource( // NOLINT + []() { return 0x1234567890ABCDEF; }), std::domain_error); } diff --git a/test/coverage/datamodel/UuidSerializerTest.cpp b/test/coverage/datamodel/UuidSerializerTest.cpp index fa19a4647..ccf68af4a 100644 --- a/test/coverage/datamodel/UuidSerializerTest.cpp +++ b/test/coverage/datamodel/UuidSerializerTest.cpp @@ -77,8 +77,8 @@ TEST_F(TestUuidSerializer, SerializeWithMixedCaseLetters) { // NOLINT } // Test serialization with leading zeros and mixed case letters -TEST_F(TestUuidSerializer, // NOLINT - SerializeWithLeadingZerosAndMixedCaseLetters) { +TEST_F(TestUuidSerializer, // NOLINT + SerializeWithLeadingZerosAndMixedCaseLetters) { constexpr uint64_t UUID_MSB = 0x00001234567890AB; constexpr uint64_t UUID_LSB = 0xFedcba0987654982; uprotocol::v1::UUID uuid; diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 46a753a38..536366792 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -80,8 +80,8 @@ TEST_F(TestUuidValidator, WrongVersion) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::WRONG_VERSION); - EXPECT_THROW(validator::uuid::getVersion(uuid), // NOLINT - validator::uuid::InvalidUuid); + EXPECT_THROW(validator::uuid::getVersion(uuid), // NOLINT + validator::uuid::InvalidUuid); } // Test UUID with unsupported variant @@ -93,8 +93,8 @@ TEST_F(TestUuidValidator, UnsupportedVariant) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::UNSUPPORTED_VARIANT); - EXPECT_THROW(validator::uuid::getVariant(uuid), // NOLINT - validator::uuid::InvalidUuid); + EXPECT_THROW(validator::uuid::getVariant(uuid), // NOLINT + validator::uuid::InvalidUuid); } // Test UUID from the future @@ -111,8 +111,9 @@ TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::FROM_THE_FUTURE); - EXPECT_THROW(validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), // NOLINT - validator::uuid::InvalidUuid); + EXPECT_THROW( // NOLINT + validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), + validator::uuid::InvalidUuid); } // Test expired UUID @@ -240,7 +241,7 @@ TEST_F(TestUuidValidator, InvalidUuidElapsedTime) { // NOLINT auto uuid = createFakeUuid(static_cast(future_timestamp)); EXPECT_THROW(validator::uuid::getElapsedTime(uuid), // NOLINT - validator::uuid::InvalidUuid); + validator::uuid::InvalidUuid); } } // namespace uprotocol::datamodel diff --git a/test/coverage/transport/UTransportTest.cpp b/test/coverage/transport/UTransportTest.cpp index ee6a9fe9c..70498a53a 100644 --- a/test/coverage/transport/UTransportTest.cpp +++ b/test/coverage/transport/UTransportTest.cpp @@ -97,8 +97,8 @@ using InvalidUUri = datamodel::validator::uri::InvalidUUri; TEST_F(TestUTransport, CreateTransportInvalidUUri) { // NOLINT auto uri = getValidUri(); uri.set_authority_name("*"); - EXPECT_THROW({ auto transport = makeTransport(uri); }, // NOLINT - InvalidUUri); + EXPECT_THROW({ auto transport = makeTransport(uri); }, // NOLINT + InvalidUUri); } using UMessageBuilder = datamodel::builder::UMessageBuilder; @@ -137,8 +137,8 @@ TEST_F(TestUTransport, SendInvalidMessage) { // NOLINT v1::UMessageType::UMESSAGE_TYPE_REQUEST); decltype(transport->send(message)) result; - EXPECT_THROW({ result = transport->send(message); }, // NOLINT - InvalidUMessge); + EXPECT_THROW({ result = transport->send(message); }, // NOLINT + InvalidUMessge); EXPECT_EQ(transport_mock->getSendCount(), 0); } @@ -419,8 +419,8 @@ TEST_F(TestUTransport, RegisterListenerWithSinkResourceOk) { // NOLINT } } -TEST_F(TestUTransport, // NOLINT - RegisterListenerWithSinkResourceInvalidSource) { +TEST_F(TestUTransport, // NOLINT + RegisterListenerWithSinkResourceInvalidSource) { auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); @@ -520,8 +520,8 @@ TEST_F(TestUTransport, DeprecatedRegisterListenerOk) { // NOLINT } } -TEST_F(TestUTransport, // NOLINT - DeprecatedRegisterListenerWithSourceFilterOk) { +TEST_F(TestUTransport, // NOLINT + DeprecatedRegisterListenerWithSourceFilterOk) { auto transport_mock = makeMockTransport(getValidUri()); auto transport = makeTransport(transport_mock); diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 44dc58794..21be48b8b 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -716,8 +716,8 @@ TEST_F(CallbackTest, EstablishWithNonCallableCleanup) { // NOLINT callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW( // NOLINT - conn = callbacks::Connection::establish(cb, empty), + EXPECT_THROW( // NOLINT + conn = callbacks::Connection::establish(cb, empty), callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; @@ -737,8 +737,8 @@ TEST_F(CallbackTest, EstablishWithNonCallableCallbackAndCleanup) { // NOLINT callbacks::Connection::Cleanup empty; callbacks::Connection::ConnectedPair conn; - EXPECT_THROW( // NOLINT - conn = callbacks::Connection::establish({}, empty), + EXPECT_THROW( // NOLINT + conn = callbacks::Connection::establish({}, empty), callbacks::EmptyFunctionObject); auto& [handle, callable] = conn; From b564410a36188051e26d4cf7379665a5942014f8 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 13:19:54 +0200 Subject: [PATCH 30/41] Adapted NOLINT Comments to formated code. Part 3 --- .../communication/NotificationSinkTest.cpp | 4 +- test/coverage/communication/PublisherTest.cpp | 8 +-- test/coverage/communication/RpcClientTest.cpp | 4 +- .../coverage/datamodel/UUriSerializerTest.cpp | 64 +++++++++---------- test/coverage/datamodel/UuidValidatorTest.cpp | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index 60c6dfe02..16cadee7b 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -271,8 +271,8 @@ TEST_F(NotificationSinkTest, NullCallback) { // NOLINT transport, transport->getEntityUri(), {}, getTestTopicUUri()); }; - EXPECT_THROW(test_create_empty(), // NOLINT - utils::callbacks::EmptyFunctionObject); + EXPECT_THROW(test_create_empty(), // NOLINT + utils::callbacks::EmptyFunctionObject); } } // namespace uprotocol::communication diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 498711bcb..8a3884d3b 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -184,10 +184,10 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT // publisher with null transport TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW(communication::Publisher publisher( // NOLINT - transport, getTopic(), - getFormat(), getPriority(), getTTL()), - uprotocol::transport::NullTransport); + EXPECT_THROW( // NOLINT + communication::Publisher publisher( + transport, getTopic(), getFormat(), getPriority(), getTTL()), + uprotocol::transport::NullTransport); } } // namespace uprotocol \ No newline at end of file diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 19e7aedb4..a2ac1e8f0 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -328,8 +328,8 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { - EXPECT_NO_THROW( // NOLINT - auto maybe_response = invoke_future.get(); + EXPECT_NO_THROW( // NOLINT + auto maybe_response = invoke_future.get(); checkErrorResponse(maybe_response, v1::UCode::CANCELLED);); } } diff --git a/test/coverage/datamodel/UUriSerializerTest.cpp b/test/coverage/datamodel/UUriSerializerTest.cpp index 78d0d2a43..43544931b 100644 --- a/test/coverage/datamodel/UUriSerializerTest.cpp +++ b/test/coverage/datamodel/UUriSerializerTest.cpp @@ -211,8 +211,8 @@ TEST_F(TestUUriSerializer, // NOLINT DeSerializeUUriStringWithIncorrectScheme) { const std::string uuri_as_string = "uprotocol://192.168.1.10/10010001/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); } @@ -234,8 +234,8 @@ TEST_F(TestUUriSerializer, DeSerializeUUriStringWithoutScheme) { // NOLINT // Test deserializing empty string to check if it thorws an exception TEST_F(TestUUriSerializer, DeSerializeEmptyUUriString) { // NOLINT const std::string uuri_as_string; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); } @@ -260,51 +260,51 @@ TEST_F(TestUUriSerializer, // NOLINT // Provided 5 arguments instead of 4 when authority exist std::string uuri_as_string = "//192.168.1.10/10010001/FE/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // UE ID is missing. Provided 3 arguments instead of 4 when authority exist. uuri_as_string = "//192.168.1.10/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Provided 4 arguments instead of 3 when authority does not exist. uuri_as_string = "/1102/FE/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // UE ID is missing. Provided 2 arguments instead of 3 when authority does // not exist. uuri_as_string = "/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "192.168.1.10/1102/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Valid Uri but no leading / uuri_as_string = "1102/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Valid Uri but leading /// . uuri_as_string = "///192.168.1.10/1102/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Valid Uri but additional trailing / uuri_as_string = "//192.168.1.10/1102/FE/7500/"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); } @@ -313,38 +313,38 @@ TEST_F(TestUUriSerializer, // NOLINT DeSerializeUUriStringWithInvalidArgument) { // UE ID provided is invalid. It should be hex numeric std::string uuri_as_string = "//192.168.1.10/testUE/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Major Version provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/^%/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Resource ID provided is invalid. It should be hex numeric uuri_as_string = "//192.168.1.10/10010001/FE/xyz"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // UE ID is outside the 32-bit int range uuri_as_string = "//192.168.1.10/110010001/FE/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Major Version is outside the 8-bit int range uuri_as_string = "//192.168.1.10/10010001/100/7500"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); // Resiource ID is outside the 16-bit int range uuri_as_string = "//192.168.1.10/10010001/FE/10000"; - ASSERT_THROW( // NOLINT - static_cast(AsString::deserialize(uuri_as_string)), + ASSERT_THROW( // NOLINT + static_cast(AsString::deserialize(uuri_as_string)), std::invalid_argument); } diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 536366792..8c03bcc50 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -111,8 +111,8 @@ TEST_F(TestUuidValidator, FromTheFuture) { // NOLINT auto [valid, reason] = validator::uuid::isUuid(uuid); EXPECT_FALSE(valid); EXPECT_EQ(reason.value(), validator::uuid::Reason::FROM_THE_FUTURE); - EXPECT_THROW( // NOLINT - validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), + EXPECT_THROW( // NOLINT + validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS), validator::uuid::InvalidUuid); } From fc82f61425c31bac1b65c6b99d0fa530512e896e Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 14:25:28 +0200 Subject: [PATCH 31/41] Dummy fix NOLINT for complicated warnings --- test/coverage/communication/RpcClientTest.cpp | 2 +- test/coverage/datamodel/UMessageBuilderTest.cpp | 8 ++++---- test/coverage/datamodel/UuidValidatorTest.cpp | 1 - test/coverage/utils/CallbackConnectionTest.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index a2ac1e8f0..e8877decd 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1315,7 +1315,7 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT workers.size()> handles; // size_t handle_counter = 0; - auto worker_handles = handles.begin(); + auto worker_handles = handles.begin(); // NOLINT for (auto& worker : workers) { worker = std::thread( diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 7cac00530..67de01da6 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -103,10 +103,10 @@ class TestUMessageBuilder : public testing::Test { ~TestUMessageBuilder() override = default; }; -v1::UUri TestUMessageBuilder::source_; -v1::UUri TestUMessageBuilder::sink_; -v1::UUri TestUMessageBuilder::method_; -v1::UUID TestUMessageBuilder::req_id_; +v1::UUri TestUMessageBuilder::source_; // NOLINT +v1::UUri TestUMessageBuilder::sink_; // NOLINT +v1::UUri TestUMessageBuilder::method_; // NOLINT +v1::UUID TestUMessageBuilder::req_id_; // NOLINT /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 8c03bcc50..6539bbdbf 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -20,7 +20,6 @@ constexpr std::chrono::seconds SIXTY_SECONDS(60); constexpr std::chrono::seconds THIRTY_SECONDS(30); namespace uprotocol::datamodel { -// using namespace uprotocol::datamodel::validator::uuid::; class TestUuidValidator : public testing::Test { protected: diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 21be48b8b..853b2071d 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -574,7 +574,7 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT auto [handle, callable] = callbacks::Connection::establish( [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); - auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, + auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, // NOLINT &main_task_sync]() mutable { ++callbacks_pending; main_task_sync.release(); From da77a78cd168540d4b8bff2eac993d11c08707cd Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 15:08:14 +0200 Subject: [PATCH 32/41] Fixed auto worker_handles warning in ParallelAccessSingleClientTest --- test/coverage/communication/RpcClientTest.cpp | 5 ++--- test/coverage/datamodel/UMessageBuilderTest.cpp | 8 ++++---- test/coverage/utils/CallbackConnectionTest.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index e8877decd..6217673ea 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1314,12 +1314,11 @@ TEST_F(RpcClientTest, ParallelAccessSingleClient) { // NOLINT std::array, workers.size()> handles; - // size_t handle_counter = 0; - auto worker_handles = handles.begin(); // NOLINT + size_t handle_counter = 0; for (auto& worker : workers) { worker = std::thread( - [&call_count, &client, &handles = *(worker_handles++)]() { + [&call_count, &client, &handles = handles.at(handle_counter++)]() { for (auto remaining = NUM_REQUESTS_PER_WORKER; remaining > 0; --remaining) { handles.emplace_back(client.invokeMethod( diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 67de01da6..7cac00530 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -103,10 +103,10 @@ class TestUMessageBuilder : public testing::Test { ~TestUMessageBuilder() override = default; }; -v1::UUri TestUMessageBuilder::source_; // NOLINT -v1::UUri TestUMessageBuilder::sink_; // NOLINT -v1::UUri TestUMessageBuilder::method_; // NOLINT -v1::UUID TestUMessageBuilder::req_id_; // NOLINT +v1::UUri TestUMessageBuilder::source_; +v1::UUri TestUMessageBuilder::sink_; +v1::UUri TestUMessageBuilder::method_; +v1::UUID TestUMessageBuilder::req_id_; /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 853b2071d..f931b82c4 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -574,7 +574,7 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT auto [handle, callable] = callbacks::Connection::establish( [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); - auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, // NOLINT + auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, &main_task_sync]() mutable { ++callbacks_pending; main_task_sync.release(); From f5c138784c2da292b816ef77e6e94541fbfaee2e Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 15:16:03 +0200 Subject: [PATCH 33/41] Solved static issue in UMessageBuilderTest --- .../datamodel/UMessageBuilderTest.cpp | 144 ++++++++++-------- 1 file changed, 77 insertions(+), 67 deletions(-) diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 7cac00530..47c5060b2 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -25,10 +25,40 @@ class TestUMessageBuilder : public testing::Test { protected: // Run once per TEST_F. // Used to set up clean environments per test. - void SetUp() override {} + void SetUp() override { + constexpr uint32_t SOURCE_UE_ID = 0x00011101; + constexpr uint32_t SINK_UE_ID = 0x00011102; + constexpr uint32_t METHOD_UE_ID = 0x00011103; + + constexpr uint32_t SOURCE_UE_VERSION_MAJOR = 0xF8; + constexpr uint32_t SINK_UE_VERSION_MAJOR = 0xF9; + constexpr uint32_t METHOD_UE_VERSION_MAJOR = 0xFA; + + constexpr uint32_t SOURCE_RESOURCE_ID = 0x8101; + constexpr uint32_t SINK_RESOURCE_ID = 0; + constexpr uint32_t METHOD_RESOURCE_ID = 0x0101; + + // Create a UUri object for testing + source_.set_authority_name("10.0.0.1"); + source_.set_ue_id(SOURCE_UE_ID); + source_.set_ue_version_major(SOURCE_UE_VERSION_MAJOR); + source_.set_resource_id(SOURCE_RESOURCE_ID); + + sink_.set_authority_name("10.0.0.2"); + sink_.set_ue_id(SINK_UE_ID); + sink_.set_ue_version_major(SINK_UE_VERSION_MAJOR); + sink_.set_resource_id(SINK_RESOURCE_ID); + + method_.set_authority_name("10.0.0.3"); + method_.set_ue_id(METHOD_UE_ID); + method_.set_ue_version_major(METHOD_UE_VERSION_MAJOR); + method_.set_resource_id(METHOD_RESOURCE_ID); + + req_id_ = datamodel::builder::UuidBuilder::getBuilder().build(); + } void TearDown() override {} - static datamodel::builder::UMessageBuilder createFakeRequest() { + datamodel::builder::UMessageBuilder createFakeRequest() { v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); v1::UUri method = method_; @@ -38,7 +68,7 @@ class TestUMessageBuilder : public testing::Test { std::move(method), std::move(source), priority, ttl); } - static datamodel::builder::UMessageBuilder createFakeResponse() { + datamodel::builder::UMessageBuilder createFakeResponse() { v1::UUri sink = sink_; v1::UUri method = method_; v1::UUID request_id = req_id_; @@ -62,55 +92,35 @@ class TestUMessageBuilder : public testing::Test { // Run once per execution of the test application. // Used only for global setup outside of tests. static void SetUpTestSuite() { - constexpr uint32_t SOURCE_UE_ID = 0x00011101; - constexpr uint32_t SINK_UE_ID = 0x00011102; - constexpr uint32_t METHOD_UE_ID = 0x00011103; - - constexpr uint32_t SOURCE_UE_VERSION_MAJOR = 0xF8; - constexpr uint32_t SINK_UE_VERSION_MAJOR = 0xF9; - constexpr uint32_t METHOD_UE_VERSION_MAJOR = 0xFA; - - constexpr uint32_t SOURCE_RESOURCE_ID = 0x8101; - constexpr uint32_t SINK_RESOURCE_ID = 0; - constexpr uint32_t METHOD_RESOURCE_ID = 0x0101; - - // Create a UUri object for testing - source_.set_authority_name("10.0.0.1"); - source_.set_ue_id(SOURCE_UE_ID); - source_.set_ue_version_major(SOURCE_UE_VERSION_MAJOR); - source_.set_resource_id(SOURCE_RESOURCE_ID); - - sink_.set_authority_name("10.0.0.2"); - sink_.set_ue_id(SINK_UE_ID); - sink_.set_ue_version_major(SINK_UE_VERSION_MAJOR); - sink_.set_resource_id(SINK_RESOURCE_ID); - - method_.set_authority_name("10.0.0.3"); - method_.set_ue_id(METHOD_UE_ID); - method_.set_ue_version_major(METHOD_UE_VERSION_MAJOR); - method_.set_resource_id(METHOD_RESOURCE_ID); - - req_id_ = datamodel::builder::UuidBuilder::getBuilder().build(); } static void TearDownTestSuite() {} - static v1::UUri source_; - static v1::UUri sink_; - static v1::UUri method_; - static v1::UUID req_id_; + const v1::UUri& getSource() const { return source_; } + + const v1::UUri& getSink() const { return sink_; } + + const v1::UUri& getMethod() const { return method_; } + + const v1::UUID& getReqId() const { return req_id_; } + +private: + v1::UUri source_; + v1::UUri sink_; + v1::UUri method_; + v1::UUID req_id_; public: ~TestUMessageBuilder() override = default; }; -v1::UUri TestUMessageBuilder::source_; -v1::UUri TestUMessageBuilder::sink_; -v1::UUri TestUMessageBuilder::method_; -v1::UUID TestUMessageBuilder::req_id_; +// v1::UUri TestUMessageBuilder::source_; +// v1::UUri TestUMessageBuilder::sink_; +// v1::UUri TestUMessageBuilder::method_; +// v1::UUID TestUMessageBuilder::req_id_; /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT - v1::UUri topic = source_; + v1::UUri topic = getSource(); EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::publish(std::move(topic)); @@ -118,7 +128,7 @@ TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_PUBLISH); EXPECT_EQ( datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(source_)); + datamodel::serializer::uri::AsString::serialize(getSource())); }); } @@ -132,8 +142,8 @@ TEST_F(TestUMessageBuilder, PublishInvalidTopicUriThrows) { // NOLINT /// @brief Test the notification function of the UMessageBuilder TEST_F(TestUMessageBuilder, NotificationTest) { // NOLINT // Call the notification function - v1::UUri source = source_; - v1::UUri sink = sink_; + v1::UUri source = getSource(); + v1::UUri sink = getSink(); EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::notification( @@ -143,9 +153,9 @@ TEST_F(TestUMessageBuilder, NotificationTest) { // NOLINT EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_NOTIFICATION); EXPECT_EQ( datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(source_)); + datamodel::serializer::uri::AsString::serialize(getSource())); EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), - datamodel::serializer::uri::AsString::serialize(sink_)); + datamodel::serializer::uri::AsString::serialize(getSink())); }); } @@ -153,7 +163,7 @@ TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); - v1::UUri sink = sink_; + v1::UUri sink = getSink(); EXPECT_THROW( // NOLINT { datamodel::builder::UMessageBuilder::notification(std::move(source), @@ -163,7 +173,7 @@ TEST_F(TestUMessageBuilder, NotificationInvalidSourceUriThrows) { // NOLINT } TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { // NOLINT - v1::UUri source = source_; + v1::UUri source = getSource(); v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); @@ -179,8 +189,8 @@ TEST_F(TestUMessageBuilder, NotificationInvalidSinkUriThrows) { // NOLINT TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); - v1::UUri method = method_; - v1::UUri source = sink_; + v1::UUri method = getMethod(); + v1::UUri source = getSink(); EXPECT_NO_THROW({ // NOLINT auto builder = datamodel::builder::UMessageBuilder::request( @@ -188,10 +198,10 @@ TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT auto attr = builder.build().attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_REQUEST); EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), - datamodel::serializer::uri::AsString::serialize(method_)); + datamodel::serializer::uri::AsString::serialize(getMethod())); EXPECT_EQ( datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(sink_)); + datamodel::serializer::uri::AsString::serialize(getSink())); EXPECT_EQ(attr.priority(), priority); EXPECT_EQ(attr.ttl(), TTL_TIME); }); @@ -199,7 +209,7 @@ TEST_F(TestUMessageBuilder, RequestValidParametersSuccess) { // NOLINT TEST_F(TestUMessageBuilder, RequestInvalidMethodUriThrows) { // NOLINT v1::UUri method; - v1::UUri source = source_; + v1::UUri source = getSource(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); EXPECT_THROW( // NOLINT @@ -214,7 +224,7 @@ TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { // NOLINT v1::UUri source; // Set the source Service Instance ID a wildcard (any) source.set_ue_id(UI_ID_INVALID_TEST); - v1::UUri method = method_; + v1::UUri method = getMethod(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(TTL_TIME); EXPECT_THROW( // NOLINT @@ -226,8 +236,8 @@ TEST_F(TestUMessageBuilder, RequestInvalidSourceUriThrows) { // NOLINT } TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { // NOLINT - v1::UUri method = method_; - v1::UUri source = sink_; + v1::UUri method = getMethod(); + v1::UUri source = getSink(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; std::chrono::milliseconds ttl(-1); // Invalid TTL EXPECT_THROW( // NOLINT @@ -240,9 +250,9 @@ TEST_F(TestUMessageBuilder, RequestInvalidTtlThrows) { // NOLINT /// @brief Test the response function of the UMessageBuilder TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { // NOLINT - v1::UUri sink = sink_; - v1::UUri method = method_; - v1::UUID request_id = req_id_; + v1::UUri sink = getSink(); + v1::UUri method = getMethod(); + v1::UUID request_id = getReqId(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_NO_THROW({ // NOLINT @@ -252,19 +262,19 @@ TEST_F(TestUMessageBuilder, ResponseValidParametersSuccess) { // NOLINT const v1::UAttributes& attr = builder.attributes(); EXPECT_EQ(attr.type(), v1::UMessageType::UMESSAGE_TYPE_RESPONSE); EXPECT_EQ(datamodel::serializer::uri::AsString::serialize(attr.sink()), - datamodel::serializer::uri::AsString::serialize(sink_)); + datamodel::serializer::uri::AsString::serialize(getSink())); EXPECT_EQ( datamodel::serializer::uri::AsString::serialize(attr.source()), - datamodel::serializer::uri::AsString::serialize(method_)); + datamodel::serializer::uri::AsString::serialize(getMethod())); // EXPECT_EQ(attr.reqid(), req_id_); EXPECT_EQ(attr.priority(), priority); }); } TEST_F(TestUMessageBuilder, ResponseInvalidMethodUriThrows) { // NOLINT - v1::UUri sink = sink_; + v1::UUri sink = getSink(); v1::UUri method; - v1::UUID request_id = req_id_; + v1::UUID request_id = getReqId(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( // NOLINT { @@ -279,8 +289,8 @@ TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { // NOLINT v1::UUri sink; // Set the source Service Instance ID a wildcard (any) sink.set_ue_id(UI_ID_INVALID_TEST); - v1::UUri method = method_; - v1::UUID request_id = req_id_; + v1::UUri method = getMethod(); + v1::UUID request_id = getReqId(); v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( // NOLINT { @@ -292,8 +302,8 @@ TEST_F(TestUMessageBuilder, ResponseInvalidSinkUriThrows) { // NOLINT } TEST_F(TestUMessageBuilder, ResponseInvalidRequestIdThrows) { // NOLINT - v1::UUri sink = sink_; - v1::UUri method = method_; + v1::UUri sink = getSink(); + v1::UUri method = getMethod(); v1::UUID request_id; v1::UPriority priority = v1::UPriority::UPRIORITY_CS4; EXPECT_THROW( // NOLINT From 9eb4686d230ebe70c93bf82b4e025d45f2fa3f43 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 15:25:58 +0200 Subject: [PATCH 34/41] Finished linter warnings --- test/coverage/utils/CallbackConnectionTest.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index f931b82c4..963f8734e 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -571,8 +571,13 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT // for startup synchronization. SemaphoreLike callee_sync; - auto [handle, callable] = callbacks::Connection::establish( + auto connected_pair = callbacks::Connection::establish( [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); + + auto handle = std::move(std::get<0>(connected_pair)); + auto callable = std::get<1>(connected_pair); + // auto [handle, callable] = callbacks::Connection::establish( + // [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, &main_task_sync]() mutable { From 29d0d9d80a460cdaa3f60e723529ac7ca7886a46 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 15:38:30 +0200 Subject: [PATCH 35/41] Formated code --- test/coverage/communication/PublisherTest.cpp | 6 +++--- test/coverage/datamodel/UMessageBuilderTest.cpp | 15 +++++++-------- test/coverage/utils/CallbackConnectionTest.cpp | 11 ++++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 8a3884d3b..2a6ed6a9e 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -184,9 +184,9 @@ TEST_F(TestPublisher, PublishSuccessWithoutPriority) { // NOLINT // publisher with null transport TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT auto transport = nullptr; - EXPECT_THROW( // NOLINT - communication::Publisher publisher( - transport, getTopic(), getFormat(), getPriority(), getTTL()), + EXPECT_THROW( // NOLINT + communication::Publisher publisher(transport, getTopic(), getFormat(), + getPriority(), getTTL()), uprotocol::transport::NullTransport); } diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 47c5060b2..1e524580e 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -91,17 +91,16 @@ class TestUMessageBuilder : public testing::Test { // Run once per execution of the test application. // Used only for global setup outside of tests. - static void SetUpTestSuite() { - } + static void SetUpTestSuite() {} static void TearDownTestSuite() {} const v1::UUri& getSource() const { return source_; } - - const v1::UUri& getSink() const { return sink_; } - - const v1::UUri& getMethod() const { return method_; } - - const v1::UUID& getReqId() const { return req_id_; } + + const v1::UUri& getSink() const { return sink_; } + + const v1::UUri& getMethod() const { return method_; } + + const v1::UUID& getReqId() const { return req_id_; } private: v1::UUri source_; diff --git a/test/coverage/utils/CallbackConnectionTest.cpp b/test/coverage/utils/CallbackConnectionTest.cpp index 963f8734e..74a284bf4 100644 --- a/test/coverage/utils/CallbackConnectionTest.cpp +++ b/test/coverage/utils/CallbackConnectionTest.cpp @@ -573,13 +573,14 @@ TEST_F(CallbackTest, HandleResetBlocksWhileCallbacksRunning) { // NOLINT auto connected_pair = callbacks::Connection::establish( [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); - - auto handle = std::move(std::get<0>(connected_pair)); - auto callable = std::get<1>(connected_pair); + + auto handle = std::move(std::get<0>(connected_pair)); + auto callable = std::get<1>(connected_pair); // auto [handle, callable] = callbacks::Connection::establish( - // [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); }); + // [&fake_blocking_op]() { return fake_blocking_op.try_acquire_for(1s); + // }); - auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, + auto caller_fn = ([callable, &callbacks_pending, &callbacks_released, &main_task_sync]() mutable { ++callbacks_pending; main_task_sync.release(); From 04c3352cad4a6b3adbbaf7bc5127333122787678 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Fri, 11 Apr 2025 17:06:19 +0200 Subject: [PATCH 36/41] Update clang-tidy.sh to check src/, inc/ and test/ --- lint/clang-tidy.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index cc4a66cd9..19e9ddc80 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,8 +58,7 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - # for f in include/**/*.h src/**/*.cpp - for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" From 963bed5ceaa8cadba6dd181689e1f248e6af0bcf Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 15 Apr 2025 08:15:22 +0200 Subject: [PATCH 37/41] remove commented code for namespace. Fix typo --- src/communication/RpcClient.cpp | 1 - src/datamodel/validator/UMessage.cpp | 1 - .../client/usubscription/v3/ConsumerTest.cpp | 36 +++++++++---------- test/coverage/datamodel/UuidBuilderTest.cpp | 1 - 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/communication/RpcClient.cpp b/src/communication/RpcClient.cpp index 87239a71f..469b51316 100644 --- a/src/communication/RpcClient.cpp +++ b/src/communication/RpcClient.cpp @@ -265,7 +265,6 @@ namespace detail { using uprotocol::v1::UCode; using uprotocol::v1::UStatus; -// using namespace std::chrono_literals; using ListenHandle = uprotocol::transport::UTransport::ListenHandle; auto PendingRequest::operator>(const PendingRequest& other) const { diff --git a/src/datamodel/validator/UMessage.cpp b/src/datamodel/validator/UMessage.cpp index 6a9db80c7..5a611bc2b 100644 --- a/src/datamodel/validator/UMessage.cpp +++ b/src/datamodel/validator/UMessage.cpp @@ -19,7 +19,6 @@ namespace uprotocol::datamodel::validator::message { using uprotocol::v1::UPRIORITY_CS4; -// using uprotocol::datamodel::validator; std::string_view message(Reason reason) { switch (reason) { diff --git a/test/coverage/client/usubscription/v3/ConsumerTest.cpp b/test/coverage/client/usubscription/v3/ConsumerTest.cpp index 58dc5e7c5..07b26b0e8 100644 --- a/test/coverage/client/usubscription/v3/ConsumerTest.cpp +++ b/test/coverage/client/usubscription/v3/ConsumerTest.cpp @@ -32,7 +32,7 @@ class ConsumerTest : public testing::Test { std::shared_ptr mockTransportServer_; uprotocol::v1::UUri client_uuri; uprotocol::v1::UUri server_uuri; - uprotocol::v1::UUri subcription_uuri; + uprotocol::v1::UUri subscription_uuri; protected: // Run once per TEST_F. @@ -48,8 +48,8 @@ class ConsumerTest : public testing::Test { } uprotocol::v1::UUri& getClientUUri() { return client_uuri; } const uprotocol::v1::UUri& getServerUUri() const { return server_uuri; } - const uprotocol::v1::UUri& getSubcriptionUUri() const { - return subcription_uuri; + const uprotocol::v1::UUri& getSubscriptionUUri() const { + return subscription_uuri; } void setMockTransportClient( const std::shared_ptr& client) { @@ -61,8 +61,8 @@ class ConsumerTest : public testing::Test { } void setClientUUri(const uprotocol::v1::UUri& uuri) { client_uuri = uuri; } void setServerUUri(const uprotocol::v1::UUri& uuri) { server_uuri = uuri; } - void setSubcriptionUUri(const uprotocol::v1::UUri& uuri) { - subcription_uuri = uuri; + void setSubscriptionUUri(const uprotocol::v1::UUri& uuri) { + subscription_uuri = uuri; } void SetUp() override { @@ -88,10 +88,10 @@ class ConsumerTest : public testing::Test { std::make_shared(server_uuri); // Create a generic subscription uri - subcription_uuri.set_authority_name("10.0.0.2"); - subcription_uuri.set_ue_id(TEST_UE_ID); - subcription_uuri.set_ue_version_major(3); - subcription_uuri.set_resource_id(DEFAULT_RESOURCE_ID); + subscription_uuri.set_authority_name("10.0.0.2"); + subscription_uuri.set_ue_id(TEST_UE_ID); + subscription_uuri.set_ue_version_major(3); + subscription_uuri.set_resource_id(DEFAULT_RESOURCE_ID); }; void TearDown() override {} @@ -115,7 +115,7 @@ class ConsumerTest : public testing::Test { // Negative test case with no source filter TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT constexpr int REQUEST_TTL_TIME = 0x8000; - auto subcription_callback = someCallBack; + auto subscription_callback = someCallBack; auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; @@ -123,8 +123,8 @@ TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, subscribe_request_ttl, options); + getMockTransportClient(), getSubscriptionUUri(), + subscription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); @@ -140,7 +140,7 @@ TEST_F(ConsumerTest, ConstructorTestSuccess) { // NOLINT TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; constexpr int REQUEST_TTL_TIME = 0x8000; - auto subcription_callback = someCallBack; + auto subscription_callback = someCallBack; auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; @@ -148,8 +148,8 @@ TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, subscribe_request_ttl, options); + getMockTransportClient(), getSubscriptionUUri(), + subscription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); @@ -186,7 +186,7 @@ TEST_F(ConsumerTest, SubscribeTestSuccess) { // NOLINT TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT constexpr uint32_t DEFAULT_RESOURCE_ID = 0x8000; constexpr int REQUEST_TTL_TIME = 0x8000; - auto subcription_callback = someCallBack; + auto subscription_callback = someCallBack; auto subscribe_request_ttl = std::chrono::milliseconds(REQUEST_TTL_TIME); auto priority = uprotocol::v1::UPriority::UPRIORITY_CS4; @@ -194,8 +194,8 @@ TEST_F(ConsumerTest, UnsubscribeTestSuccess) { // NOLINT auto consumer_or_status = uprotocol::client::usubscription::v3::Consumer::create( - getMockTransportClient(), getSubcriptionUUri(), - subcription_callback, priority, subscribe_request_ttl, options); + getMockTransportClient(), getSubscriptionUUri(), + subscription_callback, priority, subscribe_request_ttl, options); // Ensure that the consumer creation was successful ASSERT_TRUE(consumer_or_status.has_value()); diff --git a/test/coverage/datamodel/UuidBuilderTest.cpp b/test/coverage/datamodel/UuidBuilderTest.cpp index 0ee7d3fb3..0a781c6d9 100644 --- a/test/coverage/datamodel/UuidBuilderTest.cpp +++ b/test/coverage/datamodel/UuidBuilderTest.cpp @@ -14,7 +14,6 @@ #include "up-cpp/datamodel/builder/Uuid.h" #include "up-cpp/datamodel/constants/UuidConstants.h" -// using namespace uprotocol::datamodel::builder::; namespace uprotocol::datamodel { class TestUuidBuilder : public testing::Test { From 73c507d69b659cc1b89a43d8e27215d77ea7a5bf Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Tue, 15 Apr 2025 09:36:55 +0200 Subject: [PATCH 38/41] Remove setter-Methods --- .../client/usubscription/v3/ConsumerTest.cpp | 13 ------------ .../communication/NotificationSinkTest.cpp | 14 ------------- .../communication/NotificationSourceTest.cpp | 17 --------------- test/coverage/communication/PublisherTest.cpp | 21 ------------------- test/coverage/communication/RpcClientTest.cpp | 3 --- test/coverage/communication/RpcServerTest.cpp | 13 ------------ .../coverage/communication/SubscriberTest.cpp | 14 ------------- .../datamodel/UMessageBuilderTest.cpp | 8 ------- test/extra/RpcClientServerTest.cpp | 1 - test/include/UTransportMock.h | 9 -------- 10 files changed, 113 deletions(-) diff --git a/test/coverage/client/usubscription/v3/ConsumerTest.cpp b/test/coverage/client/usubscription/v3/ConsumerTest.cpp index 07b26b0e8..6c6c133e4 100644 --- a/test/coverage/client/usubscription/v3/ConsumerTest.cpp +++ b/test/coverage/client/usubscription/v3/ConsumerTest.cpp @@ -51,19 +51,6 @@ class ConsumerTest : public testing::Test { const uprotocol::v1::UUri& getSubscriptionUUri() const { return subscription_uuri; } - void setMockTransportClient( - const std::shared_ptr& client) { - mockTransportClient_ = client; - } - void setMockTransportServer( - const std::shared_ptr& server) { - mockTransportClient_ = server; - } - void setClientUUri(const uprotocol::v1::UUri& uuri) { client_uuri = uuri; } - void setServerUUri(const uprotocol::v1::UUri& uuri) { server_uuri = uuri; } - void setSubscriptionUUri(const uprotocol::v1::UUri& uuri) { - subscription_uuri = uuri; - } void SetUp() override { constexpr uint32_t TEST_UE_ID = 0x18000; diff --git a/test/coverage/communication/NotificationSinkTest.cpp b/test/coverage/communication/NotificationSinkTest.cpp index 16cadee7b..ecef04d3c 100644 --- a/test/coverage/communication/NotificationSinkTest.cpp +++ b/test/coverage/communication/NotificationSinkTest.cpp @@ -50,20 +50,6 @@ class NotificationSinkTest : public testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} - void setTestTopicUUri(const uprotocol::v1::UUri& uuri) { - testTopicUUri_ = uuri; - } - void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uuri) { - testInvalidTopicUUri_ = uuri; - } - void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uuri) { - testDefaultSourceUUri_ = uuri; - } - void setCaptureCount(size_t count) { capture_count_ = count; } - void setCaptureMsg(const uprotocol::v1::UMessage& msg) { - capture_msg_ = msg; - } - const uprotocol::v1::UUri& getTestTopicUUri() const { return testTopicUUri_; } diff --git a/test/coverage/communication/NotificationSourceTest.cpp b/test/coverage/communication/NotificationSourceTest.cpp index e3a88105a..724ac9e74 100644 --- a/test/coverage/communication/NotificationSourceTest.cpp +++ b/test/coverage/communication/NotificationSourceTest.cpp @@ -78,23 +78,6 @@ class TestNotificationSource : public testing::Test { std::optional& getPriority() { return priority_; } std::optional getTTL() const { return ttl_; } - void setTransportMock( - const std::shared_ptr& - transport_mock) { - transportMock_ = transport_mock; - } - void setSource(const uprotocol::v1::UUri& source) { source_ = source; } - void setSink(const uprotocol::v1::UUri& sink) { sink_ = sink; } - void setFormat(const uprotocol::v1::UPayloadFormat& format) { - format_ = format; - } - void setPriority(const std::optional& priority) { - priority_ = priority; - } - void setTTL(const std::optional& ttl) { - ttl_ = ttl; - } - public: ~TestNotificationSource() override = default; }; diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 2a6ed6a9e..14e7efa60 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -18,9 +18,6 @@ namespace uprotocol { -// namespace { -// using namespace uprotocol::datamodel::builder; - class TestPublisher : public testing::Test { private: std::shared_ptr transportMock_; @@ -42,24 +39,6 @@ class TestPublisher : public testing::Test { std::optional getTTL() const { return ttl_; } uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } - void setTransportMock( - const std::shared_ptr& - transport_mock) { - transportMock_ = transport_mock; - } - void setSource(const v1::UUri& source) { source_ = source; } - void setTopic(const v1::UUri& topic) { topic_ = topic; } - void setFormat(const v1::UPayloadFormat& format) { format_ = format; } - void setPriority(const std::optional& priority) { - priority_ = priority; - } - void setTTL(const std::optional& ttl) { - ttl_ = ttl; - } - void setCaptureMsg(const uprotocol::v1::UMessage& capture_msg) { - capture_msg_ = capture_msg; - } - // Run once per TEST_F. // Used to set up clean environments per test. void SetUp() override { diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 6217673ea..f0ac0ad54 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -121,9 +121,6 @@ class RpcClientTest : public testing::Test { [[nodiscard]] std::shared_ptr getTransport() const { return transport_; } - void setTransport(const std::shared_ptr& transport) { - transport_ = transport; - } public: ~RpcClientTest() override = default; diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 066ce8ac0..1aba75dc9 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -81,19 +81,6 @@ class TestRpcServer : public testing::Test { [[nodiscard]] std::chrono::milliseconds getTTL() const { return ttl_; } [[nodiscard]] v1::UPayloadFormat getFormat() const { return format; } - void setMockTransport( - const std::shared_ptr& mock_transport) { - mockTransport_ = mock_transport; - } - void setMethodUri(const std::shared_ptr& method_uri) { - method_uri_ = method_uri; - } - void setRequestUri(const std::shared_ptr& request_uri) { - request_uri_ = request_uri; - } - void setTTL(const std::chrono::milliseconds& ttl) { ttl_ = ttl; } - void setFormat(v1::UPayloadFormat format) { this->format = format; } - void SetUp() override { constexpr uint32_t DEF_UE_ID = 0x18000; constexpr uint32_t METHOD_UE_ID = 0x00010002; diff --git a/test/coverage/communication/SubscriberTest.cpp b/test/coverage/communication/SubscriberTest.cpp index 39f01165e..e58921e22 100644 --- a/test/coverage/communication/SubscriberTest.cpp +++ b/test/coverage/communication/SubscriberTest.cpp @@ -59,20 +59,6 @@ class SubscriberTest : public testing::Test { size_t getCaptureCount() const { return capture_count_; } uprotocol::v1::UMessage getCaptureMsg() const { return capture_msg_; } - void setTestTopicUUri(const uprotocol::v1::UUri& uri) { - testTopicUUri_ = uri; - } - void setTestInvalidTopicUUri(const uprotocol::v1::UUri& uri) { - testInvalidTopicUUri_ = uri; - } - void setTestDefaultSourceUUri(const uprotocol::v1::UUri& uri) { - testDefaultSourceUUri_ = uri; - } - void setCaptureCount(size_t count) { capture_count_ = count; } - void setCaptureMsg(const uprotocol::v1::UMessage& msg) { - capture_msg_ = msg; - } - public: void handleCallbackMessage(const uprotocol::v1::UMessage& message); ~SubscriberTest() override = default; diff --git a/test/coverage/datamodel/UMessageBuilderTest.cpp b/test/coverage/datamodel/UMessageBuilderTest.cpp index 1e524580e..53b007f6e 100644 --- a/test/coverage/datamodel/UMessageBuilderTest.cpp +++ b/test/coverage/datamodel/UMessageBuilderTest.cpp @@ -95,11 +95,8 @@ class TestUMessageBuilder : public testing::Test { static void TearDownTestSuite() {} const v1::UUri& getSource() const { return source_; } - const v1::UUri& getSink() const { return sink_; } - const v1::UUri& getMethod() const { return method_; } - const v1::UUID& getReqId() const { return req_id_; } private: @@ -112,11 +109,6 @@ class TestUMessageBuilder : public testing::Test { ~TestUMessageBuilder() override = default; }; -// v1::UUri TestUMessageBuilder::source_; -// v1::UUri TestUMessageBuilder::sink_; -// v1::UUri TestUMessageBuilder::method_; -// v1::UUID TestUMessageBuilder::req_id_; - /// @brief Test the publish function of the UMessageBuilder TEST_F(TestUMessageBuilder, PublishValidTopicUriSuccess) { // NOLINT v1::UUri topic = getSource(); diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index 636bb8299..5a235ee30 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -38,7 +38,6 @@ struct MyUUri { ue_version_major(ue_details.ue_version_major), resource_id(resource_id_val) {} - void set_auth(const std::string& auth_val) { auth = auth_val; } [[nodiscard]] const std::string& get_auth() const { return auth; } void set_ue_details(UeDetails ue_details) { diff --git a/test/include/UTransportMock.h b/test/include/UTransportMock.h index f14af0fca..45ac64223 100644 --- a/test/include/UTransportMock.h +++ b/test/include/UTransportMock.h @@ -34,35 +34,26 @@ class UTransportMock : public uprotocol::transport::UTransport { } size_t getSendCount() const { return send_count_.load(); } - uprotocol::v1::UStatus& getSendStatus() { return send_status_; } - uprotocol::v1::UStatus& getRegisterListenerStatus() { return registerListener_status_; } - std::optional> getListener() const { return listener_; } - std::optional> getCleanupListener() const { return cleanup_listener_; } - std::optional getSinkFilter() const { return sink_filter_; } - v1::UUri getSourceFilter() const { return source_filter_; } - std::mutex& getRegisterMtx() { return register_mtx_; } - v1::UMessage getMessage() const { return message_; } - std::mutex& getMessageMtx() { return message_mtx_; } ~UTransportMock() override = default; From f9d4cf2bdd2116242be5d22a0822fac3d7cb319c Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 16 Apr 2025 07:59:32 +0200 Subject: [PATCH 39/41] Completed with review comments --- test/coverage/communication/PublisherTest.cpp | 2 +- test/coverage/communication/RpcClientTest.cpp | 33 ++++++++++--------- test/coverage/communication/RpcServerTest.cpp | 3 +- test/coverage/datamodel/UuidBuilderTest.cpp | 8 ++--- test/coverage/datamodel/UuidValidatorTest.cpp | 3 +- test/coverage/utils/ExpectedTest.cpp | 2 +- test/extra/RpcClientServerTest.cpp | 2 +- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/test/coverage/communication/PublisherTest.cpp b/test/coverage/communication/PublisherTest.cpp index 14e7efa60..fb350f52c 100644 --- a/test/coverage/communication/PublisherTest.cpp +++ b/test/coverage/communication/PublisherTest.cpp @@ -169,4 +169,4 @@ TEST_F(TestPublisher, PublisherWithNullTransport) { // NOLINT uprotocol::transport::NullTransport); } -} // namespace uprotocol \ No newline at end of file +} // namespace uprotocol diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index f0ac0ad54..76563d528 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -23,6 +23,7 @@ #include "UTransportMock.h" +constexpr std::chrono::milliseconds ZERO_MILLISECONDS(0); constexpr std::chrono::milliseconds TEN_MILLISECONDS(10); constexpr std::chrono::milliseconds ONE_HUNDRED_FIFTY_MILLISECONDS(150); constexpr uint32_t SHIFT_AMOUNT = 16; @@ -190,7 +191,7 @@ TEST_F(RpcClientTest, // NOLINT // Bad ttl EXPECT_THROW(auto client = communication::RpcClient( // NOLINT getTransport(), methodUri(), v1::UPriority::UPRIORITY_CS4, - std::chrono::milliseconds(0)); + ZERO_MILLISECONDS); , std::out_of_range); // Bad payload format @@ -221,7 +222,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayload) { // NOLINT auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -280,7 +281,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadListenFail) { // NOLINT EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -300,7 +301,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadSendFail) { // NOLINT EXPECT_NO_THROW(invoke_future = client.invokeMethod()); // NOLINT EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -321,7 +322,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadClientDestroyed) { // NOLINT } EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -347,7 +348,7 @@ TEST_F(RpcClientTest, InvokeFutureWithoutPayloadCommstatus) { // NOLINT EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -384,7 +385,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayload) { // NOLINT auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -420,7 +421,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadAndFormatSet) { // NOLINT auto response = response_builder.build(); EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -481,7 +482,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadListenFail) { // NOLINT EXPECT_EQ(getTransport()->getSendCount(), 0); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -502,7 +503,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadSendFail) { // NOLINT client.invokeMethod(fakePayload())); EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -524,7 +525,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadClientDestroyed) { // NOLINT } EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -550,7 +551,7 @@ TEST_F(RpcClientTest, InvokeFutureWithPayloadCommstatus) { // NOLINT EXPECT_NO_THROW(getTransport()->mockMessage(response)); // NOLINT EXPECT_TRUE(invoke_future.valid()); - auto is_ready = invoke_future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = invoke_future.wait_for(ZERO_MILLISECONDS); EXPECT_EQ(is_ready, std::future_status::ready); if (is_ready == std::future_status::ready) { @@ -995,7 +996,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT auto ready_futures = [&futures]() { size_t ready = 0; for (auto& future : futures) { - auto is_ready = future.wait_for(std::chrono::milliseconds(0)); + auto is_ready = future.wait_for(ZERO_MILLISECONDS); if (is_ready == std::future_status::ready) { ++ready; } @@ -1019,7 +1020,7 @@ TEST_F(RpcClientTest, MultiplePendingInvocationsOnOneClient) { // NOLINT EXPECT_EQ(callback_count, 1); EXPECT_EQ(ready_futures(), 1); - EXPECT_EQ(futures.front().wait_for(std::chrono::milliseconds(0)), + EXPECT_EQ(futures.front().wait_for(ZERO_MILLISECONDS), std::future_status::ready); requests.pop_front(); @@ -1208,7 +1209,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT size_t num_ready = 0; for (auto& request : pending) { auto& future = std::get<1>(request); - const bool is_ready = future.wait_for(std::chrono::milliseconds(0)) == + const bool is_ready = future.wait_for(ZERO_MILLISECONDS) == std::future_status::ready; if (is_ready) { ++num_ready; @@ -1229,7 +1230,7 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT for (auto& request : pending) { auto& future = std::get<1>(request); // Ignoring the futures we have already used - if (future.valid() && (future.wait_for(std::chrono::milliseconds(0)) == + if (future.valid() && (future.wait_for(ZERO_MILLISECONDS) == std::future_status::ready)) { auto maybe_response = future.get(); checkErrorResponse(maybe_response, v1::UCode::CANCELLED); diff --git a/test/coverage/communication/RpcServerTest.cpp b/test/coverage/communication/RpcServerTest.cpp index 1aba75dc9..5ed99b726 100644 --- a/test/coverage/communication/RpcServerTest.cpp +++ b/test/coverage/communication/RpcServerTest.cpp @@ -408,6 +408,7 @@ TEST_F(TestRpcServer, RPCRequestWithoutReturnPayload) { // NOLINT // Test case to verify RPC request handling with invalid request TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT + constexpr std::chrono::milliseconds THREEHOUNDRED_MILLISECONDS(300); // Create a callback to be called when request is received communication::RpcServer::RpcCallback callback = RpcCallbackWithReturn; @@ -424,7 +425,7 @@ TEST_F(TestRpcServer, RPCRequestWithInValidRequest) { // NOLINT using namespace std::chrono_literals; auto builder = datamodel::builder::UMessageBuilder::request( std::move(*getMethodUri()), std::move(*getRequestUri()), - v1::UPriority::UPRIORITY_CS5, 300ms); + v1::UPriority::UPRIORITY_CS5, THREEHOUNDRED_MILLISECONDS); auto msg = builder.build(); diff --git a/test/coverage/datamodel/UuidBuilderTest.cpp b/test/coverage/datamodel/UuidBuilderTest.cpp index 0a781c6d9..07bc80592 100644 --- a/test/coverage/datamodel/UuidBuilderTest.cpp +++ b/test/coverage/datamodel/UuidBuilderTest.cpp @@ -64,8 +64,8 @@ TEST(UuidBuilderTest, WithTimeSource) { // NOLINT // Test RandomSource TEST(UuidBuilderTest, WithRandomSource) { // NOLINT - constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; - uint64_t fixed_random = FIXED_RANDOM_T; + constexpr uint64_t FIXED_RANDOM_UINT = 0x1234567890ABCDEF; + uint64_t fixed_random = FIXED_RANDOM_UINT; auto builder = builder::UuidBuilder::getTestBuilder().withRandomSource( [fixed_random]() { return fixed_random; }); auto uuid = builder.build(); @@ -130,13 +130,13 @@ TEST_F(TestUuidBuilder, CheckVersionAndVariant) { // NOLINT // Test custom time and random source with builder TEST(UuidBuilderTest, CustomTimeAndRandomSource) { // NOLINT constexpr std::time_t FIXED_TIME_T = 1623456789; - constexpr uint64_t FIXED_RANDOM_T = 0x1234567890ABCDEF; + constexpr uint64_t FIXED_RANDOM_UINT = 0x1234567890ABCDEF; // Create a custom time source that returns a fixed timestamp auto fixed_time = std::chrono::system_clock::from_time_t(FIXED_TIME_T); auto time_source = [fixed_time]() { return fixed_time; }; // Create a custom random source that returns a fixed random value - uint64_t fixed_random = FIXED_RANDOM_T; + uint64_t fixed_random = FIXED_RANDOM_UINT; auto random_source = [fixed_random]() { return fixed_random; }; // Create a UuidBuilder with the custom time and random sources diff --git a/test/coverage/datamodel/UuidValidatorTest.cpp b/test/coverage/datamodel/UuidValidatorTest.cpp index 6539bbdbf..e4e2f2a79 100644 --- a/test/coverage/datamodel/UuidValidatorTest.cpp +++ b/test/coverage/datamodel/UuidValidatorTest.cpp @@ -219,6 +219,7 @@ TEST_F(TestUuidValidator, RetrieveRemainingTime) { // NOLINT // Test remaining time of 0ms TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { // NOLINT + constexpr std::chrono::milliseconds ZERO_MILLISECONDS(0); auto past_time = std::chrono::system_clock::now() - HUNDRED_SECONDS; auto past_timestamp = std::chrono::duration_cast( past_time.time_since_epoch()) @@ -227,7 +228,7 @@ TEST_F(TestUuidValidator, ExpiredUuidRemainingTime) { // NOLINT auto uuid = createFakeUuid(static_cast(past_timestamp)); auto remaining_time = validator::uuid::getRemainingTime(uuid, SIXTY_SECONDS); - EXPECT_EQ(remaining_time, std::chrono::milliseconds(0)); + EXPECT_EQ(remaining_time, ZERO_MILLISECONDS); } // Future timestamp to test exception thrown on getElapsedTime() diff --git a/test/coverage/utils/ExpectedTest.cpp b/test/coverage/utils/ExpectedTest.cpp index 997b12236..9680df219 100644 --- a/test/coverage/utils/ExpectedTest.cpp +++ b/test/coverage/utils/ExpectedTest.cpp @@ -310,4 +310,4 @@ int main(int argc, char* argv[]) { return RUN_ALL_TESTS(); } -#endif \ No newline at end of file +#endif diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index 5a235ee30..aafa73dc1 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -134,7 +134,7 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT client_transport, v1::UUri(rpc_service_uuri), UPriority::UPRIORITY_CS4, 1000ms); - uprotocol::communication::RpcClient::InvokeHandle client_handle; // NOLINT + uprotocol::communication::RpcClient::InvokeHandle client_handle; EXPECT_NO_THROW( // NOLINT client_handle = client.invokeMethod( std::move(client_request_payload), From fa923ec2210f8a0b75055eca3f70650163f43650 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 16 Apr 2025 08:24:06 +0200 Subject: [PATCH 40/41] formatted code --- lint/clang-tidy.sh | 3 ++- test/coverage/communication/RpcClientTest.cpp | 8 ++++---- test/extra/RpcClientServerTest.cpp | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index 19e9ddc80..cc4a66cd9 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,7 +58,8 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + # for f in include/**/*.h src/**/*.cpp + for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'" diff --git a/test/coverage/communication/RpcClientTest.cpp b/test/coverage/communication/RpcClientTest.cpp index 76563d528..4429bc41a 100644 --- a/test/coverage/communication/RpcClientTest.cpp +++ b/test/coverage/communication/RpcClientTest.cpp @@ -1209,8 +1209,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT size_t num_ready = 0; for (auto& request : pending) { auto& future = std::get<1>(request); - const bool is_ready = future.wait_for(ZERO_MILLISECONDS) == - std::future_status::ready; + const bool is_ready = + future.wait_for(ZERO_MILLISECONDS) == std::future_status::ready; if (is_ready) { ++num_ready; auto maybe_response = future.get(); @@ -1230,8 +1230,8 @@ TEST_F(RpcClientTest, MultipleClientInstances) { // NOLINT for (auto& request : pending) { auto& future = std::get<1>(request); // Ignoring the futures we have already used - if (future.valid() && (future.wait_for(ZERO_MILLISECONDS) == - std::future_status::ready)) { + if (future.valid() && + (future.wait_for(ZERO_MILLISECONDS) == std::future_status::ready)) { auto maybe_response = future.get(); checkErrorResponse(maybe_response, v1::UCode::CANCELLED); ++num_cancelled; diff --git a/test/extra/RpcClientServerTest.cpp b/test/extra/RpcClientServerTest.cpp index aafa73dc1..3b57abd2a 100644 --- a/test/extra/RpcClientServerTest.cpp +++ b/test/extra/RpcClientServerTest.cpp @@ -134,8 +134,8 @@ TEST_F(RpcClientServerTest, SimpleRoundTrip) { // NOLINT client_transport, v1::UUri(rpc_service_uuri), UPriority::UPRIORITY_CS4, 1000ms); - uprotocol::communication::RpcClient::InvokeHandle client_handle; - EXPECT_NO_THROW( // NOLINT + uprotocol::communication::RpcClient::InvokeHandle client_handle; + EXPECT_NO_THROW( // NOLINT client_handle = client.invokeMethod( std::move(client_request_payload), [&client_called, &client_capture](auto maybe_response) { From fe88182e4034532e56e14ae53aef0cedf1e5ffd4 Mon Sep 17 00:00:00 2001 From: Lennart Becker Date: Wed, 16 Apr 2025 08:51:19 +0200 Subject: [PATCH 41/41] Added linting also for src and include --- lint/clang-tidy.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lint/clang-tidy.sh b/lint/clang-tidy.sh index cc4a66cd9..19e9ddc80 100755 --- a/lint/clang-tidy.sh +++ b/lint/clang-tidy.sh @@ -58,8 +58,7 @@ if [ -z "$target_source" ]; then shopt -s globstar pushd "$PROJECT_ROOT" > /dev/null - # for f in include/**/*.h src/**/*.cpp - for f in test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do + for f in include/**/*.h src/**/*.cpp test/coverage/**/*.cpp test/extra/**/*.cpp test/include/**/*.h; do if [[ ! ("$f" =~ "build/") ]]; then echo echo "Checking file '$f'"