From 609d0ae94b1ffe11b53c65c63590ee9921295057 Mon Sep 17 00:00:00 2001
From: armatusmiles <akurotych@gmail.com>
Date: Thu, 5 Jul 2018 16:27:38 +0300
Subject: [PATCH] Add simple test dap_config

---
 .gitignore                   |  1 +
 core/dap_config.h            |  9 +++++++++
 test/CMakeLists.txt          | 36 ++++++++++++++++++++++++++++++++++++
 test/TestHeaders.hpp         |  2 ++
 test/core/DapConfig_test.hpp | 13 +++++++++++++
 test/main.cpp                | 29 +++++++++++++++++++++++++++++
 6 files changed, 90 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 test/CMakeLists.txt
 create mode 100644 test/TestHeaders.hpp
 create mode 100644 test/core/DapConfig_test.hpp
 create mode 100644 test/main.cpp

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8a9d35c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.user
diff --git a/core/dap_config.h b/core/dap_config.h
index 10d14db..3c36c3b 100644
--- a/core/dap_config.h
+++ b/core/dap_config.h
@@ -1,9 +1,14 @@
 #ifndef _DAP_CONFIG_H_
 #define _DAP_CONFIG_H_
+
 #include <stdbool.h>
 #include <stdint.h>
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct dap_config{
     void * _internal;
 } dap_config_t;
@@ -20,5 +25,9 @@ const char * dap_config_get_item_str_default(dap_config_t * a_config, const char
 bool dap_config_get_item_bool(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
 double dap_config_get_item_double(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
 
+#ifdef __cplusplus
+}
+#endif
+
 
 #endif
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..3f5f523
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(libdap-test)
+
+# Tell CMake to run moc when necessary:
+set(CMAKE_AUTOMOC ON)
+
+# As moc files are generated in the binary dir, tell CMake
+# to always look for includes there:
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+find_package(Qt5Test REQUIRED)
+
+# dependencies for testing
+
+set(HEADERS
+    ../core/dap_config.h
+    ../core/dap_common.h
+    )
+
+set(SRC
+    ../core/dap_config.c
+    ../core/dap_common.c
+    )
+
+set(TEST_FILES
+    main.cpp
+    TestHeaders.hpp
+    core/DapConfig_test.hpp
+)
+
+add_executable(${PROJECT_NAME} ${TEST_FILES} ${SRC} ${HEADERS}) # ${SRC} ${HEADERS}
+
+target_include_directories(${PROJECT_NAME} PUBLIC ../core)
+target_link_libraries(${PROJECT_NAME} Qt5::Test)
+
diff --git a/test/TestHeaders.hpp b/test/TestHeaders.hpp
new file mode 100644
index 0000000..4c7b3ea
--- /dev/null
+++ b/test/TestHeaders.hpp
@@ -0,0 +1,2 @@
+#pragma once
+#include "core/DapConfig_test.hpp"
diff --git a/test/core/DapConfig_test.hpp b/test/core/DapConfig_test.hpp
new file mode 100644
index 0000000..2c8077c
--- /dev/null
+++ b/test/core/DapConfig_test.hpp
@@ -0,0 +1,13 @@
+#pragma once
+#include <QTest>
+#include "dap_config.h"
+
+class DapConfigTest : public QObject {
+    Q_OBJECT
+private:
+    // helper functions
+private slots:
+    void dapConfigOpenFail() {
+        QVERIFY(dap_config_open("RandomNeverExistName") == NULL);
+    }
+};
diff --git a/test/main.cpp b/test/main.cpp
new file mode 100644
index 0000000..c0519f0
--- /dev/null
+++ b/test/main.cpp
@@ -0,0 +1,29 @@
+#include <QTest>
+#include <QDebug>
+
+#define RUN_TESTS(TestObject) { \
+    TestObject tc; \
+    if(QTest::qExec(&tc)) \
+        exit(1); }
+
+/* comment this and add RUN_TESTS in main function
+ * for run and debugging one testing class */
+#define RUN_ALL_TESTS
+
+#ifdef RUN_ALL_TESTS
+#include "TestHeaders.hpp"
+void run_all_tests() {
+    RUN_TESTS(DapConfigTest)
+}
+#endif
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication app(argc, argv);
+    app.setAttribute(Qt::AA_Use96Dpi, true);
+    QTEST_SET_MAIN_SOURCE_PATH
+#ifdef RUN_ALL_TESTS
+    run_all_tests();
+#endif
+}
-- 
GitLab