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/tac_range.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "tac_range.h"
6
7
OpenAPI_tac_range_t *OpenAPI_tac_range_create(
8
    char *start,
9
    char *end,
10
    char *pattern
11
)
12
154
{
13
154
    OpenAPI_tac_range_t *tac_range_local_var = ogs_malloc(sizeof(OpenAPI_tac_range_t));
14
154
    ogs_assert(tac_range_local_var);
15
16
154
    tac_range_local_var->start = start;
17
154
    tac_range_local_var->end = end;
18
154
    tac_range_local_var->pattern = pattern;
19
20
154
    return tac_range_local_var;
21
154
}
22
23
void OpenAPI_tac_range_free(OpenAPI_tac_range_t *tac_range)
24
154
{
25
154
    OpenAPI_lnode_t *node = NULL;
26
27
154
    if (NULL == tac_range) {
28
0
        return;
29
0
    }
30
154
    if (tac_range->start) {
31
5
        ogs_free(tac_range->start);
32
5
        tac_range->start = NULL;
33
5
    }
34
154
    if (tac_range->end) {
35
32
        ogs_free(tac_range->end);
36
32
        tac_range->end = NULL;
37
32
    }
38
154
    if (tac_range->pattern) {
39
0
        ogs_free(tac_range->pattern);
40
0
        tac_range->pattern = NULL;
41
0
    }
42
154
    ogs_free(tac_range);
43
154
}
44
45
cJSON *OpenAPI_tac_range_convertToJSON(OpenAPI_tac_range_t *tac_range)
46
0
{
47
0
    cJSON *item = NULL;
48
0
    OpenAPI_lnode_t *node = NULL;
49
50
0
    if (tac_range == NULL) {
51
0
        ogs_error("OpenAPI_tac_range_convertToJSON() failed [TacRange]");
52
0
        return NULL;
53
0
    }
54
55
0
    item = cJSON_CreateObject();
56
0
    if (tac_range->start) {
57
0
    if (cJSON_AddStringToObject(item, "start", tac_range->start) == NULL) {
58
0
        ogs_error("OpenAPI_tac_range_convertToJSON() failed [start]");
59
0
        goto end;
60
0
    }
61
0
    }
62
63
0
    if (tac_range->end) {
64
0
    if (cJSON_AddStringToObject(item, "end", tac_range->end) == NULL) {
65
0
        ogs_error("OpenAPI_tac_range_convertToJSON() failed [end]");
66
0
        goto end;
67
0
    }
68
0
    }
69
70
0
    if (tac_range->pattern) {
71
0
    if (cJSON_AddStringToObject(item, "pattern", tac_range->pattern) == NULL) {
72
0
        ogs_error("OpenAPI_tac_range_convertToJSON() failed [pattern]");
73
0
        goto end;
74
0
    }
75
0
    }
76
77
0
end:
78
0
    return item;
79
0
}
80
81
OpenAPI_tac_range_t *OpenAPI_tac_range_parseFromJSON(cJSON *tac_rangeJSON)
82
155
{
83
155
    OpenAPI_tac_range_t *tac_range_local_var = NULL;
84
155
    OpenAPI_lnode_t *node = NULL;
85
155
    cJSON *start = NULL;
86
155
    cJSON *end = NULL;
87
155
    cJSON *pattern = NULL;
88
155
    start = cJSON_GetObjectItemCaseSensitive(tac_rangeJSON, "start");
89
155
    if (start) {
90
6
    if (!cJSON_IsString(start) && !cJSON_IsNull(start)) {
91
0
        ogs_error("OpenAPI_tac_range_parseFromJSON() failed [start]");
92
0
        goto end;
93
0
    }
94
6
    }
95
96
155
    end = cJSON_GetObjectItemCaseSensitive(tac_rangeJSON, "end");
97
155
    if (end) {
98
33
    if (!cJSON_IsString(end) && !cJSON_IsNull(end)) {
99
1
        ogs_error("OpenAPI_tac_range_parseFromJSON() failed [end]");
100
1
        goto end;
101
1
    }
102
33
    }
103
104
154
    pattern = cJSON_GetObjectItemCaseSensitive(tac_rangeJSON, "pattern");
105
154
    if (pattern) {
106
0
    if (!cJSON_IsString(pattern) && !cJSON_IsNull(pattern)) {
107
0
        ogs_error("OpenAPI_tac_range_parseFromJSON() failed [pattern]");
108
0
        goto end;
109
0
    }
110
0
    }
111
112
154
    tac_range_local_var = OpenAPI_tac_range_create (
113
154
        start && !cJSON_IsNull(start) ? ogs_strdup(start->valuestring) : NULL,
114
154
        end && !cJSON_IsNull(end) ? ogs_strdup(end->valuestring) : NULL,
115
154
        pattern && !cJSON_IsNull(pattern) ? ogs_strdup(pattern->valuestring) : NULL
116
154
    );
117
118
154
    return tac_range_local_var;
119
1
end:
120
1
    return NULL;
121
154
}
122
123
OpenAPI_tac_range_t *OpenAPI_tac_range_copy(OpenAPI_tac_range_t *dst, OpenAPI_tac_range_t *src)
124
0
{
125
0
    cJSON *item = NULL;
126
0
    char *content = NULL;
127
128
0
    ogs_assert(src);
129
0
    item = OpenAPI_tac_range_convertToJSON(src);
130
0
    if (!item) {
131
0
        ogs_error("OpenAPI_tac_range_convertToJSON() failed");
132
0
        return NULL;
133
0
    }
134
135
0
    content = cJSON_Print(item);
136
0
    cJSON_Delete(item);
137
138
0
    if (!content) {
139
0
        ogs_error("cJSON_Print() failed");
140
0
        return NULL;
141
0
    }
142
143
0
    item = cJSON_Parse(content);
144
0
    ogs_free(content);
145
0
    if (!item) {
146
0
        ogs_error("cJSON_Parse() failed");
147
0
        return NULL;
148
0
    }
149
150
0
    OpenAPI_tac_range_free(dst);
151
0
    dst = OpenAPI_tac_range_parseFromJSON(item);
152
0
    cJSON_Delete(item);
153
154
0
    return dst;
155
0
}
156