Skip to content

Commit

Permalink
Fix null callback assertions in L2 tests
Browse files Browse the repository at this point in the history
Some L2 tests were asserting that the std::bad_function_call exception
should be thrown when a bad callback is called. We will be changing that
behavior so that the exception is thrown when the callback connection is
established, requiring updated test cases.
  • Loading branch information
gregmedd committed Aug 17, 2024
1 parent ae9a12d commit 2f8285e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
23 changes: 16 additions & 7 deletions test/coverage/communication/NotificationSinkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,23 @@ TEST_F(NotificationSinkTest, NullCallback) {
testDefaultSourceUUri_);

// bind to null callback
auto result = NotificationSink::create(transport, transport->getEntityUri(),
std::move(nullptr), testTopicUUri_);
auto test_create_nullptr = [transport, this]() {
std::ignore =
NotificationSink::create(transport, transport->getEntityUri(),
std::move(nullptr), testTopicUUri_);
};

using namespace uprotocol::utils;

EXPECT_THROW(test_create_nullptr(), callbacks::EmptyFunctionObject);

// Default construct a function object
auto test_create_empty = [transport, this]() {
std::ignore = NotificationSink::create(
transport, transport->getEntityUri(), {}, testTopicUUri_);
};

uprotocol::v1::UMessage msg;
auto attr = std::make_shared<uprotocol::v1::UAttributes>();
*msg.mutable_attributes() = *attr;
msg.set_payload(get_random_string(1400));
EXPECT_THROW(transport->mockMessage(msg), std::bad_function_call);
EXPECT_THROW(test_create_empty(), callbacks::EmptyFunctionObject);
}

} // namespace
21 changes: 14 additions & 7 deletions test/coverage/communication/SubscriberTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,21 @@ TEST_F(SubscriberTest, SubscribeNullCallback) {
testDefaultSourceUUri_);

// bind to null callback
auto result =
Subscriber::subscribe(transport, testTopicUUri_, std::move(nullptr));
auto test_subscribe_nullptr = [transport, this]() {
std::ignore = Subscriber::subscribe(transport, testTopicUUri_,
std::move(nullptr));
};

using namespace uprotocol::utils;

EXPECT_THROW(test_subscribe_nullptr(), callbacks::EmptyFunctionObject);

// Default construct a function object
auto test_subscribe_empty = [transport, this]() {
std::ignore = Subscriber::subscribe(transport, testTopicUUri_, {});
};

uprotocol::v1::UMessage msg;
auto attr = std::make_shared<uprotocol::v1::UAttributes>();
*msg.mutable_attributes() = *attr;
msg.set_payload(get_random_string(1400));
EXPECT_THROW(transport->mockMessage(msg), std::bad_function_call);
EXPECT_THROW(test_subscribe_empty(), callbacks::EmptyFunctionObject);
}

} // namespace

0 comments on commit 2f8285e

Please sign in to comment.