summaryrefslogtreecommitdiff
path: root/tests/test_json.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_json.c')
-rw-r--r--tests/test_json.c171
1 files changed, 64 insertions, 107 deletions
diff --git a/tests/test_json.c b/tests/test_json.c
index e87003f74..08837de06 100644
--- a/tests/test_json.c
+++ b/tests/test_json.c
@@ -41,6 +41,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/test.h"
+#define CATEGORY "/main/json/"
+
/*!
* Number of allocations from JSON library that have not yet been freed.
*/
@@ -68,33 +70,34 @@ static void json_debug_free(void *p)
ast_free(p);
}
-static void *json_test_init(struct ast_test *test)
+static int json_test_init(struct ast_test_info *info, struct ast_test *test)
{
ast_json_set_alloc_funcs(json_debug_malloc, json_debug_free);
alloc_count = 0;
- return test;
+ return 0;
}
-static void json_test_finish(void *test)
+static int json_test_cleanup(struct ast_test_info *info, struct ast_test *test)
{
- struct ast_test *t = test;
ast_json_reset_alloc_funcs();
if (0 != alloc_count) {
- ast_test_status_update(t, "JSON test leaked %zd allocations!", alloc_count);
+ ast_test_status_update(test,
+ "JSON test leaked %zd allocations!\n", alloc_count);
+ return -1;
}
+ return 0;
}
/*!@}*/
AST_TEST_DEFINE(json_test_false)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "false";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing fundamental JSON false value.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -114,13 +117,12 @@ AST_TEST_DEFINE(json_test_false)
AST_TEST_DEFINE(json_test_true)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "true";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON true value.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -140,13 +142,12 @@ AST_TEST_DEFINE(json_test_true)
AST_TEST_DEFINE(json_test_bool0)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "bool0";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON boolean function (false).";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -168,13 +169,12 @@ AST_TEST_DEFINE(json_test_bool0)
AST_TEST_DEFINE(json_test_bool1)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "bool1";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON boolean function (true).";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -196,13 +196,12 @@ AST_TEST_DEFINE(json_test_bool1)
AST_TEST_DEFINE(json_test_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON null value.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -222,11 +221,10 @@ AST_TEST_DEFINE(json_test_null)
AST_TEST_DEFINE(json_test_null_val)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
switch (cmd) {
case TEST_INIT:
info->name = "null_val";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON handling of NULL.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -249,14 +247,13 @@ AST_TEST_DEFINE(json_test_null_val)
AST_TEST_DEFINE(json_test_string)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "string";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Basic string tests.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -290,13 +287,12 @@ AST_TEST_DEFINE(json_test_string)
AST_TEST_DEFINE(json_test_string_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "string_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "JSON string NULL tests.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -323,14 +319,13 @@ AST_TEST_DEFINE(json_test_string_null)
AST_TEST_DEFINE(json_test_stringf)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "stringf";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Basic string formatting tests.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -357,14 +352,13 @@ AST_TEST_DEFINE(json_test_stringf)
AST_TEST_DEFINE(json_test_int)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "int";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Basic JSON integer tests.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -399,13 +393,12 @@ AST_TEST_DEFINE(json_test_int)
AST_TEST_DEFINE(json_test_non_int)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "non_int";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing integer functions with non-integer types.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -438,13 +431,12 @@ AST_TEST_DEFINE(json_test_non_int)
AST_TEST_DEFINE(json_test_array_create)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "array_create";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing creating JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -463,14 +455,13 @@ AST_TEST_DEFINE(json_test_array_create)
AST_TEST_DEFINE(json_test_array_append)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "array_append";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing appending to JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -493,14 +484,13 @@ AST_TEST_DEFINE(json_test_array_append)
AST_TEST_DEFINE(json_test_array_inset)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "array_insert";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing inserting into JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -521,14 +511,13 @@ AST_TEST_DEFINE(json_test_array_inset)
AST_TEST_DEFINE(json_test_array_set)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "array_set";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing setting a value in JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -549,7 +538,6 @@ AST_TEST_DEFINE(json_test_array_set)
AST_TEST_DEFINE(json_test_array_remove)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
int uut_res;
@@ -557,7 +545,7 @@ AST_TEST_DEFINE(json_test_array_remove)
switch (cmd) {
case TEST_INIT:
info->name = "array_remove";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing removing a value from JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -577,14 +565,13 @@ AST_TEST_DEFINE(json_test_array_remove)
AST_TEST_DEFINE(json_test_array_clear)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "array_clear";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing clearing JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -603,7 +590,6 @@ AST_TEST_DEFINE(json_test_array_clear)
AST_TEST_DEFINE(json_test_array_extend)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, tail, NULL, ast_json_unref);
@@ -612,7 +598,7 @@ AST_TEST_DEFINE(json_test_array_extend)
switch (cmd) {
case TEST_INIT:
info->name = "array_extend";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing extending JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -650,13 +636,12 @@ AST_TEST_DEFINE(json_test_array_extend)
AST_TEST_DEFINE(json_test_array_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "array_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing NULL conditions for JSON arrays.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -682,13 +667,12 @@ AST_TEST_DEFINE(json_test_array_null)
AST_TEST_DEFINE(json_test_object_alloc)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "object_alloc";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing creating JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -707,7 +691,6 @@ AST_TEST_DEFINE(json_test_object_alloc)
AST_TEST_DEFINE(json_test_object_set)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
int uut_res;
@@ -715,7 +698,7 @@ AST_TEST_DEFINE(json_test_object_set)
switch (cmd) {
case TEST_INIT:
info->name = "object_set";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing setting values in JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -740,14 +723,13 @@ AST_TEST_DEFINE(json_test_object_set)
AST_TEST_DEFINE(json_test_object_set_overwrite)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "object_set_overwriting";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing changing values in JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -766,13 +748,12 @@ AST_TEST_DEFINE(json_test_object_set_overwrite)
AST_TEST_DEFINE(json_test_object_get)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "object_get";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing getting values from JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -791,7 +772,6 @@ AST_TEST_DEFINE(json_test_object_get)
AST_TEST_DEFINE(json_test_object_del)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
int uut_res;
@@ -799,7 +779,7 @@ AST_TEST_DEFINE(json_test_object_del)
switch (cmd) {
case TEST_INIT:
info->name = "object_del";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing deleting values from JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -821,14 +801,13 @@ AST_TEST_DEFINE(json_test_object_del)
AST_TEST_DEFINE(json_test_object_clear)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "object_clear";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing clearing values from JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -850,7 +829,6 @@ AST_TEST_DEFINE(json_test_object_clear)
AST_TEST_DEFINE(json_test_object_merge_all)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -859,7 +837,7 @@ AST_TEST_DEFINE(json_test_object_merge_all)
switch (cmd) {
case TEST_INIT:
info->name = "object_alloc";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing merging JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -896,7 +874,6 @@ AST_TEST_DEFINE(json_test_object_merge_all)
AST_TEST_DEFINE(json_test_object_merge_existing)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -905,7 +882,7 @@ AST_TEST_DEFINE(json_test_object_merge_existing)
switch (cmd) {
case TEST_INIT:
info->name = "object_alloc";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing merging JSON objects, updating only existing fields.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -940,7 +917,6 @@ AST_TEST_DEFINE(json_test_object_merge_existing)
AST_TEST_DEFINE(json_test_object_merge_missing)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -949,7 +925,7 @@ AST_TEST_DEFINE(json_test_object_merge_missing)
switch (cmd) {
case TEST_INIT:
info->name = "object_merge_missing";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing merging JSON objects, adding only missing fields.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -986,13 +962,12 @@ AST_TEST_DEFINE(json_test_object_merge_missing)
AST_TEST_DEFINE(json_test_object_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "object_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON object NULL behavior.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1022,7 +997,6 @@ AST_TEST_DEFINE(json_test_object_null)
AST_TEST_DEFINE(json_test_object_iter)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
struct ast_json_iter *iter;
int count;
int uut_res;
@@ -1031,7 +1005,7 @@ AST_TEST_DEFINE(json_test_object_iter)
switch (cmd) {
case TEST_INIT:
info->name = "object_iter";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing iterating through JSON objects.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1086,13 +1060,12 @@ AST_TEST_DEFINE(json_test_object_iter)
AST_TEST_DEFINE(json_test_object_iter_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "object_iter_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing JSON object iterator NULL testings.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1116,7 +1089,6 @@ AST_TEST_DEFINE(json_test_object_iter_null)
AST_TEST_DEFINE(json_test_dump_load_string)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
RAII_VAR(char *, str, NULL, json_debug_free);
@@ -1124,7 +1096,7 @@ AST_TEST_DEFINE(json_test_dump_load_string)
switch (cmd) {
case TEST_INIT:
info->name = "dump_load_string";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing dumping strings from JSON.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1146,7 +1118,6 @@ AST_TEST_DEFINE(json_test_dump_load_string)
AST_TEST_DEFINE(json_test_dump_load_str)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
RAII_VAR(struct ast_str *, astr, NULL, ast_free);
@@ -1155,7 +1126,7 @@ AST_TEST_DEFINE(json_test_dump_load_str)
switch (cmd) {
case TEST_INIT:
info->name = "dump_load_str";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing dumping ast_str from JSON.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1177,7 +1148,6 @@ AST_TEST_DEFINE(json_test_dump_load_str)
AST_TEST_DEFINE(json_test_dump_str_fail)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct ast_str *astr;
@@ -1186,7 +1156,7 @@ AST_TEST_DEFINE(json_test_dump_str_fail)
switch (cmd) {
case TEST_INIT:
info->name = "dump_str_fail";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing dumping to ast_str when it can't grow.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1205,14 +1175,13 @@ AST_TEST_DEFINE(json_test_dump_str_fail)
AST_TEST_DEFINE(json_test_load_buffer)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
const char *str;
switch (cmd) {
case TEST_INIT:
info->name = "load_buffer";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing loading JSON from buffer.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1241,7 +1210,6 @@ static int safe_fclose(FILE *f)
AST_TEST_DEFINE(json_test_dump_load_file)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
RAII_VAR(char *, filename, NULL, free);
@@ -1251,7 +1219,7 @@ AST_TEST_DEFINE(json_test_dump_load_file)
switch (cmd) {
case TEST_INIT:
info->name = "dump_load_file";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing dumping/loading JSON to/from file by FILE *.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1275,7 +1243,6 @@ AST_TEST_DEFINE(json_test_dump_load_file)
AST_TEST_DEFINE(json_test_dump_load_new_file)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
RAII_VAR(char *, filename, NULL, free);
@@ -1284,7 +1251,7 @@ AST_TEST_DEFINE(json_test_dump_load_new_file)
switch (cmd) {
case TEST_INIT:
info->name = "dump_load_new_file";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing dumping/load JSON to/from file by filename.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1305,7 +1272,6 @@ AST_TEST_DEFINE(json_test_dump_load_new_file)
AST_TEST_DEFINE(json_test_dump_load_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(char *, filename, NULL, free);
RAII_VAR(FILE *, file, NULL, safe_fclose);
@@ -1313,7 +1279,7 @@ AST_TEST_DEFINE(json_test_dump_load_null)
switch (cmd) {
case TEST_INIT:
info->name = "dump_load_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing NULL handling of dump/load functions.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1343,13 +1309,12 @@ AST_TEST_DEFINE(json_test_dump_load_null)
AST_TEST_DEFINE(json_test_parse_errors)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "parse_errors";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing various parse errors.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1372,14 +1337,13 @@ AST_TEST_DEFINE(json_test_parse_errors)
AST_TEST_DEFINE(json_test_pack)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "pack";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing json_pack function.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1403,13 +1367,12 @@ AST_TEST_DEFINE(json_test_pack)
AST_TEST_DEFINE(json_test_pack_ownership)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "pack_ownership";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing json_pack failure conditions.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1424,13 +1387,12 @@ AST_TEST_DEFINE(json_test_pack_ownership)
AST_TEST_DEFINE(json_test_pack_errors)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "object_alloc";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing json_pack failure conditions.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1448,14 +1410,13 @@ AST_TEST_DEFINE(json_test_pack_errors)
AST_TEST_DEFINE(json_test_copy)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "copy";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing copying JSON.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1475,14 +1436,13 @@ AST_TEST_DEFINE(json_test_copy)
AST_TEST_DEFINE(json_test_deep_copy)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "deep_copy";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing deep copying of JSON.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1505,11 +1465,10 @@ AST_TEST_DEFINE(json_test_deep_copy)
AST_TEST_DEFINE(json_test_copy_null)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
switch (cmd) {
case TEST_INIT:
info->name = "copy_null";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Testing NULL handling of copy functions.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1526,14 +1485,13 @@ AST_TEST_DEFINE(json_test_copy_null)
AST_TEST_DEFINE(json_test_circular_object)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "circular_object";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Object cannot be added to itself.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1553,14 +1511,13 @@ AST_TEST_DEFINE(json_test_circular_object)
AST_TEST_DEFINE(json_test_circular_array)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
int uut_res;
switch (cmd) {
case TEST_INIT:
info->name = "circular_array";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "Array cannot be added to itself.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1579,7 +1536,6 @@ AST_TEST_DEFINE(json_test_circular_array)
AST_TEST_DEFINE(json_test_clever_circle)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, inner_child, NULL, ast_json_unref);
RAII_VAR(char *, str, NULL, json_debug_free);
@@ -1588,7 +1544,7 @@ AST_TEST_DEFINE(json_test_clever_circle)
switch (cmd) {
case TEST_INIT:
info->name = "clever_circle";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "JSON with circular references cannot be encoded.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1613,14 +1569,13 @@ AST_TEST_DEFINE(json_test_clever_circle)
AST_TEST_DEFINE(json_test_name_number)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "name_number";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "JSON encoding of name/number pair.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1643,7 +1598,6 @@ AST_TEST_DEFINE(json_test_name_number)
AST_TEST_DEFINE(json_test_timeval)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct timeval tv = {};
@@ -1651,7 +1605,7 @@ AST_TEST_DEFINE(json_test_timeval)
switch (cmd) {
case TEST_INIT:
info->name = "timeval";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "JSON encoding of timevals.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1672,14 +1626,13 @@ AST_TEST_DEFINE(json_test_timeval)
AST_TEST_DEFINE(json_test_cep)
{
- RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
switch (cmd) {
case TEST_INIT:
info->name = "cep";
- info->category = "/main/json/";
+ info->category = CATEGORY;
info->summary = "JSON with circular references cannot be encoded.";
info->description = "Test JSON abstraction library.";
return AST_TEST_NOT_RUN;
@@ -1815,6 +1768,10 @@ static int load_module(void)
AST_TEST_REGISTER(json_test_name_number);
AST_TEST_REGISTER(json_test_timeval);
AST_TEST_REGISTER(json_test_cep);
+
+ ast_test_register_init(CATEGORY, json_test_init);
+ ast_test_register_cleanup(CATEGORY, json_test_cleanup);
+
return AST_MODULE_LOAD_SUCCESS;
}