[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pdf-devel] Missing List module functions.
From: |
gerel |
Subject: |
Re: [pdf-devel] Missing List module functions. |
Date: |
Sun, 13 Apr 2008 16:51:15 -0300 |
Here are patches
##
Index: ChangeLog
===================================================================
RCS file: /sources/pdf/libgnupdf/ChangeLog,v
retrieving revision 1.196
diff -u -r1.196 ChangeLog
--- ChangeLog 13 Apr 2008 18:54:39 -0000 1.196
+++ ChangeLog 13 Apr 2008 19:54:06 -0000
@@ -1,3 +1,17 @@
+2008-04-13 gerel <address@hidden>
+
+ * doc/gnupdf-tsd.texi: added missing List module tests.
+ * torture/unit/Makefile.am: Idem.
+ * torture/unit/base/list/tsuite-list.c: Idem.
+ * src/base/pdf-list.h: added sorted list functions.
+ * torture/unit/base/list/pdf-list-create.c: added comparision funcs.
+ * torture/unit/base/list/pdf-list-sorted-add.c: initial add
+ * torture/unit/base/list/pdf-list-sorted-remove.c: initial add
+ * torture/unit/base/list/pdf-list-sorted-indexof-from-to.c: initial add
+ * torture/unit/base/list/pdf-list-sorted-indexof.c: initial add
+ * torture/unit/base/list/pdf-list-sorted-search-from-to.c: initial add
+ * torture/unit/base/list/pdf-list-sorted-search.c: initial add
+
2008-04-13 Jose E. Marchesi <address@hidden>
* lib/gl_linkedhash_list.h: Imported from gnulib.
Index: doc/gnupdf-tsd.texi
===================================================================
RCS file: /sources/pdf/libgnupdf/doc/gnupdf-tsd.texi,v
retrieving revision 1.7
diff -u -r1.7 gnupdf-tsd.texi
--- doc/gnupdf-tsd.texi 8 Apr 2008 10:21:29 -0000 1.7
+++ doc/gnupdf-tsd.texi 13 Apr 2008 19:54:12 -0000
@@ -3150,6 +3150,12 @@
* pdf_list_search::
* pdf_list_set_at::
* pdf_list_size::
+* pdf_list_sorted_add::
+* pdf_list_sorted_remove::
+* pdf_list_sorted_indexof::
+* pdf_list_sorted_indexof_from_to::
+* pdf_list_sorted_search::
+* pdf_list_sorted_search_from_to::
@end menu
@node pdf_list_add_at
@@ -3672,6 +3678,216 @@
@end table
@end deffn
+
address@hidden pdf_list_sorted_add
address@hidden pdf_list_sorted_add
+
address@hidden Test pdf_list_sorted_add_001
+Try to add an element at the beginning of the list.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_add_002
+Try to add an element at the beginning of the list with NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
address@hidden pdf_list_sorted_remove
address@hidden pdf_list_sorted_remove
+
address@hidden Test pdf_list_sorted_remove_001
+Try to remove an existing element in a list.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_remove_002
+Try to remove an non-existent element.
address@hidden @strong
address@hidden Success condition
+Returns PDF_ENONODE
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_remove_003
+Try to remove an element with a NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
+
address@hidden pdf_list_sorted_indexof
address@hidden pdf_list_sorted_indexof
+
address@hidden Test pdf_list_sorted_indexof_001
+Try to get the index of an existent element.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_002
+Try to get the index of a non-existent element.
address@hidden @strong
address@hidden Success condition
+Returns PDF_ENONODE
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_003
+Try to get the index of an element given a NULL position pointer.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_004
+Try to get the index of an element given a NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
+
address@hidden pdf_list_sorted_indexof_from_to
address@hidden pdf_list_sorted_indexof_from_to
+
address@hidden Test pdf_list_sorted_indexof_from_to_001
+Try to get the index of a existent element from position '0'.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_from_to_002
+Try to get the index of a existent element from invalid position.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EINVRANGE
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_from_to_003
+Try to get the index of a existent element given a NULL position pointer.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_from_to_004
+Try to get the index of a non-existent element.
address@hidden @strong
address@hidden Success condition
+Returns PDF_ENONODE
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_indexof_from_to_005
+Try to get the index of a existent element given a NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
+
address@hidden pdf_list_sorted_search
address@hidden pdf_list_sorted_search
+
+
address@hidden Test pdf_list_sorted_search_001
+Try to search for an existing element in a list.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_002
+Try to search an existent element given a NULL node pointer.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_003
+Try to search for a non-existent element in a list.
address@hidden @strong
address@hidden Success condition
+Returns PDF_ENONODE
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_004
+Try to search an existent element given a NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
+
address@hidden pdf_list_sorted_search_from_to
address@hidden pdf_list_sorted_search_from_to
+
+
address@hidden Test pdf_list_sorted_search_from_to_001
+Try to search an existent element in the correct range.
address@hidden @strong
address@hidden Success condition
+Returns PDF_OK
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_from_to_002
+Try to seach an element in an invalid range.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EINVRANGE.
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_from_to_003
+Try to search a non-existent element in a list.
address@hidden @strong
address@hidden Success condition
+Returns PDF_ENONODE.
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_from_to_004
+Try search an element given a NULL node pointer.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
address@hidden Test pdf_list_sorted_search_from_to_005
+Try search an element given a NULL compar_fn.
address@hidden @strong
address@hidden Success condition
+Returns PDF_EBADDATA
address@hidden table
address@hidden deffn
+
+
@node Subsystem Testing
@chapter Subsystem Testing
Index: src/base/pdf-list.h
===================================================================
RCS file: /sources/pdf/libgnupdf/src/base/pdf-list.h,v
retrieving revision 1.6
diff -u -r1.6 pdf-list.h
--- src/base/pdf-list.h 25 Mar 2008 15:53:32 -0000 1.6
+++ src/base/pdf-list.h 13 Apr 2008 19:54:12 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "2008-03-25 12:33:59 gerel"
+/* -*- mode: C -*- Time-stamp: "2008-04-13 12:09:09 gerel"
*
* File: pdf-list.h
* Date: Sat Mar 1 02:14:35 2008
@@ -64,6 +64,8 @@
typedef bool (*pdf_list_element_equals_fn_t) (const void *elt1, const void
*elt2);
typedef pdf_size_t (*pdf_list_element_hashcode_fn_t) (const void *elt);
typedef void (*pdf_list_element_dispose_fn_t) (const void *elt);
+typedef int (*pdf_list_element_compar_fn_t) (const void *elt1, const void
*elt2);
+
/* END PUBLIC */
@@ -118,6 +120,37 @@
pdf_status_t pdf_list_remove_at (pdf_list_t list, pdf_size_t position);
pdf_status_t pdf_list_remove (pdf_list_t list, const void * element);
+/* Sorted list functions */
+
+pdf_status_t
+pdf_list_sorted_add (pdf_list_t list, pdf_list_element_compar_fn_t compar_fn,
+ const void* element, pdf_list_node_t * element_node);
+
+pdf_status_t
+pdf_list_sorted_remove (pdf_list_t list, pdf_list_element_compar_fn_t
compar_fn,
+ const void * element);
+
+pdf_status_t
+pdf_list_sorted_search (pdf_list_t list, pdf_list_element_compar_fn_t
compar_fn,
+ const void* element, pdf_list_node_t *node);
+
+pdf_status_t
+pdf_list_sorted_search_from_to (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ pdf_size_t start_index, pdf_size_t end_index,
+ const void* element, pdf_list_node_t *node);
+
+pdf_status_t
+pdf_list_sorted_indexof (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ const void* element, pdf_size_t *position);
+
+pdf_status_t
+pdf_list_sorted_indexof_from_to (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ pdf_size_t start_index, pdf_size_t end_index,
+ const void* element, pdf_size_t *position);
+
/* Element iterator functions */
pdf_status_t pdf_list_iterator (pdf_list_t list, pdf_list_iterator_t *itr);
@@ -717,6 +750,190 @@
return PDF_OK;
}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_add (pdf_list_t list, pdf_list_element_compar_fn_t compar_fn,
+ const void* element, pdf_list_node_t * element_node)
+{
+ pdf_list_node_t node;
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL)
+ {
+ node.gl_node = gl_sortedlist_add ((gl_list_t)list.gl_list, compar_fn,
+ element);
+ if (element_node != NULL)
+ {
+ *element_node = node;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+
+}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_remove (pdf_list_t list, pdf_list_element_compar_fn_t
compar_fn,
+ const void * element)
+{
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL)
+ {
+ if (!gl_sortedlist_remove ((gl_list_t)list.gl_list, compar_fn, element))
+ st = PDF_ENONODE;
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+
+}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_search (pdf_list_t list, pdf_list_element_compar_fn_t
compar_fn,
+ const void* element, pdf_list_node_t *node)
+{
+
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL && node != NULL && element != NULL)
+ {
+ node->gl_node = gl_sortedlist_search ((gl_list_t)list.gl_list,
+ compar_fn, element);
+ if (node->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_search_from_to (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ pdf_size_t start_index, pdf_size_t end_index,
+ const void* element, pdf_list_node_t *node)
+{
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL && node != NULL && element != NULL)
+ {
+ if (((start_index < pdf_list_size (list) && start_index > 0) ||
+ (start_index == 0)) &&
+ ((end_index <= pdf_list_size (list) && end_index > 0) ||
+ (end_index == 0)) &&
+ (start_index < end_index))
+ {
+ node->gl_node = gl_sortedlist_search_from_to((gl_list_t)list.gl_list,
+ compar_fn, start_index,
+ end_index, element);
+ if (node->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_indexof (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ const void* element, pdf_size_t *position)
+{
+
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL && position != NULL && element != NULL )
+ {
+ *position = (pdf_size_t) gl_sortedlist_indexof ((gl_list_t)list.gl_list,
+ compar_fn, element);
+ if (*position == -1)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+}
+
+EXTERN_INLINE pdf_status_t
+pdf_list_sorted_indexof_from_to (pdf_list_t list,
+ pdf_list_element_compar_fn_t compar_fn,
+ pdf_size_t start_index, pdf_size_t end_index,
+ const void* element, pdf_size_t *position)
+{
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (compar_fn != NULL && position != NULL && element != NULL)
+ {
+ if (((start_index > 0 && start_index < pdf_list_size (list)) ||
+ start_index == 0) &&
+ (end_index > 0 && end_index <= pdf_list_size (list)) &&
+ (start_index < end_index))
+ {
+ *position = (pdf_size_t)
+ gl_sortedlist_indexof_from_to ((gl_list_t)list.gl_list, compar_fn,
+ start_index, end_index,
+ element);
+ if (*position == -1)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+
+ return (st);
+}
+
+
+
#endif /* HAVE_INLINE */
#endif /* PDF_LIST_H */
Index: torture/unit/Makefile.am
===================================================================
RCS file: /sources/pdf/libgnupdf/torture/unit/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- torture/unit/Makefile.am 13 Apr 2008 18:51:55 -0000 1.6
+++ torture/unit/Makefile.am 13 Apr 2008 19:54:13 -0000
@@ -40,6 +40,7 @@
TEST_SUITE_LIST = base/list/pdf-list-add-first.c \
base/list/pdf-list-add-at.c \
base/list/pdf-list-add-last.c \
+ base/list/pdf-list-size.c \
base/list/pdf-list-create.c \
base/list/pdf-list-get-at.c \
base/list/pdf-list-indexof.c \
@@ -58,7 +59,12 @@
base/list/pdf-list-search-from.c \
base/list/pdf-list-search-from-to.c \
base/list/pdf-list-set-at.c \
- base/list/pdf-list-size.c
+ base/list/pdf-list-sorted-add.c \
+ base/list/pdf-list-sorted-remove.c \
+ base/list/pdf-list-sorted-search.c \
+ base/list/pdf-list-sorted-search-from-to.c \
+ base/list/pdf-list-sorted-indexof.c \
+ base/list/pdf-list-sorted-indexof-from-to.c
# Unit tests for the Encoded Text Module test suite
TEST_SUITE_TEXT = base/text/pdf-text-test-common.h \
Index: torture/unit/base/list/pdf-list-create.c
===================================================================
RCS file: /sources/pdf/libgnupdf/torture/unit/base/list/pdf-list-create.c,v
retrieving revision 1.1
diff -u -r1.1 pdf-list-create.c
--- torture/unit/base/list/pdf-list-create.c 17 Mar 2008 13:43:02 -0000
1.1
+++ torture/unit/base/list/pdf-list-create.c 13 Apr 2008 19:54:13 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "08/03/17 14:34:28 jemarch"
+/* -*- mode: C -*- Time-stamp: "2008-04-13 11:54:34 gerel"
*
* File: pdf-list-create.c
* Date: Wed Mar 12 12:43:00 2008
@@ -33,11 +33,11 @@
bool l_comp (const void * elemb, const void * elema)
{
- int *elem, *elem2;
- elem = (int*) elemb;
- elem2 = (int*) elema;
+ int *elem1, *elem2;
+ elem1 = (int*) elema;
+ elem2 = (int*) elemb;
- if (*elem == *elem2)
+ if (*elem1 == *elem2)
{
return 1;
}
@@ -49,6 +49,47 @@
}
+int l_comp_desc (const void *elema, const void * elemb)
+{
+ int *elem1, *elem2;
+ elem1 = (int*) elema;
+ elem2 = (int*) elemb;
+
+ if (*elem1 > *elem2)
+ {
+ return -1;
+ }
+ else if (*elem1 < *elem2)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+int l_comp_asc (const void *elema, const void * elemb)
+{
+ int *elem1, *elem2;
+ elem1 = (int*) elema;
+ elem2 = (int*) elemb;
+
+ if (*elem1 > *elem2)
+ {
+ return 1;
+ }
+ else if (*elem1 < *elem2)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
/*
* Test: pdf_list_create_001
* Description:
Index: torture/unit/base/list/tsuite-list.c
===================================================================
RCS file: /sources/pdf/libgnupdf/torture/unit/base/list/tsuite-list.c,v
retrieving revision 1.1
diff -u -r1.1 tsuite-list.c
--- torture/unit/base/list/tsuite-list.c 17 Mar 2008 13:43:04 -0000
1.1
+++ torture/unit/base/list/tsuite-list.c 13 Apr 2008 19:54:13 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "08/03/17 14:32:31 jemarch"
+/* -*- mode: C -*- Time-stamp: "2008-04-13 15:32:48 gerel"
*
* File: tsuite-list.c
* Date: Wed Mar 12 12:43:00 2008
@@ -47,6 +47,13 @@
extern TCase *test_pdf_list_iterator (void);
extern TCase *test_pdf_list_iterator_from_to (void);
extern TCase *test_pdf_list_iterator_next (void);
+extern TCase *test_pdf_list_sorted_add (void);
+extern TCase *test_pdf_list_sorted_remove (void);
+extern TCase *test_pdf_list_sorted_search_from_to (void);
+extern TCase *test_pdf_list_sorted_search (void);
+extern TCase *test_pdf_list_sorted_indexof (void);
+extern TCase *test_pdf_list_sorted_indexof_from_to (void);
+
Suite *
@@ -78,6 +85,13 @@
suite_add_tcase (s, test_pdf_list_iterator ());
suite_add_tcase (s, test_pdf_list_iterator_from_to ());
suite_add_tcase (s, test_pdf_list_iterator_next ());
+ suite_add_tcase (s, test_pdf_list_sorted_add ());
+ suite_add_tcase (s, test_pdf_list_sorted_remove ());
+ suite_add_tcase (s, test_pdf_list_sorted_search ());
+ suite_add_tcase (s, test_pdf_list_sorted_search_from_to ());
+ suite_add_tcase (s, test_pdf_list_sorted_indexof ());
+ suite_add_tcase (s, test_pdf_list_sorted_indexof_from_to ());
+
return s;
###
Now the tests,
##
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:27:15 gerel"
*
* File: pdf-list-sorted-add.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_add
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern bool l_comp (const void * elemb, const void * elema);
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_add_001
* Description:
* Try to add an element at the beginning of the list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_add_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 5123;
pdf_list_create (l_comp, NULL, 0, &list);
st = pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_add_002
* Description:
* Try to add an element at the beginning of the list with NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_add_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 5123;
pdf_list_create (l_comp, NULL, 0, &list);
st = pdf_list_sorted_add (list, NULL, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_add (void)
{
TCase *tc = tcase_create("pdf_list_sorted_add");
tcase_add_test(tc, pdf_list_sorted_add_001);
tcase_add_test(tc, pdf_list_sorted_add_002);
return tc;
}
/* End of pdf-list-sorted-add.c */
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:28:44 gerel"
*
* File: pdf-list-sorted-remove.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_remove
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern bool l_comp (const void * elemb, const void * elema);
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_remove_001
* Description:
* Try to remove an existing element in a list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_remove_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 1212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_remove (list, l_comp_asc, &elem);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_remove_002
* Description:
* Try to remove an non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_sorted_remove_002)
{
pdf_list_t list;
int elem,elem2;
pdf_status_t st;
elem = 1212;
elem2 = 3333;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_remove (list, l_comp_asc, &elem2);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_remove_003
* Description:
* Try to remove an element with a NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_remove_003)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 1212;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_remove (list, NULL, &elem);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_remove (void)
{
TCase *tc = tcase_create("pdf_list_sorted_remove");
tcase_add_test(tc, pdf_list_sorted_remove_001);
tcase_add_test(tc, pdf_list_sorted_remove_002);
tcase_add_test(tc, pdf_list_sorted_remove_003);
return tc;
}
/* End of pdf-list-sorted-remove.c */
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:44:54 gerel"
*
* File: pdf-list-sorted-search.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_search
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern bool l_comp (const void * elemb, const void * elema);
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_search_001
* Description:
* Try to search for an existing element in a list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_search_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search (list, l_comp_asc, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_002
* Description:
* Try to search an existent element given a NULL node pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_search_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search (list, l_comp_asc, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_003
* Description:
* Try to search for a non-existent element in a list.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_sorted_search_003)
{
pdf_list_t list;
int elem, elem2;
pdf_list_node_t node;
pdf_status_t st;
elem = 2232;
elem2 = 1223;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search (list, l_comp_asc, &elem2, &node);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_004
* Description:
* Try to search an existent element given a NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_search_004)
{
pdf_list_t list;
int elem;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search (list, NULL, &elem, &node);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_search (void)
{
TCase *tc = tcase_create("pdf_list_sorted_search");
tcase_add_test(tc, pdf_list_sorted_search_001);
tcase_add_test(tc, pdf_list_sorted_search_002);
tcase_add_test(tc, pdf_list_sorted_search_003);
tcase_add_test(tc, pdf_list_sorted_search_004);
return tc;
}
/* End of pdf-list-sorted-search.c */
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:29:11 gerel"
*
* File: pdf-list-sorted-search-from-to.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_search_from_to
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern bool l_comp (const void * elemb, const void * elema);
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_search_from_to_001
* Description:
* Try to search an existent element in the correct range.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_search_from_to_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search_from_to (list, l_comp_asc, 0, 1, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_from_to_002
* Description:
* Try to seach an element in an invalid range.
* Success condition:
* Returns PDF_EINVRANGE.
*/
START_TEST (pdf_list_sorted_search_from_to_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search_from_to (list, l_comp_asc, 0, 5, &elem, &node);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_from_to_003
* Description:
* Try to search a non-existent element in a list.
* Success condition:
* Returns PDF_ENONODE.
*/
START_TEST (pdf_list_sorted_search_from_to_003)
{
pdf_list_t list;
int elem, elem2;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
elem2 = 232323;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search_from_to (list, l_comp_asc, 0, 1, &elem2, &node);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_from_to_004
* Description:
* Try search an element given a NULL node pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_search_from_to_004)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search_from_to (list, l_comp_asc, 0, 1, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_search_from_to_005
* Description:
* Try search an element given a NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_search_from_to_005)
{
pdf_list_t list;
int elem;
pdf_status_t st;
pdf_list_node_t node;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_search_from_to (list, NULL, 0, 1, &elem, &node);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_search_from_to (void)
{
TCase *tc = tcase_create("pdf_list_sorted_search_from_to");
tcase_add_test(tc, pdf_list_sorted_search_from_to_001);
tcase_add_test(tc, pdf_list_sorted_search_from_to_002);
tcase_add_test(tc, pdf_list_sorted_search_from_to_003);
tcase_add_test(tc, pdf_list_sorted_search_from_to_004);
tcase_add_test(tc, pdf_list_sorted_search_from_to_005);
return tc;
}
/* End of pdf-list-sorted-search-from-to.c */
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:28:14 gerel"
*
* File: pdf-list-sorted-indexof.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_indexof
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_indexof_001
* Description:
* Try to get the index of an existent element.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_indexof_001)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof (list, l_comp_asc, &elem, &pos);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_002
* Description:
* Try to get the index of a non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_sorted_indexof_002)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_sorted_indexof (list, l_comp_asc, &elem, &pos);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_003
* Description:
* Try to get the index of an element given a NULL position pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_indexof_003)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_sorted_indexof (list, l_comp_asc, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_004
* Description:
* Try to get the index of an element given a NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_indexof_004)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_sorted_indexof (list, NULL, &elem, &pos);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_indexof (void)
{
TCase *tc = tcase_create("pdf_list_sorted_indexof");
tcase_add_test(tc, pdf_list_sorted_indexof_001);
tcase_add_test(tc, pdf_list_sorted_indexof_002);
tcase_add_test(tc, pdf_list_sorted_indexof_003);
tcase_add_test(tc, pdf_list_sorted_indexof_004);
return tc;
}
/* End of pdf-list-sorted-indexof.c */
/* -*- mode: C -*- Time-stamp: "2008-04-13 15:27:58 gerel"
*
* File: pdf-list-sorted-indexof-from-to.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_sorted_indexof_from_to
*
*/
/* Copyright (C) 2008 Free Software Foundation, Inc. */
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <pdf.h>
#include <check.h>
extern int l_comp_desc (const void *elema, const void * elemb);
extern int l_comp_asc (const void *elema, const void * elemb);
/*
* Test: pdf_list_sorted_indexof_from_to_001
* Description:
* Try to get the index of a existent element from position '0'.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_sorted_indexof_from_to_001)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, 0, 1, &elem, &pos);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_from_to_002
* Description:
* Try to get the index of a existent element from invalid position.
* Success condition:
* Returns PDF_EINVRANGE
*/
START_TEST (pdf_list_sorted_indexof_from_to_002)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, 0, 2, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, -2, 1, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, 1, -1, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_from_to_003
* Description:
* Try to get the index of a existent element given a NULL position pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_indexof_from_to_003)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, 0, 1, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_from_to_004
* Description:
* Try to get the index of a non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_sorted_indexof_from_to_004)
{
pdf_list_t list;
int elem, elem2;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
elem2 = 2222;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof_from_to (list, l_comp_asc, 0, 1, &elem2, &pos);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_sorted_indexof_from_to_005
* Description:
* Try to get the index of a existent element given a NULL compar_fn.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_sorted_indexof_from_to_005)
{
pdf_list_t list;
int elem;
pdf_size_t pos;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_sorted_add (list, l_comp_asc, &elem, NULL);
st = pdf_list_sorted_indexof_from_to (list, NULL, 0, 1, &elem, &pos);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_sorted_indexof_from_to (void)
{
TCase *tc = tcase_create("pdf_list_sorted_indexof_from_to");
tcase_add_test(tc, pdf_list_sorted_indexof_from_to_001);
tcase_add_test(tc, pdf_list_sorted_indexof_from_to_002);
tcase_add_test(tc, pdf_list_sorted_indexof_from_to_003);
tcase_add_test(tc, pdf_list_sorted_indexof_from_to_004);
tcase_add_test(tc, pdf_list_sorted_indexof_from_to_005);
return tc;
}
/* End of pdf-list-sorted-indexof-from-to.c */
Re: [pdf-devel] Missing List module functions., jemarch, 2008/04/13