Change version after creation of r2 branch
[ric-plt/resource-status-manager.git] / RSM / asn1codec / src / tests / unpack_xer.c
1 /*
2  *
3  * Copyright 2019 AT&T Intellectual Property
4  * Copyright 2019 Nokia
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 #include <errno.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <asn1codec_utils.h>
24
25 int
26 main(int argc, char* argv[])
27 {
28         char responseErrorBuf[1<< 16];
29         uint8_t buf[1 << 16];
30         size_t count = fread(buf, 1, sizeof(buf), stdin);
31         if (count == sizeof(buf)) {
32                 printf("#%s failed. Input is too big\n", __func__);
33                 exit(-1);
34         }
35         if (!feof(stdin)){
36                 printf("#%s failed. Error while reading input: %s\n", __func__, strerror(errno));
37                 exit(-1);
38         }
39
40         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
41         if (!unpack_pdu_aux(pdu, count, buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_BASIC_XER)){
42                 printf("#%s failed. Unpacking error %s\n", __func__, responseErrorBuf);
43                 exit(-1);
44         }
45
46         responseErrorBuf[0] = 0;
47         asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
48         printf("#%s: %s\n", __func__, responseErrorBuf);
49
50         {
51         size_t per_packed_buf_size;
52         uint8_t per_packed_buf[1 << 16];
53
54         responseErrorBuf[0] = 0;
55         per_packed_buf_size = sizeof(per_packed_buf);
56
57         if (!pack_pdu_aux(pdu,&per_packed_buf_size, per_packed_buf,sizeof(responseErrorBuf), responseErrorBuf, ATS_ALIGNED_BASIC_PER)){
58                 printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
59                 exit(-1);
60         }
61         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
62         printf("#%s packed size:%zu\nPayload:\n", __func__, per_packed_buf_size);
63         for (size_t i= 0; i < per_packed_buf_size; i++)
64                 printf("%02x",per_packed_buf[i]);
65         printf("\n");
66
67         pdu =calloc(1, sizeof(E2AP_PDU_t));
68         if (!unpack_pdu_aux(pdu, per_packed_buf_size, per_packed_buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
69                 printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
70         }
71
72         responseErrorBuf[0] = 0;
73         asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
74         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
75         printf("#%s: %s\n", __func__, responseErrorBuf);
76         }
77     exit(0);
78 }
79
80