Skip to content

Commit

Permalink
testhash: add the forgotten c file
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Dec 31, 2024
1 parent 4545d89 commit f040454
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/lib/hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Baptiste Daroussin <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <atf-c.h>
#include <pkghash.h>
#include <xmalloc.h>

ATF_TC_WITHOUT_HEAD(hash);

ATF_TC_BODY(hash, tc)
{
struct pkghash *h = pkghash_new();
ATF_REQUIRE_EQ(pkghash_count(h), 0);
ATF_REQUIRE(pkghash_add(h, "key", "value", NULL));
ATF_REQUIRE_EQ(pkghash_count(h), 1);
ATF_REQUIRE(!pkghash_del(h, "plop"));
ATF_REQUIRE_EQ(pkghash_count(h), 1);
ATF_REQUIRE(pkghash_del(h, "key"));
ATF_REQUIRE_EQ(pkghash_count(h), 0);
char *val = xstrdup("value");
ATF_REQUIRE(pkghash_add(h, "key", val, free));
ATF_REQUIRE_EQ(pkghash_count(h), 1);
ATF_REQUIRE_STREQ((char *)pkghash_delete(h, "key"), "value");
ATF_REQUIRE_STREQ(val, "value");
ATF_REQUIRE_EQ(pkghash_count(h), 0);
ATF_REQUIRE(pkghash_add(h, "key", val, free));
ATF_REQUIRE_EQ(pkghash_count(h), 1);
ATF_REQUIRE(pkghash_del(h, "key"));
ATF_REQUIRE_EQ(pkghash_count(h), 0);
val = xstrdup("value");
ATF_REQUIRE(pkghash_add(h, "key", val, free));
ATF_REQUIRE_EQ(pkghash_delete(h, "bla"), NULL);
pkghash_destroy(h);
}

ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, hash);

return (atf_no_error());
}

0 comments on commit f040454

Please sign in to comment.