summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a929ff)
raw | patch | inline | side by side (parent: 0a929ff)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 7 Dec 2013 14:46:21 +0000 (15:46 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 7 Dec 2013 14:46:21 +0000 (15:46 +0100) |
For now, testing basic insertion operations.
t/Makefile.am | patch | blob | history | |
t/core/store_test.c | [new file with mode: 0644] | patch | blob |
t/libsysdb_test.c | patch | blob | history | |
t/libsysdb_test.h | patch | blob | history |
diff --git a/t/Makefile.am b/t/Makefile.am
index c31ac502de3f22757eb4d9a908934500be2219be..87140cf2016051b371baed84369e145b36d32a10 100644 (file)
--- a/t/Makefile.am
+++ b/t/Makefile.am
libsysdb_test_SOURCES = \
libsysdb_test.c libsysdb_test.h \
core/object_test.c \
+ core/store_test.c \
utils/channel_test.c \
utils/dbi_test.c \
utils/llist_test.c \
diff --git a/t/core/store_test.c b/t/core/store_test.c
--- /dev/null
+++ b/t/core/store_test.c
@@ -0,0 +1,171 @@
+/*
+ * SysDB - t/core/store_test.c
+ * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "core/store.h"
+#include "libsysdb_test.h"
+
+#include <check.h>
+
+START_TEST(test_store_host)
+{
+ struct {
+ const char *name;
+ sdb_time_t last_update;
+ int expected;
+ } golden_data[] = {
+ { "a", 2, 0 },
+ { "a", 3, 0 },
+ { "a", 1, 1 },
+ { "b", 2, 0 },
+ { "b", 1, 1 },
+ { "A", 1, 1 }, /* case-insensitive */
+ { "A", 4, 0 },
+ };
+
+ struct {
+ const char *name;
+ _Bool has;
+ } golden_hosts[] = {
+ { "a", 1 == 1 },
+ { "b", 1 == 1 },
+ { "c", 0 == 1 },
+ { "A", 1 == 1 },
+ };
+
+ size_t i;
+
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ int status;
+
+ status = sdb_store_host(golden_data[i].name,
+ golden_data[i].last_update);
+ fail_unless(status == golden_data[i].expected,
+ "sdb_store_host(%s, %d) = %d; expected: %d",
+ golden_data[i].name, (int)golden_data[i].last_update,
+ status, golden_data[i].expected);
+ }
+
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
+ _Bool has;
+
+ has = sdb_store_has_host(golden_hosts[i].name);
+ fail_unless(has == golden_hosts[i].has,
+ "sdb_store_has_host(%s) = %d; expected: %d",
+ golden_hosts[i].name, has, golden_hosts[i].has);
+ }
+}
+END_TEST
+
+START_TEST(test_store_attr)
+{
+ struct {
+ const char *host;
+ const char *key;
+ const char *value;
+ sdb_time_t last_update;
+ int expected;
+ } golden_data[] = {
+ { "k", "k", "v", 1, -1 },
+ { "k", "k", "v", 1, -1 }, /* retry to ensure the host is not created */
+ { "l", "k1", "v1", 1, 0 },
+ { "l", "k1", "v2", 2, 0 },
+ { "l", "k1", "v3", 1, 1 },
+ { "l", "k2", "v1", 1, 0 },
+ { "m", "k", "v1", 2, 0 },
+ { "m", "k", "v2", 1, 1 },
+ };
+
+ size_t i;
+
+ sdb_store_host("l", 1);
+ sdb_store_host("m", 1);
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ int status;
+
+ status = sdb_store_attribute(golden_data[i].host,
+ golden_data[i].key, golden_data[i].value,
+ golden_data[i].last_update);
+ fail_unless(status == golden_data[i].expected,
+ "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
+ golden_data[i].host, golden_data[i].key, golden_data[i].value,
+ golden_data[i].last_update, status, golden_data[i].expected);
+ }
+}
+END_TEST
+
+START_TEST(test_store_service)
+{
+ struct {
+ const char *host;
+ const char *svc;
+ sdb_time_t last_update;
+ int expected;
+ } golden_data[] = {
+ { "k", "s", 1, -1 },
+ { "k", "s", 1, -1 }, /* retry to ensure the host is not created */
+ { "l", "s1", 1, 0 },
+ { "l", "s1", 2, 0 },
+ { "l", "s1", 1, 1 },
+ { "l", "s2", 1, 0 },
+ { "m", "s", 2, 0 },
+ { "m", "s", 1, 1 },
+ };
+
+ size_t i;
+
+ sdb_store_host("m", 1);
+ sdb_store_host("l", 1);
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ int status;
+
+ status = sdb_store_service(golden_data[i].host,
+ golden_data[i].svc, golden_data[i].last_update);
+ fail_unless(status == golden_data[i].expected,
+ "sdb_store_attribute(%s, %s, %d) = %d; expected: %d",
+ golden_data[i].host, golden_data[i].svc,
+ golden_data[i].last_update, status, golden_data[i].expected);
+ }
+}
+END_TEST
+
+Suite *
+core_store_suite(void)
+{
+ Suite *s = suite_create("core::store");
+ TCase *tc;
+
+ tc = tcase_create("core");
+ tcase_add_test(tc, test_store_host);
+ tcase_add_test(tc, test_store_attr);
+ tcase_add_test(tc, test_store_service);
+ suite_add_tcase(s, tc);
+
+ return s;
+} /* core_store_suite */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
diff --git a/t/libsysdb_test.c b/t/libsysdb_test.c
index 91909b8448bd2ed7562af9a65055075b734b8e6f..c21f0bee7785d05e3bde2039b10aa2eb5c58a948 100644 (file)
--- a/t/libsysdb_test.c
+++ b/t/libsysdb_test.c
suite_creator_t creators[] = {
{ core_object_suite, NULL },
+ { core_store_suite, NULL },
{ util_channel_suite, NULL },
{ util_dbi_suite, NULL },
{ util_llist_suite, NULL },
diff --git a/t/libsysdb_test.h b/t/libsysdb_test.h
index eadeca5d06716d4f29a5e466913ea36f292db0d7..f9fddebdec64b48ec23f2473cf7c7d8b602d8e09 100644 (file)
--- a/t/libsysdb_test.h
+++ b/t/libsysdb_test.h
Suite *
core_object_suite(void);
+/* t/core/store_test */
+Suite *
+core_store_suite(void);
+
/* t/utils/channel_test */
Suite *
util_channel_suite(void);