diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-07-01 18:22:19 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-07-02 08:16:35 -0400 |
commit | 9a28c36d323c14e31a3895ffe7dc905b815291f8 (patch) | |
tree | 9f43b63b340092f9e63d7e403a36a22f51643124 /common/collection/collection_stack_ut.c | |
parent | 203d8d4ffb03897ab995bc2a6311f2a603245269 (diff) | |
download | sssd-9a28c36d323c14e31a3895ffe7dc905b815291f8.tar.gz sssd-9a28c36d323c14e31a3895ffe7dc905b815291f8.tar.bz2 sssd-9a28c36d323c14e31a3895ffe7dc905b815291f8.zip |
Queue and stack APIs using collection.
Patch adds two interfaces for stack and queue using
collection as underlaying implementation.
It also fixes a bug in the insterion code -
the unsigned properties were created as long.
Diffstat (limited to 'common/collection/collection_stack_ut.c')
-rw-r--r-- | common/collection/collection_stack_ut.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/common/collection/collection_stack_ut.c b/common/collection/collection_stack_ut.c new file mode 100644 index 00000000..667af103 --- /dev/null +++ b/common/collection/collection_stack_ut.c @@ -0,0 +1,108 @@ +/* + STACK INTERFACE + + Stack unit test. + + Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 + + Collection Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Collection Library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Collection Library. If not, see <http://www.gnu.org/licenses/>. +*/ + + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#define TRACE_HOME +#include "trace.h" +#include "collection_stack.h" +#include "collection_tools.h" + + +int stack_test() +{ + struct collection_item *stack = NULL; + char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + struct collection_item *item1 = NULL; + struct collection_item *item2 = NULL; + + int error = EOK; + + TRACE_FLOW_STRING("stack_test", "Entry."); + + printf("\n\nSTACK TEST!!!.\n\n\n"); + + if ((error = create_stack(&stack)) || + (error = push_str_property(stack, "item1", "value 1", 0)) || + (error = push_int_property(stack, "item2", -1)) || + (error = push_unsigned_property(stack, "item3", 1)) || + (error = push_long_property(stack, "item4", 100)) || + (error = push_ulong_property(stack, "item5", 1000)) || + (error = push_double_property(stack, "item6", 1.1)) || + (error = push_bool_property(stack, "item7", 1)) || + (error = push_binary_property(stack, "item8", binary_dump, sizeof(binary_dump)))) { + printf("Failed to push property. Error %d\n", error); + destroy_collection(stack); + return error; + } + + debug_collection(stack, COL_TRAVERSE_DEFAULT); + + printf("Swapping last two items by popping and pushing them back.\n"); + + if ((error = pop_item(stack, &item1)) || + (error = pop_item(stack, &item2))) { + printf("Failed to pop items. Error %d\n", error); + destroy_collection(stack); + return error; + } + + printf("\nPopped two last items.\n"); + debug_collection(stack, COL_TRAVERSE_DEFAULT); + + printf("\nLast item.\n"); + debug_item(item1); + + printf("\nPrevious item.\n"); + debug_item(item2); + + if ((error = push_item(stack, item1)) || + (error = push_item(stack, item2))) { + printf("Failed to pop or push items. Error %d\n", error); + destroy_collection(stack); + return error; + } + + printf("\n\nPushed two items again in reverse order.\n\n"); + + debug_collection(stack, COL_TRAVERSE_DEFAULT); + destroy_collection(stack); + TRACE_FLOW_NUMBER("stack_test. Returning", error); + + printf("\n\nEND OF STACK TEST!!!.\n\n"); + + return error; +} + +/* Main function of the unit test */ + +int main() +{ + int error = EOK; + + printf("Start\n"); + if ((error = stack_test())) printf("Failed!\n"); + else printf("Success!\n"); + + return error; +} |