From f17121ad06de80f28dce98e89851da339963bbe1 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Thu, 10 Sep 2009 18:02:51 -0400 Subject: COLLECTION Functions to deal with hash The hashing logic was internal to the collection item. But if someone wants to effectively deal with the items and compare the property to a string he should compare hashes first. But it was not possible without the provided functions. As a result some of the ELAPI modules had to take advantage of knowledge of the item structure. This is bad. So this patch lays foundation for refactoring of the ELAPI code that was using internals of the item directly (file_util.c mostly). Also patch adds a unit test that was required for testing new functionality and for ticket #83 --- common/collection/collection_ut.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'common/collection/collection_ut.c') diff --git a/common/collection/collection_ut.c b/common/collection/collection_ut.c index f1ec905a..050c6ef1 100644 --- a/common/collection/collection_ut.c +++ b/common/collection/collection_ut.c @@ -592,6 +592,7 @@ int iterator_test(void) char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; int depth = 0; int idepth = 0; + int len = 0; printf("\n\n==== ITERATOR TEST ====\n\n"); @@ -767,6 +768,26 @@ int iterator_test(void) col_destroy_collection(peer); return error; } + + printf("Item name: %s\n", col_get_item_property(item, NULL)); + printf("Item hash: %lu\n", (unsigned long int)col_get_item_hash(item)); + error = col_modify_item_property(item, "new_name"); + if (error) { + printf("We expected success but got error %d\n", error); + col_unbind_iterator(iterator); + col_destroy_collection(peer); + return error; + } + len = 0; + printf("Item name: %s\n", col_get_item_property(item, &len)); + printf("Item hash: %lu\n", (unsigned long int)col_get_item_hash(item)); + printf("Item length: %d\n", len); + + len = 0; + printf("String name: %s\n", "new_name"); + printf("String hash: %lu\n", (unsigned long int)col_make_hash("new_name", &len)); + printf("String length: %d\n", len); + } } while(1); -- cgit