#include "random-util.h"
#include "set.h"
#include "strv.h"
+#include "tests.h"
const bool mempool_use_allowed = VALGRIND;
-static void test_set_steal_first(void) {
+TEST(set_steal_first) {
_cleanup_set_free_ Set *m = NULL;
int seen[3] = {};
char *val;
item->seen++;
}
-static void test_set_free_with_destructor(void) {
+TEST(set_free_with_destructor) {
Set *m;
struct Item items[4] = {};
unsigned i;
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_hash_ops, void, trivial_hash_func, trivial_compare_func, Item, item_seen);
-static void test_set_free_with_hash_ops(void) {
+TEST(set_free_with_hash_ops) {
Set *m;
struct Item items[4] = {};
unsigned i;
assert_se(items[3].seen == 0);
}
-static void test_set_put(void) {
+TEST(set_put) {
_cleanup_set_free_ Set *m = NULL;
m = set_new(&string_hash_ops);
assert_se(strv_length(t) == 3);
}
-static void test_set_put_strdup(void) {
+TEST(set_put_strdup) {
_cleanup_set_free_ Set *m = NULL;
assert_se(set_put_strdup(&m, "aaa") == 1);
assert_se(set_size(m) == 2);
}
-static void test_set_put_strdupv(void) {
+TEST(set_put_strdupv) {
_cleanup_set_free_ Set *m = NULL;
assert_se(set_put_strdupv(&m, STRV_MAKE("aaa", "aaa", "bbb", "bbb", "aaa")) == 2);
assert_se(set_size(m) == 3);
}
-static void test_set_ensure_allocated(void) {
+TEST(set_ensure_allocated) {
_cleanup_set_free_ Set *m = NULL;
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 1);
assert_se(set_size(m) == 0);
}
-static void test_set_copy(void) {
+TEST(set_copy) {
Set *s, *copy;
char *key1, *key2, *key3, *key4;
- log_info("/* %s */", __func__);
-
key1 = strdup("key1");
assert_se(key1);
key2 = strdup("key2");
set_free_free(copy);
}
-static void test_set_ensure_put(void) {
+TEST(set_ensure_put) {
_cleanup_set_free_ Set *m = NULL;
assert_se(set_ensure_put(&m, &string_hash_ops, "a") == 1);
assert_se(set_size(m) == 2);
}
-static void test_set_ensure_consume(void) {
+TEST(set_ensure_consume) {
_cleanup_set_free_ Set *m = NULL;
char *s, *t;
assert_se(set_size(m) == 2);
}
-static void test_set_strjoin(void) {
+TEST(set_strjoin) {
_cleanup_set_free_ Set *m = NULL;
_cleanup_free_ char *joined = NULL;
assert_se(STR_IN_SET(joined, "xxxaaaxxxbbbxxx", "xxxbbbxxxaaaxxx"));
}
-static void test_set_equal(void) {
+TEST(set_equal) {
_cleanup_set_free_ Set *a = NULL, *b = NULL;
void *p;
int r;
assert_se(set_equal(b, a));
}
-int main(int argc, const char *argv[]) {
- test_set_steal_first();
- test_set_free_with_destructor();
- test_set_free_with_hash_ops();
- test_set_put();
- test_set_put_strdup();
- test_set_put_strdupv();
- test_set_ensure_allocated();
- test_set_ensure_put();
- test_set_ensure_consume();
- test_set_strjoin();
- test_set_equal();
- test_set_copy();
-
- return 0;
-}
+DEFINE_TEST_MAIN(LOG_INFO);