1. Transitioned to using latest asn1c compiler
[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   ric_indication test_check;
49   
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++){
54       data[i] = 'z';
55     }
56  
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); 
61   }
62   
63   SECTION("Verify E2AP Indication Encoding Successful"){
64     
65     dinput.action_id = 100;
66     dinput.func_id = 10;
67     dinput.indication_sn = 100;
68     dinput.indication_type = 1;
69     dinput.req_id = 6;
70     dinput.req_seq_no = 11;
71
72     strcpy((char *)buf_header, "X2AP Header");
73     strcpy((char *)buf_msg, "X2AP_Message");
74     
75     dinput.indication_header = buf_header;
76     dinput.indication_header_size = strlen((const char *)buf_header);
77   
78     dinput.indication_msg = buf_msg;
79     dinput.indication_msg_size = strlen((const char *)buf_msg);
80     
81     
82     /* encoding */
83     size_t data_size = 512;
84     unsigned char data[data_size];
85     
86     ric_indication indication_pdu;
87     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
88     REQUIRE(res == true);
89   }
90
91
92   SECTION("Verify constraint checks"){
93
94     dinput.action_id = 100;
95     dinput.func_id = 10;
96     dinput.indication_sn = 100;
97     dinput.indication_type = 100;
98     dinput.req_id = 6;
99     dinput.req_seq_no = 11;
100
101     strcpy((char *)buf_header, "X2AP Header");
102     strcpy((char *)buf_msg, "X2AP_Message");
103     
104     dinput.indication_header = buf_header;
105     dinput.indication_header_size = strlen((const char *)buf_header);
106   
107     dinput.indication_msg = buf_msg;
108     dinput.indication_msg_size = strlen((const char *)buf_msg);
109     
110     
111     /* encoding */
112     size_t data_size = 512;
113     unsigned char data[data_size];
114     
115     ric_indication indication_pdu;
116     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
117     REQUIRE(res == false);
118
119
120   }
121   SECTION("Verify E2AP Decoding Successful"){
122
123     dinput.action_id = 100;
124     dinput.func_id = 10;
125     dinput.indication_sn = 100;
126     dinput.indication_type = 1;
127     dinput.req_id = 6;
128     dinput.req_seq_no = 11;
129
130
131     strcpy((char *)buf_header, "X2AP Header");
132     strcpy((char *)buf_msg, "X2AP_Message");
133     
134     dinput.indication_header = buf_header;
135     dinput.indication_header_size = strlen((const char *)buf_header);
136   
137     dinput.indication_msg = buf_msg;
138     dinput.indication_msg_size = strlen((const char *)buf_msg);
139     
140     
141     /* encoding */
142     size_t data_size = 512;
143     unsigned char data[data_size];
144     
145     ric_indication indication_pdu;
146     bool res = indication_pdu.encode_e2ap_indication(&data[0], &data_size, dinput);
147     
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);
151     
152     res = indication_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
153     REQUIRE(res == true);
154
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);
158
159     res = indication_pdu.get_fields(NULL, dout);
160     REQUIRE(res == false);
161     
162     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv); 
163   }
164     
165 }
166
167