summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-30 16:35:19 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-30 16:35:19 +0000
commitaa0aa44aaab4b0693400dc4307822ac493014224 (patch)
tree0fbce8307517d84a2f1eb1a295778e8dd6fff6d4 /test
parent7712c61effc3ef39d0b9eaf060049d11441884bf (diff)
downloadlibparserutils-aa0aa44aaab4b0693400dc4307822ac493014224.tar.gz
libparserutils-aa0aa44aaab4b0693400dc4307822ac493014224.tar.bz2
New datastructures:
+ Chunked array + Hash table (open addressing) Constify parameter to parserutils_stack_push svn path=/trunk/libparserutils/; revision=5850
Diffstat (limited to 'test')
-rw-r--r--test/INDEX1
-rw-r--r--test/Makefile2
-rw-r--r--test/hash.c56
3 files changed, 58 insertions, 1 deletions
diff --git a/test/INDEX b/test/INDEX
index bcd782a..f055717 100644
--- a/test/INDEX
+++ b/test/INDEX
@@ -10,6 +10,7 @@ cscodec-utf16 UTF-16 charset codec implementation cscodec-utf16
cscodec-ext8 Extended 8bit charset codec cscodec-ext8
cscodec-8859 ISO-8859-n codec cscodec-8859
dict Dictionary handling
+hash Hashtable implementation
rbtree Red-black tree implementation
filter Input stream filtering
inputstream Inputstream handling input
diff --git a/test/Makefile b/test/Makefile
index 0786f5d..aeffc1e 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -36,7 +36,7 @@ CFLAGS := $(CFLAGS) -I$(TOP)/src/ -I$(d)
# Tests
TESTS_$(d) := aliases cscodec-8859 cscodec-ext8 cscodec-utf8 cscodec-utf16 \
- charset dict filter inputstream parserutils rbtree
+ charset dict filter hash inputstream parserutils rbtree
TESTS_$(d) := $(TESTS_$(d)) regression/cscodec-segv regression/filter-segv \
regression/stream-nomem regression/filter-badenc-segv
diff --git a/test/hash.c b/test/hash.c
new file mode 100644
index 0000000..3eceeae
--- /dev/null
+++ b/test/hash.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <parserutils/utils/hash.h>
+
+#include "testutils.h"
+
+extern void parserutils_hash_dump(parserutils_hash *hash);
+
+static void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
+int main(int argc, char **argv)
+{
+ parserutils_hash *hash;
+ uint8_t buf[256];
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ /* Seed buffer with printable ascii */
+ for (int i = 0; i < (int) sizeof(buf); i++) {
+ buf[i] = 97 + (int) (26.0 * (rand() / (RAND_MAX + 1.0)));
+ }
+ buf[sizeof(buf) - 1] = '\0';
+
+ assert(parserutils_hash_create(myrealloc, NULL, &hash) ==
+ PARSERUTILS_OK);
+
+ for (int i = 0; i < (int) sizeof(buf); i++) {
+ uint8_t *s = buf;
+
+ while (s - buf <= i) {
+ const parserutils_hash_entry *e;
+
+ parserutils_hash_insert(hash,
+ s, (size_t) (sizeof(buf) - i), &e);
+
+ s++;
+ }
+ }
+
+// parserutils_hash_dump(hash);
+
+ parserutils_hash_destroy(hash);
+
+ printf("PASS\n");
+
+ return 0;
+}
+