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 ric_indication test_check;
50 SECTION("Incorrect E2AP Indication PDU"){
51 size_t data_size = 512;
52 unsigned char data[data_size];
53 for(int i = 0; i < 510; i++){
57 E2N_E2AP_PDU_t * e2ap_recv = 0;
58 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
59 REQUIRE(dec_res.code != RC_OK);
60 ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
63 SECTION("Verify E2AP Indication Encoding Successful"){
65 dinput.action_id = 100;
67 dinput.indication_sn = 100;
68 dinput.indication_type = 1;
70 dinput.req_seq_no = 11;
72 strcpy((char *)buf_header, "X2AP Header");
73 strcpy((char *)buf_msg, "X2AP_Message");
75 dinput.indication_header = buf_header;
76 dinput.indication_header_size = strlen((const char *)buf_header);
78 dinput.indication_msg = buf_msg;
79 dinput.indication_msg_size = strlen((const char *)buf_msg);
83 size_t data_size = 512;
84 unsigned char data[data_size];
86 ric_indication indication_pdu;
87 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
92 SECTION("Verify constraint checks"){
94 dinput.action_id = 100;
96 dinput.indication_sn = 100;
97 dinput.indication_type = 100;
99 dinput.req_seq_no = 11;
101 strcpy((char *)buf_header, "X2AP Header");
102 strcpy((char *)buf_msg, "X2AP_Message");
104 dinput.indication_header = buf_header;
105 dinput.indication_header_size = strlen((const char *)buf_header);
107 dinput.indication_msg = buf_msg;
108 dinput.indication_msg_size = strlen((const char *)buf_msg);
112 size_t data_size = 512;
113 unsigned char data[data_size];
115 ric_indication indication_pdu;
116 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
117 REQUIRE(res == false);
121 SECTION("Verify E2AP Decoding Successful"){
123 dinput.action_id = 100;
125 dinput.indication_sn = 100;
126 dinput.indication_type = 1;
128 dinput.req_seq_no = 11;
131 strcpy((char *)buf_header, "X2AP Header");
132 strcpy((char *)buf_msg, "X2AP_Message");
134 dinput.indication_header = buf_header;
135 dinput.indication_header_size = strlen((const char *)buf_header);
137 dinput.indication_msg = buf_msg;
138 dinput.indication_msg_size = strlen((const char *)buf_msg);
142 size_t data_size = 512;
143 unsigned char data[data_size];
145 ric_indication indication_pdu;
146 bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
148 E2N_E2AP_PDU_t * e2ap_recv = 0;
149 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
150 REQUIRE(dec_res.code == RC_OK);
152 res = indication_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
153 REQUIRE(res == true);
155 std::string din_string((const char *)dinput.indication_header, dinput.indication_header_size);
156 std::string dout_string((const char*)dout.indication_header, dout.indication_header_size);
157 REQUIRE(din_string == dout_string);
159 res = indication_pdu.get_fields(NULL, dout);
160 REQUIRE(res == false);
162 ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);