2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
21 * Created on: Apr, 2020
22 * Author: Shraboni Jana
25 #ifndef TEST_TEST_ASN_H_
26 #define TEST_TEST_ASN_H_
28 #include<gtest/gtest.h>
30 #include "subscription_request.hpp"
32 #include "e2sm_helpers.hpp"
33 #include "e2sm_subscription.hpp"
34 #include "e2sm_indication.hpp"
35 #include "e2sm_control.hpp"
38 TEST(E2SM, SubscriptionRequest)
41 unsigned char event_buf[128];
42 size_t event_buf_len = 128;
44 unsigned char act_buf[128];
45 size_t act_buf_len = 128;
50 e2sm_subscription_helper e2sm_subsdata;
51 std::unique_ptr<ranparam_helper> *ranhelp;
52 e2sm_subscription e2sm_subs;
55 e2sm_subsdata.triger_nature = 0;
58 unsigned char param_name[20];
59 strcpy((char*)param_name,"ParamName");
60 int param_name_len = strlen((const char*)param_name);
63 unsigned char param_value[20];
64 strcpy((char*)param_value,"ParamValue");
65 int param_value_len = strlen((const char*)param_value);
67 e2sm_subsdata.add_param(param_id, param_name, param_name_len, param_test, param_value, param_value_len);
70 // Encode the event trigger definition
71 res = e2sm_subs.encode_event_trigger(&event_buf[0], &event_buf_len, e2sm_subsdata);
73 std::cout << e2sm_subs.get_error() << std::endl;
77 // Encode the action defintion
78 res = e2sm_subs.encode_action_defn(&act_buf[0], &act_buf_len, e2sm_subsdata);
80 std::cout << e2sm_subs.get_error() << std::endl;
84 TEST(E2SM, IndicationMessage)
87 unsigned char header_buf[128];
88 size_t header_buf_len = 128;
90 unsigned char msg_buf[128];
91 size_t msg_buf_len = 128;
94 asn_dec_rval_t retval;
97 e2sm_indication_helper e2sm_inddata;
98 e2sm_indication e2sm_inds;
100 unsigned char msg[20] = "HelloWorld";
102 e2sm_inddata.header = 1001;
103 e2sm_inddata.message = msg;
104 e2sm_inddata.message_len = strlen((const char*)e2sm_inddata.message);
107 // Encode the indication header
108 res = e2sm_inds.encode_indication_header(&header_buf[0], &header_buf_len, e2sm_inddata);
110 std::cout << e2sm_inds.get_error() << std::endl;
114 // Encode the indication message
115 res = e2sm_inds.encode_indication_message(&msg_buf[0], &msg_buf_len, e2sm_inddata);
117 std::cout << e2sm_inds.get_error() << std::endl;
120 //decode the indication header
121 e2sm_indication_helper e2sm_decodedata;
124 E2SM_HelloWorld_IndicationHeader_t *header = 0; // used for decoding
125 retval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, (void**)&(header), &header_buf[0], header_buf_len);
127 ASSERT_TRUE(retval.code == RC_OK);
128 res = e2sm_inds.get_fields(header, e2sm_decodedata);
130 //decode the indication message
132 E2SM_HelloWorld_IndicationMessage_t *mesg = 0; // used for decoding
133 retval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, (void**)&(mesg), &msg_buf[0], msg_buf_len);
135 ASSERT_TRUE(retval.code == RC_OK);
136 res = e2sm_inds.get_fields(mesg, e2sm_decodedata);
139 std::cout << "Indication Header:" << e2sm_decodedata.header << std::endl;
140 std::cout << "Indication Message:" << e2sm_decodedata.message << std::endl;
141 std::cout << "Indication Message Len:" << e2sm_decodedata.message_len << std::endl;
143 ASSERT_EQ(e2sm_inddata.header, e2sm_decodedata.header);
144 ASSERT_EQ(e2sm_inddata.message_len, e2sm_decodedata.message_len);
145 for (int i = 0; i < e2sm_inddata.message_len; ++i) {
146 EXPECT_EQ(e2sm_inddata.message[i], e2sm_decodedata.message[i]) << "Encoded and Decoded Msg differ at index " << i;
152 TEST(E2SM, ControlMessage)
155 unsigned char header_buf[128];
156 size_t header_buf_len = 128;
158 unsigned char msg_buf[128];
159 size_t msg_buf_len = 128;
162 asn_dec_rval_t retval;
165 e2sm_control_helper e2sm_cntrldata;
166 e2sm_control e2sm_cntrl;
168 unsigned char msg[20] = "HelloWorld";
170 e2sm_cntrldata.header = 1001;
171 e2sm_cntrldata.message = msg;
172 e2sm_cntrldata.message_len = strlen((const char*)e2sm_cntrldata.message);
175 // Encode the indication header
176 res = e2sm_cntrl.encode_control_header(&header_buf[0], &header_buf_len, e2sm_cntrldata);
178 std::cout << e2sm_cntrl.get_error() << std::endl;
182 // Encode the indication message
183 res = e2sm_cntrl.encode_control_message(&msg_buf[0], &msg_buf_len, e2sm_cntrldata);
185 std::cout << e2sm_cntrl.get_error() << std::endl;
189 #endif /* TEST_TEST_ASN_H_ */