Coverage Report

Created: 2026-11-12 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/direction_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "direction_info.h"
6
7
OpenAPI_direction_info_t *OpenAPI_direction_info_create(
8
    char *supi,
9
    char *gpsi,
10
    bool is_num_of_ue,
11
    int num_of_ue,
12
    bool is_avr_speed,
13
    float avr_speed,
14
    bool is_ratio,
15
    int ratio,
16
    OpenAPI_direction_e direction
17
)
18
0
{
19
0
    OpenAPI_direction_info_t *direction_info_local_var = ogs_malloc(sizeof(OpenAPI_direction_info_t));
20
0
    ogs_assert(direction_info_local_var);
21
22
0
    direction_info_local_var->supi = supi;
23
0
    direction_info_local_var->gpsi = gpsi;
24
0
    direction_info_local_var->is_num_of_ue = is_num_of_ue;
25
0
    direction_info_local_var->num_of_ue = num_of_ue;
26
0
    direction_info_local_var->is_avr_speed = is_avr_speed;
27
0
    direction_info_local_var->avr_speed = avr_speed;
28
0
    direction_info_local_var->is_ratio = is_ratio;
29
0
    direction_info_local_var->ratio = ratio;
30
0
    direction_info_local_var->direction = direction;
31
32
0
    return direction_info_local_var;
33
0
}
34
35
void OpenAPI_direction_info_free(OpenAPI_direction_info_t *direction_info)
36
0
{
37
0
    OpenAPI_lnode_t *node = NULL;
38
39
0
    if (NULL == direction_info) {
40
0
        return;
41
0
    }
42
0
    if (direction_info->supi) {
43
0
        ogs_free(direction_info->supi);
44
0
        direction_info->supi = NULL;
45
0
    }
46
0
    if (direction_info->gpsi) {
47
0
        ogs_free(direction_info->gpsi);
48
0
        direction_info->gpsi = NULL;
49
0
    }
50
0
    ogs_free(direction_info);
51
0
}
52
53
cJSON *OpenAPI_direction_info_convertToJSON(OpenAPI_direction_info_t *direction_info)
54
0
{
55
0
    cJSON *item = NULL;
56
0
    OpenAPI_lnode_t *node = NULL;
57
58
0
    if (direction_info == NULL) {
59
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [DirectionInfo]");
60
0
        return NULL;
61
0
    }
62
63
0
    item = cJSON_CreateObject();
64
0
    if (direction_info->supi) {
65
0
    if (cJSON_AddStringToObject(item, "supi", direction_info->supi) == NULL) {
66
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [supi]");
67
0
        goto end;
68
0
    }
69
0
    }
70
71
0
    if (direction_info->gpsi) {
72
0
    if (cJSON_AddStringToObject(item, "gpsi", direction_info->gpsi) == NULL) {
73
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [gpsi]");
74
0
        goto end;
75
0
    }
76
0
    }
77
78
0
    if (direction_info->is_num_of_ue) {
79
0
    if (cJSON_AddNumberToObject(item, "numOfUe", direction_info->num_of_ue) == NULL) {
80
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [num_of_ue]");
81
0
        goto end;
82
0
    }
83
0
    }
84
85
0
    if (direction_info->is_avr_speed) {
86
0
    if (cJSON_AddNumberToObject(item, "avrSpeed", direction_info->avr_speed) == NULL) {
87
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [avr_speed]");
88
0
        goto end;
89
0
    }
90
0
    }
91
92
0
    if (direction_info->is_ratio) {
93
0
    if (cJSON_AddNumberToObject(item, "ratio", direction_info->ratio) == NULL) {
94
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [ratio]");
95
0
        goto end;
96
0
    }
97
0
    }
98
99
0
    if (direction_info->direction == OpenAPI_direction_NULL) {
100
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [direction]");
101
0
        return NULL;
102
0
    }
103
0
    if (cJSON_AddStringToObject(item, "direction", OpenAPI_direction_ToString(direction_info->direction)) == NULL) {
104
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed [direction]");
105
0
        goto end;
106
0
    }
107
108
0
end:
109
0
    return item;
110
0
}
111
112
OpenAPI_direction_info_t *OpenAPI_direction_info_parseFromJSON(cJSON *direction_infoJSON)
113
0
{
114
0
    OpenAPI_direction_info_t *direction_info_local_var = NULL;
115
0
    OpenAPI_lnode_t *node = NULL;
116
0
    cJSON *supi = NULL;
117
0
    cJSON *gpsi = NULL;
118
0
    cJSON *num_of_ue = NULL;
119
0
    cJSON *avr_speed = NULL;
120
0
    cJSON *ratio = NULL;
121
0
    cJSON *direction = NULL;
122
0
    OpenAPI_direction_e directionVariable = 0;
123
0
    supi = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "supi");
124
0
    if (supi) {
125
0
    if (!cJSON_IsString(supi) && !cJSON_IsNull(supi)) {
126
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [supi]");
127
0
        goto end;
128
0
    }
129
0
    }
130
131
0
    gpsi = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "gpsi");
132
0
    if (gpsi) {
133
0
    if (!cJSON_IsString(gpsi) && !cJSON_IsNull(gpsi)) {
134
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [gpsi]");
135
0
        goto end;
136
0
    }
137
0
    }
138
139
0
    num_of_ue = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "numOfUe");
140
0
    if (num_of_ue) {
141
0
    if (!cJSON_IsNumber(num_of_ue)) {
142
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [num_of_ue]");
143
0
        goto end;
144
0
    }
145
0
    }
146
147
0
    avr_speed = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "avrSpeed");
148
0
    if (avr_speed) {
149
0
    if (!cJSON_IsNumber(avr_speed)) {
150
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [avr_speed]");
151
0
        goto end;
152
0
    }
153
0
    }
154
155
0
    ratio = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "ratio");
156
0
    if (ratio) {
157
0
    if (!cJSON_IsNumber(ratio)) {
158
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [ratio]");
159
0
        goto end;
160
0
    }
161
0
    }
162
163
0
    direction = cJSON_GetObjectItemCaseSensitive(direction_infoJSON, "direction");
164
0
    if (!direction) {
165
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [direction]");
166
0
        goto end;
167
0
    }
168
0
    if (!cJSON_IsString(direction)) {
169
0
        ogs_error("OpenAPI_direction_info_parseFromJSON() failed [direction]");
170
0
        goto end;
171
0
    }
172
0
    directionVariable = OpenAPI_direction_FromString(direction->valuestring);
173
174
0
    direction_info_local_var = OpenAPI_direction_info_create (
175
0
        supi && !cJSON_IsNull(supi) ? ogs_strdup(supi->valuestring) : NULL,
176
0
        gpsi && !cJSON_IsNull(gpsi) ? ogs_strdup(gpsi->valuestring) : NULL,
177
0
        num_of_ue ? true : false,
178
0
        num_of_ue ? num_of_ue->valuedouble : 0,
179
0
        avr_speed ? true : false,
180
0
        avr_speed ? avr_speed->valuedouble : 0,
181
0
        ratio ? true : false,
182
0
        ratio ? ratio->valuedouble : 0,
183
0
        directionVariable
184
0
    );
185
186
0
    return direction_info_local_var;
187
0
end:
188
0
    return NULL;
189
0
}
190
191
OpenAPI_direction_info_t *OpenAPI_direction_info_copy(OpenAPI_direction_info_t *dst, OpenAPI_direction_info_t *src)
192
0
{
193
0
    cJSON *item = NULL;
194
0
    char *content = NULL;
195
196
0
    ogs_assert(src);
197
0
    item = OpenAPI_direction_info_convertToJSON(src);
198
0
    if (!item) {
199
0
        ogs_error("OpenAPI_direction_info_convertToJSON() failed");
200
0
        return NULL;
201
0
    }
202
203
0
    content = cJSON_Print(item);
204
0
    cJSON_Delete(item);
205
206
0
    if (!content) {
207
0
        ogs_error("cJSON_Print() failed");
208
0
        return NULL;
209
0
    }
210
211
0
    item = cJSON_Parse(content);
212
0
    ogs_free(content);
213
0
    if (!item) {
214
0
        ogs_error("cJSON_Parse() failed");
215
0
        return NULL;
216
0
    }
217
218
0
    OpenAPI_direction_info_free(dst);
219
0
    dst = OpenAPI_direction_info_parseFromJSON(item);
220
0
    cJSON_Delete(item);
221
222
0
    return dst;
223
0
}
224