diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-07-10 11:43:05 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-07-15 11:19:46 -0400 |
commit | 9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2 (patch) | |
tree | 8247496c0ca89532944b069467e67c875712e123 /common/collection/collection_ut.c | |
parent | 1a91062d7d82407a6e376b62b29dca709170a66b (diff) | |
download | sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.tar.gz sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.tar.xz sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.zip |
COLLECTION Fixed: iterator_up and insert_into_current
During a review of the previous patch the two issues
were found:
a) The col_iterator_up function was not implemented properly
so it got reworked. New implementation changes
the way error condition is handled. Comments were updated accordingly.
b) There was a mising check for validity of the argument in
the col_insert_into_current function. Check was added.
c) Unit test modified to reflect the change in functionality.
Diffstat (limited to 'common/collection/collection_ut.c')
-rw-r--r-- | common/collection/collection_ut.c | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/common/collection/collection_ut.c b/common/collection/collection_ut.c index c0adf34..c50a838 100644 --- a/common/collection/collection_ut.c +++ b/common/collection/collection_ut.c @@ -676,13 +676,14 @@ int iterator_test(void) return error; } + /* Are we done ? */ + if (item == (struct collection_item *)(NULL)) break; + depth = 0; col_get_item_depth(iterator, &depth); idepth = 0; col_get_iterator_depth(iterator, &idepth); - /* Are we done ? */ - if (item == (struct collection_item *)(NULL)) break; printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n", depth * 4, "", @@ -695,13 +696,7 @@ int iterator_test(void) if ((strcmp(col_get_item_property(item, NULL), "id")==0) && (*((int *)(col_get_item_data(item))) == 1)) { printf("\n\nFound property we need - go up!!!\n\n\n"); - error = col_iterate_up(iterator, 5); - if (!error) { - printf("We expected error but got seucces - bad.\n"); - col_unbind_iterator(iterator); - col_destroy_collection(peer); - return -1; - } + /* This should work! */ error = col_iterate_up(iterator, 1); if (error) { @@ -925,9 +920,6 @@ int iterator_test(void) return error; } - /* This should also work becuase iterator holds to collection */ - col_destroy_collection(peer); - printf("\n\nIteration (7 show headers only no END):\n\n"); do { @@ -936,6 +928,7 @@ int iterator_test(void) error = col_iterate_collection(iterator, &item); if (error) { printf("Error (iterate): %d\n", error); + col_destroy_collection(peer); col_unbind_iterator(iterator); return error; } @@ -954,6 +947,65 @@ int iterator_test(void) /* Do not forget to unbind iterator - otherwise there will be a leak */ col_unbind_iterator(iterator); + + /* Bind iterator */ + error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_DEFAULT); + if (error) { + printf("Error (bind): %d\n", error); + col_destroy_collection(peer); + return error; + } + + col_destroy_collection(peer); + + printf("\n\nIterate up test:\n\n"); + + do { + + /* Loop through a collection */ + error = col_iterate_collection(iterator, &item); + if (error) { + printf("Error (iterate): %d\n", error); + col_unbind_iterator(iterator); + return error; + } + + /* Are we done ? */ + if (item == (struct collection_item *)(NULL)) break; + + depth = 0; + col_get_item_depth(iterator, &depth); + idepth = 0; + col_get_iterator_depth(iterator, &idepth); + + + printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n", + depth * 4, "", + col_get_item_property(item, NULL), + col_get_item_type(item), + col_get_item_length(item), + depth, + idepth); + + if (strcmp(col_get_item_property(item, NULL), "queue") == 0) { + + printf("\n\nFound property we need - go up!!!\n"); + printf("Expect bail out of collection processing.\n\n"); + + /* This should work! */ + error = col_iterate_up(iterator, 10); + if (error) { + printf("We expected success but got error %d\n", error); + col_unbind_iterator(iterator); + col_destroy_collection(peer); + return error; + } + + } + } + while(1); + + col_unbind_iterator(iterator); return EOK; } |