Initialization script now passes signal to xapp process
[ric-app/admin.git] / test / unit_test_e2ap_indication.cc
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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 ==================================================================================
18 */
19
20
21 #define CATCH_CONFIG_MAIN
22 #include <catch2/catch.hpp>
23 #include <iostream>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <e2ap_indication.hpp>
28 #include <unistd.h>
29 #include <inttypes.h>
30
31 #define BUFFER_SIZE 512
32
33 TEST_CASE("E2AP Indication", "Encoding/Decoding"){
34   
35   ric_indication_helper dinput ;
36   ric_indication_helper dout;
37
38
39   mdclog_attr_t *attr;
40   mdclog_attr_init(&attr);
41   mdclog_attr_set_ident(attr, "UNIT TEST E2AP INDICATION");
42   mdclog_init(attr);
43   mdclog_level_set(MDCLOG_INFO);
44   mdclog_attr_destroy(attr);
45
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;
50   
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++){
55       data[i] = 'z';
56     }
57  
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); 
62   }
63   
64   SECTION("Verify E2AP Indication Encoding Successful"){
65     
66     dinput.action_id = 100;
67     dinput.func_id = 10;
68     dinput.indication_sn = 100;
69     dinput.indication_type = 1;
70     dinput.req_id = 6;
71     dinput.req_seq_no = 11;
72
73     strcpy((char *)buf_header, "X2AP Header");
74     strcpy((char *)buf_msg, "X2AP_Message");
75     strcpy((char *)buf_callproc, "Call Process ID=10");
76     
77     dinput.indication_header = buf_header;
78     dinput.indication_header_size = strlen((const char *)buf_header);
79   
80     dinput.indication_msg = buf_msg;
81     dinput.indication_msg_size = strlen((const char *)buf_msg);
82
83     dinput.call_process_id = buf_callproc;
84     dinput.call_process_id_size = strlen((const char *)buf_callproc);
85     
86     /* encoding */
87     size_t data_size = 512;
88     unsigned char data[data_size];
89     
90     ric_indication indication_pdu;
91     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
92     REQUIRE(res == true);
93   }
94
95
96   SECTION("Verify constraint checks"){
97
98     dinput.action_id = 100;
99     dinput.func_id = 10;
100     dinput.indication_sn = 100;
101     dinput.indication_type = 100;
102     dinput.req_id = 6;
103     dinput.req_seq_no = 11;
104
105     strcpy((char *)buf_header, "X2AP Header");
106     strcpy((char *)buf_msg, "X2AP_Message");
107     
108     dinput.indication_header = buf_header;
109     dinput.indication_header_size = strlen((const char *)buf_header);
110   
111     dinput.indication_msg = buf_msg;
112     dinput.indication_msg_size = strlen((const char *)buf_msg);
113     
114     
115     /* encoding */
116     size_t data_size = 512;
117     unsigned char data[data_size];
118     
119     ric_indication indication_pdu;
120     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
121     REQUIRE(res == false);
122
123
124   }
125   SECTION("Verify E2AP Decoding Successful"){
126
127     dinput.action_id = 100;
128     dinput.func_id = 10;
129     dinput.indication_sn = 100;
130     dinput.indication_type = 1;
131     dinput.req_id = 6;
132     dinput.req_seq_no = 11;
133
134
135     strcpy((char *)buf_header, "X2AP Header");
136     strcpy((char *)buf_msg, "X2AP_Message");
137     
138     dinput.indication_header = buf_header;
139     dinput.indication_header_size = strlen((const char *)buf_header);
140   
141     dinput.indication_msg = buf_msg;
142     dinput.indication_msg_size = strlen((const char *)buf_msg);
143     
144     
145     /* encoding */
146     size_t data_size = 512;
147     unsigned char data[data_size];
148     
149     ric_indication indication_pdu;
150     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
151     
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);
155     
156     res = indication_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
157     REQUIRE(res == true);
158
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);
162
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);
166
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);
170
171     res = indication_pdu.get_fields(NULL, dout);
172     REQUIRE(res == false);
173     
174     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv); 
175   }
176     
177 }
178
179