Commit d7e35240 authored by Dan Fandrich's avatar Dan Fandrich
Browse files

unit1603: Added unit tests for hash functions

parent 278ea24a
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -46,7 +46,12 @@ hash_element_dtor(void *user, void *element)
  free(e);
}

/* return 1 on error, 0 is fine */
/* Initializes a hash structure.
 * Return 1 on error, 0 is fine.
 *
 * @unittest: 1602
 * @unittest: 1603
 */
int
Curl_hash_init(struct curl_hash *h,
               int slots,
@@ -119,6 +124,8 @@ mk_hash_element(const void *key, size_t key_len, const void *p)
 * that data is replaced.
 *
 * @unittest: 1305
 * @unittest: 1602
 * @unittest: 1603
 */
void *
Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
@@ -155,7 +162,11 @@ Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
  return NULL; /* failure */
}

/* remove the identified hash entry, returns non-zero on failure */
/* Remove the identified hash entry.
 * Returns non-zero on failure.
 *
 * @unittest: 1603
 */
int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
{
  struct curl_llist_element *le;
@@ -173,6 +184,10 @@ int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
  return 1;
}

/* Retrieves a hash element.
 *
 * @unittest: 1603
 */
void *
Curl_hash_pick(struct curl_hash *h, void *key, size_t key_len)
{
@@ -214,6 +229,10 @@ Curl_hash_apply(curl_hash *h, void *user,

/* Destroys all the entries in the given hash and resets its attributes,
 * prepping the given hash for [static|dynamic] deallocation.
 *
 * @unittest: 1305
 * @unittest: 1602
 * @unittest: 1603
 */
void
Curl_hash_destroy(struct curl_hash *h)
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ test1520 \
\
test1525 test1526 test1527 test1528 test1529 test1530 test1531 \
\
test1600 test1601 test1602 \
test1600 test1601 test1602 test1603 \
\
test1800 test1801 \
\

tests/data/test1603

0 → 100644
+26 −0
Original line number Diff line number Diff line
<testcase>
<info>
<keywords>
unittest
hash
</keywords>
</info>

#
# Client-side
<client>
<server>
none
</server>
<features>
unittest
</features>
 <name>
Internal hash add, retrieval, deletion testing
 </name>
<tool>
unit1603
</tool>
</client>

</testcase>
+4 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ UNITFILES = curlcheck.h \
# These are all unit test programs
UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307	\
 unit1308 unit1309 unit1330 unit1394 unit1395 unit1396 unit1397 unit1398	\
 unit1600 unit1601 unit1602
 unit1600 unit1601 unit1602 unit1603

unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1300_CPPFLAGS = $(AM_CPPFLAGS)
@@ -66,3 +66,6 @@ unit1601_CPPFLAGS = $(AM_CPPFLAGS)
unit1602_SOURCES = unit1602.c $(UNITFILES)
unit1602_CPPFLAGS = $(AM_CPPFLAGS)

unit1603_SOURCES = unit1603.c $(UNITFILES)
unit1603_CPPFLAGS = $(AM_CPPFLAGS)
+0 −2
Original line number Diff line number Diff line
@@ -134,8 +134,6 @@ UNITTEST_START
    abort_unless(nodep, "insertion into hash failed");
    /* Freeing will now be done by Curl_hash_destroy */
    data_node = NULL;

    /* To do: test retrieval, deletion, edge conditions */
  }

UNITTEST_STOP
Loading