summaryrefslogtreecommitdiffstats
path: root/common/collection/collection_stack_ut.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-12-14 15:00:02 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-02-01 08:50:57 -0500
commit3c401be933498710042d9298870a9a5311f0c658 (patch)
tree68e26b68e3ed4c3cdba8b30f85a7f51161417813 /common/collection/collection_stack_ut.c
parent3994ec2219ab7c7d5afbea4dad189d6920f94bbc (diff)
downloadsssd-3c401be933498710042d9298870a9a5311f0c658.tar.gz
sssd-3c401be933498710042d9298870a9a5311f0c658.tar.xz
sssd-3c401be933498710042d9298870a9a5311f0c658.zip
COLLECTION: Fixing queue collection and unit tests.
This patch includes following functionality: 1) Fixed the invalid handling of the pointers in the collection when last element is removed from the collection. 2) Added unit test to verify the fix. 3) Modified the three unit test to be verbose on demand. 4) Switched the main of the unit test to use array of functions rather than big if statement.
Diffstat (limited to 'common/collection/collection_stack_ut.c')
-rw-r--r--common/collection/collection_stack_ut.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/common/collection/collection_stack_ut.c b/common/collection/collection_stack_ut.c
index ebf62fc6b..e0633b7b7 100644
--- a/common/collection/collection_stack_ut.c
+++ b/common/collection/collection_stack_ut.c
@@ -28,6 +28,16 @@
#include "collection_stack.h"
#include "collection_tools.h"
+typedef int (*test_fn)(void);
+
+int verbose = 0;
+
+#define COLOUT(foo) \
+ do { \
+ if (verbose) foo; \
+ } while(0)
+
+
int stack_test(void)
{
@@ -40,7 +50,7 @@ int stack_test(void)
TRACE_FLOW_STRING("stack_test", "Entry.");
- printf("\n\nSTACK TEST!!!.\n\n\n");
+ COLOUT(printf("\n\nSTACK TEST!!!.\n\n\n"));
if ((error = col_create_stack(&stack)) ||
(error = col_push_str_property(stack, "item1", "value 1", 0)) ||
@@ -56,9 +66,9 @@ int stack_test(void)
return error;
}
- col_debug_collection(stack, COL_TRAVERSE_DEFAULT);
+ COLOUT(col_debug_collection(stack, COL_TRAVERSE_DEFAULT));
- printf("Swapping last two items by popping and pushing them back.\n");
+ COLOUT(printf("Swapping last two items by popping and pushing them back.\n"));
if ((error = col_pop_item(stack, &item1)) ||
(error = col_pop_item(stack, &item2))) {
@@ -67,14 +77,14 @@ int stack_test(void)
return error;
}
- printf("\nPopped two last items.\n");
- col_debug_collection(stack, COL_TRAVERSE_DEFAULT);
+ COLOUT(printf("\nPopped two last items.\n"));
+ COLOUT(col_debug_collection(stack, COL_TRAVERSE_DEFAULT));
- printf("\nLast item.\n");
- col_debug_item(item1);
+ COLOUT(printf("\nLast item.\n"));
+ COLOUT(col_debug_item(item1));
- printf("\nPrevious item.\n");
- col_debug_item(item2);
+ COLOUT(printf("\nPrevious item.\n"));
+ COLOUT(col_debug_item(item2));
if ((error = col_push_item(stack, item1)) ||
(error = col_push_item(stack, item2))) {
@@ -83,13 +93,13 @@ int stack_test(void)
return error;
}
- printf("\n\nPushed two items again in reverse order.\n\n");
+ COLOUT(printf("\n\nPushed two items again in reverse order.\n\n"));
- col_debug_collection(stack, COL_TRAVERSE_DEFAULT);
+ COLOUT(col_debug_collection(stack, COL_TRAVERSE_DEFAULT));
col_destroy_collection(stack);
TRACE_FLOW_NUMBER("stack_test. Returning", error);
- printf("\n\nEND OF STACK TEST!!!.\n\n");
+ COLOUT(printf("\n\nEND OF STACK TEST!!!.\n\n"));
return error;
}
@@ -98,11 +108,24 @@ int stack_test(void)
int main(int argc, char *argv[])
{
- int error = EOK;
+ int error = 0;
+ test_fn tests[] = { stack_test,
+ NULL };
+ test_fn t;
+ int i = 0;
+
+ if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = 1;
printf("Start\n");
- if ((error = stack_test())) printf("Failed!\n");
- else printf("Success!\n");
- return error;
+ while ((t = tests[i++])) {
+ error = t();
+ if (error) {
+ printf("Failed!\n");
+ return error;
+ }
+ }
+
+ printf("Success!\n");
+ return 0;
}