Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions | Variables
test_dlinklists.c File Reference

Doubly-Linked List Tests. More...

#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"
Include dependency graph for test_dlinklists.c:

Go to the source code of this file.

Data Structures

struct  test_container::entries
 
struct  test1
 
struct  test_container
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void destroy_test_container (struct test_container *x)
 
static void dll_tests (void)
 
static int load_module (void)
 
static struct test_containermake_cont (void)
 
static struct test1make_test1 (char *name)
 
static void print_list (struct test_container *x, char *expect)
 
static void print_list_backwards (struct test_container *x, char *expect)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Test Doubly-Linked Lists" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Doubly-Linked List Tests.

Author
Steve Murphy <murf@digium.com> 

This module will run some DLL tests at load time

Definition in file test_dlinklists.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 364 of file test_dlinklists.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 364 of file test_dlinklists.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 364 of file test_dlinklists.c.

◆ destroy_test_container()

static void destroy_test_container ( struct test_container x)
static

Definition at line 101 of file test_dlinklists.c.

102{
103 /* remove all the test1's */
104 struct test1 *t1;
107 ast_free(t1);
108 }
110 ast_free(x);
111}
#define ast_free(a)
Definition: astmm.h:180
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: dlinkedlists.h:888
#define AST_DLLIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: dlinkedlists.h:753
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END
Closes a safe loop traversal block.
Definition: dlinkedlists.h:921
struct test1::@497 list
struct test_container::entries entries

References AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END, ast_free, test_container::entries, and test1::list.

Referenced by dll_tests().

◆ dll_tests()

static void dll_tests ( void  )
static

Definition at line 172 of file test_dlinklists.c.

173{
174 struct test_container *tc;
175 struct test1 *a;
176 struct test1 *b;
177 struct test1 *c;
178 struct test1 *d;
179 struct test1 *e;
180
181 ast_debug(1,"Test AST_DLLIST_INSERT_HEAD, AST_DLLIST_TRAVERSE, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END\n");
182 tc = make_cont();
183 a = make_test1("A");
184 b = make_test1("B");
185 c = make_test1("C");
186 d = make_test1("D");
191 print_list(tc, "A <=> B <=> C <=> D");
192
194
195 tc = make_cont();
196
197 if (AST_DLLIST_EMPTY(&tc->entries))
198 ast_debug(1,"Test AST_DLLIST_EMPTY....OK\n");
199 else
200 ast_log(LOG_ERROR,"Test AST_DLLIST_EMPTY....PROBLEM!!\n");
201
202
203 a = make_test1("A");
204 b = make_test1("B");
205 c = make_test1("C");
206 d = make_test1("D");
207
208 ast_debug(1,"Test AST_DLLIST_INSERT_TAIL\n");
213 print_list(tc, "A <=> B <=> C <=> D");
214
215 if (AST_DLLIST_FIRST(&tc->entries) == a)
216 ast_debug(1,"Test AST_DLLIST_FIRST....OK\n");
217 else
218 ast_log(LOG_ERROR,"Test AST_DLLIST_FIRST....PROBLEM\n");
219
220 if (AST_DLLIST_LAST(&tc->entries) == d)
221 ast_debug(1,"Test AST_DLLIST_LAST....OK\n");
222 else
223 ast_log(LOG_ERROR,"Test AST_DLLIST_LAST....PROBLEM\n");
224
225 if (AST_DLLIST_NEXT(a,list) == b)
226 ast_debug(1,"Test AST_DLLIST_NEXT....OK\n");
227 else
228 ast_log(LOG_ERROR,"Test AST_DLLIST_NEXT....PROBLEM\n");
229
230 if (AST_DLLIST_PREV(d,list) == c)
231 ast_debug(1,"Test AST_DLLIST_PREV....OK\n");
232 else
233 ast_log(LOG_ERROR,"Test AST_DLLIST_PREV....PROBLEM\n");
234
236
237 tc = make_cont();
238
239 a = make_test1("A");
240 b = make_test1("B");
241 c = make_test1("C");
242 d = make_test1("D");
243
244 ast_debug(1,"Test AST_DLLIST_INSERT_AFTER, AST_DLLIST_TRAVERSE_BACKWARDS\n");
249 print_list_backwards(tc, "D <=> C <=> B <=> A");
250
251 ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n");
253 print_list_backwards(tc, "D <=> C <=> B");
254 ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n");
256 print_list_backwards(tc, "D <=> C");
257 ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD\n");
259 print_list_backwards(tc, "D");
261
262 if (AST_DLLIST_EMPTY(&tc->entries))
263 ast_debug(1,"Test AST_DLLIST_REMOVE_HEAD....OK\n");
264 else
265 ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE_HEAD....PROBLEM!!\n");
266
271
272 ast_debug(1,"Test AST_DLLIST_REMOVE\n");
274 print_list(tc, "A <=> B <=> D");
276 print_list(tc, "B <=> D");
278 print_list(tc, "B");
280
281 if (AST_DLLIST_EMPTY(&tc->entries))
282 ast_debug(1,"Test AST_DLLIST_REMOVE....OK\n");
283 else
284 ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE....PROBLEM!!\n");
285
290
293 }
295 if (AST_DLLIST_EMPTY(&tc->entries))
296 ast_debug(1,"Test AST_DLLIST_REMOVE_CURRENT... OK\n");
297 else
298 ast_log(LOG_ERROR,"Test AST_DLLIST_REMOVE_CURRENT... PROBLEM\n");
299
300 ast_debug(1,"Test AST_DLLIST_MOVE_CURRENT, AST_DLLIST_INSERT_BEFORE_CURRENT\n");
305 if (e == a) {
307 }
308
309 if (e == b) {
310 AST_DLLIST_MOVE_CURRENT(&tc->entries, list); /* D A C B */
311 }
312
313 }
315 print_list(tc, "D <=> A <=> C <=> B");
316
318
319 tc = make_cont();
320
321 a = make_test1("A");
322 b = make_test1("B");
323 c = make_test1("C");
324 d = make_test1("D");
325
326 ast_debug(1,"Test: AST_DLLIST_MOVE_CURRENT_BACKWARDS and AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS\n");
331 if (e == c && AST_DLLIST_FIRST(&tc->entries) != c) {
333 print_list(tc, "C <=> A <=> B");
334 }
335
336 if (e == b) {
338 ast_free(b);
339 print_list(tc, "C <=> A");
340 }
341 if (e == a) {
343 print_list(tc, "C <=> A <=> D");
344 }
345
346 }
348 print_list(tc, "C <=> A <=> D");
349
351}
#define ast_log
Definition: astobj2.c:42
#define AST_DLLIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: dlinkedlists.h:469
#define AST_DLLIST_MOVE_CURRENT_BACKWARDS(newhead, field)
Move the current list entry to another list at the head.
Definition: dlinkedlists.h:801
#define AST_DLLIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: dlinkedlists.h:446
#define AST_DLLIST_INSERT_AFTER(head, listelm, elm, field)
Inserts a list entry after a given entry.
#define AST_DLLIST_MOVE_CURRENT(newhead, field)
Move the current list entry to another list at the tail.
Definition: dlinkedlists.h:782
#define AST_DLLIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_DLLIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_DLLIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: dlinkedlists.h:849
#define AST_DLLIST_PREV(elm, field)
Returns the previous entry in the list before the given entry.
Definition: dlinkedlists.h:457
#define AST_DLLIST_INSERT_BEFORE_CURRENT(elm, field)
Inserts a list node before the current node during a traversal.
Definition: dlinkedlists.h:696
#define AST_DLLIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_DLLIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_DLLIST_FIRST(head)
Returns the first entry contained in a list.
Definition: dlinkedlists.h:422
#define AST_DLLIST_LAST(head)
Returns the last entry contained in a list.
Definition: dlinkedlists.h:431
#define AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS(elm, field)
Inserts a list entry after the current entry during a backwards traversal. Since this is a backwards ...
Definition: dlinkedlists.h:904
#define AST_DLLIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: dlinkedlists.h:913
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
static struct test1 * make_test1(char *name)
static void print_list(struct test_container *x, char *expect)
static void print_list_backwards(struct test_container *x, char *expect)
static struct test_container * make_cont(void)
static void destroy_test_container(struct test_container *x)
static struct test_val b
static struct test_val a
static struct test_val d
static struct test_val c

References a, ast_debug, AST_DLLIST_EMPTY, AST_DLLIST_FIRST, AST_DLLIST_INSERT_AFTER, AST_DLLIST_INSERT_BEFORE_CURRENT, AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS, AST_DLLIST_INSERT_HEAD, AST_DLLIST_INSERT_TAIL, AST_DLLIST_LAST, AST_DLLIST_MOVE_CURRENT, AST_DLLIST_MOVE_CURRENT_BACKWARDS, AST_DLLIST_NEXT, AST_DLLIST_PREV, AST_DLLIST_REMOVE, AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_REMOVE_HEAD, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_SAFE_BEGIN, AST_DLLIST_TRAVERSE_SAFE_END, ast_free, ast_log, b, c, d, destroy_test_container(), test_container::entries, test1::list, LOG_ERROR, make_cont(), make_test1(), print_list(), and print_list_backwards().

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 358 of file test_dlinklists.c.

359{
360 dll_tests();
362}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
static void dll_tests(void)

References AST_MODULE_LOAD_SUCCESS, and dll_tests().

◆ make_cont()

static struct test_container * make_cont ( void  )
static

Definition at line 88 of file test_dlinklists.c.

89{
90 struct test_container *t = ast_calloc(sizeof(struct test_container),1);
91 return t;
92}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202

References ast_calloc.

Referenced by dll_tests().

◆ make_test1()

static struct test1 * make_test1 ( char *  name)
static

Definition at line 94 of file test_dlinklists.c.

95{
96 struct test1 *t1 = ast_calloc(sizeof(struct test1),1);
97 strcpy(t1->name, name);
98 return t1;
99}
static const char name[]
Definition: format_mp3.c:68
char name[10]

References ast_calloc, test1::name, and name.

Referenced by dll_tests().

◆ print_list()

static void print_list ( struct test_container x,
char *  expect 
)
static

Definition at line 60 of file test_dlinklists.c.

61{
62 struct test1 *t1;
63 char buff[1000];
64 buff[0] = 0;
66 strcat(buff,t1->name);
67 if (t1 != AST_DLLIST_LAST(&x->entries))
68 strcat(buff," <=> ");
69 }
70
71 ast_debug(1,"Got: %s [expect %s]\n", buff, expect);
72}
static unsigned char * buff
Definition: chan_unistim.c:259
#define AST_DLLIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: dlinkedlists.h:576

References ast_debug, AST_DLLIST_LAST, AST_DLLIST_TRAVERSE, buff, test_container::entries, test1::list, and test1::name.

Referenced by dll_tests().

◆ print_list_backwards()

static void print_list_backwards ( struct test_container x,
char *  expect 
)
static

Definition at line 74 of file test_dlinklists.c.

75{
76 struct test1 *t1;
77 char buff[1000];
78 buff[0] = 0;
80 strcat(buff,t1->name);
81 if (t1 != AST_DLLIST_FIRST(&x->entries))
82 strcat(buff," <=> ");
83 }
84
85 ast_debug(1,"Got: %s [expect %s]\n", buff, expect);
86}
#define AST_DLLIST_TRAVERSE_BACKWARDS(head, var, field)
Loops over (traverses) the entries in a list in reverse order, starting at the end.
Definition: dlinkedlists.h:618

References ast_debug, AST_DLLIST_FIRST, AST_DLLIST_TRAVERSE_BACKWARDS, buff, test_container::entries, test1::list, and test1::name.

Referenced by dll_tests().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 353 of file test_dlinklists.c.

354{
355 return 0;
356}

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Test Doubly-Linked Lists" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 364 of file test_dlinklists.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 364 of file test_dlinklists.c.