Adding new comments for Oran in all files with licenses
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / src / tests / unpack_xer.c
1 /*
2  * Copyright 2019 AT&T Intellectual Property
3  * Copyright 2019 Nokia
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*
19  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20  * platform project (RICP).
21  */
22
23 #include <errno.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <asn1codec_utils.h>
28
29 int
30 main(int argc, char* argv[])
31 {
32         char responseErrorBuf[1<< 16];
33         uint8_t buf[1 << 16];
34         size_t count = fread(buf, 1, sizeof(buf), stdin);
35         if (count == sizeof(buf)) {
36                 printf("#%s failed. Input is too big\n", __func__);
37                 exit(-1);
38         }
39         if (!feof(stdin)){
40                 printf("#%s failed. Error while reading input: %s\n", __func__, strerror(errno));
41                 exit(-1);
42         }
43
44         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
45         if (!unpack_pdu_aux(pdu, count, buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_BASIC_XER)){
46                 printf("#%s failed. Unpacking error %s\n", __func__, responseErrorBuf);
47                 exit(-1);
48         }
49
50         responseErrorBuf[0] = 0;
51         asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
52         printf("#%s: %s\n", __func__, responseErrorBuf);
53
54         {
55         size_t per_packed_buf_size;
56         uint8_t per_packed_buf[1 << 16];
57
58         responseErrorBuf[0] = 0;
59         per_packed_buf_size = sizeof(per_packed_buf);
60
61         if (!pack_pdu_aux(pdu,&per_packed_buf_size, per_packed_buf,sizeof(responseErrorBuf), responseErrorBuf, ATS_ALIGNED_BASIC_PER)){
62                 printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
63                 exit(-1);
64         }
65         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
66         printf("#%s packed size:%zu\nPayload:\n", __func__, per_packed_buf_size);
67         for (size_t i= 0; i < per_packed_buf_size; i++)
68                 printf("%02x",per_packed_buf[i]);
69         printf("\n");
70
71         pdu =calloc(1, sizeof(E2AP_PDU_t));
72         if (!unpack_pdu_aux(pdu, per_packed_buf_size, per_packed_buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
73                 printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
74         }
75
76         responseErrorBuf[0] = 0;
77         asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
78         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
79         printf("#%s: %s\n", __func__, responseErrorBuf);
80         }
81     exit(0);
82 }
83
84