2 ==================================================================================
4 Copyright (c) 2018-2019 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 #define CATCH_CONFIG_MAIN
22 #include <catch2/catch.hpp>
27 #include <e2ap_indication.hpp>
31 #define BUFFER_SIZE 512
33 TEST_CASE("E2AP Indication", "Encoding/Decoding"){
35 ric_indication_helper dinput ;
36 ric_indication_helper dout;
40 mdclog_attr_init(&attr);
41 mdclog_attr_set_ident(attr, "UNIT TEST E2AP INDICATION");
43 mdclog_level_set(MDCLOG_INFO);
44 mdclog_attr_destroy(attr);
46 unsigned char buf_header[BUFFER_SIZE];
47 unsigned char buf_msg[BUFFER_SIZE];
48 unsigned char buf_callproc[BUFFER_SIZE];
49 ric_indication test_check;
51 SECTION("Incorrect E2AP Indication PDU"){
52 size_t data_size = 512;
53 unsigned char data[data_size];
54 for(int i = 0; i < 510; i++){
58 E2N_E2AP_PDU_t * e2ap_recv = 0;
59 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
60 REQUIRE(dec_res.code != RC_OK);
61 ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
64 SECTION("Verify E2AP Indication Encoding Successful"){
66 dinput.action_id = 100;
68 dinput.indication_sn = 100;
69 dinput.indication_type = 1;
71 dinput.req_seq_no = 11;
73 strcpy((char *)buf_header, "X2AP Header");
74 strcpy((char *)buf_msg, "X2AP_Message");
75 strcpy((char *)buf_callproc, "Call Process ID=10");
77 dinput.indication_header = buf_header;
78 dinput.indication_header_size = strlen((const char *)buf_header);
80 dinput.indication_msg = buf_msg;
81 dinput.indication_msg_size = strlen((const char *)buf_msg);
83 dinput.call_process_id = buf_callproc;
84 dinput.call_process_id_size = strlen((const char *)buf_callproc);
87 size_t data_size = 512;
88 unsigned char data[data_size];
90 ric_indication indication_pdu;
91 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
96 SECTION("Verify constraint checks"){
98 dinput.action_id = 100;
100 dinput.indication_sn = 100;
101 dinput.indication_type = 100;
103 dinput.req_seq_no = 11;
105 strcpy((char *)buf_header, "X2AP Header");
106 strcpy((char *)buf_msg, "X2AP_Message");
108 dinput.indication_header = buf_header;
109 dinput.indication_header_size = strlen((const char *)buf_header);
111 dinput.indication_msg = buf_msg;
112 dinput.indication_msg_size = strlen((const char *)buf_msg);
116 size_t data_size = 512;
117 unsigned char data[data_size];
119 ric_indication indication_pdu;
120 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
121 REQUIRE(res == false);
125 SECTION("Verify E2AP Decoding Successful"){
127 dinput.action_id = 100;
129 dinput.indication_sn = 100;
130 dinput.indication_type = 1;
132 dinput.req_seq_no = 11;
135 strcpy((char *)buf_header, "X2AP Header");
136 strcpy((char *)buf_msg, "X2AP_Message");
138 dinput.indication_header = buf_header;
139 dinput.indication_header_size = strlen((const char *)buf_header);
141 dinput.indication_msg = buf_msg;
142 dinput.indication_msg_size = strlen((const char *)buf_msg);
146 size_t data_size = 512;
147 unsigned char data[data_size];
149 ric_indication indication_pdu;
150 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
152 E2N_E2AP_PDU_t * e2ap_recv = 0;
153 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
154 REQUIRE(dec_res.code == RC_OK);
156 res = indication_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
157 REQUIRE(res == true);
159 std::string din_string((const char *)dinput.indication_header, dinput.indication_header_size);
160 std::string dout_string((const char*)dout.indication_header, dout.indication_header_size);
161 REQUIRE(din_string == dout_string);
163 din_string.assign((const char *)dinput.indication_msg, dinput.indication_msg_size);
164 dout_string.assign((const char*)dout.indication_msg, dout.indication_msg_size);
165 REQUIRE(din_string == dout_string);
167 din_string.assign((const char *)dinput.call_process_id, dinput.call_process_id_size);
168 dout_string.assign((const char*)dout.call_process_id, dout.call_process_id_size);
169 REQUIRE(din_string == dout_string);
171 res = indication_pdu.get_fields(NULL, dout);
172 REQUIRE(res == false);
174 ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);