[asterisk-commits] rmudgett: branch 10 r342662 - in /branches/10: ./ include/asterisk/ tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Oct 28 23:26:32 CDT 2011
Author: rmudgett
Date: Fri Oct 28 23:26:28 2011
New Revision: 342662
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342662
Log:
Fix AST_LIST_INSERT_BEFORE_CURRENT() updating the wrong variable.
AST_LIST_INSERT_BEFORE_CURRENT() could not be used twice in an iteration
or before AST_LIST_REMOVE_CURRENT() without corrupting the list.
AST_LIST_INSERT_BEFORE_CURRENT() could also corrupt the list if
AST_LIST_INSERT_BEFORE_CURRENT() or AST_LIST_REMOVE_CURRENT() is used on
the next iteration.
* Fixed cut and paste error using the wrong variable in
AST_LIST_INSERT_BEFORE_CURRENT().
* Added linked list unit tests for AST_LIST_INSERT_BEFORE_CURRENT(),
AST_LIST_APPEND_LIST(), and AST_LIST_INSERT_LIST_AFTER().
........
Merged revisions 342661 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/10/ (props changed)
branches/10/include/asterisk/linkedlists.h
branches/10/tests/test_linkedlists.c
Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/10/include/asterisk/linkedlists.h
URL: http://svnview.digium.com/svn/asterisk/branches/10/include/asterisk/linkedlists.h?view=diff&rev=342662&r1=342661&r2=342662
==============================================================================
--- branches/10/include/asterisk/linkedlists.h (original)
+++ branches/10/include/asterisk/linkedlists.h Fri Oct 28 23:26:28 2011
@@ -589,7 +589,7 @@
(elm)->field.next = __list_head->first; \
__list_head->first = (elm); \
} \
- __new_prev = (elm); \
+ __list_prev = (elm); \
} while (0)
#define AST_RWLIST_INSERT_BEFORE_CURRENT AST_LIST_INSERT_BEFORE_CURRENT
Modified: branches/10/tests/test_linkedlists.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/tests/test_linkedlists.c?view=diff&rev=342662&r1=342661&r2=342662
==============================================================================
--- branches/10/tests/test_linkedlists.c (original)
+++ branches/10/tests/test_linkedlists.c Fri Oct 28 23:26:28 2011
@@ -48,9 +48,9 @@
static struct test_val c = { "C" };
static struct test_val d = { "D" };
-AST_LIST_HEAD_NOLOCK(test_list, test_val);
-
-static int list_expect(struct test_list *test_list, char *expect, struct ast_str **buf)
+AST_LIST_HEAD_NOLOCK(test_llist, test_val);
+
+static int list_expect(struct test_llist *test_list, const char *expect, struct ast_str **buf)
{
struct test_val *i;
@@ -75,19 +75,20 @@
return AST_TEST_FAIL; \
}
-AST_TEST_DEFINE(ll_tests)
+AST_TEST_DEFINE(single_ll_tests)
{
struct ast_str *buf;
- struct test_list test_list = { 0, };
+ struct test_llist test_list = { 0, };
+ struct test_llist other_list = { 0, };
struct test_val *bogus;
switch (cmd) {
case TEST_INIT:
info->name = "ll_tests";
info->category = "/main/linkedlists";
- info->summary = "linked list unit test";
+ info->summary = "single linked list unit test";
info->description =
- "Test the linked list API";
+ "Test the single linked list API";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
@@ -111,28 +112,24 @@
MATCH_OR_FAIL(&test_list, "A", buf);
AST_LIST_INSERT_HEAD(&test_list, &b, list);
MATCH_OR_FAIL(&test_list, "BA", buf);
- AST_LIST_INSERT_HEAD(&test_list, &c, list);
- MATCH_OR_FAIL(&test_list, "CBA", buf);
- AST_LIST_INSERT_HEAD(&test_list, &d, list);
- MATCH_OR_FAIL(&test_list, "DCBA", buf);
- AST_LIST_REMOVE_HEAD(&test_list, list);
- MATCH_OR_FAIL(&test_list, "CBA", buf);
- AST_LIST_REMOVE_HEAD(&test_list, list);
- MATCH_OR_FAIL(&test_list, "BA", buf);
AST_LIST_REMOVE_HEAD(&test_list, list);
MATCH_OR_FAIL(&test_list, "A", buf);
AST_LIST_REMOVE_HEAD(&test_list, list);
MATCH_OR_FAIL(&test_list, "", buf);
-
if (AST_LIST_REMOVE_HEAD(&test_list, list)) {
ast_test_status_update(test, "Somehow removed an item from the head of a list that didn't exist\n");
return AST_TEST_FAIL;
}
+ MATCH_OR_FAIL(&test_list, "", buf);
+
+ /* ** */
if (!AST_LIST_EMPTY(&test_list)) {
ast_test_status_update(test, "List should be empty\n");
return AST_TEST_FAIL;
}
+
+ /* ** */
AST_LIST_INSERT_TAIL(&test_list, &a, list);
MATCH_OR_FAIL(&test_list, "A", buf);
@@ -142,19 +139,15 @@
MATCH_OR_FAIL(&test_list, "ABC", buf);
AST_LIST_INSERT_TAIL(&test_list, &d, list);
MATCH_OR_FAIL(&test_list, "ABCD", buf);
-
if (AST_LIST_REMOVE(&test_list, bogus, list)) {
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for missing element\n");
return AST_TEST_FAIL;
}
-
bogus = NULL;
-
if (AST_LIST_REMOVE(&test_list, bogus, list)) {
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for element set to NULL\n");
return AST_TEST_FAIL;
}
-
AST_LIST_REMOVE(&test_list, &b, list);
MATCH_OR_FAIL(&test_list, "ACD", buf);
AST_LIST_REMOVE(&test_list, &d, list);
@@ -163,35 +156,128 @@
MATCH_OR_FAIL(&test_list, "C", buf);
AST_LIST_REMOVE(&test_list, &c, list);
MATCH_OR_FAIL(&test_list, "", buf);
-
if (!AST_LIST_EMPTY(&test_list)) {
ast_test_status_update(test, "List should be empty\n");
return AST_TEST_FAIL;
}
-
if (AST_LIST_REMOVE(&test_list, bogus, list)) {
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL asked to remove a NULL pointer from an empty list\n");
return AST_TEST_FAIL;
}
+ /* ** */
+
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &c, list);
+ MATCH_OR_FAIL(&test_list, "AC", buf);
+ AST_LIST_INSERT_AFTER(&test_list, &a, &b, list);
+ MATCH_OR_FAIL(&test_list, "ABC", buf);
+ AST_LIST_INSERT_AFTER(&test_list, &c, &d, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+
+ ELEM_OR_FAIL(AST_LIST_FIRST(&test_list), &a);
+ ELEM_OR_FAIL(AST_LIST_LAST(&test_list), &d);
+ ELEM_OR_FAIL(AST_LIST_NEXT(&a, list), &b);
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* ** */
+
AST_LIST_INSERT_HEAD(&test_list, &a, list);
MATCH_OR_FAIL(&test_list, "A", buf);
AST_LIST_INSERT_TAIL(&test_list, &b, list);
MATCH_OR_FAIL(&test_list, "AB", buf);
- AST_LIST_INSERT_AFTER(&test_list, &a, &c, list);
- MATCH_OR_FAIL(&test_list, "ACB", buf);
- AST_LIST_INSERT_AFTER(&test_list, &b, &d, list);
- MATCH_OR_FAIL(&test_list, "ACBD", buf);
-
- ELEM_OR_FAIL(AST_LIST_FIRST(&test_list), &a);
- ELEM_OR_FAIL(AST_LIST_LAST(&test_list), &d);
- ELEM_OR_FAIL(AST_LIST_NEXT(&a, list), &c);
-
- AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
- AST_LIST_REMOVE_CURRENT(list);
- }
- AST_LIST_TRAVERSE_SAFE_END;
-
+ AST_LIST_INSERT_HEAD(&other_list, &c, list);
+ MATCH_OR_FAIL(&other_list, "C", buf);
+ AST_LIST_INSERT_TAIL(&other_list, &d, list);
+ MATCH_OR_FAIL(&other_list, "CD", buf);
+ AST_LIST_APPEND_LIST(&test_list, &other_list, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+ MATCH_OR_FAIL(&other_list, "", buf);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* ** */
+
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &d, list);
+ MATCH_OR_FAIL(&test_list, "AD", buf);
+ AST_LIST_INSERT_HEAD(&other_list, &b, list);
+ MATCH_OR_FAIL(&other_list, "B", buf);
+ AST_LIST_INSERT_TAIL(&other_list, &c, list);
+ MATCH_OR_FAIL(&other_list, "BC", buf);
+ AST_LIST_INSERT_LIST_AFTER(&test_list, &other_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+ MATCH_OR_FAIL(&other_list, "", buf);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* ** */
+
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "AB", buf);
+ AST_LIST_INSERT_HEAD(&other_list, &c, list);
+ MATCH_OR_FAIL(&other_list, "C", buf);
+ AST_LIST_INSERT_TAIL(&other_list, &d, list);
+ MATCH_OR_FAIL(&other_list, "CD", buf);
+ AST_LIST_INSERT_LIST_AFTER(&test_list, &other_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+ MATCH_OR_FAIL(&other_list, "", buf);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* ** */
+
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &d, list);
+ MATCH_OR_FAIL(&test_list, "AD", buf);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ if (bogus == &d) {
+ AST_LIST_INSERT_BEFORE_CURRENT(&b, list);
+ MATCH_OR_FAIL(&test_list, "ABD", buf);
+ AST_LIST_INSERT_BEFORE_CURRENT(&c, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+ AST_LIST_REMOVE_CURRENT(list);
+ MATCH_OR_FAIL(&test_list, "ABC", buf);
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ MATCH_OR_FAIL(&test_list, "ABC", buf);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
if (!AST_LIST_EMPTY(&test_list)) {
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
return AST_TEST_FAIL;
@@ -202,13 +288,13 @@
static int unload_module(void)
{
- AST_TEST_UNREGISTER(ll_tests);
+ AST_TEST_UNREGISTER(single_ll_tests);
return 0;
}
static int load_module(void)
{
- AST_TEST_REGISTER(ll_tests);
+ AST_TEST_REGISTER(single_ll_tests);
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list