| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2008, Steve Murphy | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Steve Murphy <murf@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief Doubly-Linked List Tests | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \author\verbatim Steve Murphy <murf@digium.com> \endverbatim | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  |  * This module will run some DLL tests at load time | 
					
						
							|  |  |  |  * \ingroup tests | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*** MODULEINFO
 | 
					
						
							| 
									
										
										
										
											2011-09-29 21:16:07 +00:00
										 |  |  | 	<depend>TEST_FRAMEWORK</depend> | 
					
						
							| 
									
										
										
										
											2011-08-16 20:15:23 +00:00
										 |  |  | 	<support_level>core</support_level> | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/app.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/dlinkedlists.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Tests for DLLists! We really should, and here is a nice place to do it in asterisk */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct test1 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char name[10]; | 
					
						
							|  |  |  | 	AST_DLLIST_ENTRY(test1) list; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct test_container | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	AST_DLLIST_HEAD(entries, test1) entries; | 
					
						
							|  |  |  |     int count; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void print_list(struct test_container *x, char *expect) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct test1 *t1; | 
					
						
							|  |  |  | 	char buff[1000]; | 
					
						
							|  |  |  | 	buff[0] = 0; | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE(&x->entries, t1, list) { | 
					
						
							|  |  |  | 		strcat(buff,t1->name); | 
					
						
							|  |  |  | 		if (t1 != AST_DLLIST_LAST(&x->entries)) | 
					
						
							|  |  |  | 			strcat(buff," <=> "); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Got: %s  [expect %s]\n", buff, expect); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void print_list_backwards(struct test_container *x, char *expect) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct test1 *t1; | 
					
						
							|  |  |  | 	char buff[1000]; | 
					
						
							|  |  |  | 	buff[0] = 0; | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_BACKWARDS(&x->entries, t1, list) { | 
					
						
							|  |  |  | 		strcat(buff,t1->name); | 
					
						
							|  |  |  | 		if (t1 != AST_DLLIST_FIRST(&x->entries)) | 
					
						
							|  |  |  | 			strcat(buff," <=> "); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Got: %s  [expect %s]\n", buff, expect); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct test_container *make_cont(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct test_container *t = ast_calloc(sizeof(struct test_container),1); | 
					
						
							|  |  |  | 	return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct test1 *make_test1(char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct test1 *t1 = ast_calloc(sizeof(struct test1),1); | 
					
						
							|  |  |  | 	strcpy(t1->name, name); | 
					
						
							|  |  |  | 	return t1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void destroy_test_container(struct test_container *x) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* remove all the test1's */ | 
					
						
							|  |  |  | 	struct test1 *t1; | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&x->entries, t1, list) { | 
					
						
							|  |  |  | 		AST_DLLIST_REMOVE_CURRENT(list); | 
					
						
							| 
									
										
										
										
											2014-09-26 14:41:38 +00:00
										 |  |  | 		ast_free(t1); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; | 
					
						
							| 
									
										
										
										
											2014-09-26 14:41:38 +00:00
										 |  |  | 	ast_free(x); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Macros to test:
 | 
					
						
							|  |  |  | AST_DLLIST_LOCK(head) | 
					
						
							|  |  |  | AST_RWDLLIST_WRLOCK(head) | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | AST_RWDLLIST_WRLOCK(head) | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | AST_RWDLLIST_RDLOCK(head) | 
					
						
							|  |  |  | AST_DLLIST_TRYLOCK(head) | 
					
						
							|  |  |  | AST_RWDLLIST_TRYWRLOCK(head) | 
					
						
							|  |  |  | AST_RWDLLIST_TRYRDLOCK(head) | 
					
						
							|  |  |  | AST_DLLIST_UNLOCK(head) | 
					
						
							|  |  |  | AST_RWDLLIST_UNLOCK(head) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_DLLIST_HEAD(name, type) | 
					
						
							|  |  |  | AST_RWDLLIST_HEAD(name, type) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_NOLOCK(name, type) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_STATIC(name, type) | 
					
						
							|  |  |  | AST_RWDLLIST_HEAD_STATIC(name, type) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_NOLOCK_STATIC(name, type) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_SET(head, entry) | 
					
						
							|  |  |  | AST_RWDLLIST_HEAD_SET(head, entry) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_SET_NOLOCK(head, entry) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_INIT(head) | 
					
						
							|  |  |  | AST_RWDLLIST_HEAD_INIT(head) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_INIT_NOLOCK(head) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_RWDLLIST_HEAD_DESTROY(head) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_DLLIST_ENTRY(type) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | --- the above not going to be dealt with here --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_DLLIST_INSERT_HEAD(head, elm, field) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE(head,var,field) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(head, var, field) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END | 
					
						
							|  |  |  | AST_DLLIST_FIRST(head) | 
					
						
							|  |  |  | AST_DLLIST_LAST(head) | 
					
						
							|  |  |  | AST_DLLIST_NEXT(elm, field) | 
					
						
							|  |  |  | AST_DLLIST_PREV(elm, field) | 
					
						
							|  |  |  | AST_DLLIST_EMPTY(head) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE_BACKWARDS(head,var,field) | 
					
						
							|  |  |  | AST_DLLIST_INSERT_AFTER(head, listelm, elm, field) | 
					
						
							|  |  |  | AST_DLLIST_INSERT_TAIL(head, elm, field) | 
					
						
							|  |  |  | AST_DLLIST_REMOVE_HEAD(head, field) | 
					
						
							|  |  |  | AST_DLLIST_REMOVE(head, elm, field) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE_SAFE_BEGIN(head, var, field) | 
					
						
							|  |  |  | AST_DLLIST_TRAVERSE_SAFE_END | 
					
						
							|  |  |  | AST_DLLIST_REMOVE_CURRENT(field) | 
					
						
							|  |  |  | AST_DLLIST_MOVE_CURRENT(newhead, field) | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | AST_DLLIST_INSERT_BEFORE_CURRENT(elm, field) | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_DLLIST_MOVE_CURRENT_BACKWARDS(newhead, field) | 
					
						
							|  |  |  | AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS(elm, field) | 
					
						
							|  |  |  | AST_DLLIST_HEAD_DESTROY(head) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_DLLIST_APPEND_DLLIST(head, list, field) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dll_tests(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct test_container *tc; | 
					
						
							|  |  |  | 	struct test1 *a; | 
					
						
							|  |  |  | 	struct test1 *b; | 
					
						
							|  |  |  | 	struct test1 *c; | 
					
						
							|  |  |  | 	struct test1 *d; | 
					
						
							|  |  |  | 	struct test1 *e; | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_INSERT_HEAD, AST_DLLIST_TRAVERSE, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	tc = make_cont(); | 
					
						
							|  |  |  | 	a = make_test1("A"); | 
					
						
							|  |  |  | 	b = make_test1("B"); | 
					
						
							|  |  |  | 	c = make_test1("C"); | 
					
						
							|  |  |  | 	d = make_test1("D"); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, d, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	print_list(tc, "A <=> B <=> C <=> D"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	destroy_test_container(tc); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	tc = make_cont(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_EMPTY(&tc->entries)) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_EMPTY....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_EMPTY....PROBLEM!!\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	a = make_test1("A"); | 
					
						
							|  |  |  | 	b = make_test1("B"); | 
					
						
							|  |  |  | 	c = make_test1("C"); | 
					
						
							|  |  |  | 	d = make_test1("D"); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_INSERT_TAIL\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_INSERT_TAIL(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_TAIL(&tc->entries, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_TAIL(&tc->entries, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_TAIL(&tc->entries, d, list); | 
					
						
							|  |  |  | 	print_list(tc, "A <=> B <=> C <=> D"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_FIRST(&tc->entries) == a) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_FIRST....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_FIRST....PROBLEM\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_LAST(&tc->entries) == d) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_LAST....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_LAST....PROBLEM\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_NEXT(a,list) == b) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_NEXT....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_NEXT....PROBLEM\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_PREV(d,list) == c) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_PREV....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_PREV....PROBLEM\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	destroy_test_container(tc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc = make_cont(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	a = make_test1("A"); | 
					
						
							|  |  |  | 	b = make_test1("B"); | 
					
						
							|  |  |  | 	c = make_test1("C"); | 
					
						
							|  |  |  | 	d = make_test1("D"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_INSERT_AFTER, AST_DLLIST_TRAVERSE_BACKWARDS\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, a, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, b, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, c, d, list); | 
					
						
							|  |  |  | 	print_list_backwards(tc, "D <=> C <=> B <=> A"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_REMOVE_HEAD(&tc->entries, list); | 
					
						
							|  |  |  | 	print_list_backwards(tc, "D <=> C <=> B"); | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_REMOVE_HEAD(&tc->entries, list); | 
					
						
							|  |  |  | 	print_list_backwards(tc, "D <=> C"); | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_REMOVE_HEAD(&tc->entries, list); | 
					
						
							|  |  |  | 	print_list_backwards(tc, "D"); | 
					
						
							|  |  |  | 	AST_DLLIST_REMOVE_HEAD(&tc->entries, list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (AST_DLLIST_EMPTY(&tc->entries)) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE_HEAD....PROBLEM!!\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, a, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, b, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, c, d, list); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_REMOVE\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_REMOVE(&tc->entries, c, list); | 
					
						
							|  |  |  | 	print_list(tc, "A <=> B <=> D"); | 
					
						
							|  |  |  | 	AST_DLLIST_REMOVE(&tc->entries, a, list); | 
					
						
							|  |  |  | 	print_list(tc, "B <=> D"); | 
					
						
							|  |  |  | 	AST_DLLIST_REMOVE(&tc->entries, d, list); | 
					
						
							|  |  |  | 	print_list(tc, "B"); | 
					
						
							|  |  |  | 	AST_DLLIST_REMOVE(&tc->entries, b, list); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	if (AST_DLLIST_EMPTY(&tc->entries)) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_REMOVE....OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE....PROBLEM!!\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, a, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, b, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, c, d, list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_SAFE_BEGIN(&tc->entries, e, list) { | 
					
						
							|  |  |  | 		AST_DLLIST_REMOVE_CURRENT(list); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_SAFE_END; | 
					
						
							|  |  |  | 	if (AST_DLLIST_EMPTY(&tc->entries)) | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_debug(1,"Test AST_DLLIST_REMOVE_CURRENT... OK\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 		ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE_CURRENT... PROBLEM\n"); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test AST_DLLIST_MOVE_CURRENT, AST_DLLIST_INSERT_BEFORE_CURRENT\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, a, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, b, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_SAFE_BEGIN(&tc->entries, e, list) { | 
					
						
							|  |  |  | 		if (e == a) { | 
					
						
							|  |  |  | 			AST_DLLIST_INSERT_BEFORE_CURRENT(d, list);  /* D A B C */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 		if (e == b) { | 
					
						
							|  |  |  | 			AST_DLLIST_MOVE_CURRENT(&tc->entries, list); /* D A C B */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_SAFE_END; | 
					
						
							|  |  |  | 	print_list(tc, "D <=> A <=> C <=> B"); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	destroy_test_container(tc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc = make_cont(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	a = make_test1("A"); | 
					
						
							|  |  |  | 	b = make_test1("B"); | 
					
						
							|  |  |  | 	c = make_test1("C"); | 
					
						
							|  |  |  | 	d = make_test1("D"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:07:07 -07:00
										 |  |  | 	ast_debug(1,"Test: AST_DLLIST_MOVE_CURRENT_BACKWARDS and AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS\n"); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	AST_DLLIST_INSERT_HEAD(&tc->entries, a, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, a, b, list); | 
					
						
							|  |  |  | 	AST_DLLIST_INSERT_AFTER(&tc->entries, b, c, list); | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&tc->entries, e, list) { | 
					
						
							|  |  |  | 		if (e == c && AST_DLLIST_FIRST(&tc->entries) != c) { | 
					
						
							|  |  |  | 			AST_DLLIST_MOVE_CURRENT_BACKWARDS(&tc->entries, list); /* C A B */ | 
					
						
							|  |  |  | 			print_list(tc, "C <=> A <=> B"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (e == b) { | 
					
						
							|  |  |  | 			AST_DLLIST_REMOVE_CURRENT(list);  /* C A */ | 
					
						
							| 
									
										
										
										
											2014-09-26 14:41:38 +00:00
										 |  |  | 			ast_free(b); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 			print_list(tc, "C <=> A"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (e == a) { | 
					
						
							|  |  |  | 			AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS(d, list); /* C A D */ | 
					
						
							|  |  |  | 			print_list(tc, "C <=> A <=> D"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	AST_DLLIST_TRAVERSE_SAFE_END; | 
					
						
							|  |  |  | 	print_list(tc, "C <=> A <=> D"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-23 20:10:30 +00:00
										 |  |  | 	destroy_test_container(tc); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:14:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int unload_module(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int load_module(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dll_tests(); | 
					
						
							|  |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Doubly-Linked Lists"); |