Control Message Encode/Decode
[ric-app/hw.git] / test / test_e2ap.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 /*
20  * test_e2ap.h
21  *
22  *  Created on: Oct 23, 2020
23  *  Author: Shraboni Jana
24  */
25
26 #ifndef TEST_TEST_E2AP_H_
27 #define TEST_TEST_E2AP_H_
28 #include<iostream>
29 #include<gtest/gtest.h>
30
31 #include "e2ap_control_failure.hpp"
32 #include "xapp.hpp"
33 #include "e2ap_control_ack.hpp"
34 TEST(E2AP, ControlAcknowledgementEncode)
35 {
36
37         unsigned char buff[1024];
38         size_t buf_len = 1024;
39
40         E2APControlAcknowledge::ControlAcknowledgeIEs infoObj;
41         infoObj.set_ranFunctionID(1);
42         infoObj.set_ricRequestorID(1);
43         infoObj.set_ricInstanceID(1);
44         infoObj.set_ricControlStatus(1);
45         infoObj.set_ricCallProcessID("CallProcessID");
46         infoObj.set_ricControlOutcome("ControlOutcome");
47
48
49         E2APControlAcknowledge  cntrlObj(infoObj);
50
51         bool res = cntrlObj.encode(buff, &buf_len);
52         if(!res)
53         {
54                 std::cout << cntrlObj.get_error() << std::endl;
55         }
56         ASSERT_TRUE(res);
57         FILE * pFile;
58                 pFile = fopen ("controlack1.per","w");
59                 if (pFile!=NULL)
60                  {
61                           fwrite (buff , sizeof(char), buf_len, pFile);
62                       sleep(2);
63                           fclose (pFile);
64                   }
65
66 }
67 TEST(E2SM, ControlAcknowledgementDecode)
68 {
69        unsigned char e2ap_buff[4096];
70        char filename[100] = "controlack1.per";
71        FILE *fp;
72        fp = fopen(filename,"rb");
73        if(!fp) {
74                      perror(filename);
75                      exit(1); }
76
77            size_t e2ap_buff_size = fread(e2ap_buff, 1, 4096, fp);
78            fclose(fp);
79        if(!e2ap_buff_size){
80              fprintf(stderr, "%s: Empty or broken\n", filename);
81               exit(1);
82            } else {
83               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
84        }
85
86        bool decode_status = true;
87           try{
88                 E2APControlAcknowledge e2obj(&e2ap_buff[0],&e2ap_buff_size);
89
90
91           } catch(const char* e){
92                         decode_status = false;
93                         std::cout << "Error Message: " << e << std::endl;
94         }
95
96
97         ASSERT_TRUE(decode_status);
98
99 }
100 TEST(E2AP, ControlFailureEncode)
101 {
102
103         unsigned char buff[1024];
104         size_t buf_len = 1024;
105
106         E2APControlFailure::ControlFailureIEs infoObj;
107         infoObj.set_ranFunctionID(1);
108         infoObj.set_ricRequestorID(1);
109         infoObj.set_ricInstanceID(1);
110         infoObj.set_ricCause(1);
111         infoObj.set_ricSubCause(1);
112         infoObj.set_ricCallProcessID("CallProcessID");
113         infoObj.set_ricControlOutcome("ControlOutcome");
114
115
116         E2APControlFailure  cntrlObj(infoObj);
117
118         bool res = cntrlObj.encode(buff, &buf_len);
119         if(!res)
120         {
121                 std::cout << cntrlObj.get_error() << std::endl;
122         }
123         ASSERT_TRUE(res);
124         FILE * pFile;
125                 pFile = fopen ("controlfail1.per","w");
126                 if (pFile!=NULL)
127                  {
128                           fwrite (buff , sizeof(char), buf_len, pFile);
129                       sleep(2);
130                           fclose (pFile);
131                   }
132
133 }
134 TEST(E2SM, ControlFailureDecode)
135 {
136        unsigned char e2ap_buff[1024];
137        char filename[100] = "controlfail1.per";
138        FILE *fp;
139        fp = fopen(filename,"rb");
140        if(!fp) {
141                      perror(filename);
142                      exit(1); }
143
144            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
145            fclose(fp);
146        if(!e2ap_buff_size){
147              fprintf(stderr, "%s: Empty or broken\n", filename);
148               exit(1);
149            } else {
150               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
151        }
152
153        bool decode_status = true;
154           try{
155                 E2APControlFailure e2obj(&e2ap_buff[0],&e2ap_buff_size);
156
157
158           } catch(const char* e){
159                         decode_status = false;
160                         std::cout << "Error Message: " << e << std::endl;
161         }
162
163
164         ASSERT_TRUE(decode_status);
165
166 }
167
168 #endif /* TEST_TEST_E2AP_H_ */