From d4fa095a647a0a8d472f0fd66c8728cb920a0138 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Wed, 16 May 2012 16:34:42 +0000 Subject: Change ao2 global array to ao2 global object holder. Review: https://reviewboard.asterisk.org/r/1921/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366663 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- tests/test_astobj2.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'tests/test_astobj2.c') diff --git a/tests/test_astobj2.c b/tests/test_astobj2.c index 9dcff34ed..275c260af 100644 --- a/tests/test_astobj2.c +++ b/tests/test_astobj2.c @@ -567,7 +567,7 @@ cleanup: return res; } -static AO2_GLOBAL_OBJ_STATIC(astobj2_array, 2); +static AO2_GLOBAL_OBJ_STATIC(astobj2_holder); AST_TEST_DEFINE(astobj2_test_3) { @@ -582,15 +582,15 @@ AST_TEST_DEFINE(astobj2_test_3) case TEST_INIT: info->name = "astobj2_test3"; info->category = "/main/astobj2/"; - info->summary = "Test global ao2 array container"; + info->summary = "Test global ao2 holder"; info->description = - "This test is to see if the global ao2 array container works as intended."; + "This test is to see if the global ao2 holder works as intended."; return AST_TEST_NOT_RUN; case TEST_EXECUTE: break; } - /* Put an object in index 0 */ + /* Put an object in the holder */ obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor); if (!obj) { ast_test_status_update(test, "ao2_alloc failed.\n"); @@ -599,7 +599,7 @@ AST_TEST_DEFINE(astobj2_test_3) } obj->destructor_count = &destructor_count; obj->i = ++num_objects; - obj2 = ao2_t_global_obj_replace(astobj2_array, 0, obj, "Save object in index 0"); + obj2 = ao2_t_global_obj_replace(astobj2_holder, obj, "Save object in the holder"); if (obj2) { ast_test_status_update(test, "Returned object not expected.\n"); res = AST_TEST_FAIL; @@ -608,7 +608,7 @@ AST_TEST_DEFINE(astobj2_test_3) /* Save object for next check. */ obj3 = obj; - /* Replace an object in index 0 */ + /* Replace an object in the holder */ obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor); if (!obj) { ast_test_status_update(test, "ao2_alloc failed.\n"); @@ -617,7 +617,7 @@ AST_TEST_DEFINE(astobj2_test_3) } obj->destructor_count = &destructor_count; obj->i = ++num_objects; - obj2 = ao2_t_global_obj_replace(astobj2_array, 0, obj, "Replace object in index 0"); + obj2 = ao2_t_global_obj_replace(astobj2_holder, obj, "Replace object in the holder"); if (!obj2) { ast_test_status_update(test, "Expected an object.\n"); res = AST_TEST_FAIL; @@ -634,7 +634,7 @@ AST_TEST_DEFINE(astobj2_test_3) obj2 = NULL; ao2_ref(obj, -1); - /* Put an object in index 1 */ + /* Replace with unref of an object in the holder */ obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor); if (!obj) { ast_test_status_update(test, "ao2_alloc failed.\n"); @@ -643,25 +643,23 @@ AST_TEST_DEFINE(astobj2_test_3) } obj->destructor_count = &destructor_count; obj->i = ++num_objects; - obj2 = ao2_t_global_obj_replace(astobj2_array, 1, obj, "Save object in index 1"); - if (obj2) { - ao2_ref(obj2, -1); - ast_test_status_update(test, "Returned object not expected.\n"); + if (!ao2_t_global_obj_replace_unref(astobj2_holder, obj, "Replace w/ unref object in the holder")) { + ast_test_status_update(test, "Expected an object to be replaced.\n"); res = AST_TEST_FAIL; goto cleanup; } /* Save object for next check. */ obj3 = obj; - /* Get a reference to the object in index 1. */ - obj = ao2_t_global_obj_ref(astobj2_array, 1, "Get reference of index 1 object"); + /* Get reference to held object. */ + obj = ao2_t_global_obj_ref(astobj2_holder, "Get a held object reference"); if (!obj) { ast_test_status_update(test, "Expected an object.\n"); res = AST_TEST_FAIL; goto cleanup; } if (obj != obj3) { - ast_test_status_update(test, "Returned object not expected.\n"); + ast_test_status_update(test, "Referenced object not expected object.\n"); res = AST_TEST_FAIL; goto cleanup; } @@ -670,8 +668,8 @@ AST_TEST_DEFINE(astobj2_test_3) ao2_ref(obj, -1); obj = NULL; - /* Release all objects in the global array. */ - ao2_t_global_obj_release(astobj2_array, "Check release all objects"); + /* Release the object in the global holder. */ + ao2_t_global_obj_release(astobj2_holder, "Check release all objects"); destructor_count += num_objects; if (0 < destructor_count) { ast_test_status_update(test, @@ -695,7 +693,7 @@ cleanup: if (obj3) { ao2_t_ref(obj3, -1, "Test cleanup external object 3"); } - ao2_t_global_obj_release(astobj2_array, "Test cleanup array"); + ao2_t_global_obj_release(astobj2_holder, "Test cleanup holder"); return res; } -- cgit v1.2.3