[asterisk-commits] dlee: branch dlee/json-test-fix r394064 - /team/dlee/json-test-fix/tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 11 08:49:23 CDT 2013


Author: dlee
Date: Thu Jul 11 08:49:21 2013
New Revision: 394064

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394064
Log:
Use ast_test_register_{init,cleanup} for much good

Modified:
    team/dlee/json-test-fix/tests/test_json.c

Modified: team/dlee/json-test-fix/tests/test_json.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json-test-fix/tests/test_json.c?view=diff&rev=394064&r1=394063&r2=394064
==============================================================================
--- team/dlee/json-test-fix/tests/test_json.c (original)
+++ team/dlee/json-test-fix/tests/test_json.c Thu Jul 11 08:49:21 2013
@@ -41,6 +41,8 @@
 #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 @@
 	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;
-}
-
-static void json_test_finish(void *test)
-{
-	struct ast_test *t = test;
+	return 0;
+}
+
+static int json_test_cleanup(struct ast_test_info *info, struct ast_test *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_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_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_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_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_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_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;
@@ -285,18 +282,19 @@
 	ast_test_validate(test, 0 == uut_res);
 	ast_test_validate(test, 0 == strcmp("Goodbye, json", ast_json_string_get(uut)));
 
+	ast_json_ref(uut);
+
 	return AST_TEST_PASS;
 }
 
 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 +321,13 @@
 
 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 +354,13 @@
 
 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 +395,12 @@
 
 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 +433,12 @@
 
 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 +457,13 @@
 
 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 +486,13 @@
 
 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 +513,13 @@
 
 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 +540,6 @@
 
 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 +547,7 @@
 	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 +567,13 @@
 
 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 +592,6 @@
 
 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 +600,7 @@
 	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 +638,12 @@
 
 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 +669,12 @@
 
 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 +693,6 @@
 
 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 +700,7 @@
 	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 +725,13 @@
 
 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 +750,12 @@
 
 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 +774,6 @@
 
 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 +781,7 @@
 	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 +803,13 @@
 
 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 +831,6 @@
 
 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 +839,7 @@
 	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 +876,6 @@
 
 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 +884,7 @@
 	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 +919,6 @@
 
 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 +927,7 @@
 	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 +964,12 @@
 
 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 +999,6 @@
 
 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 +1007,7 @@
 	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 +1062,12 @@
 
 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 +1091,6 @@
 
 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 +1098,7 @@
 	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 +1120,6 @@
 
 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 +1128,7 @@
 	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 +1150,6 @@
 
 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 +1158,7 @@
 	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 +1177,13 @@
 
 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 +1212,6 @@
 
 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 +1221,7 @@
 	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 +1245,6 @@
 
 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 +1253,7 @@
 	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 +1274,6 @@
 
 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 +1281,7 @@
 	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 +1311,12 @@
 
 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 +1339,13 @@
 
 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 +1369,12 @@
 
 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 +1389,12 @@
 
 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 +1412,13 @@
 
 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 +1438,13 @@
 
 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 +1467,10 @@
 
 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 +1487,13 @@
 
 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 +1513,13 @@
 
 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 +1538,6 @@
 
 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 +1546,7 @@
 	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 +1571,13 @@
 
 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 +1600,6 @@
 
 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 +1607,7 @@
 	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 +1628,13 @@
 
 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 +1770,10 @@
 	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;
 }
 




More information about the asterisk-commits mailing list