tests: Add database adapter for testing purposes 39/145739/4
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Wed, 23 Aug 2017 11:51:58 +0000 (13:51 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 24 Aug 2017 11:50:28 +0000 (13:50 +0200)
Change-Id: I2a8fe6cb432da5120cde1a5133b5fd3c63190157
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
Makefile.am
tests/unit/runner.c
tests/unit/test_dbadapter.c [new file with mode: 0644]
tests/unit/test_dbadapter.h [new file with mode: 0644]

index 951bf6a70f96cc1e0b43aff6c2b30863009964fe..b5ba3e7f8cddd46041cacd6193e585036644cba3 100644 (file)
@@ -158,6 +158,7 @@ test_SOURCES = \
     tests/unit/faultd_object_tests.c \
     tests/unit/runner.c \
     tests/unit/helpers.c \
+    tests/unit/test_dbadapter.c \
     src/core/event.c \
     src/core/database.c \
     src/core/service.c \
index d541245d8ef81dcc04f7e44aa76c78f84484cb14..f82e7f8d7de9b5d3aace5d07216914fd04546cc6 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "fdtf.h"
 #include "module.h"
+#include "test_dbadapter.h"
 
 static struct list_head test_groups = LIST_HEAD_INIT(test_groups);
 
@@ -40,6 +41,8 @@ int fdtf_run_all_test_groups()
 
 int main(int argc, char **argv)
 {
+       testdb_init();
+
        /*
         * TODO:
         * Add here some more logic to allow to run
diff --git a/tests/unit/test_dbadapter.c b/tests/unit/test_dbadapter.c
new file mode 100644 (file)
index 0000000..11f55ec
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * This file is a part of fauld.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test_dbadapter.h"
+#include "database.h"
+
+struct testdb_adapter {
+       struct faultd_database_adapter database_adapter;
+};
+
+#define to_testdb_adapter(MOD)                         \
+       container_of(MOD, struct testdb_adapter, database_adapter)
+
+static int init_testdb_adapter(struct faultd_module *module,
+                                                       struct faultd_config *config,
+                                                       sd_event *event_loop)
+{
+       return 0;
+}
+
+static void cleanup_testdb_adapter(struct faultd_module *module)
+{
+}
+
+static int testdb_store(struct faultd_database_adapter *adapter,
+                                        struct faultd_object *obj, faultd_oid_t *oid)
+{
+       return 0;
+}
+
+static int testdb_get_by_oid(struct faultd_database_adapter *adapter,
+                                                 faultd_oid_t *oid, struct faultd_object *result)
+{
+       return 0;
+}
+
+static int testdb_load(struct faultd_database_adapter *adapter,
+                                       struct faultd_object *query,
+                                       struct faultd_object *result, uint32_t *nr)
+{
+       *nr = 0;
+       return 0;
+}
+
+static int testdb_new_oid(faultd_oid_t *oid)
+{
+       return 0;
+}
+
+static struct testdb_adapter testdb_adapter = {
+       .database_adapter = {
+               .module = {
+                       .name = "testdb_dbadapter",
+                       .type = FAULTD_MODULE_TYPE_DBADAPTER,
+                       .init = init_testdb_adapter,
+                       .cleanup = cleanup_testdb_adapter,
+                       .node = LIST_HEAD_INIT(testdb_adapter.database_adapter.module.node),
+               },
+               .id_key = "testdb_id",
+               .store = testdb_store,
+               .get_by_oid = testdb_get_by_oid,
+               .load = testdb_load,
+               .new_oid = testdb_new_oid,
+       }
+};
+
+void testdb_init()
+{
+       faultd_set_database_adapter(&testdb_adapter.database_adapter);
+}
diff --git a/tests/unit/test_dbadapter.h b/tests/unit/test_dbadapter.h
new file mode 100644 (file)
index 0000000..4fd0b83
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * This file is a part of fauld.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FAULTD_TEST_DBADAPTER
+#define FAULTD_TEST_DBADAPTER
+
+void testdb_init();
+
+#endif