23003034b2762f8b92ce4d5db32cb3e558826f40
[ric-app/hw.git] / test / test_e2sm.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 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  * test_asn.h
20  *
21  *  Created on: Apr, 2020
22  *      Author: Shraboni Jana
23  */
24
25 #ifndef TEST_TEST_ASN_H_
26 #define TEST_TEST_ASN_H_
27 #include<iostream>
28 #include<gtest/gtest.h>
29
30 #include "subscription_request.hpp"
31 #include "xapp.hpp"
32 #include "e2sm_helpers.hpp"
33 #include "e2sm_subscription.hpp"
34 #include "e2sm_indication.hpp"
35 #include "e2sm_control.hpp"
36
37 using namespace std;
38 TEST(E2SM, SubscriptionRequest)
39 {
40
41         unsigned char event_buf[128];
42         size_t event_buf_len = 128;
43
44         unsigned char act_buf[128];
45         size_t act_buf_len = 128;
46
47         bool res;
48
49
50         e2sm_subscription_helper e2sm_subsdata;
51         std::unique_ptr<ranparam_helper> *ranhelp;
52         e2sm_subscription e2sm_subs;
53
54
55         e2sm_subsdata.triger_nature = 0;
56
57         int param_id = 1;
58         unsigned char param_name[20];
59         strcpy((char*)param_name,"ParamName");
60         int param_name_len = strlen((const char*)param_name);
61
62         int param_test = 0;
63         unsigned char param_value[20];
64         strcpy((char*)param_value,"ParamValue");
65         int param_value_len = strlen((const char*)param_value);
66
67         e2sm_subsdata.add_param(param_id, param_name, param_name_len, param_test, param_value, param_value_len);
68
69
70         // Encode the event trigger definition
71         res = e2sm_subs.encode_event_trigger(&event_buf[0], &event_buf_len, e2sm_subsdata);
72         if(!res)
73                 std::cout << e2sm_subs.get_error() << std::endl;
74
75         ASSERT_TRUE(res);
76
77         // Encode the action defintion
78         res = e2sm_subs.encode_action_defn(&act_buf[0], &act_buf_len, e2sm_subsdata);
79         if(!res)
80                 std::cout << e2sm_subs.get_error() << std::endl;
81         ASSERT_TRUE(res);
82
83 }
84 TEST(E2SM, IndicationMessage)
85 {
86
87         unsigned char header_buf[128];
88         size_t header_buf_len = 128;
89
90         unsigned char msg_buf[128];
91         size_t msg_buf_len = 128;
92
93         bool res;
94         asn_dec_rval_t retval;
95
96
97         e2sm_indication_helper e2sm_inddata;
98         e2sm_indication e2sm_inds;
99
100         unsigned char msg[20] = "HelloWorld";
101
102         e2sm_inddata.header = 1001;
103         e2sm_inddata.message = msg;
104         e2sm_inddata.message_len = strlen((const char*)e2sm_inddata.message);
105
106
107         // Encode the indication header
108         res = e2sm_inds.encode_indication_header(&header_buf[0], &header_buf_len, e2sm_inddata);
109         if(!res)
110                 std::cout << e2sm_inds.get_error() << std::endl;
111
112         ASSERT_TRUE(res);
113
114         // Encode the indication message
115         res = e2sm_inds.encode_indication_message(&msg_buf[0], &msg_buf_len, e2sm_inddata);
116         if(!res)
117                 std::cout << e2sm_inds.get_error() << std::endl;
118         ASSERT_TRUE(res);
119
120         //decode the indication header
121         e2sm_indication_helper e2sm_decodedata;
122
123
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);
126
127         ASSERT_TRUE(retval.code == RC_OK);
128         res = e2sm_inds.get_fields(header, e2sm_decodedata);
129
130         //decode the indication message
131
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);
134
135         ASSERT_TRUE(retval.code == RC_OK);
136         res = e2sm_inds.get_fields(mesg, e2sm_decodedata);
137
138
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;
142
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;
147         }
148
149
150 }
151
152 TEST(E2SM, ControlMessage)
153 {
154
155         unsigned char header_buf[128];
156         size_t header_buf_len = 128;
157
158         unsigned char msg_buf[128];
159         size_t msg_buf_len = 128;
160
161         bool res;
162         asn_dec_rval_t retval;
163
164
165         e2sm_control_helper e2sm_cntrldata;
166         e2sm_control e2sm_cntrl;
167
168         unsigned char msg[20] = "HelloWorld";
169
170         e2sm_cntrldata.header = 1001;
171         e2sm_cntrldata.message = msg;
172         e2sm_cntrldata.message_len = strlen((const char*)e2sm_cntrldata.message);
173
174
175         // Encode the indication header
176         res = e2sm_cntrl.encode_control_header(&header_buf[0], &header_buf_len, e2sm_cntrldata);
177         if(!res)
178                 std::cout << e2sm_cntrl.get_error() << std::endl;
179
180         ASSERT_TRUE(res);
181
182         // Encode the indication message
183         res = e2sm_cntrl.encode_control_message(&msg_buf[0], &msg_buf_len, e2sm_cntrldata);
184         if(!res)
185                 std::cout << e2sm_cntrl.get_error() << std::endl;
186         ASSERT_TRUE(res);
187 }
188
189 #endif /* TEST_TEST_ASN_H_ */