diff options
author | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2009-06-23 09:19:14 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2009-06-23 09:19:14 +0000 |
commit | f27eb11e3f225d71d6fba59e3ca31cd68e420238 (patch) | |
tree | d70fd298b69ba031b9cb38eb931ea47f20d78d70 | |
parent | 841e061609fed066c32b0913ba93692dfc327021 (diff) | |
download | libwapcaplet-f27eb11e3f225d71d6fba59e3ca31cd68e420238.tar.gz libwapcaplet-f27eb11e3f225d71d6fba59e3ca31cd68e420238.tar.bz2 |
Merge Bo's libwapcaplet lwc_string_hash_value function and tests. r=dsilvers
svn path=/trunk/libwapcaplet/; revision=7927
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/libwapcaplet/libwapcaplet.h | 11 | ||||
-rw-r--r-- | src/libwapcaplet.c | 9 | ||||
-rw-r--r-- | test/basictests.c | 16 |
4 files changed, 36 insertions, 2 deletions
@@ -1,6 +1,6 @@ # Component settings COMPONENT := wapcaplet -COMPONENT_VERSION := 0.0.1 +COMPONENT_VERSION := 0.0.2 # Default to a static library COMPONENT_TYPE ?= lib-static diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h index 919d1e1..e896fc5 100644 --- a/include/libwapcaplet/libwapcaplet.h +++ b/include/libwapcaplet/libwapcaplet.h @@ -11,6 +11,7 @@ #include <sys/types.h> #include <stdbool.h> +#include <stdint.h> /** * Memory allocator type @@ -126,5 +127,15 @@ extern const char *lwc_string_data(lwc_string *str); */ extern size_t lwc_string_length(lwc_string *str); +/** + * Retrieve (or compute if unavailable) a hash value for the content of the string. + * + * @note This API should only be used as a convenient way to retrieve a hash + * value for the string. This hash value should not be relied on to be + * unique within an invocation of the program, nor should it be relied upon + * to be stable between invocations of the program. Never use the hash + * value as a way to directly identify the value of the string. + */ +extern uint32_t lwc_string_hash_value(lwc_string *str); #endif /* libwapcaplet_h_ */ diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c index 29b9795..58ebf6b 100644 --- a/src/libwapcaplet.c +++ b/src/libwapcaplet.c @@ -7,7 +7,6 @@ */ #include <string.h> -#include <stdint.h> #include <assert.h> #include "libwapcaplet/libwapcaplet.h" @@ -342,3 +341,11 @@ lwc_string_length(lwc_string *str) return str->len; } + +uint32_t +lwc_string_hash_value(lwc_string *str) +{ + assert(str); + + return str->hash; +} diff --git a/test/basictests.c b/test/basictests.c index 07c54a3..80d3d38 100644 --- a/test/basictests.c +++ b/test/basictests.c @@ -174,6 +174,12 @@ START_TEST (test_lwc_string_length_aborts) } END_TEST +START_TEST (test_lwc_string_hash_value_aborts) +{ + lwc_string_hash_value(NULL); +} +END_TEST + #endif START_TEST (test_lwc_context_creation_ok) @@ -381,6 +387,12 @@ START_TEST (test_lwc_extract_data_ok) } END_TEST +START_TEST (test_lwc_string_hash_value_ok) +{ + lwc_string_hash_value(intern_one); +} +END_TEST + /**** And the suites are set up here ****/ void @@ -444,6 +456,9 @@ lwc_basic_suite(SRunner *sr) tcase_add_test_raise_signal(tc_basic, test_lwc_string_length_aborts, SIGABRT); + tcase_add_test_raise_signal(tc_basic, + test_lwc_string_hash_value_aborts, + SIGABRT); #endif tcase_add_test(tc_basic, test_lwc_context_creation_ok); @@ -471,6 +486,7 @@ lwc_basic_suite(SRunner *sr) tcase_add_test(tc_basic, test_lwc_context_string_isequal_ok); tcase_add_test(tc_basic, test_lwc_context_string_caseless_isequal_ok); tcase_add_test(tc_basic, test_lwc_extract_data_ok); + tcase_add_test(tc_basic, test_lwc_string_hash_value_ok); suite_add_tcase(s, tc_basic); srunner_add_suite(sr, s); |