37 #include "../res/ari/ari_model_validators.h"
39 #if defined(TEST_FRAMEWORK)
46 static int wrap_ast_ari_validate_int(
struct ast_json *json)
52 #if defined(TEST_FRAMEWORK)
59 static int wrap_ast_ari_validate_string(
struct ast_json *json)
73 info->name = __func__;
74 info->category =
"/ari/validators/";
75 info->summary =
"Test byte validation";
77 "Test byte validation";
78 return AST_TEST_NOT_RUN;
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);
104 ast_test_validate(
test, NULL != str);
109 ast_test_validate(
test, 0 == res);
114 return AST_TEST_PASS;
124 info->name = __func__;
125 info->category =
"/ari/validators/";
126 info->summary =
"Test byte validation";
128 "Test byte validation";
129 return AST_TEST_NOT_RUN;
138 ast_test_validate(
test, NULL != str);
143 ast_test_validate(
test, 0 == res);
148 ast_test_validate(
test, 0 == res);
153 return AST_TEST_PASS;
164 info->name = __func__;
165 info->category =
"/ari/validators/";
166 info->summary =
"Test int validation";
168 "Test int validation";
169 return AST_TEST_NOT_RUN;
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);
195 ast_test_validate(
test, NULL != str);
200 ast_test_validate(
test, 0 == res);
205 return AST_TEST_PASS;
216 info->name = __func__;
217 info->category =
"/ari/validators/";
218 info->summary =
"Test long validation";
220 "Test long validation";
221 return AST_TEST_NOT_RUN;
227 ast_test_validate(
test, NULL != uut);
231 ast_test_validate(
test, NULL != str);
236 ast_test_validate(
test, 0 == res);
241 return AST_TEST_PASS;
252 info->name = __func__;
253 info->category =
"/ari/validators/";
254 info->summary =
"Test string validation";
256 "Test string validation";
257 return AST_TEST_NOT_RUN;
263 ast_test_validate(
test, NULL != uut);
267 ast_test_validate(
test, 0 == res);
272 return AST_TEST_PASS;
279 enum ast_test_result_state 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";
354 return AST_TEST_NOT_RUN;
360 ast_test_validate(
test, NULL != uut);
364 test_res = AST_TEST_PASS;
365 for (i = 0; i < ARRAY_LEN(valid_dates); ++i) {
367 ast_test_validate(
test, 0 == res);
369 ast_test_status_update(
test,
370 "Expected '%s' to be a valid date\n",
372 test_res = AST_TEST_FAIL;
376 for (i = 0; i < ARRAY_LEN(invalid_dates); ++i) {
378 ast_test_validate(
test, 0 == res);
380 ast_test_status_update(
test,
381 "Expected '%s' to be an invalid date\n",
383 test_res = AST_TEST_FAIL;
400 info->name = __func__;
401 info->category =
"/ari/validators/";
402 info->summary =
"Test list validation";
404 "Test list validation";
405 return AST_TEST_NOT_RUN;
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,
428 return AST_TEST_PASS;
431 static int unload_module(
void)
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);
443 static int load_module(
void)
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);
455 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Skeleton (sample) Test",
456 .support_level = AST_MODULE_SUPPORT_CORE,
458 .unload = unload_module,
459 .requires =
"res_ari_model",
Asterisk main include file. File version handling, generic pbx functions.
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.
int ast_ari_validate_date(struct ast_json *json)
Validator for native Swagger date.
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.
int ast_ari_validate_long(struct ast_json *json)
Validator for native Swagger long.
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.
int ast_ari_validate_byte(struct ast_json *json)
Validator for native Swagger byte.
struct ast_json * ast_json_false(void)
Get the JSON false value.
int ast_ari_validate_string(struct ast_json *json)
Validator for native Swagger string.
#define AST_TEST_DEFINE(hdr)
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.
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#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_true(void)
Get the JSON true value.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.