• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #include <gtest/gtest.h>
7 
8 #include <vsomeip/vsomeip.hpp>
9 
10 #include "../someip_test_globals.hpp"
11 
12 class someip_header_factory_test: public ::testing::Test
13 {
14 protected:
15     std::shared_ptr<vsomeip::message> request_;
16     std::shared_ptr<vsomeip::message> response_;
17     std::shared_ptr<vsomeip::message> notification_;
18     std::shared_ptr<vsomeip::application> app_;
19     std::shared_ptr<vsomeip::message> message_;
20 
21     vsomeip::service_t service_id_ = vsomeip_test::TEST_SERVICE_SERVICE_ID;
22     vsomeip::method_t method_id_ = vsomeip_test::TEST_SERVICE_METHOD_ID;
23     vsomeip::instance_t instance_id_ = vsomeip_test::TEST_SERVICE_INSTANCE_ID;
24     vsomeip::interface_version_t interface_version_ = 0x01;
25     vsomeip::client_t client_id_ = vsomeip_test::TEST_CLIENT_CLIENT_ID;
26     vsomeip::session_t session_id_ = vsomeip_test::TEST_INITIAL_SESSION_ID;
27 };
28 
TEST_F(someip_header_factory_test,create_request_test)29 TEST_F(someip_header_factory_test, create_request_test)
30 {
31     ASSERT_TRUE(request_.get() == nullptr);
32     request_ = vsomeip::runtime::get()->create_request();
33 
34     // check that returned shared_ptr is not null
35     ASSERT_TRUE(request_.get() != nullptr);
36 
37     // Check the protocol version
38     // this shall be set to 0x01 according to the spec. TR_SOMEIP_00052
39     ASSERT_EQ(request_->get_protocol_version(), 0x01);
40     // Check the message type
41     // this shall be 0x00 (REQUEST) according to the spec. TR_SOMEIP_00055
42     ASSERT_EQ(request_->get_message_type(), vsomeip::message_type_e::MT_REQUEST);
43     // Check the return code
44     // this shall be 0x00 (E_OK) according to the spec. TR_SOMEIP_00058
45     ASSERT_EQ(request_->get_return_code(), vsomeip::return_code_e::E_OK);
46 
47 }
48 
TEST_F(someip_header_factory_test,create_request_and_response_test)49 TEST_F(someip_header_factory_test, create_request_and_response_test)
50 {
51     ASSERT_TRUE(request_.get() == nullptr);
52     request_ = vsomeip::runtime::get()->create_request();
53     // check that returned shared_ptr is not null
54     ASSERT_TRUE(request_.get() != nullptr);
55 
56     request_->set_service(service_id_);
57     request_->set_method(method_id_);
58     request_->set_interface_version(interface_version_);
59     // set the request_id (client_id + session_id). This normally is set by the
60     // application_impl::send() if a request is send, we set it here to test the
61     // correct initialization of the response
62     request_->set_client(client_id_);
63     request_->set_session(session_id_);
64 
65     ASSERT_TRUE(response_.get() == nullptr);
66     response_ = vsomeip::runtime::get()->create_response(request_);
67     // check that returned shared_ptr is not null
68     ASSERT_TRUE(response_.get() != nullptr);
69 
70     ASSERT_EQ(response_->get_service(), request_->get_service());
71     ASSERT_EQ(response_->get_method(), request_->get_method());
72     ASSERT_EQ(response_->get_session(), request_->get_session());
73 
74     // length? --> gets only set if a payload is added
75 
76     ASSERT_EQ(response_->get_protocol_version(), request_->get_protocol_version());
77     ASSERT_EQ(response_->get_interface_version(), request_->get_interface_version());
78 
79     // Check the message type
80     // this shall be 0x00 (REQUEST) according to the spec. TR_SOMEIP_00055
81     ASSERT_EQ(request_->get_message_type(), vsomeip::message_type_e::MT_REQUEST);
82 
83     // Check the message type
84     // this shall be 0x80 (RESPONSE) according to the spec. TR_SOMEIP_00055
85     ASSERT_EQ(response_->get_message_type(), vsomeip::message_type_e::MT_RESPONSE);
86 
87     // Check the return code
88     // this shall be 0x00 (E_OK) according to the spec. TR_SOMEIP_00058
89     // and TR_SOMEIP_00191
90     ASSERT_EQ(response_->get_return_code(), vsomeip::return_code_e::E_OK);
91 
92 }
93 
TEST_F(someip_header_factory_test,create_notification_test)94 TEST_F(someip_header_factory_test, create_notification_test)
95 {
96     ASSERT_TRUE(notification_.get() == nullptr);
97     notification_ = vsomeip::runtime::get()->create_notification();
98 
99     // check that returned shared_ptr is not null
100     ASSERT_TRUE(notification_.get() != nullptr);
101 
102     // Check the protocol version
103     // this shall be set to 0x01 according to the spec. TR_SOMEIP_00052
104     ASSERT_EQ(notification_->get_protocol_version(), 0x01);
105     // Check the message type
106     // this shall be 0x02 (NOTIFICATION) according to the spec. TR_SOMEIP_00055
107     ASSERT_EQ(notification_->get_message_type(), vsomeip::message_type_e::MT_NOTIFICATION);
108     // Check the return code
109     // this shall be 0x00 (E_OK) according to the spec. TR_SOMEIP_00058
110     ASSERT_EQ(notification_->get_return_code(), vsomeip::return_code_e::E_OK);
111 }
112 
113 #ifndef _WIN32
main(int argc,char ** argv)114 int main(int argc, char** argv)
115 {
116     ::testing::InitGoogleTest(&argc, argv);
117     return RUN_ALL_TESTS();
118 }
119 #endif
120