From 2aaad10bbdf03dade4f8e821f3dccdb80431eac8 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 5 Sep 2007 07:07:52 +0200 Subject: [PATCH] fixed typos and added some basic tests for the llist.h --- src/lib/llist.h | 39 +++++++++----------- tests/15list.tests | 55 ++++++++++++++++++++++++++++ tests/Makefile.am | 6 +++- tests/library/test-llist.c | 73 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 24 deletions(-) create mode 100644 tests/15list.tests create mode 100644 tests/library/test-llist.c diff --git a/src/lib/llist.h b/src/lib/llist.h index 49d531492..4480e507b 100644 --- a/src/lib/llist.h +++ b/src/lib/llist.h @@ -88,6 +88,12 @@ typedef llist * LList; typedef const llist * const_LList; typedef llist ** LList_ref; +/** + * Macro to instantiate a local llist. + * @param name of the llist node + */ +#define LLIST_AUTO(name) llist name = {&name,&name} + /** * cast back from a member of a structure to a pointer of the structure @@ -110,7 +116,7 @@ typedef llist ** LList_ref; */ #define LLIST_FOREACH(list, node) \ if (!list); else \ - for (LList node = llist_get_head (list); \ + for (LList node = llist_head (list); \ ! llist_is_end (node, list); \ llist_forward (&node)) @@ -121,7 +127,7 @@ typedef llist ** LList_ref; */ #define LLIST_FOREACH_REV(list, node) \ if (!list); else \ - for (LList node = llist_get_tail (list); \ + for (LList node = llist_tail (list); \ ! llist_is_end (node, list); \ llist_backward (&node)) @@ -133,9 +139,9 @@ typedef llist ** LList_ref; */ #define LLIST_WHILE_HEAD(list, head) \ if (!list); else \ - for (LList head = llist_get_head (list); \ + for (LList head = llist_head (list); \ !llist_is_empty (list); \ - head = llist_get_head (list)) + head = llist_head (list)) /** * Consume a list from tail. @@ -145,22 +151,9 @@ typedef llist ** LList_ref; */ #define LLIST_WHILE_TAIL(list, tail) \ if (!list); else \ - for (LList tail = llist_get_tail (list); \ + for (LList tail = llist_tail (list); \ !llist_is_empty (list); \ - tail = llist_get_tail (list)) - - -/** - * Macro to instantiate a local llist. - * @param name becomes a LList handle - * the underlying instance is hidden as name_llist_, this list is statically initialized - */ -#define LLIST_AUTO(name) \ -llist name##_llist_ = LLIST_STATIC_INITIALIZER(name##_llist_);\ -LList name = &name##_llist_ -#define LLIST_STATIC_INITIALIZER(name) {&name,&name} - - + tail = llist_tail (list)) /** * Initialize a new llist. @@ -474,10 +467,10 @@ LLIST_FUNC (void llist_backward (LList_ref self), LLIST_FUNC (LList llist_nth (LList self, int n), if (n>0) while (n--) - self = llist_get_next (self); + self = llist_next (self); else while (n++) - self = llist_get_prev (self); + self = llist_prev (self); return self; ); @@ -491,14 +484,14 @@ LLIST_FUNC (LList llist_get_nth_stop (LList self, int n, const_LList stop), if (n>0) while (n--) { - self = llist_get_next (self); + self = llist_next (self); if (self == stop) return NULL; } else while (n++) { - self = llist_get_prev (self); + self = llist_prev (self); if (self == stop) return NULL; } diff --git a/tests/15list.tests b/tests/15list.tests new file mode 100644 index 000000000..6d43064f7 --- /dev/null +++ b/tests/15list.tests @@ -0,0 +1,55 @@ +TESTING "Linked Lists" ./test-llist + +TEST "init nodes" basic < + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +//#include +//#include + +#include "lib/llist.h" +#include "lib/framerate.h" + + +CINELERRA_ERROR_DEFINE(TEST, "test error"); + +int +main (int argc, char** argv) +{ + NOBUG_INIT; + + if (argc == 1) + return 0; + + if (!strcmp(argv[1], "basic")) + { + LLIST_AUTO (node1); + + llist node2; + llist_init (&node2); + + printf ("%d\n", llist_is_empty (&node1)); + printf ("%d\n", llist_is_empty (&node2)); + } + else if (!strcmp(argv[1], "nodeinsert")) + { + LLIST_AUTO (list); + LLIST_AUTO (node1); + LLIST_AUTO (node2); + LLIST_AUTO (node3); + + llist_insert_next (&list, &node1); + printf ("%d\n", llist_is_empty (&list)); + printf ("%d\n", llist_is_empty (&node1)); + printf ("%d\n", llist_is_single (&node1)); + llist_insert_next (&node1, &node2); + printf ("%d\n", llist_is_single (&node1)); + llist_insert_prev (&node1, &node3); + printf ("%d\n", llist_next (&list) == &node3); + printf ("%d\n", llist_next (&node3) == &node1); + printf ("%d\n", llist_next (&node1) == &node2); + printf ("%d\n", llist_prev (&list) == &node2); + + } + else + return 1; + + return 0; +}