Test the native ARI JSON validators.
More...
Go to the source code of this file.
|
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_info * | ast_module_info = &__mod_info |
|
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.
◆ __reg_module()
static void __reg_module |
( |
void |
| ) |
|
|
static |
◆ __unreg_module()
static void __unreg_module |
( |
void |
| ) |
|
|
static |
◆ AST_MODULE_SELF_SYM()
◆ 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.
73 info->name = __func__;
74 info->category =
"/ari/validators/";
75 info->summary =
"Test byte validation";
77 "Test byte validation";
84 ast_test_validate(
test,
NULL != uut);
88 ast_test_validate(
test, 0 == res);
92 ast_test_validate(
test, 0 == res);
96 ast_test_validate(
test, 0 == res);
100 ast_test_validate(
test, 0 == res);
109 ast_test_validate(
test, 0 == res);
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
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.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
◆ 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.
124 info->name = __func__;
125 info->category =
"/ari/validators/";
126 info->summary =
"Test byte validation";
128 "Test byte validation";
143 ast_test_validate(
test, 0 == res);
148 ast_test_validate(
test, 0 == res);
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
int ast_ari_validate_boolean(struct ast_json *json)
Validator for native Swagger boolean.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
struct ast_json * ast_json_false(void)
Get the JSON false value.
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.
struct ast_json * ast_json_true(void)
Get the JSON true value.
◆ 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.
164 info->name = __func__;
165 info->category =
"/ari/validators/";
166 info->summary =
"Test int validation";
168 "Test int validation";
175 ast_test_validate(
test,
NULL != uut);
179 ast_test_validate(
test, 0 == res);
183 ast_test_validate(
test, 0 == res);
187 ast_test_validate(
test, 0 == res);
191 ast_test_validate(
test, 0 == res);
200 ast_test_validate(
test, 0 == res);
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
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.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
◆ 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.
216 info->name = __func__;
217 info->category =
"/ari/validators/";
218 info->summary =
"Test long validation";
220 "Test long validation";
227 ast_test_validate(
test,
NULL != uut);
236 ast_test_validate(
test, 0 == res);
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
int ast_ari_validate_long(struct ast_json *json)
Validator for native Swagger long.
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.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
◆ 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.
252 info->name = __func__;
253 info->category =
"/ari/validators/";
254 info->summary =
"Test string validation";
256 "Test string validation";
263 ast_test_validate(
test,
NULL != uut);
267 ast_test_validate(
test, 0 == res);
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
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.
◆ 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.
282 const char *valid_dates[] = {
288 "2013-06-17T23:59:59Z",
290 "2013-06-30T23:59:61Z",
292 "2013-06-17T23:59:59.999999Z",
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",
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",
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",
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",
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",
328 const char *invalid_dates[] = {
332 "2013-06-17T23:59:59.Z",
334 "2013-06-17T23:59:59.999999",
335 "9999-99-31T23:59:61.999999Z",
336 "9999-12-99T23:59:61.999999Z",
337 "9999-12-31T99:59:61.999999Z",
338 "9999-12-31T23:99:61.999999Z",
339 "9999-12-31T23:59:99.999999Z",
340 "2013-06-17T23:59:59.999999-99:00",
341 "2013-06-17T23:59:59.999999-06:99",
342 "2013-06-17T23:59:59.999999-06:",
343 "2013-06-17T23:59:59.999999-06:0",
344 "2013-06-17T23:59:59.999999-060",
349 info->name = __func__;
350 info->category =
"/ari/validators/";
351 info->summary =
"Test date validation";
353 "Test date validation";
360 ast_test_validate(
test,
NULL != uut);
365 for (i = 0; i <
ARRAY_LEN(valid_dates); ++i) {
367 ast_test_validate(
test, 0 == res);
370 "Expected '%s' to be a valid date\n",
376 for (i = 0; i <
ARRAY_LEN(invalid_dates); ++i) {
378 ast_test_validate(
test, 0 == res);
381 "Expected '%s' to be an invalid date\n",
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_json * ast_json_null(void)
Get the JSON null value.
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.
#define ast_test_status_update(a, b, c...)
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
static enum ast_test_result_state test_res
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.
◆ 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().
400 info->name = __func__;
401 info->category =
"/ari/validators/";
402 info->summary =
"Test list validation";
404 "Test list validation";
411 ast_test_validate(
test,
NULL != uut);
416 ast_test_validate(
test, 0 == res);
421 ast_test_validate(
test, 0 == res);
425 ast_test_validate(
test,
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.
struct ast_json * ast_json_null(void)
Get the JSON null value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
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.
◆ load_module()
static int load_module |
( |
void |
| ) |
|
|
static |
◆ unload_module()
static int unload_module |
( |
void |
| ) |
|
|
static |
◆ 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().
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 |
◆ __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 |
◆ ast_module_info