tc: Add test cases for testing libtpl-egl 83/94583/2
authorHoyub Lee <hoyub.lee@samsung.com>
Mon, 31 Oct 2016 12:48:50 +0000 (21:48 +0900)
committerGwan-gyeong Mun <kk.moon@samsung.com>
Tue, 24 Jan 2017 07:40:39 +0000 (23:40 -0800)
Change-Id: I2ddab75f5ffd0b0e6ccf64f087f07bc1fcdeef1e
Signed-off-by: Hoyub Lee <hoyub.lee@samsung.com>
tc/test/tpl-test_display_test.cpp [new file with mode: 0644]
tc/test/tpl-test_object_test.cpp [new file with mode: 0644]
tc/test/tpl-test_surface_test.cpp [new file with mode: 0644]

diff --git a/tc/test/tpl-test_display_test.cpp b/tc/test/tpl-test_display_test.cpp
new file mode 100644 (file)
index 0000000..f76f901
--- /dev/null
@@ -0,0 +1,137 @@
+/**
+ * @file tpl-test_display_test.cpp
+ * @brief TPL Test case of display
+ *
+ */
+
+#include "gtest/gtest.h"
+
+#include "src/tpl-test_base.h"
+
+
+class TPLDisplay : public TPLTestBase {};
+class TPLDisplaySupport : public TPLDisplay {};
+
+
+// Tests tpl_display_get(tpl_handle_t)
+TEST_F(TPLDisplay, tpl_display_get)
+{
+       tpl_display_t *tpl_display = tpl_display_get(backend->display_handle);
+
+       ASSERT_EQ(tpl_display, backend->tpl_display);
+}
+
+
+// Tests tpl_display_get_native_handle(tpl_handle_t)
+TEST_F(TPLDisplay, tpl_display_get_native_handle)
+{
+       tpl_handle_t display_handle =
+               tpl_display_get_native_handle(backend->tpl_display);
+
+       ASSERT_EQ(display_handle, backend->display_handle);
+}
+
+
+// Tests tpl_display_query_config(...)
+//
+// 1. Tests with normal cases
+// 2. Tests with abnormal case
+TEST_F(TPLDisplay, tpl_display_query_config)
+{
+       tpl_result_t result;
+
+       // #1: Normal case
+       // Expected Value: TPL_ERROR_NONE
+       result = tpl_display_query_config(backend->tpl_display,
+                                                                         TPL_SURFACE_TYPE_WINDOW,
+                                                                         8,            // red size
+                                                                         8,            // green size
+                                                                         8,            // blue size
+                                                                         8,            // alpha size
+                                                                         32,           // depth size
+                                                                         NULL,
+                                                                         NULL);
+
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+
+       // #2: Normal case
+       // Expected Value: TPL_ERROR_NONE
+       result = tpl_display_query_config(backend->tpl_display,
+                                                                         TPL_SURFACE_TYPE_WINDOW,
+                                                                         8,
+                                                                         8,
+                                                                         8,
+                                                                         8,
+                                                                         24,
+                                                                         NULL,
+                                                                         NULL);
+
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+
+       // #3: Abnormal case
+       // Expected Value: not TPL_ERROR_NONE
+       result = tpl_display_query_config(backend->tpl_display,
+                                                                         TPL_SURFACE_TYPE_WINDOW,
+                                                                         0,            // red size can't be zero
+                                                                         8,
+                                                                         8,
+                                                                         8,
+                                                                         24,
+                                                                         NULL,
+                                                                         NULL);
+
+       ASSERT_NE(TPL_ERROR_NONE, result);
+}
+
+
+// Tests tpl_display_filter_config(...)
+TEST_F(TPLDisplay, tpl_display_filter_config)
+{
+       tpl_result_t result;
+       int test_visual_id = GBM_FORMAT_ARGB8888;
+       result = tpl_display_filter_config(backend->tpl_display,
+                        &test_visual_id, 0);
+
+       // Expected Value: TPL_ERROR_NONE
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+}
+
+
+// Tests tpl_display_get_native_window_info(...)
+TEST_F(TPLDisplay, tpl_display_get_native_window_info)
+{
+       tpl_result_t result;
+       int width, height;
+       tbm_format format;
+
+       result = tpl_display_get_native_window_info(backend->tpl_display,
+                        backend->surface_handle, &width, &height, &format,
+                        config.depth, 8);
+
+       EXPECT_EQ(config.width, width);
+       EXPECT_EQ(config.height, height);
+       EXPECT_EQ(TBM_FORMAT_ARGB8888, format);
+
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+}
+
+
+TEST_F(TPLDisplaySupport,
+          tpl_display_query_supported_buffer_count_from_native_window)
+{
+       tpl_result_t result;
+       int min, max;
+
+       result = tpl_display_query_supported_buffer_count_from_native_window(
+                        backend->tpl_display, backend->surface_handle,
+                        &min, &max);
+
+       // SUCCEED() if backend does not support operation
+       if (result == TPL_ERROR_INVALID_OPERATION) {
+               SUCCEED() << "Backend does not support this operation";
+               return;
+       }
+
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+}
+
diff --git a/tc/test/tpl-test_object_test.cpp b/tc/test/tpl-test_object_test.cpp
new file mode 100644 (file)
index 0000000..e292fa7
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * @file tpl-test_object_test.cpp
+ * @brief TPL Test case of object
+ *
+ */
+
+#include "gtest/gtest.h"
+
+#include "src/tpl-test_base.h"
+
+
+class TPLObject : public TPLTestBase {};
+
+
+// Tests tpl_object_get_type(tpl_object_t *)
+TEST_F(TPLObject, tpl_object_get_type)
+{
+       int obj_type = -1;
+       obj_type = tpl_object_get_type((tpl_object_t *)backend->tpl_display);
+       ASSERT_EQ(TPL_OBJECT_DISPLAY, obj_type);
+
+       obj_type = -1;
+       obj_type = tpl_object_get_type((tpl_object_t *)backend->tpl_surface);
+       ASSERT_EQ(TPL_OBJECT_SURFACE, obj_type);
+}
+
+
+// Tests setting user data flow:
+// 1. Set user data
+// 2. Get user data
+TEST_F(TPLObject, tpl_object_userdata_test)
+{
+       unsigned long key;
+
+       // TODO: Check
+       // set user data
+       tpl_object_set_user_data((tpl_object_t *)backend->tpl_display, &key,
+                                                        (void *)backend->display_handle, NULL);
+
+       // get user data
+       void *get_dpy = NULL;
+       get_dpy = (void *)tpl_object_get_user_data(
+                         (tpl_object_t *)backend->tpl_display, &key);
+
+       ASSERT_EQ(get_dpy, (void *)backend->display_handle);
+}
+
+// Tests object reference flow:
+// 1. Reference
+// 2. Unreference
+TEST_F(TPLObject, tpl_object_reference)
+{
+       // tpl_object_reference
+       tpl_object_reference((tpl_object_t *)backend->tpl_display);
+
+       // tpl_object_get_reference
+       int ref_count = -1;
+       ref_count = tpl_object_get_reference((tpl_object_t *)backend->tpl_display);
+       ASSERT_NE(-1, ref_count);
+
+       // tpl_object_unreference
+       int unref_count = -1;
+       unref_count = tpl_object_unreference((tpl_object_t *)backend->tpl_display);
+       ASSERT_EQ(ref_count - 1, unref_count);
+}
+
diff --git a/tc/test/tpl-test_surface_test.cpp b/tc/test/tpl-test_surface_test.cpp
new file mode 100644 (file)
index 0000000..d2066ab
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * @file tpl-test_surface_test.cpp
+ * @brief TPL Test case of surface
+ *
+ */
+
+#include "gtest/gtest.h"
+
+#include "src/tpl-test_base.h"
+
+
+class TPLSurface : public TPLTestBase {};
+class TPLSurfaceSupport : public TPLSurface {};
+
+
+// Tests tpl_surface_validate(tpl_surface_t *)
+TEST_F(TPLSurface, tpl_surface_validate)
+{
+       tpl_bool_t result = tpl_surface_validate(backend->tpl_surface);
+
+       // Expected Value: TPL_TRUE
+       ASSERT_EQ(TPL_TRUE, result);
+}
+
+
+TEST_F(TPLSurface, tpl_surface_get_args)
+{
+       // tpl_surface_get_display test
+       tpl_display_t *test_dpy = tpl_surface_get_display(backend->tpl_surface);
+       ASSERT_EQ(test_dpy, backend->tpl_display);
+
+       // tpl_surface_get_native_handle
+       tpl_handle_t test_handle =
+               tpl_surface_get_native_handle(backend->tpl_surface);
+       ASSERT_EQ(test_handle, backend->surface_handle);
+
+       // tpl_surface_get_type test
+       tpl_surface_type_t test_type = tpl_surface_get_type(backend->tpl_surface);
+       ASSERT_EQ(TPL_SURFACE_TYPE_WINDOW, test_type);
+
+       // tpl_surface_get_size test
+       int width, height;
+       tpl_result_t test_size =
+               tpl_surface_get_size(backend->tpl_surface, &width, &height);
+
+       EXPECT_EQ(config.width, width);
+       EXPECT_EQ(config.height, height);
+       ASSERT_EQ(TPL_ERROR_NONE, test_size);
+}
+
+
+// Tests simple normal buffer flow:
+// 1. Dequeue buffer by calling tpl_surface_dequeue_buffer
+// 2. Set post interval
+// 3. Enqueue buffer by calling tpl_surface_enqueue_buffer
+TEST_F(TPLSurface, tpl_surface_dequeue_and_enqueue_buffer_test)
+{
+       // dequeue
+       tbm_surface_h tbm_surf = NULL;
+       tbm_surf = tpl_surface_dequeue_buffer(backend->tpl_surface);
+       ASSERT_NE((void *)NULL, tbm_surf);
+
+       // set and get interval
+       int interval_set = 2;
+       tpl_surface_set_post_interval(backend->tpl_surface, interval_set);
+       int interval_get = tpl_surface_get_post_interval(backend->tpl_surface);
+       ASSERT_EQ(interval_set, interval_get);
+
+       // enqueue
+       tpl_result_t result = TPL_ERROR_INVALID_PARAMETER;
+       result = tpl_surface_enqueue_buffer(backend->tpl_surface, tbm_surf);
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+}
+
+
+TEST_F(TPLSurfaceSupport, tpl_surface_create_get_destroy_swapchain_test)
+{
+       int buffer_set = 2;
+       tpl_result_t result;
+
+       // Create swapchain
+       result = tpl_surface_create_swapchain(backend->tpl_surface,
+                        TBM_FORMAT_ARGB8888, config.width, config.height, buffer_set);
+
+       // SUCCEED() if backend does not support operation
+       if (result == TPL_ERROR_INVALID_OPERATION) {
+               SUCCEED() << "Backend does not support this operation";
+               return;
+       }
+
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+
+       tbm_surface_h **buffers;
+       int buffer_get;
+
+       // Get swapchain buffers
+       result = tpl_surface_get_swapchain_buffers(backend->tpl_surface,
+                        buffers, &buffer_get);
+
+       EXPECT_EQ(buffer_set, buffer_get);
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+
+       // Destroy swapchain
+       result = tpl_surface_destroy_swapchain(backend->tpl_surface);
+       ASSERT_EQ(TPL_ERROR_NONE, result);
+}
+