MCPcopy Create free account
hub / github.com/COVESA/vsomeip / TEST

Function TEST

test/network_tests/regression_tests/invalid_event_test_client.cpp:26–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24static std::atomic_bool is_invalid{false};
25
26TEST(invalid_event_test, subscription_succeeds) {
27 // vsomeip application that subscribes to the service.
28 std::shared_ptr<vsomeip_v3::application> app_ = vsomeip_v3::runtime::get()->create_application();
29 ASSERT_TRUE(app_ && app_->init()) << "should create service application";
30
31 // Run the vsomeip application in a dedicated thread.
32 auto worker = std::thread([app_] { app_->start(); });
33
34 // Request the test service.
35 app_->request_service(TEST_SERVICE_ID, TEST_INSTANCE_ID);
36 app_->request_event(TEST_SERVICE_ID, TEST_INSTANCE_ID, TEST_VALID_EVENT_ID, {TEST_EVENTGROUP_ID}, vsomeip_v3::event_type_e::ET_EVENT,
37 vsomeip_v3::reliability_type_e::RT_RELIABLE);
38
39 // Request the invalid event.
40 if (is_invalid.load()) {
41 app_->request_event(TEST_SERVICE_ID, TEST_INSTANCE_ID, TEST_INVALID_EVENT_ID, {TEST_EVENTGROUP_ID},
42 vsomeip_v3::event_type_e::ET_EVENT, vsomeip_v3::reliability_type_e::RT_BOTH); // <-- Wrong reliability!
43 // Let the master know that the invalid event is registered.
44 app_->offer_service(ON_REGISTERED_SERVICE_ID, ON_REGISTERED_INSTANCE_ID);
45 }
46
47 // Prepare to receive subscription status updates.
48 auto subscribed = std::promise<bool>();
49 app_->register_subscription_status_handler(TEST_SERVICE_ID, TEST_INSTANCE_ID, TEST_EVENTGROUP_ID, TEST_VALID_EVENT_ID,
50 [&](const vsomeip_v3::service_t, const vsomeip_v3::instance_t,
51 const vsomeip_v3::eventgroup_t, const vsomeip_v3::event_t, const uint16_t _status) {
52 constexpr uint8_t SUBSCRIPTION_OK = 0x00;
53 // constexpr uint8_t SUBSCRIPTION_NOK = 0x07; <-- For reference.
54 try {
55 subscribed.set_value(_status == SUBSCRIPTION_OK);
56 } catch (...) { }
57 });
58
59 // Subscribe to the event group.
60 app_->subscribe(TEST_SERVICE_ID, TEST_INSTANCE_ID, TEST_EVENTGROUP_ID);
61
62 // Check if the subscription was successful.
63 auto subscribed_fut = subscribed.get_future();
64 subscribed_fut.wait();
65 ASSERT_TRUE(subscribed_fut.get()) << "should subscribe to the event group";
66
67 // Wait for the termination signal.
68 if (is_invalid.load()) {
69 wait_for_signal();
70 }
71 // Stop the app.
72 app_->stop();
73
74 // Wait for the app to stop.
75 worker.join();
76}
77
78int main(int argc, char* argv[]) {
79 // Block SIGUSR1 for the test.

Callers

nothing calls this directly

Calls 14

create_applicationMethod · 0.80
request_eventMethod · 0.80
wait_for_signalFunction · 0.70
initMethod · 0.45
startMethod · 0.45
request_serviceMethod · 0.45
loadMethod · 0.45
offer_serviceMethod · 0.45
subscribeMethod · 0.45
waitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected