[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pdf-devel] List module unit tests
From: |
gerel |
Subject: |
[pdf-devel] List module unit tests |
Date: |
Fri, 14 Mar 2008 15:23:52 -0300 |
Well, finally I have some simple tests for the List module.
Notice that I needed to change the List module API too (and gnupdf.texi
accordingly).
Here are the corresponding patches and the unit tests (holy emacs):
##
Index: doc/gnupdf.texi
===================================================================
RCS file: /sources/pdf/libgnupdf/doc/gnupdf.texi,v
retrieving revision 1.32
diff -u -r1.32 gnupdf.texi
--- doc/gnupdf.texi 10 Mar 2008 17:50:19 -0000 1.32
+++ doc/gnupdf.texi 14 Mar 2008 18:28:26 -0000
@@ -959,7 +959,7 @@
@node Creating and Destroying Lists
@subsection Creating and Destroying Lists
address@hidden pdf_list_t pdf_list_create (pdf_list_element_equals_fn_t
@var{equals_fn}, pdf_list_element_dipose_fn_t @var{dispose_fn}, pdf_bool_t
@var{allow_duplicates})
address@hidden pdf_status_t pdf_list_create (pdf_list_element_equals_fn_t
@var{equals_fn}, pdf_list_element_dipose_fn_t @var{dispose_fn}, pdf_bool_t
@var{allow_duplicates}, pdf_list_t @var{*list})
Create a new list containing no elements.
@@ -976,14 +976,28 @@
This parameter indicate if the list is allowed to contain duplicate
elements (elements for which @var{equals_fn} evaluate to
@code{PDF_TRUE}).
address@hidden list
+A pointer to a list where the new one will be saved.
@end table
@item Returns
-The newly created list.
+A status variable:
address@hidden @code
address@hidden PDF_OK
address@hidden contains a new empty list.
address@hidden PDF_EBADDATA
address@hidden points to NULL.
address@hidden PDF_ERROR
+An unexpected error or no memory available.
address@hidden table
@item Usage example
@example
pdf_list_t mylist;
-mylist = pdf_list_create (list_element_equal_p, list_element_destroy,
PDF_FALSE);
+if (pdf_list_create (list_element_equal_p, list_element_destroy, PDF_FALSE,
+ &mylist) != PDF_OK)
+ @{
+ /* manage the error... */
+ @}
@end example
@end table
@end deftypefun
@@ -1045,7 +1059,7 @@
@node Searching for List Elements
@subsection Searching for List Elements
address@hidden pdf_list_node_t pdf_list_search (pdf_list_t @var{list}, const
void* @var{element})
address@hidden pdf_status_t pdf_list_search (pdf_list_t @var{list}, const void*
@var{element}, pdf_list_node_t @var{*node})
Search whether an element is already in the list.
@@ -1056,10 +1070,19 @@
A list.
@item element
The element to search for.
address@hidden node
+The searched node if it was found.
@end table
@item Returns
-The searched node if found, or @code{NULL} if not present in the
-list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid @var{node} pointer.
address@hidden table
@item Usage example
@example
XXX
@@ -1067,7 +1090,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_search_from (pdf_list_t @var{list},
pdf_size_t @var{start_index}, const void* @var{element})
address@hidden pdf_status_t pdf_list_search_from (pdf_list_t @var{list},
pdf_size_t @var{start_index}, const void* @var{element}, pdf_list_node_t
@var{*node})
Search whether an element is already in the list, at a position >=
@var{start_index}.
@@ -1078,9 +1101,21 @@
A list.
@item start_index
Index indicating the begin of the search.
address@hidden node
+The searched node if it was found.
@end table
@item Returns
-The searched node if found, or NULL if not present in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid @var{node} pointer.
address@hidden PDF_EINVRANGE
address@hidden is greater than the list size or less than 0.
address@hidden table
@item Usage example
@example
XXX
@@ -1088,7 +1123,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_search_from_to (pdf_list_t @var{list},
pdf_size_t @var{start_index}, pdf_size_t @var{end_index}, const void*
@var{element})
address@hidden pdf_status_t pdf_list_search_from_to (pdf_list_t @var{list},
pdf_size_t @var{start_index}, pdf_size_t @var{end_index}, const void*
@var{element}, pdf_list_node_t @var{*node})
Search whether an element is already in the list, at a position >=
@var{start_index} and < @var{end_index}.
@@ -1104,9 +1139,21 @@
Index to the last list position to be searched.
@item element
The element to search for.
address@hidden node
+The seached node if it was found.
@end table
@item Returns
-The node if found, or @code{NULL} if not present in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid @var{node} pointer.
address@hidden PDF_EINVRANGE
address@hidden or @var{end_index} is greater than the list size or less than 0.
address@hidden table
@item Usage example
@example
XXX
@@ -1114,7 +1161,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_next_node (pdf_list_t @var{list},
pdf_list_node_t @var{node})
address@hidden pdf_status_t pdf_list_next_node (pdf_list_t @var{list},
pdf_list_node_t @var{node}, pdf_list_node_t @var{*next})
Return the node immediately after the given node in the list.
@@ -1125,10 +1172,19 @@
A list.
@item node
A node contained in @var{list}.
address@hidden prev
+A pointer where the next node will be saved.
@end table
@item Returns
-The node immediately after the given node in the list, or @code{NULL}
-if the given node is the last (rightmost) one in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
+Next node not found.
address@hidden PDF_EBADDATA
+Invalid @var{next} pointer.
address@hidden table
@item Usage example
@example
XXX
@@ -1136,7 +1192,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_previous_node (pdf_list_t @var{list},
pdf_list_node_t @var{node})
address@hidden pdf_status_t pdf_list_previous_node (pdf_list_t @var{list},
pdf_list_node_t @var{node}, pdf_list_node_t @var{*prev})
Return the node immediately before the given node in the list.
@@ -1147,10 +1203,19 @@
A list.
@item node
A node contained in @var{list}.
address@hidden prev
+A pointer where the previous node will be saved.
address@hidden table
address@hidden Returns
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
+Previous node not found.
address@hidden PDF_EBADDATA
+Invalid @var{prev} pointer.
@end table
address@hidden Returns
-The node immediately before the given node in the list, or @code{NULL}
-if the given node is the first (leftmost) one in the list.
@item Usage example
@example
XXX
@@ -1158,7 +1223,7 @@
@end table
@end deftypefun
address@hidden pdf_size_t pdf_list_indexof (pdf_list_t @var{list}, const void*
@var{element})
address@hidden pdf_status_t pdf_list_indexof (pdf_list_t @var{list}, const
void* @var{element}, pdf_size_t @var{*position})
Search whether an element is already in the list.
@@ -1169,10 +1234,21 @@
A list.
@item element
A pointer to user data.
address@hidden position
+A pointer where the element position will be saved.
@end table
@item Returns
-The position of @var{element} if found, or @code{(pdf_size_t)(-1)} if
-not present in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid or NULL pointers.
address@hidden PDF_EINVRANGE
address@hidden or @var{end_index} is greater than the list size or less than 0.
address@hidden table
@item Usage Example
@example
XXX
@@ -1180,7 +1256,7 @@
@end table
@end deftypefun
address@hidden pdf_size_t pdf_list_indexof_from (pdf_list_t @var{list},
pdf_size_t @var{start_index}, const void* @var{element})
address@hidden pdf_status_t pdf_list_indexof_from (pdf_list_t @var{list},
pdf_size_t @var{start_index}, const void* @var{element}, pdf_size_t
@var{*position})
Search whether an element is already in the list, at a position >=
@var{start_index}.
@@ -1193,10 +1269,21 @@
An index to a position in @var{list}.
@item element
The element to search for.
address@hidden position
+A pointer where the element position will be saved.
@end table
@item Returns
-The position of the element containing @var{element} if found, or
address@hidden(size_t)(-1)} if not present in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid or NULL pointers.
address@hidden PDF_EINVRANGE
address@hidden or @var{end_index} is greater than the list size or less than 0.
address@hidden table
@item Usage example
@example
XXX
@@ -1204,7 +1291,7 @@
@end table
@end deftypefun
address@hidden pdf_size_t pdf_list_indexof_from_to (pdf_list_t @var{list},
pdf_size_t @var{start_index}, pdf_size_t @var{end_index}, const void*
@var{element})
address@hidden pdf_status_t pdf_list_indexof_from_to (pdf_list_t @var{list},
pdf_size_t @var{start_index}, pdf_size_t @var{end_index}, const void*
@var{element}, pdf_size_t @var{*position})
Search whether an element is already in the list, at a position >=
@var{start_index} and < @var{end_index}.
@@ -1219,10 +1306,21 @@
A position in @var{list}.
@item element
A pointer to some user data.
address@hidden position
+A pointer where the element position will be saved.
@end table
@item Returns
-The position of the node containin @var{element} if found, or
address@hidden(size_t)(-1)} if not present in the list.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_ENONODE
address@hidden not found.
address@hidden PDF_EBADDATA
+Invalid or NULL pointers.
address@hidden PDF_EINVRANGE
address@hidden or @var{end_index} is greater than the list size or less than 0.
address@hidden table
@item Usage example
@example
XXX
@@ -1254,7 +1352,7 @@
@end table
@end deftypefun
address@hidden {void *} pdf_list_get_at (pdf_list_t @var{list}, pdf_size_t
@var{position})
address@hidden pdf_status_t pdf_list_get_at (pdf_list_t @var{list}, pdf_size_t
@var{position}, const void @var{**value})
Get the element at a given position in the list.
@@ -1266,9 +1364,19 @@
@item position
A position in @var{list}.
Must be @code{>= 0} and @code{< pdf_list_size (list)}.
address@hidden value
+A pointer to which the element will be saved.
@end table
@item Returns
-The element
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_EINVRANGE
+Invalid @var{position}
address@hidden PDF_EBADDATA
+Invalid @var{value} pointer.
address@hidden table
@item Usage example
@example
XXX
@@ -1276,7 +1384,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_set_at (pdf_list_t @var{list},
pdf_size_t @var{position}, const void* @var{element})
address@hidden pdf_status_t pdf_list_set_at (pdf_list_t @var{list}, pdf_size_t
@var{position}, const void* @var{element}, pdf_list_node_t @var{*node})
Replace the element at a given position in a list.
@@ -1288,9 +1396,19 @@
@item position
A position in @var{list}.
Must be @code{>= 0} and @code{< pdf_list_size (list)}.
address@hidden element
+The new element.
address@hidden node
+A pointer to save the node containing the replaced element or NULL.
@end table
@item Returns
-The node containing the replaced element.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_EINVRANGE
+Invalid @var{position} range.
address@hidden table
@item Usage example
@example
XXX
@@ -1343,7 +1461,7 @@
@end table
@end deftypefun
address@hidden pdf_list_node_t pdf_list_add_at (pdf_list_t @var{list},
pdf_size_t @var{position}, const void* @var{element})
address@hidden pdf_status_t pdf_list_add_at (pdf_list_t @var{list}, pdf_size_t
@var{position}, const void* @var{element}, pdf_list_node_t @var{*node})
Add an element at a given position in the list.
@@ -1357,9 +1475,17 @@
Should be @code{>= 0} and @code{<= pdf_list_size (list)}.
@item element
A pointer to the user data to be stored as a list element.
address@hidden node
+A pointer to the node where the given element was stored or NULL.
@end table
@item Returns
-The node containing the given @var{element}.
+A pdf status value:
address@hidden @code
address@hidden PDF_OK
+The operation succeeded.
address@hidden PDF_EINVRANGE
+Invalid range of given @var{position}.
address@hidden table
@item Usage example
@example
XXX
@@ -1408,6 +1534,9 @@
A pdf status value:
@table @code
@item PDF_OK
+The operation succeeded.
address@hidden PDF_EINVRANGE
+Invalid @var{position} range.
@end table
@item Usage example
@example
@@ -1446,7 +1575,7 @@
@node Working with Iterators
@subsection Working with Iterators
address@hidden pdf_list_iterator_t pdf_list_iterator (pdf_list_t @var{list})
address@hidden pdf_status_t pdf_list_iterator (pdf_list_t @var{list},
pdf_list_iterator_t @var{*itr})
Create an iterator traversing a list.
@@ -1458,9 +1587,19 @@
@table @var
@item list
A list.
address@hidden itr
+A pointer to where the new iterator will be saved.
@end table
@item Returns
-An iterator pointing to the head of @var{list}.
+A status variable:
address@hidden @code
address@hidden PDF_OK
address@hidden contains a new iterator for @var{list}.
address@hidden PDF_ENOMEM
+There is no memory available for a new iterator.
address@hidden PDF_EBADDATA
address@hidden points to NULL.
address@hidden table
@item Usage example
@example
XXX
@@ -1468,7 +1607,7 @@
@end table
@end deftypefun
address@hidden pdf_list_iterator_t pdf_list_iterator_from_to (pdf_list_t
@var{list}, pdf_size_t @var{start_index}, pdf_size_t @var{end_index})
address@hidden pdf_status_t pdf_list_iterator_from_to (pdf_list_t @var{list},
pdf_size_t @var{start_index}, pdf_size_t @var{end_index}, pdf_list_iterator_t
@var{*itr})
Create an iterator traversing the element with indices @code{i},
@code{start_index <= i < end_index}, of a list.
@@ -1485,9 +1624,19 @@
A position in @var{list}.
@item end_index
A position in @var{list}.
address@hidden itr
+A pointer to an iterator where the new one will be saved.
@end table
@item Returns
-An iterator pointing to @var{start_index}.
+A status variable:
address@hidden @code
address@hidden PDF_OK
address@hidden contains a new iterator for @var{list} pointing to
@var{start_index}.
address@hidden PDF_ENOMEM
+There is no memory available for a new iterator.
address@hidden PDF_EBADDATA
address@hidden points to NULL.
address@hidden table
@item Usage example
@example
XXX
Index: src/base/pdf-list.c
===================================================================
RCS file: /sources/pdf/libgnupdf/src/base/pdf-list.c,v
retrieving revision 1.2
diff -u -r1.2 pdf-list.c
--- src/base/pdf-list.c 11 Mar 2008 19:16:49 -0000 1.2
+++ src/base/pdf-list.c 14 Mar 2008 18:28:26 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "2008-03-11 14:16:11 gerel"
+/* -*- mode: C -*- Time-stamp: "2008-03-14 14:59:15 gerel"
*
* File: pdf-list.c
* Date: Sat Mar 1 02:14:35 2008
@@ -29,18 +29,34 @@
/* Creation and destruction functions */
-inline pdf_list_t
+pdf_status_t
pdf_list_create (pdf_list_element_equals_fn_t equals_fn,
pdf_list_element_dispose_fn_t dispose_fn,
- pdf_bool_t allow_duplicates)
+ pdf_bool_t allow_duplicates, pdf_list_t * list)
{
- pdf_list_t list;
- list.gl_list = gl_list_create_empty(GL_ARRAY_LIST, equals_fn, NULL,
- dispose_fn, allow_duplicates);
- return (list);
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (list != NULL)
+ {
+ list->gl_list = gl_list_create_empty(GL_ARRAY_LIST, equals_fn, NULL,
+ dispose_fn, allow_duplicates);
+ if (list->gl_list == NULL)
+ {
+ st = PDF_ERROR;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_status_t
+
+pdf_status_t
pdf_list_destroy (pdf_list_t list)
{
gl_list_free ((gl_list_t) list.gl_list);
@@ -49,7 +65,7 @@
/* Property management functions */
-inline pdf_size_t
+pdf_size_t
pdf_list_size (pdf_list_t list)
{
return ((pdf_size_t) gl_list_size((gl_list_t) list.gl_list));
@@ -57,92 +73,252 @@
/* Element searching functions */
-inline pdf_list_node_t
-pdf_list_search (pdf_list_t list, const void* element)
+pdf_status_t
+pdf_list_search (pdf_list_t list, const void* element, pdf_list_node_t *node)
{
+ pdf_status_t st;
- pdf_list_node_t node;
-
- node.gl_node = gl_list_search ((gl_list_t)list.gl_list, element);
+ st = PDF_OK;
+ if (node != NULL && element != NULL)
+ {
+ node->gl_node = gl_list_search ((gl_list_t)list.gl_list, element);
+ if (node->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
- return (node);
+ return (st);
}
-inline pdf_list_node_t
+pdf_status_t
pdf_list_search_from (pdf_list_t list, pdf_size_t start_index,
- const void* element)
+ const void* element, pdf_list_node_t *node)
{
- pdf_list_node_t node;
+ pdf_status_t st;
+
+ st = PDF_OK;
- node.gl_node = gl_list_search_from((gl_list_t)list.gl_list, start_index,
- element);
+ if (node != NULL && element != NULL)
+ {
+ if ((start_index < pdf_list_size (list) && start_index > 0) ||
+ (start_index == 0))
+ {
+ node->gl_node = gl_list_search_from((gl_list_t)list.gl_list,
+ start_index, element);
+ if (node->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
- return (node);
+ return (st);
}
-inline pdf_list_node_t
+pdf_status_t
pdf_list_search_from_to (pdf_list_t list, pdf_size_t start_index,
- pdf_size_t end_index, const void* element)
+ pdf_size_t end_index, const void* element,
+ pdf_list_node_t *node)
{
- pdf_list_node_t node;
+ pdf_status_t st;
- node.gl_node = gl_list_search_from_to((gl_list_t)list.gl_list, start_index,
- end_index, element);
- return (node);
+ st = PDF_OK;
+
+ if (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_list_search_from_to((gl_list_t)list.gl_list,
+ start_index, end_index,
+ element);
+ if (node->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_list_node_t
-pdf_list_next_node (pdf_list_t list, pdf_list_node_t node)
+pdf_status_t
+pdf_list_next_node (pdf_list_t list, pdf_list_node_t node, pdf_list_node_t
*next)
{
- pdf_list_node_t next;
-
- next.gl_node = gl_list_next_node ((gl_list_t)list.gl_list,
- (gl_list_node_t)node.gl_node);
+ pdf_status_t st;
- return (next);
+ st = PDF_OK;
+
+ if (next != NULL)
+ {
+ next->gl_node = gl_list_next_node ((gl_list_t)list.gl_list,
+ (gl_list_node_t)node.gl_node);
+ if (next->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
+
}
-inline pdf_list_node_t
-pdf_list_previous_node (pdf_list_t list, pdf_list_node_t node)
+pdf_status_t
+pdf_list_previous_node (pdf_list_t list, pdf_list_node_t node,
pdf_list_node_t *prev)
{
- pdf_list_node_t prev;
-
- prev.gl_node = gl_list_previous_node ((gl_list_t)list.gl_list,
- (gl_list_node_t)node.gl_node);
- return (prev);
+
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (prev != NULL)
+ {
+ prev->gl_node = gl_list_previous_node ((gl_list_t)list.gl_list,
+ (gl_list_node_t)node.gl_node);
+ if (prev->gl_node == NULL)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_size_t
-pdf_list_indexof (pdf_list_t list, const void*element)
+pdf_status_t
+pdf_list_indexof (pdf_list_t list, const void*element, pdf_size_t *position)
{
- return ((pdf_size_t) gl_list_indexof ((gl_list_t)list.gl_list, element));
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (position != NULL && element != NULL)
+ {
+ *position = (pdf_size_t) gl_list_indexof ((gl_list_t)list.gl_list,
+ element);
+ if (*position == -1)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_size_t
+pdf_status_t
pdf_list_indexof_from (pdf_list_t list, pdf_size_t start_index,
- const void* element)
+ const void* element, pdf_size_t *position)
{
- return ((pdf_size_t) gl_list_indexof_from ((gl_list_t)list.gl_list,
- start_index, element));
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if ((position != NULL) && (element != NULL))
+ {
+ if ((start_index > 0 && start_index < pdf_list_size (list)) ||
+ start_index == 0)
+ {
+ *position = (pdf_size_t) gl_list_indexof_from
((gl_list_t)list.gl_list,
+ start_index, element);
+ if (*position == -1)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_size_t
+pdf_status_t
pdf_list_indexof_from_to (pdf_list_t list, pdf_size_t start_index,
- pdf_size_t end_index, const void* element)
+ pdf_size_t end_index, const void* element,
+ pdf_size_t * position)
{
- return ((pdf_size_t) gl_list_indexof_from_to ((gl_list_t)list.gl_list,
- start_index, end_index,
- element));
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if ((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_list_indexof_from_to ((gl_list_t)list.gl_list,
+ start_index, end_index,
+ element);
+ if (*position == -1)
+ {
+ st = PDF_ENONODE;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
/* Element setting and getting functions */
-inline const void *
+const void *
pdf_list_node_value (pdf_list_t list, pdf_list_node_t node)
{
return (gl_list_node_value ((gl_list_t)list.gl_list,
@@ -150,29 +326,68 @@
}
-inline const void *
-pdf_list_get_at (pdf_list_t list, pdf_size_t position)
+pdf_status_t
+pdf_list_get_at (pdf_list_t list, pdf_size_t position, const void ** value)
{
- return (gl_list_get_at ((gl_list_t)list.gl_list, position));
+ pdf_status_t st;
+
+ st = PDF_OK;
+
+ if (value != NULL)
+ {
+ if ((position > 0 && position < pdf_list_size (list)) ||
+ (position == 0))
+ {
+ *value = gl_list_get_at ((gl_list_t)list.gl_list, position);
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+ }
+ else
+ {
+ st = PDF_EBADDATA;
+ }
+
+ return (st);
}
-inline pdf_list_node_t
-pdf_list_set_at (pdf_list_t list, pdf_size_t position, const void* element)
+pdf_status_t
+pdf_list_set_at (pdf_list_t list, pdf_size_t position, const void* element,
+ pdf_list_node_t * node)
{
- pdf_list_node_t node;
+ pdf_status_t st;
- node.gl_node = gl_list_set_at ((gl_list_t)list.gl_list, position, element);
+ st = PDF_OK;
- return (node);
-
+ if ((position > 0 && position < pdf_list_size (list)) ||
+ (position == 0))
+ {
+ if (node != NULL)
+ {
+ node->gl_node = gl_list_set_at ((gl_list_t)list.gl_list, position,
+ element);
+ }
+ else
+ {
+ gl_list_set_at ((gl_list_t)list.gl_list, position, element);
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+
+ return (st);
}
/* Element addition and removal functions */
-inline pdf_list_node_t
+pdf_list_node_t
pdf_list_add_first (pdf_list_t list, const void* element)
{
pdf_list_node_t node;
@@ -183,7 +398,7 @@
}
-inline pdf_list_node_t
+pdf_list_node_t
pdf_list_add_last (pdf_list_t list, const void* element)
{
pdf_list_node_t node;
@@ -194,18 +409,39 @@
}
-inline pdf_list_node_t
-pdf_list_add_at (pdf_list_t list, pdf_size_t position, const void* element)
+pdf_status_t
+pdf_list_add_at (pdf_list_t list, pdf_size_t position, const void* element,
+ pdf_list_node_t * node)
{
- pdf_list_node_t node;
- node.gl_node = gl_list_add_at ((gl_list_t)list.gl_list, position, element);
+ pdf_status_t st;
+
+ st = PDF_OK;
- return (node);
+ if ((position > 0 && position < pdf_list_size (list)) ||
+ (position == 0))
+ {
+ if (node != NULL)
+
+ {
+ node->gl_node = gl_list_add_at ((gl_list_t)list.gl_list,
+ position, element);
+ }
+ else
+ {
+ gl_list_add_at ((gl_list_t)list.gl_list, position, element);
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
+
+ return st;
}
-inline pdf_status_t
+pdf_status_t
pdf_list_remove_node (pdf_list_t list, pdf_list_node_t node)
{
gl_list_remove_node ((gl_list_t)list.gl_list, (gl_list_node_t)node.gl_node);
@@ -213,23 +449,28 @@
}
-inline pdf_status_t
+pdf_status_t
pdf_list_remove_at (pdf_list_t list, pdf_size_t position)
{
pdf_status_t st;
st = PDF_OK;
- if (position >= 0 && position < pdf_list_size (list))
- gl_list_remove_at ((gl_list_t)list.gl_list, position);
+ if ((position > 0 && position < pdf_list_size (list)) ||
+ (position == 0))
+ {
+ gl_list_remove_at ((gl_list_t)list.gl_list, position);
+ }
else
- st = PDF_EINVRANGE;
+ {
+ st = PDF_EINVRANGE;
+ }
return st;
}
-inline pdf_status_t
+pdf_status_t
pdf_list_remove (pdf_list_t list, const void * element)
{
pdf_status_t st;
@@ -246,50 +487,80 @@
/* Element iterator functions */
-inline pdf_list_iterator_t
-pdf_list_iterator (pdf_list_t list)
+pdf_status_t
+pdf_list_iterator (pdf_list_t list, pdf_list_iterator_t * itr)
{
- pdf_list_iterator_t itr;
+ pdf_status_t st;
- itr.gl_iterator = pdf_alloc (sizeof(gl_list_iterator_t));
+ st = PDF_OK;
- if (itr.gl_iterator != NULL)
+ if (itr != NULL)
{
- *((gl_list_iterator_t*)itr.gl_iterator) =
- gl_list_iterator ((gl_list_t)list.gl_list);
+ itr->gl_iterator = pdf_alloc (sizeof(gl_list_iterator_t));
+
+ if (itr->gl_iterator != NULL)
+ {
+ *((gl_list_iterator_t*)itr->gl_iterator) =
+ gl_list_iterator ((gl_list_t)list.gl_list);
+ }
+ else
+ {
+ st = PDF_ENOMEM;
+ }
}
else
{
- pdf_perror (PDF_ENOMEM, "pdf_list_iterator()");
+ st = PDF_EBADDATA;
}
-
- return (itr);
+
+ return (st);
}
-inline pdf_list_iterator_t
+pdf_status_t
pdf_list_iterator_from_to (pdf_list_t list, pdf_size_t start_index,
- pdf_size_t end_index)
+ pdf_size_t end_index, pdf_list_iterator_t *itr)
{
- pdf_list_iterator_t itr;
+ pdf_status_t st;
- itr.gl_iterator = pdf_alloc (sizeof(gl_list_iterator_t));
+ st = PDF_OK;
- if (itr.gl_iterator != NULL)
+ if (itr != NULL)
{
- *((gl_list_iterator_t*)itr.gl_iterator) =
- gl_list_iterator_from_to ((gl_list_t)list.gl_list, start_index,
- end_index);
+ 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)
+ {
+
+ itr->gl_iterator = pdf_alloc (sizeof(gl_list_iterator_t));
+
+ if (itr->gl_iterator != NULL)
+ {
+ *((gl_list_iterator_t*)itr->gl_iterator) =
+ gl_list_iterator_from_to ((gl_list_t)list.gl_list, start_index,
+ end_index);
+ }
+ else
+ {
+ st = PDF_ENOMEM;
+ }
+ }
+ else
+ {
+ st = PDF_EINVRANGE;
+ }
}
else
{
- pdf_perror (PDF_ENOMEM, "pdf_list_iterator_from_to()");
+ st = PDF_EBADDATA;
}
- return (itr);
+ return (st);
}
-inline pdf_status_t
+pdf_status_t
pdf_list_iterator_next (pdf_list_iterator_t *iterator,
const void **element_pointer,
pdf_list_node_t *node_pointer)
@@ -306,7 +577,7 @@
return st;
}
-inline pdf_status_t
+pdf_status_t
pdf_list_iterator_free (pdf_list_iterator_t *iterator)
{
gl_list_iterator_free ((gl_list_iterator_t*)(iterator->gl_iterator));
Index: src/base/pdf-list.h
===================================================================
RCS file: /sources/pdf/libgnupdf/src/base/pdf-list.h,v
retrieving revision 1.2
diff -u -r1.2 pdf-list.h
--- src/base/pdf-list.h 11 Mar 2008 19:16:49 -0000 1.2
+++ src/base/pdf-list.h 14 Mar 2008 18:28:30 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "2008-03-11 15:21:56 gerel"
+/* -*- mode: C -*- Time-stamp: "2008-03-14 11:34:06 gerel"
*
* File: pdf-list.h
* Date: Sat Mar 1 02:14:35 2008
@@ -61,9 +61,9 @@
/* Creation and destruction functions */
-pdf_list_t pdf_list_create (pdf_list_element_equals_fn_t
+pdf_status_t pdf_list_create (pdf_list_element_equals_fn_t
equals_fn, pdf_list_element_dispose_fn_t
dispose_fn,
- pdf_bool_t allow_duplicates);
+ pdf_bool_t allow_duplicates, pdf_list_t *list);
pdf_status_t pdf_list_destroy (pdf_list_t list);
/* Property management functions */
@@ -72,44 +72,54 @@
/* Element searching functions */
-pdf_list_node_t pdf_list_search (pdf_list_t list, const void* element);
-pdf_list_node_t pdf_list_search_from (pdf_list_t list, pdf_size_t start_index,
- const void* element);
-pdf_list_node_t pdf_list_search_from_to (pdf_list_t list,
- pdf_size_t start_index,
- pdf_size_t end_index,
- const void* element);
-pdf_list_node_t pdf_list_next_node (pdf_list_t list, pdf_list_node_t node);
-pdf_list_node_t pdf_list_previous_node (pdf_list_t list, pdf_list_node_t node);
-pdf_size_t pdf_list_indexof (pdf_list_t list, const void*element);
-pdf_size_t pdf_list_indexof_from (pdf_list_t list, pdf_size_t start_index,
- const void* element);
-pdf_size_t pdf_list_indexof_from_to (pdf_list_t list, pdf_size_t start_index,
- pdf_size_t end_index, const void*
element);
+pdf_status_t pdf_list_search (pdf_list_t list, const void* element,
+ pdf_list_node_t * node);
+pdf_status_t pdf_list_search_from (pdf_list_t list, pdf_size_t start_index,
+ const void* element, pdf_list_node_t *node);
+pdf_status_t pdf_list_search_from_to (pdf_list_t list,
+ pdf_size_t start_index,
+ pdf_size_t end_index,
+ const void* element,
+ pdf_list_node_t * node);
+
+pdf_status_t pddf_list_previous_node (pdf_list_t list, pdf_list_node_t node,
+ pdf_list_node_t *prev);
+pdf_status_t pdf_list_next_node (pdf_list_t list, pdf_list_node_t node,
+ pdf_list_node_t *next);
+
+pdf_status_t pdf_list_indexof (pdf_list_t list, const void*element,
+ pdf_size_t *position);
+pdf_status_t pdf_list_indexof_from (pdf_list_t list, pdf_size_t start_index,
+ const void* element, pdf_size_t *position);
+pdf_status_t pdf_list_indexof_from_to (pdf_list_t list, pdf_size_t start_index,
+ pdf_size_t end_index, const
void*element,
+ pdf_size_t * position);
/* Element setting and getting functions */
const void * pdf_list_node_value (pdf_list_t list, pdf_list_node_t node);
-const void * pdf_list_get_at (pdf_list_t list, pdf_size_t position);
-pdf_list_node_t pdf_list_set_at (pdf_list_t list, pdf_size_t position,
- const void* element);
+pdf_status_t pdf_list_get_at (pdf_list_t list, pdf_size_t position,
+ const void ** value);
+pdf_status_t pdf_list_set_at (pdf_list_t list, pdf_size_t position,
+ const void* element, pdf_list_node_t * node);
/* Element addition and removal functions */
pdf_list_node_t pdf_list_add_first (pdf_list_t list, const void* element);
pdf_list_node_t pdf_list_add_last (pdf_list_t list, const void* element);
-pdf_list_node_t pdf_list_add_at (pdf_list_t list, pdf_size_t position,
- const void* element);
+pdf_status_t pdf_list_add_at (pdf_list_t list, pdf_size_t position,
+ const void* element, pdf_list_node_t * node);
pdf_status_t pdf_list_remove_node (pdf_list_t list, pdf_list_node_t node);
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);
/* Element iterator functions */
-pdf_list_iterator_t pdf_list_iterator (pdf_list_t list);
-pdf_list_iterator_t pdf_list_iterator_from_to (pdf_list_t list,
- pdf_size_t start_index,
- pdf_size_t end_index);
+pdf_status_t pdf_list_iterator (pdf_list_t list, pdf_list_iterator_t *itr);
+pdf_status_t pdf_list_iterator_from_to (pdf_list_t list,
+ pdf_size_t start_index,
+ pdf_size_t end_index,
+ pdf_list_iterator_t *itr);
pdf_status_t pdf_list_iterator_next (pdf_list_iterator_t *iterator,
const void **element_pointer,
pdf_list_node_t *node_pointer);
@@ -118,6 +128,7 @@
/* END PUBLIC */
+
#endif /* PDF_LIST_H */
/* End of pdf-list.h */
Index: src/base/pdf-stm.c
===================================================================
RCS file: /sources/pdf/libgnupdf/src/base/pdf-stm.c,v
retrieving revision 1.6
diff -u -r1.6 pdf-stm.c
--- src/base/pdf-stm.c 8 Mar 2008 23:49:31 -0000 1.6
+++ src/base/pdf-stm.c 14 Mar 2008 18:28:31 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "08/03/09 00:28:34 jemarch"
+/* -*- mode: C -*- Time-stamp: "2008-03-13 17:05:59 gerel"
*
* File: pdf-stm.c
* Date: Fri Jul 6 18:43:15 2007
@@ -658,14 +658,14 @@
pdf_stm_t stm;
stm = (pdf_stm_t) pdf_alloc (sizeof (struct pdf_stm_s));
- stm->read_filter_list =
- pdf_list_create (NULL, /* compare_fn */
- pdf_stm_filter_dealloc_list,
- PDF_TRUE); /* allow duplicates */
- stm->write_filter_list =
- pdf_list_create (NULL, /* compare_fn */
- pdf_stm_filter_dealloc_list,
- PDF_TRUE); /* allow duplicates */
+ pdf_list_create (NULL, /* compare_fn */
+ pdf_stm_filter_dealloc_list,
+ PDF_TRUE,
+ &stm->read_filter_list); /* allow duplicates */
+ pdf_list_create (NULL, /* compare_fn */
+ pdf_stm_filter_dealloc_list,
+ PDF_TRUE,
+ &stm->write_filter_list); /* allow duplicates */
return stm;
}
@@ -756,7 +756,7 @@
return PDF_TRUE;
}
- iter = pdf_list_iterator (filter_list);
+ pdf_list_iterator (filter_list, &iter);
while (pdf_list_iterator_next (&iter, (const void **) &filter, &node) ==
PDF_OK)
{
if (filter->funcs.apply (filter->data,
Index: torture/unit/Makefile.am
===================================================================
RCS file: /sources/pdf/libgnupdf/torture/unit/Makefile.am,v
retrieving revision 1.3
diff -u -r1.3 Makefile.am
--- torture/unit/Makefile.am 23 Feb 2008 22:20:53 -0000 1.3
+++ torture/unit/Makefile.am 14 Mar 2008 18:28:31 -0000
@@ -29,8 +29,35 @@
TESTS = runtests
-TEST_FILES = base/stm/pdf-create-file-stm.c
-TSUITE_FILES = base/alloc/tsuite-alloc.c base/stm/tsuite-stm.c
+TEST_FILES = base/stm/pdf-create-file-stm.c \
+ 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-create.c \
+ base/list/pdf-list-get-at.c \
+ base/list/pdf-list-indexof.c \
+ base/list/pdf-list-indexof-from.c \
+ base/list/pdf-list-indexof-from-to.c \
+ base/list/pdf-list-iterator.c \
+ base/list/pdf-list-iterator-from-to.c \
+ base/list/pdf-list-iterator-next.c \
+ base/list/pdf-list-next-node.c \
+ base/list/pdf-list-node-value.c \
+ base/list/pdf-list-previous-node.c \
+ base/list/pdf-list-remove-at.c \
+ base/list/pdf-list-remove.c \
+ base/list/pdf-list-remove-node.c \
+ base/list/pdf-list-search.c \
+ 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
+
+
+
+
+TSUITE_FILES = base/alloc/tsuite-alloc.c base/stm/tsuite-stm.c \
+ base/list/tsuite-list.c
runtests_SOURCES = runtests.c $(TSUITE_FILES) $(TEST_FILES)
Index: torture/unit/runtests.c
===================================================================
RCS file: /sources/pdf/libgnupdf/torture/unit/runtests.c,v
retrieving revision 1.3
diff -u -r1.3 runtests.c
--- torture/unit/runtests.c 23 Feb 2008 22:20:53 -0000 1.3
+++ torture/unit/runtests.c 14 Mar 2008 18:28:31 -0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "08/02/23 23:13:17 jemarch"
+/* -*- mode: C -*- Time-stamp: "2008-03-12 12:09:50 gerel"
*
* File: runtests.c
* Date: Sat Feb 23 21:40:43 2008
@@ -11,6 +11,7 @@
extern Suite *tsuite_alloc (void);
extern Suite *tsuite_stm (void);
+extern Suite *tsuite_list (void);
int
main (int argc, char **argv)
@@ -22,6 +23,7 @@
s = tsuite_alloc ();
sr = srunner_create (s);
+ srunner_add_suite (sr, tsuite_list ());
srunner_add_suite (sr, tsuite_stm ());
srunner_set_log (sr, "ut.log");
--- pdf-list-search.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 15:14:02 gerel"
*
* File: pdf-list-search.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_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 <stdio.h>
#include <pdf.h>
#include <check.h>
extern pdf_bool_t l_comp (const void * elemb, const void * elema);
/*
* Test: pdf_list_search_001
* Description:
* Try to search for an existing element in a list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search (list, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_002
* Description:
* Try to search an existent element given a NULL node pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_search_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_search (list, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_003
* Description:
* Try to search for a non-existent element in a list.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search (list, &elem2, &node);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_search (void)
{
TCase *tc = tcase_create("pdf_list_search");
tcase_add_test(tc, pdf_list_search_001);
tcase_add_test(tc, pdf_list_search_002);
tcase_add_test(tc, pdf_list_search_003);
return tc;
}
/* End of pdf-list-search.c */
--- EOF pdf-list-search.c ---
--- pdf-list-remove.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:40:13 gerel"
*
* File: pdf-list-remove.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_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 <stdio.h>
#include <pdf.h>
#include <check.h>
extern pdf_bool_t l_comp (const void * elemb, const void * elema);
/*
* Test: pdf_list_remove_001
* Description:
* Try to remove an existing element in a list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_remove_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 1212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_first (list, &elem);
st = pdf_list_remove (list, &elem);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_remove_002
* Description:
* Try to remove an non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_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_add_first (list, &elem);
st = pdf_list_remove (list, &elem2);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_remove (void)
{
TCase *tc = tcase_create("pdf_list_remove");
tcase_add_test(tc, pdf_list_remove_001);
tcase_add_test(tc, pdf_list_remove_002);
return tc;
}
/* End of pdf-list-remove.c */
--- EOF pdf-list-remove.c ---
--- pdf-list-iterator-from-to.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 15:00:28 gerel"
*
* File: pdf-list-iterator-from-to.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_iterator_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>
/*
* Test: pdf_list_iterator_from_to_001
* Description:
* Try to get an iterator in a given range.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_iterator_from_to_001)
{
pdf_list_t list;
int elem, elem2;
pdf_list_iterator_t itr;
pdf_status_t st;
elem = 123;
elem2 = 321;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
pdf_list_add_last (list, &elem2);
st = pdf_list_iterator_from_to (list, 0, 1, &itr);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_iterator_from_to_002
* Description:
* Try to get an iterator in an invalid range.
* Success condition:
* Returns PDF_EINVRANGE
*/
START_TEST (pdf_list_iterator_from_to_002)
{
pdf_list_t list;
int elem, elem2;
pdf_status_t st;
pdf_list_iterator_t itr;
elem = 123;
elem2 = 321;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
pdf_list_add_last (list, &elem2);
st = pdf_list_iterator_from_to (list, 0, 2, &itr);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_iterator_from_to (list, 0, -2, &itr);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_iterator_from_to (list, -1, 2, &itr);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_iterator_from_to (list, -1, -2, &itr);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_iterator_from_to_003
* Description:
* Try to get an iterator given a NULL iterator pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_iterator_from_to_003)
{
pdf_list_t list;
pdf_status_t st;
pdf_list_iterator_t itr;
int elem;
elem = 123;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_iterator_from_to (list, 0, 0, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_iterator_from_to (void)
{
TCase *tc = tcase_create("pdf_list_iterator_from_to");
tcase_add_test(tc, pdf_list_iterator_from_to_001);
tcase_add_test(tc, pdf_list_iterator_from_to_002);
tcase_add_test(tc, pdf_list_iterator_from_to_003);
return tc;
}
/* End of pdf-list-iterator-from-to.c */
--- EOF pdf-list-iterator-from-to.c ---
--- pdf-list-add-at.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:27:17 gerel"
*
* File: pdf-list-add-at.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_add_at
*
*/
/* 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>
/*
* Test: pdf_list_add_at_001
* Description:
* Try to add a new element at the 0 position.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_add_at_001)
{
pdf_list_t list;
int elem;
pdf_list_node_t node;
pdf_status_t st;
elem = 333;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_add_at (list, 0, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_add_at_002
* Description:
* Try to add a new element at an invalid position.
* Success condition:
* Returns PDF_EINVRANGE
*/
START_TEST (pdf_list_add_at_002)
{
pdf_list_t list;
int elem;
pdf_list_node_t node;
pdf_status_t st;
elem = 321;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_add_at (list, 1, &elem, &node);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_add_at (void)
{
TCase *tc = tcase_create("pdf_list_add_at");
tcase_add_test(tc, pdf_list_add_at_001);
tcase_add_test(tc, pdf_list_add_at_002);
return tc;
}
/* End of pdf-list-add-at.c */
--- EOF pdf-list-add-at.c ---
--- pdf-list-indexof-from-to.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 11:16:57 gerel"
*
* File: pdf-list-indexof-from-to.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_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>
/*
* Test: pdf_list_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_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_add_first (list, &elem);
st = pdf_list_indexof_from_to (list, 0, 1, &elem, &pos);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_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_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_add_first (list, &elem);
st = pdf_list_indexof_from_to (list, 0, 2, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_indexof_from_to (list, -2, 1, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_indexof_from_to (list, 1, -1, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_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_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_add_first (list, &elem);
st = pdf_list_indexof_from_to (list, 0, 1, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_indexof_from_to_004
* Description:
* Try to get the index of a non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_indexof_from_to (list, 0, 1, &elem2, &pos);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_indexof_from_to (void)
{
TCase *tc = tcase_create("pdf_list_indexof_from_to");
tcase_add_test(tc, pdf_list_indexof_from_to_001);
tcase_add_test(tc, pdf_list_indexof_from_to_002);
tcase_add_test(tc, pdf_list_indexof_from_to_003);
tcase_add_test(tc, pdf_list_indexof_from_to_004);
return tc;
}
/* End of pdf-list-indexof-from-to.c */
--- EOF pdf-list-indexof-from-to.c ---
--- pdf-list-remove-node.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 21:22:48 gerel"
*
* File: pdf-list-remove-node.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_remove_node
*
*/
/* 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>
/*
* Test: pdf_list_remove_node_001
* Description:
* Try to remove a given node from a list.
* Success condition:
* The size is the expected.
*/
START_TEST (pdf_list_remove_node_001)
{
pdf_list_t list;
pdf_list_node_t node;
int elem;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
pdf_list_remove_node (list, node);
fail_if (pdf_list_size (list) != 0);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_remove_node (void)
{
TCase *tc = tcase_create("pdf_list_remove_node");
tcase_add_test(tc, pdf_list_remove_node_001);
return tc;
}
/* End of pdf-list-remove-node.c */
--- EOF pdf-list-remove-node.c ---
--- pdf-list-add-last.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 20:04:16 gerel"
*
* File: pdf-list-add-last.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_add_last
*
*/
/* 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>
/*
* Test: pdf_list_add_last_001
* Description:
* Try to add some elements.
* Success condition:
* We get the right pdf_list_size().
*/
START_TEST (pdf_list_add_last_001)
{
pdf_list_t list;
int elem, elem2;
elem = 12345;
elem2 = 4567;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
fail_if (pdf_list_size(list) != 1);
pdf_list_add_last (list, &elem2);
fail_if (pdf_list_size(list) != 2);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_add_last (void)
{
TCase *tc = tcase_create("pdf_list_add_last");
tcase_add_test(tc, pdf_list_add_last_001);
return tc;
}
/* End of pdf-list-add-last.c */
--- EOF pdf-list-add-last.c ---
--- pdf-list-size.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 17:33:11 gerel"
*
* File: pdf-list-size.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_size
*
*/
/* 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>
/*
* Test: pdf_list_size_001
* Description:
* Try to get an empty list size.
* Success condition:
* should return '0'
*/
START_TEST (pdf_list_size_001)
{
pdf_list_t list;
pdf_size_t size;
pdf_list_create (NULL, NULL, 0, &list);
size = pdf_list_size (list);
fail_if (size != 0);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_size (void)
{
TCase *tc = tcase_create("pdf_list_size");
tcase_add_test(tc, pdf_list_size_001);
return tc;
}
/* End of pdf-list-size.c */
--- EOF pdf-list-size.c ---
--- pdf-list-search-from-to.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 00:09:22 gerel"
*
* File: pdf-list-search-from-to.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_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 <stdio.h>
#include <pdf.h>
#include <check.h>
extern pdf_bool_t l_comp (const void * elemb, const void * elema);
/*
* Test: pdf_list_search_from_to_001
* Description:
* Try to search an existent element in the correct range.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search_from_to (list, 0, 1, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_to_002
* Description:
* Try to seach an element in an invalid range.
* Success condition:
* Returns PDF_EINVRANGE.
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search_from_to (list, 0, 5, &elem, &node);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_to_003
* Description:
* Try to search a non-existent element in a list.
* Success condition:
* Returns PDF_ENONODE.
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search_from_to (list, 0, 1, &elem2, &node);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_to_004
* Description:
* Try search an element given a NULL node pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_search_from_to (list, 0, 1, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_search_from_to (void)
{
TCase *tc = tcase_create("pdf_list_search_from_to");
tcase_add_test(tc, pdf_list_search_from_to_001);
tcase_add_test(tc, pdf_list_search_from_to_002);
tcase_add_test(tc, pdf_list_search_from_to_003);
tcase_add_test(tc, pdf_list_search_from_to_004);
return tc;
}
/* End of pdf-list-search-from-to.c */
--- EOF pdf-list-search-from-to.c ---
--- pdf-list-remove-at.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:21:21 gerel"
*
* File: pdf-list-remove-at.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_remove_at
*
*/
/* 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>
/*
* Test: pdf_list_remove_at_001
* Description:
* Try to remove a node at some position
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_remove_at_001)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_remove_at (list, 0);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_remove_at_002
* Description:
* Try to remove a node at an invalid position
* Success condition:
* Returns PDF_EINVRANGE
*/
START_TEST (pdf_list_remove_at_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_remove_at (list, 3);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_remove_at (void)
{
TCase *tc = tcase_create("pdf_list_remove_at");
tcase_add_test(tc, pdf_list_remove_at_001);
tcase_add_test(tc, pdf_list_remove_at_002);
return tc;
}
/* End of pdf-list-remove-at.c */
--- EOF pdf-list-remove-at.c ---
--- pdf-list-iterator.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 14:39:58 gerel"
*
* File: pdf-list-iterator.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_iterator
*
*/
/* 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>
/*
* Test: pdf_list_iterator_001
* Description:
* Try to create an iterator from list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_iterator_001)
{
pdf_list_t list;
pdf_list_iterator_t itr;
pdf_status_t st;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_iterator (list, &itr);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_iterator_002
* Description:
* Try to create an iterator given a NULL iterator pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_iterator_002)
{
pdf_list_t list;
pdf_status_t st;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_iterator (list, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_iterator (void)
{
TCase *tc = tcase_create("pdf_list_iterator");
tcase_add_test(tc, pdf_list_iterator_001);
tcase_add_test(tc, pdf_list_iterator_002);
return tc;
}
/* End of pdf-list-iterator.c */
--- EOF pdf-list-iterator.c ---
--- pdf-list-create.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:23:12 gerel"
*
* File: pdf-list-create.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_create
*
*/
/* 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>
pdf_bool_t l_comp (const void * elemb, const void * elema)
{
int *elem, *elem2;
elem = (int*) elemb;
elem2 = (int*) elema;
if (*elem == *elem2)
{
return 1;
}
return 0;
}
void l_disp (const void * elema)
{
}
/*
* Test: pdf_list_create_001
* Description:
* Try to create an empty list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_create_001)
{
pdf_list_t list;
fail_if (pdf_list_create (l_comp, l_disp, 0, &list) != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_create_002
* Description:
* Try to create an empty list given a NULL list pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_create_002)
{
fail_if (pdf_list_create (l_comp, l_disp, 0, NULL) != PDF_EBADDATA);
}
END_TEST
/*
* Test: pdf_list_create_003
* Description:
* Try to create an empty list allowing duplicates.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_create_003)
{
pdf_list_t list;
fail_if (pdf_list_create (l_comp, l_disp, 1, &list) != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_create (void)
{
TCase *tc = tcase_create("pdf_list_create");
tcase_add_test(tc, pdf_list_create_001);
tcase_add_test(tc, pdf_list_create_002);
tcase_add_test(tc, pdf_list_create_003);
return tc;
}
/* End of pdf-list-create.c */
--- EOF pdf-list-create.c ---
--- pdf-list-search-from.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 00:06:07 gerel"
*
* File: pdf-list-search-from.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_search_from
*
*/
/* 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 pdf_bool_t l_comp (const void * elemb, const void * elema);
/*
* Test: pdf_list_search_from_001
* Description:
* Try to search an existent element in the correct range.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_search_from_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_add_last (list, &elem);
st = pdf_list_search_from (list, 0, &elem, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_002
* Description:
* Try to seach an element in an invalid range.
* Success condition:
* Returns PDF_EINVRANGE.
*/
START_TEST (pdf_list_search_from_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_add_last (list, &elem);
st = pdf_list_search_from (list, 5, &elem, &node);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_003
* Description:
* Try to search a non-existent element in a list.
* Success condition:
* Returns PDF_ENONODE.
*/
START_TEST (pdf_list_search_from_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_add_last (list, &elem);
st = pdf_list_search_from (list, 0, &elem2, &node);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_search_from_004
* Description:
* Try search an element given a NULL node pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_search_from_004)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2232;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_search_from (list, 0, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_search_from (void)
{
TCase *tc = tcase_create("pdf_list_search_from");
tcase_add_test(tc, pdf_list_search_from_001);
tcase_add_test(tc, pdf_list_search_from_002);
tcase_add_test(tc, pdf_list_search_from_003);
tcase_add_test(tc, pdf_list_search_from_004);
return tc;
}
/* End of pdf-list-search-from.c */
--- EOF pdf-list-search-from.c ---
--- pdf-list-node-value.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 20:15:43 gerel"
*
* File: pdf-list-node-value.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_node_value
*
*/
/* 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>
/*
* Test: pdf_list_node_value_001
* Description:
* Try to get a node value.
* Success condition:
* The returned value is the expected.
*/
START_TEST (pdf_list_node_value_001)
{
pdf_list_t list;
pdf_list_node_t node;
int elem;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
fail_if ( *((int*)pdf_list_node_value (list, node)) != 2212);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_node_value (void)
{
TCase *tc = tcase_create("pdf_list_node_value");
tcase_add_test(tc, pdf_list_node_value_001);
return tc;
}
/* End of pdf-list-node-value.c */
--- EOF pdf-list-node-value.c ---
--- pdf-list-iterator-next.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 14:46:16 gerel"
*
* File: pdf-list-iterator-next.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_iterator_next
*
*/
/* 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>
/*
* Test: pdf_list_iterator_next_001
* Description:
* Try to get the next element using an iterator.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_iterator_next_001)
{
pdf_list_t list;
pdf_list_iterator_t itr;
int elem, *next;
pdf_status_t st;
elem = 222;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
pdf_list_iterator (list, &itr);
st = pdf_list_iterator_next (&itr, &next, NULL);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_iterator_next_002
* Description:
* Try to get the next element using an iterator from an empty list.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_iterator_next_002)
{
pdf_list_t list;
pdf_list_iterator_t itr;
pdf_status_t st;
int *next;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_iterator (list, &itr);
st = pdf_list_iterator_next (&itr, &next, NULL);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_iterator_next (void)
{
TCase *tc = tcase_create("pdf_list_iterator_next");
tcase_add_test(tc, pdf_list_iterator_next_001);
tcase_add_test(tc, pdf_list_iterator_next_002);
return tc;
}
/* End of pdf-list-iterator-next.c */
--- EOF pdf-list-iterator-next.c ---
--- pdf-list-set-at.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:31:14 gerel"
*
* File: pdf-list-set-at.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_set_at
*
*/
/* 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>
/*
* Test: pdf_list_set_at_001
* Description:
* Try to replace a node value in a list.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_set_at_001)
{
pdf_list_t list;
int elem, elem2;
pdf_list_node_t node;
pdf_status_t st;
elem = 1123;
elem2 = 3323;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_set_at (list, 0, &elem2, &node);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_set_at_002
* Description:
* Try to replace a node value at an invalid position.
* Success condition:
* Returns PDF_INVRANGE
*/
START_TEST (pdf_list_set_at_002)
{
pdf_list_t list;
int elem, elem2;
pdf_list_node_t node;
pdf_status_t st;
elem = 1123;
elem2 = 3323;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_set_at (list, 6, &elem2, &node);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_set_at (void)
{
TCase *tc = tcase_create("pdf_list_set_at");
tcase_add_test(tc, pdf_list_set_at_001);
tcase_add_test(tc, pdf_list_set_at_002);
return tc;
}
/* End of pdf-list-set-at.c */
--- EOF pdf-list-set-at.c ---
--- pdf-list-previous-node.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 14:32:59 gerel"
*
* File: pdf-list-previous-node.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_previous_node
*
*/
/* 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>
/*
* Test: pdf_list_previous_node_001
* Description:
* Try to get the previous node given another node.
* Success condition:
* Returns PDF_OK.
*/
START_TEST (pdf_list_previous_node_001)
{
pdf_list_t list;
pdf_list_node_t node,prev;
int elem, elem2;
pdf_status_t st;
elem = 222;
elem2 = 333;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
node = pdf_list_add_last (list, &elem2);
st = pdf_list_previous_node (list, node, &prev);
fail_if (st != PDF_OK);
fail_if (*((int*) pdf_list_node_value (list, prev)) != 222);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_previous_node_002
* Description:
* Try to get the previous node given the first node.
* Success condition:
* Returns PDF_ENONODE.
*/
START_TEST (pdf_list_previous_node_002)
{
pdf_list_t list;
pdf_list_node_t node,prev;
int elem;
pdf_status_t st;
elem = 222;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
st = pdf_list_previous_node (list, node, &prev);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_previous_node_003
* Description:
* Try to get the previous node given a NULL prev pointer.
* Success condition:
* Returns PDF_EBADDATA.
*/
START_TEST (pdf_list_previous_node_003)
{
pdf_list_t list;
pdf_list_node_t node;
int elem;
pdf_status_t st;
elem = 222;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
st = pdf_list_previous_node (list, node, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_previous_node (void)
{
TCase *tc = tcase_create("pdf_list_previous_node");
tcase_add_test(tc, pdf_list_previous_node_001);
tcase_add_test(tc, pdf_list_previous_node_002);
tcase_add_test(tc, pdf_list_previous_node_003);
return tc;
}
/* End of pdf-list-previous-node.c */
--- EOF pdf-list-previous-node.c ---
--- tsuit-list.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 14:33:58 gerel"
*
* File: tsuit-list.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Testcase definition for the List module
*
*/
/* 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 <check.h>
extern TCase *test_pdf_list_create (void);
extern TCase *test_pdf_list_size (void);
extern TCase *test_pdf_list_add_first (void);
extern TCase *test_pdf_list_add_at (void);
extern TCase *test_pdf_list_add_last (void);
extern TCase *test_pdf_list_set_at (void);
extern TCase *test_pdf_list_get_at (void);
extern TCase *test_pdf_list_remove_at (void);
extern TCase *test_pdf_list_remove_node (void);
extern TCase *test_pdf_list_remove (void);
extern TCase *test_pdf_list_search (void);
extern TCase *test_pdf_list_search_from (void);
extern TCase *test_pdf_list_search_from_to (void);
extern TCase *test_pdf_list_indexof (void);
extern TCase *test_pdf_list_indexof_from (void);
extern TCase *test_pdf_list_indexof_from_to (void);
extern TCase *test_pdf_list_node_value (void);
extern TCase *test_pdf_list_previous_node (void);
extern TCase *test_pdf_list_next_node (void);
extern TCase *test_pdf_list_iterator (void);
extern TCase *test_pdf_list_iterator_from_to (void);
extern TCase *test_pdf_list_iterator_next (void);
Suite *
tsuite_list ()
{
Suite *s;
s = suite_create("list");
suite_add_tcase (s, test_pdf_list_create ());
suite_add_tcase (s, test_pdf_list_size ());
suite_add_tcase (s, test_pdf_list_add_first ());
suite_add_tcase (s, test_pdf_list_add_at ());
suite_add_tcase (s, test_pdf_list_add_last ());
suite_add_tcase (s, test_pdf_list_node_value ());
suite_add_tcase (s, test_pdf_list_set_at ());
suite_add_tcase (s, test_pdf_list_get_at ());
suite_add_tcase (s, test_pdf_list_remove_at ());
suite_add_tcase (s, test_pdf_list_remove_node ());
suite_add_tcase (s, test_pdf_list_remove ());
suite_add_tcase (s, test_pdf_list_search ());
suite_add_tcase (s, test_pdf_list_search_from ());
suite_add_tcase (s, test_pdf_list_search_from_to ());
suite_add_tcase (s, test_pdf_list_indexof ());
suite_add_tcase (s, test_pdf_list_indexof_from ());
suite_add_tcase (s, test_pdf_list_indexof_from_to ());
suite_add_tcase (s, test_pdf_list_previous_node ());
suite_add_tcase (s, test_pdf_list_next_node ());
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 ());
return s;
}
/* End of tsuit-list.c */
--- EOF tsuit-list.c ---
--- pdf-list-indexof.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 11:03:27 gerel"
*
* File: pdf-list-indexof.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_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>
/*
* Test: pdf_list_indexof_001
* Description:
* Try to get the index of an existent element.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_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_add_last (list, &elem);
st = pdf_list_indexof (list, &elem, &pos);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_indexof_002
* Description:
* Try to get the index of a non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_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_indexof (list, &elem, &pos);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_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_indexof_003)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
st = pdf_list_indexof (list, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_indexof (void)
{
TCase *tc = tcase_create("pdf_list_indexof");
tcase_add_test(tc, pdf_list_indexof_001);
tcase_add_test(tc, pdf_list_indexof_002);
tcase_add_test(tc, pdf_list_indexof_003);
return tc;
}
/* End of pdf-list-indexof.c */
--- EOF pdf-list-indexof.c ---
--- pdf-list-indexof-from.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 11:12:01 gerel"
*
* File: pdf-list-indexof-from.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_indexof_from
*
*/
/* 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>
/*
* Test: pdf_list_indexof_from_001
* Description:
* Try to get the index of a existent element from position '0'.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_indexof_from_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_add_first (list, &elem);
st = pdf_list_indexof_from (list, 0, &elem, &pos);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_indexof_from_002
* Description:
* Try to get the index of a existent element from invalid position.
* Success condition:
* Returns PDF_EINVRANGE
*/
START_TEST (pdf_list_indexof_from_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_add_first (list, &elem);
st = pdf_list_indexof_from (list, 2, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
st = pdf_list_indexof_from (list, -2, &elem, &pos);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_indexof_from_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_indexof_from_003)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2121;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_first (list, &elem);
st = pdf_list_indexof_from (list, 0, &elem, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_indexof_from_004
* Description:
* Try to get the index of a non-existent element.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_indexof_from_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_indexof_from (list, 0, &elem, &pos);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_indexof_from (void)
{
TCase *tc = tcase_create("pdf_list_indexof_from");
tcase_add_test(tc, pdf_list_indexof_from_001);
tcase_add_test(tc, pdf_list_indexof_from_002);
tcase_add_test(tc, pdf_list_indexof_from_003);
tcase_add_test(tc, pdf_list_indexof_from_004);
return tc;
}
/* End of pdf-list-indexof-from.c */
--- EOF pdf-list-indexof-from.c ---
--- pdf-list-get-at.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 22:20:58 gerel"
*
* File: pdf-list-get-at.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_get_at
*
*/
/* 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>
/*
* Test: pdf_list_get_at_001
* Description:
* Try to get a node value.
* Success condition:
* Returns PDF_OK
*/
START_TEST (pdf_list_get_at_001)
{
pdf_list_t list;
int elem, *val;
pdf_status_t st;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_get_at (list, 0, (void*)&val);
fail_if (st != PDF_OK);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_get_at_002
* Description:
* Try to get a node value given a NULL value pointer.
* Success condition:
* Returns PDF_EBADDATA
*/
START_TEST (pdf_list_get_at_002)
{
pdf_list_t list;
int elem;
pdf_status_t st;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_get_at (list, 0, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_get_at_003
* Description:
* Try to get a node value at an invalid position.
* Success condition:
* Returns EINVRANGE
*/
START_TEST (pdf_list_get_at_003)
{
pdf_list_t list;
int elem, *val;
pdf_status_t st;
elem = 2212;
pdf_list_create (NULL, NULL, 0, &list);
pdf_list_add_last (list, &elem);
st = pdf_list_get_at (list, 4, (void*)&val);
fail_if (st != PDF_EINVRANGE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_get_at (void)
{
TCase *tc = tcase_create("pdf_list_get_at");
tcase_add_test(tc, pdf_list_get_at_001);
tcase_add_test(tc, pdf_list_get_at_002);
tcase_add_test(tc, pdf_list_get_at_003);
return tc;
}
/* End of pdf-list-get-at.c */
--- EOF pdf-list-get-at.c ---
--- pdf-list-next-node.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-14 14:26:58 gerel"
*
* File: pdf-list-next-node.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_next_node
*
*/
/* 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>
/*
* Test: pdf_list_next_node_001
* Description:
* Try to get the next node given another node.
* Success condition:
* Returns PDF_OK.
*/
START_TEST (pdf_list_next_node_001)
{
pdf_list_t list;
pdf_list_node_t node,next;
int elem, elem2;
pdf_status_t st;
elem = 222;
elem2 = 333;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
pdf_list_add_last (list, &elem2);
st = pdf_list_next_node (list, node, &next);
fail_if (st != PDF_OK);
fail_if (*((int*) pdf_list_node_value (list, next)) != 333);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_next_node_002
* Description:
* Try to get the next node given the last node in the list.
* Success condition:
* Returns PDF_ENONODE
*/
START_TEST (pdf_list_next_node_002)
{
pdf_list_t list;
pdf_list_node_t node, next;
int elem;
pdf_status_t st;
elem = 222;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_first (list, &elem);
st = pdf_list_next_node (list, node, &next);
fail_if (st != PDF_ENONODE);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_next_node_003
* Description:
* Try to get the next node given a NULL next pointer.
* Success condition:
* Returns PDF_EBADDATA.
*/
START_TEST (pdf_list_next_node_003)
{
pdf_list_t list;
pdf_list_node_t node;
int elem;
pdf_status_t st;
elem = 222;
pdf_list_create (NULL, NULL, 0, &list);
node = pdf_list_add_last (list, &elem);
st = pdf_list_next_node (list, node, NULL);
fail_if (st != PDF_EBADDATA);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_next_node (void)
{
TCase *tc = tcase_create("pdf_list_next_node");
tcase_add_test(tc, pdf_list_next_node_001);
tcase_add_test(tc, pdf_list_next_node_002);
tcase_add_test(tc, pdf_list_next_node_003);
return tc;
}
/* End of pdf-list-next-node.c */
--- EOF pdf-list-next-node.c ---
--- pdf-list-add-first.c ---
/* -*- mode: C -*- Time-stamp: "2008-03-13 18:39:45 gerel"
*
* File: pdf-list-add-first.c
* Date: Wed Mar 12 12:43:00 2008
*
* GNU PDF Library - Unit tests for pdf_list_add_first
*
*/
/* 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 pdf_bool_t l_comp (const void * elemb, const void * elema);
/*
* Test: pdf_list_add_first_001
* Description:
* Try to add an element at the beginning of the list.
* Success condition:
* We get the right pdf_list_size().
*/
START_TEST (pdf_list_add_first_001)
{
pdf_list_t list;
int elem, elem2;
elem = 5123;
elem2 = 5431;
pdf_list_create (l_comp, NULL, 0, &list);
pdf_list_add_first (list, &elem);
pdf_list_add_first (list, &elem);
fail_if (pdf_list_size(list) != 1);
pdf_list_add_first (list, &elem2);
fail_if (pdf_list_size(list) != 2);
pdf_list_destroy (list);
}
END_TEST
/*
* Test: pdf_list_add_first_002
* Description:
* Try to add an element at the beginning of the list allowing duplicates.
* Success condition:
* We get the right pdf_list_size().
*/
START_TEST (pdf_list_add_first_002)
{
pdf_list_t list;
int elem;
elem = 5123;
pdf_list_create (l_comp, NULL, 1, &list);
pdf_list_add_first (list, &elem);
pdf_list_add_first (list, &elem);
fail_if (pdf_list_size(list) != 2);
pdf_list_destroy (list);
}
END_TEST
/*
* Test case creation function
*/
TCase *
test_pdf_list_add_first (void)
{
TCase *tc = tcase_create("pdf_list_add_first");
tcase_add_test(tc, pdf_list_add_first_001);
return tc;
}
/* End of pdf-list-add-first.c */
--- EOF pdf-list-add-first.c ---
###
BTW, gcc complains about the haders in pdf.h defined at src/Makefile.am.
I solved the problem by removing them :-P
##
make[1]: Entering directory `/home/gerel/PROJECTS/libgnupdf/utils'
gcc -DHAVE_CONFIG_H -I. -I../src -I../lib -I../src/ -I../src/base -I
../src/object -I/usr/include -g -O2 -MT pdf-filter.o -MD -MP -MF
.deps/pdf-filter.Tpo -c -o pdf-filter.o pdf-filter.c
In file included from pdf-filter.c:40:
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘n’
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘#’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘#’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:1: error: stray ‘\’ in program
../src/pdf.h:554: error: stray ‘\’ in program
../src/pdf.h:554: error: stray ‘#’ in program
../src/pdf.h:554: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
before ‘endif’
../src/pdf.h:554: error: stray ‘\’ in program
../src/pdf.h:554: error: stray ‘\’ in program
../src/pdf.h:554: error: stray ‘\’ in program
pdf-filter.c: In function ‘main’:
pdf-filter.c:178: error: ‘GNU_longOptions’ undeclared (first use in this
function)
pdf-filter.c:178: error: (Each undeclared identifier is reported only once
pdf-filter.c:178: error: for each function it appears in.)
make[1]: *** [pdf-filter.o] Error 1
make[1]: Leaving directory `/home/gerel/PROJECTS/libgnupdf/utils'
make: *** [all-recursive] Error 1
###
Can anyone fix it ? :-)
cheers
-gerel
- [pdf-devel] List module unit tests,
gerel <=