summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-02-05 11:57:26 (GMT)
committer Daniel Silverstone <dsilvers@digital-scurf.org>2017-02-05 11:57:26 (GMT)
commit51062e55b00b8b307d9f45cb150dcefa4d710cfc (patch)
tree6ddce1e39ed8b51098460438c68d13b97b701885
parent4b3f2bb946ad201f99a20ddaff980ecea05e5ebc (diff)
downloadnetsurf-51062e55b00b8b307d9f45cb150dcefa4d710cfc.tar.gz
netsurf-51062e55b00b8b307d9f45cb150dcefa4d710cfc.tar.bz2
Ensure hash table test doesn't go over-time
-rw-r--r--test/hashtable.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/hashtable.c b/test/hashtable.c
index 9f46e4c..11c58c6 100644
--- a/test/hashtable.c
+++ b/test/hashtable.c
@@ -32,6 +32,9 @@
#include "utils/hashtable.h"
+/* Limit for hash table tests which use /usr/share/dict/words */
+#define DICT_TEST_WORD_COUNT 100000
+
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
struct test_pairs {
@@ -91,6 +94,7 @@ static void dict_hashtable_create(int dict_hash_size)
{
FILE *dictf;
char keybuf[BUFSIZ], valbuf[BUFSIZ];
+ uint32_t counter = 0;
dictf = fopen("/usr/share/dict/words", "r");
ck_assert(dictf != NULL);
@@ -102,6 +106,7 @@ static void dict_hashtable_create(int dict_hash_size)
fscanf(dictf, "%s", keybuf);
fscanf(dictf, "%s", valbuf);
hash_add(dict_hash, keybuf, valbuf);
+ if (counter++ > DICT_TEST_WORD_COUNT) break;
}
fclose(dictf);
@@ -227,6 +232,7 @@ START_TEST(hashtable_dict_test)
FILE *dictf;
char keybuf[BUFSIZ], valbuf[BUFSIZ];
const char *res;
+ uint32_t counter = 0;
dictf = fopen("/usr/share/dict/words", "r");
ck_assert(dictf != NULL);
@@ -238,6 +244,7 @@ START_TEST(hashtable_dict_test)
res = hash_get(dict_hash, keybuf);
ck_assert(res != NULL);
ck_assert_str_eq(res, valbuf);
+ if (counter++ > DICT_TEST_WORD_COUNT) break;
}
fclose(dictf);