Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
test_ari_model.c File Reference

Test the native ARI JSON validators. More...

#include "asterisk.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "../res/ari/ari_model_validators.h"
Include dependency graph for test_ari_model.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (validate_byte)
 
 AST_TEST_DEFINE (validate_boolean)
 
 AST_TEST_DEFINE (validate_int)
 
 AST_TEST_DEFINE (validate_long)
 
 AST_TEST_DEFINE (validate_string)
 
 AST_TEST_DEFINE (validate_date)
 
 AST_TEST_DEFINE (validate_list)
 
static int load_module (void)
 
static int unload_module (void)
 
static int wrap_ast_ari_validate_int (struct ast_json *json)
 
static int wrap_ast_ari_validate_string (struct ast_json *json)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Skeleton (sample) Test" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari_model", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Test the native ARI JSON validators.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file test_ari_model.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 460 of file test_ari_model.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 460 of file test_ari_model.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 460 of file test_ari_model.c.

◆ AST_TEST_DEFINE() [1/7]

AST_TEST_DEFINE ( validate_byte  )

Definition at line 65 of file test_ari_model.c.

References ast_ari_validate_byte(), ast_json_integer_create(), ast_json_integer_set(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, and TEST_INIT.

66 {
67  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
69  int res;
70 
71  switch (cmd) {
72  case TEST_INIT:
73  info->name = __func__;
74  info->category = "/ari/validators/";
75  info->summary = "Test byte validation";
76  info->description =
77  "Test byte validation";
78  return AST_TEST_NOT_RUN;
79  case TEST_EXECUTE:
80  break;
81  }
82 
83  uut = ast_json_integer_create(-128);
84  ast_test_validate(test, NULL != uut);
85  ast_test_validate(test, ast_ari_validate_byte(uut));
86 
87  res = ast_json_integer_set(uut, 0);
88  ast_test_validate(test, 0 == res);
89  ast_test_validate(test, ast_ari_validate_byte(uut));
90 
91  res = ast_json_integer_set(uut, 255);
92  ast_test_validate(test, 0 == res);
93  ast_test_validate(test, ast_ari_validate_byte(uut));
94 
95  res = ast_json_integer_set(uut, -129);
96  ast_test_validate(test, 0 == res);
97  ast_test_validate(test, !ast_ari_validate_byte(uut));
98 
99  res = ast_json_integer_set(uut, 256);
100  ast_test_validate(test, 0 == res);
101  ast_test_validate(test, !ast_ari_validate_byte(uut));
102 
103  str = ast_json_string_create("not a byte");
104  ast_test_validate(test, NULL != str);
105  ast_test_validate(test, !ast_ari_validate_byte(str));
106 
107  /* Even if the string has an integral value */
108  res = ast_json_string_set(str, "0");
109  ast_test_validate(test, 0 == res);
110  ast_test_validate(test, !ast_ari_validate_byte(str));
111 
112  ast_test_validate(test, !ast_ari_validate_byte(ast_json_null()));
113 
114  return AST_TEST_PASS;
115 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
Definition: json.c:327
def info(msg)
int ast_ari_validate_byte(struct ast_json *json)
Validator for native Swagger byte.
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ AST_TEST_DEFINE() [2/7]

AST_TEST_DEFINE ( validate_boolean  )

Definition at line 117 of file test_ari_model.c.

References ast_ari_validate_boolean(), ast_json_false(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_true(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, and TEST_INIT.

118 {
119  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
120  int res;
121 
122  switch (cmd) {
123  case TEST_INIT:
124  info->name = __func__;
125  info->category = "/ari/validators/";
126  info->summary = "Test byte validation";
127  info->description =
128  "Test byte validation";
129  return AST_TEST_NOT_RUN;
130  case TEST_EXECUTE:
131  break;
132  }
133 
134  ast_test_validate(test, ast_ari_validate_boolean(ast_json_true()));
135  ast_test_validate(test, ast_ari_validate_boolean(ast_json_false()));
136 
137  str = ast_json_string_create("not a bool");
138  ast_test_validate(test, NULL != str);
139  ast_test_validate(test, !ast_ari_validate_boolean(str));
140 
141  /* Even if the string has a boolean value */
142  res = ast_json_string_set(str, "true");
143  ast_test_validate(test, 0 == res);
144  ast_test_validate(test, !ast_ari_validate_boolean(str));
145 
146  /* Even if the string has a boolean text in it */
147  res = ast_json_string_set(str, "true");
148  ast_test_validate(test, 0 == res);
149  ast_test_validate(test, !ast_ari_validate_boolean(str));
150 
151  ast_test_validate(test, !ast_ari_validate_boolean(ast_json_null()));
152 
153  return AST_TEST_PASS;
154 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_ari_validate_boolean(struct ast_json *json)
Validator for native Swagger boolean.
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
def info(msg)
struct ast_json * ast_json_false(void)
Get the JSON false value.
Definition: json.c:238
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278
struct ast_json * ast_json_true(void)
Get the JSON true value.
Definition: json.c:233

◆ AST_TEST_DEFINE() [3/7]

AST_TEST_DEFINE ( validate_int  )

Definition at line 156 of file test_ari_model.c.

References ast_ari_validate_int(), ast_json_integer_create(), ast_json_integer_set(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, and TEST_INIT.

157 {
158  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
159  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
160  int res;
161 
162  switch (cmd) {
163  case TEST_INIT:
164  info->name = __func__;
165  info->category = "/ari/validators/";
166  info->summary = "Test int validation";
167  info->description =
168  "Test int validation";
169  return AST_TEST_NOT_RUN;
170  case TEST_EXECUTE:
171  break;
172  }
173 
174  uut = ast_json_integer_create(-2147483648LL);
175  ast_test_validate(test, NULL != uut);
176  ast_test_validate(test, ast_ari_validate_int(uut));
177 
178  res = ast_json_integer_set(uut, 0);
179  ast_test_validate(test, 0 == res);
180  ast_test_validate(test, ast_ari_validate_int(uut));
181 
182  res = ast_json_integer_set(uut, 2147483647LL);
183  ast_test_validate(test, 0 == res);
184  ast_test_validate(test, ast_ari_validate_int(uut));
185 
186  res = ast_json_integer_set(uut, -2147483649LL);
187  ast_test_validate(test, 0 == res);
188  ast_test_validate(test, !ast_ari_validate_int(uut));
189 
190  res = ast_json_integer_set(uut, 2147483648LL);
191  ast_test_validate(test, 0 == res);
192  ast_test_validate(test, !ast_ari_validate_int(uut));
193 
194  str = ast_json_string_create("not a int");
195  ast_test_validate(test, NULL != str);
196  ast_test_validate(test, !ast_ari_validate_int(str));
197 
198  /* Even if the string has an integral value */
199  res = ast_json_string_set(str, "0");
200  ast_test_validate(test, 0 == res);
201  ast_test_validate(test, !ast_ari_validate_int(str));
202 
203  ast_test_validate(test, !ast_ari_validate_int(ast_json_null()));
204 
205  return AST_TEST_PASS;
206 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
Definition: json.c:327
def info(msg)
int ast_ari_validate_int(struct ast_json *json)
Validator for native Swagger int.
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ AST_TEST_DEFINE() [4/7]

AST_TEST_DEFINE ( validate_long  )

Definition at line 208 of file test_ari_model.c.

References ast_ari_validate_long(), ast_json_integer_create(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, and TEST_INIT.

209 {
210  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
211  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
212  int res;
213 
214  switch (cmd) {
215  case TEST_INIT:
216  info->name = __func__;
217  info->category = "/ari/validators/";
218  info->summary = "Test long validation";
219  info->description =
220  "Test long validation";
221  return AST_TEST_NOT_RUN;
222  case TEST_EXECUTE:
223  break;
224  }
225 
226  uut = ast_json_integer_create(0);
227  ast_test_validate(test, NULL != uut);
228  ast_test_validate(test, ast_ari_validate_long(uut));
229 
230  str = ast_json_string_create("not a long");
231  ast_test_validate(test, NULL != str);
232  ast_test_validate(test, !ast_ari_validate_long(str));
233 
234  /* Even if the string has an integral value */
235  res = ast_json_string_set(str, "0");
236  ast_test_validate(test, 0 == res);
237  ast_test_validate(test, !ast_ari_validate_long(str));
238 
239  ast_test_validate(test, !ast_ari_validate_long(ast_json_null()));
240 
241  return AST_TEST_PASS;
242 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
int ast_ari_validate_long(struct ast_json *json)
Validator for native Swagger long.
def info(msg)
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ AST_TEST_DEFINE() [5/7]

AST_TEST_DEFINE ( validate_string  )

Definition at line 244 of file test_ari_model.c.

References ast_ari_validate_string(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, and TEST_INIT.

245 {
246  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
247  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
248  int res;
249 
250  switch (cmd) {
251  case TEST_INIT:
252  info->name = __func__;
253  info->category = "/ari/validators/";
254  info->summary = "Test string validation";
255  info->description =
256  "Test string validation";
257  return AST_TEST_NOT_RUN;
258  case TEST_EXECUTE:
259  break;
260  }
261 
262  uut = ast_json_string_create("text");
263  ast_test_validate(test, NULL != uut);
264  ast_test_validate(test, ast_ari_validate_string(uut));
265 
266  res = ast_json_string_set(uut, "");
267  ast_test_validate(test, 0 == res);
268  ast_test_validate(test, ast_ari_validate_string(uut));
269 
270  ast_test_validate(test, !ast_ari_validate_string(ast_json_null()));
271 
272  return AST_TEST_PASS;
273 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
def info(msg)
int ast_ari_validate_string(struct ast_json *json)
Validator for native Swagger string.
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278

◆ AST_TEST_DEFINE() [6/7]

AST_TEST_DEFINE ( validate_date  )

Definition at line 275 of file test_ari_model.c.

References ARRAY_LEN, ast_ari_validate_date(), ast_ari_validate_string(), ast_json_null(), ast_json_string_create(), ast_json_string_set(), ast_json_unref(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, TEST_INIT, and test_res.

276 {
277  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
278  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
280  int res;
281  int i;
282  const char *valid_dates[] = {
283  /* Time is optional */
284  "2013-06-17",
285  /* Seconds are optional */
286  "2013-06-17T23:59Z",
287  /* Subseconds are optional */
288  "2013-06-17T23:59:59Z",
289  /* Leap seconds are valid */
290  "2013-06-30T23:59:61Z",
291  /* Subseconds are allowed */
292  "2013-06-17T23:59:59.999999Z",
293  /* Now with -06:00 for the timezone */
294  "2013-06-17T23:59-06:00",
295  "2013-06-17T23:59:59-06:00",
296  "2013-06-30T23:59:61-06:00",
297  "2013-06-17T23:59:59.999999-06:00",
298  /* Again, with +06:30 for the timezone */
299  "2013-06-17T23:59+06:30",
300  "2013-06-17T23:59:59+06:30",
301  "2013-06-30T23:59:61+06:30",
302  "2013-06-17T23:59:59.999999+06:30",
303  /* So the colon in the timezone is optional */
304  "2013-06-17T23:59-0600",
305  "2013-06-17T23:59:59-0600",
306  "2013-06-30T23:59:61-0600",
307  "2013-06-17T23:59:59.999999-0600",
308  /* Sure, why not */
309  "2013-06-17T23:59+0630",
310  "2013-06-17T23:59:59+0630",
311  "2013-06-30T23:59:61+0630",
312  "2013-06-17T23:59:59.999999+0630",
313  "9999-12-31T23:59:61.999999Z",
314  /* In fact, you don't even have to specify minutes */
315  "2013-06-17T23:59-06",
316  "2013-06-17T23:59:59-06",
317  "2013-06-30T23:59:61-06",
318  "2013-06-17T23:59:59.999999-06",
319  };
320 
321  /* There are lots of invalid dates that the validator lets through.
322  * Those would be strings properly formatted as a ridiculous date. Such
323  * as 0000-00-00, or 9999-19-39. Those are harder to catch with a regex,
324  * and actually aren't as important. So long as the valid dates pass the
325  * validator, and poorly formatted dates are rejected, it's fine.
326  * Catching the occasional ridiculous date is just bonus.
327  */
328  const char *invalid_dates[] = {
329  "",
330  "Not a date",
331  "2013-06-17T", /* Missing time, but has T */
332  "2013-06-17T23:59:59.Z", /* Missing subsecond, but has dot */
333  "2013-06-17T23:59", /* Missing timezone, but has time */
334  "2013-06-17T23:59:59.999999", /* Missing timezone */
335  "9999-99-31T23:59:61.999999Z", /* Invalid month */
336  "9999-12-99T23:59:61.999999Z", /* Invalid day */
337  "9999-12-31T99:59:61.999999Z", /* Invalid hour */
338  "9999-12-31T23:99:61.999999Z", /* Invalid minute */
339  "9999-12-31T23:59:99.999999Z", /* Invalid second */
340  "2013-06-17T23:59:59.999999-99:00", /* Invalid timezone */
341  "2013-06-17T23:59:59.999999-06:99", /* Invalid timezone */
342  "2013-06-17T23:59:59.999999-06:", /* Invalid timezone */
343  "2013-06-17T23:59:59.999999-06:0", /* Invalid timezone */
344  "2013-06-17T23:59:59.999999-060", /* Invalid timezone */
345  };
346 
347  switch (cmd) {
348  case TEST_INIT:
349  info->name = __func__;
350  info->category = "/ari/validators/";
351  info->summary = "Test date validation";
352  info->description =
353  "Test date validation";
354  return AST_TEST_NOT_RUN;
355  case TEST_EXECUTE:
356  break;
357  }
358 
359  uut = ast_json_string_create("");
360  ast_test_validate(test, NULL != uut);
361 
362  /* Instead of using ast_test_validate, we'll collect the results from
363  * several test cases, since we have so many */
364  test_res = AST_TEST_PASS;
365  for (i = 0; i < ARRAY_LEN(valid_dates); ++i) {
366  res = ast_json_string_set(uut, valid_dates[i]);
367  ast_test_validate(test, 0 == res);
368  if (!ast_ari_validate_date(uut)) {
370  "Expected '%s' to be a valid date\n",
371  valid_dates[i]);
372  test_res = AST_TEST_FAIL;
373  }
374  }
375 
376  for (i = 0; i < ARRAY_LEN(invalid_dates); ++i) {
377  res = ast_json_string_set(uut, invalid_dates[i]);
378  ast_test_validate(test, 0 == res);
379  if (ast_ari_validate_date(uut)) {
381  "Expected '%s' to be an invalid date\n",
382  invalid_dates[i]);
383  test_res = AST_TEST_FAIL;
384  }
385  }
386 
387  ast_test_validate(test, !ast_ari_validate_string(ast_json_null()));
388 
389  return test_res;
390 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
int ast_ari_validate_date(struct ast_json *json)
Validator for native Swagger date.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
static enum ast_test_result_state test_res
def info(msg)
int ast_ari_validate_string(struct ast_json *json)
Validator for native Swagger string.
Abstract JSON element (object, array, string, int, ...).
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
Definition: json.c:278
ast_test_result_state
Definition: test.h:200

◆ AST_TEST_DEFINE() [7/7]

AST_TEST_DEFINE ( validate_list  )

Definition at line 392 of file test_ari_model.c.

References ast_ari_validate_list(), ast_json_array_append(), ast_json_array_create(), ast_json_integer_create(), ast_json_null(), ast_json_string_create(), ast_json_unref(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), NULL, RAII_VAR, str, TEST_EXECUTE, TEST_INIT, wrap_ast_ari_validate_int(), and wrap_ast_ari_validate_string().

393 {
394  RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
395  RAII_VAR(struct ast_json *, str, NULL, ast_json_unref);
396  int res;
397 
398  switch (cmd) {
399  case TEST_INIT:
400  info->name = __func__;
401  info->category = "/ari/validators/";
402  info->summary = "Test list validation";
403  info->description =
404  "Test list validation";
405  return AST_TEST_NOT_RUN;
406  case TEST_EXECUTE:
407  break;
408  }
409 
410  uut = ast_json_array_create();
411  ast_test_validate(test, NULL != uut);
412  ast_test_validate(test, ast_ari_validate_list(uut, wrap_ast_ari_validate_string));
413  ast_test_validate(test, ast_ari_validate_list(uut, wrap_ast_ari_validate_int));
414 
416  ast_test_validate(test, 0 == res);
417  ast_test_validate(test, ast_ari_validate_list(uut, wrap_ast_ari_validate_string));
418  ast_test_validate(test, !ast_ari_validate_list(uut, wrap_ast_ari_validate_int));
419 
421  ast_test_validate(test, 0 == res);
422  ast_test_validate(test, !ast_ari_validate_list(uut, wrap_ast_ari_validate_string));
423  ast_test_validate(test, !ast_ari_validate_list(uut, wrap_ast_ari_validate_int));
424 
425  ast_test_validate(test,
427 
428  return AST_TEST_PASS;
429 }
static int wrap_ast_ari_validate_string(struct ast_json *json)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:368
def info(msg)
Abstract JSON element (object, array, string, int, ...).
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
static int wrap_ast_ari_validate_int(struct ast_json *json)
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ load_module()

static int load_module ( void  )
static

Definition at line 443 of file test_ari_model.c.

References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, AST_TEST_REGISTER, ASTERISK_GPL_KEY, and unload_module().

444 {
445  AST_TEST_REGISTER(validate_byte);
446  AST_TEST_REGISTER(validate_boolean);
447  AST_TEST_REGISTER(validate_int);
448  AST_TEST_REGISTER(validate_long);
449  AST_TEST_REGISTER(validate_string);
450  AST_TEST_REGISTER(validate_date);
451  AST_TEST_REGISTER(validate_list);
453 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 431 of file test_ari_model.c.

References AST_TEST_UNREGISTER.

Referenced by load_module().

432 {
433  AST_TEST_UNREGISTER(validate_byte);
434  AST_TEST_UNREGISTER(validate_boolean);
435  AST_TEST_UNREGISTER(validate_int);
436  AST_TEST_UNREGISTER(validate_long);
437  AST_TEST_UNREGISTER(validate_string);
438  AST_TEST_UNREGISTER(validate_date);
439  AST_TEST_UNREGISTER(validate_list);
440  return 0;
441 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

◆ wrap_ast_ari_validate_int()

static int wrap_ast_ari_validate_int ( struct ast_json json)
static

Wrapper of ast_test_validate_int() so an external function pointer is not used.

Note
We do this because using an external function pointer did not play nicely when we loaded with RTLD_LAZY.

Definition at line 46 of file test_ari_model.c.

References ast_ari_validate_int().

Referenced by AST_TEST_DEFINE().

47 {
48  return ast_ari_validate_int(json);
49 }
int ast_ari_validate_int(struct ast_json *json)
Validator for native Swagger int.

◆ wrap_ast_ari_validate_string()

static int wrap_ast_ari_validate_string ( struct ast_json json)
static

Wrapper of ast_ari_validate_string() so an external function pointer is not used.

Note
We do this because using an external function pointer did not play nicely when we loaded with RTLD_LAZY.

Definition at line 59 of file test_ari_model.c.

References ast_ari_validate_string().

Referenced by AST_TEST_DEFINE().

60 {
61  return ast_ari_validate_string(json);
62 }
int ast_ari_validate_string(struct ast_json *json)
Validator for native Swagger string.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Skeleton (sample) Test" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari_model", }
static

Definition at line 460 of file test_ari_model.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 460 of file test_ari_model.c.