test Canvas: Set up unit test based on gtest.
authorJunsuChoi <jsuya.choi@samsung.com>
Thu, 29 Oct 2020 10:45:21 +0000 (19:45 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 3 Nov 2020 03:17:47 +0000 (12:17 +0900)
In test directory, set up unit_test based on gtest
First, add a test for SwCanvas generate.

Change-Id: I2b7ab96b5f7bc17408cc43cebda2ec731f73d1e7

meson.build
meson_options.txt
test/meson.build [new file with mode: 0644]
test/test_canvas.cpp [new file with mode: 0644]
test/testsuite.cpp [new file with mode: 0644]

index 8cff0aa..3673c53 100644 (file)
@@ -38,16 +38,22 @@ headers = [include_directories('inc'), include_directories('.')]
 subdir('inc')
 subdir('src')
 
+if get_option('test') == true
+   subdir('test')
+endif
+
 summary = '''
 
 Summary:
     thorvg version :        @0@
     Build type      :       @1@
     Prefix          :       @2@
+    Test            :       @3@
 '''.format(
         meson.project_version(),
         get_option('buildtype'),
         get_option('prefix'),
+        get_option('test'),
     )
 
 message(summary)
index d784bb2..b14e3b5 100644 (file)
@@ -32,3 +32,8 @@ option('examples',
     type: 'boolean',
     value: false,
     description: 'Enable building examples')
+
+option('test',
+   type: 'boolean',
+   value: false,
+   description: 'Enable building unit tests')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644 (file)
index 0000000..61286fc
--- /dev/null
@@ -0,0 +1,19 @@
+
+#TODO:Need to change warning level to 3
+override_default = ['warning_level=0', 'werror=false']
+
+gtest_dep  = dependency('gtest')
+
+canvas_test_sources = [
+    'testsuite.cpp',
+    'test_canvas.cpp',
+    ]
+
+canvas_testsuite = executable('canvasTestSuite',
+                              canvas_test_sources,
+                              include_directories : headers,
+                              override_options : override_default,
+                              dependencies : [gtest_dep, thorvg_lib_dep],
+                              )
+
+test('Canvas Testsuite', canvas_testsuite)
diff --git a/test/test_canvas.cpp b/test/test_canvas.cpp
new file mode 100644 (file)
index 0000000..e74ac89
--- /dev/null
@@ -0,0 +1,28 @@
+#include <gtest/gtest.h>
+#include <iostream>
+#include <thread>
+#include <thorvg.h>
+
+class CanvasTest : public ::testing::Test {
+public:
+    void SetUp() {
+        auto threads = std::thread::hardware_concurrency();
+        //Initialize ThorVG Engine
+        if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
+            swCanvas = tvg::SwCanvas::gen();
+        }
+    }
+    void TearDown() {
+
+        //Terminate ThorVG Engine
+        tvg::Initializer::term(tvgEngine);
+    }
+public:
+    std::unique_ptr<tvg::SwCanvas> swCanvas;
+    tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
+};
+
+TEST_F(CanvasTest, GenerateCanvas) {
+    ASSERT_TRUE(swCanvas != nullptr);
+}
+
diff --git a/test/testsuite.cpp b/test/testsuite.cpp
new file mode 100644 (file)
index 0000000..5633721
--- /dev/null
@@ -0,0 +1,7 @@
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv) {
+    testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
+