|
8 | 8 | #include "general.h" |
9 | 9 |
|
10 | 10 | #include "acutest.h" |
| 11 | +#include "htable.h" |
11 | 12 | #include "routines.h" |
12 | 13 | #include <string.h> |
13 | 14 |
|
| 15 | +void test_htable_update(void) |
| 16 | +{ |
| 17 | + hashTable *htable = hashTableNew (3, hashCstrhash, hashCstreq, |
| 18 | + eFree, NULL); |
| 19 | + TEST_CHECK(htable != NULL); |
| 20 | + |
| 21 | + hashTablePutItem (htable, strdup("a"), "A"); |
| 22 | + TEST_CHECK (hashTableUpdateItem (htable, "a", "B") == true); |
| 23 | + TEST_CHECK (hashTableUpdateItem (htable, "b", "B") == false); |
| 24 | + TEST_CHECK (strcmp (hashTableGetItem (htable, "a"), "B") == 0); |
| 25 | + TEST_CHECK (hashTableUpdateOrPutItem (htable, "a", "C") == true); |
| 26 | + TEST_CHECK (hashTableUpdateOrPutItem (htable, strdup("x"), "X") == false); |
| 27 | + TEST_CHECK (strcmp (hashTableGetItem (htable, "x"), "X") == 0); |
| 28 | + hashTableDelete(htable); |
| 29 | +} |
| 30 | + |
14 | 31 | void test_routines_strrstr(void) |
15 | 32 | { |
16 | 33 | TEST_CHECK(strcmp(strrstr("abcdcdb", "cd"), "cdb") == 0); |
17 | 34 | } |
18 | 35 |
|
19 | 36 | TEST_LIST = { |
| 37 | + { "htable/update", test_htable_update }, |
20 | 38 | { "routines/strrstr", test_routines_strrstr }, |
21 | 39 | { NULL, NULL } /* zeroed record marking the end of the list */ |
22 | 40 | }; |
0 commit comments