test: Add test for ds_surface_get_buffer_source_box() 66/304866/1 accepted/tizen/unified/20240125.112705 accepted/tizen/unified/x/20240205.063658
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 17 Jan 2024 00:46:47 +0000 (09:46 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Thu, 25 Jan 2024 02:49:56 +0000 (11:49 +0900)
Change-Id: I2c82eaef33a14a1b548da107eeba3c17b44bcdd5

tests/meson.build
tests/surface-test.c [moved from tests/test-surface.c with 66% similarity]

index 1d66f1d..340c298 100644 (file)
@@ -17,6 +17,7 @@ executable('libds-tests',
 tests = [
   'box',
   'allocator',
+  'surface',
 ]
 
 foreach t : tests
similarity index 66%
rename from tests/test-surface.c
rename to tests/surface-test.c
index eab2b77..fcd8b2d 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <wayland-server.h>
 #include <wayland-client.h>
+#include <libds/types/ds_surface.h>
 #include <libds/compositor.h>
 #include <libds/surface.h>
 #include <libds/log.h>
@@ -128,7 +129,7 @@ run_client(const char *name)
 }
 
 static void
-test_surface_create_and_destroy(void)
+test_ds_surface_create_and_destroy(void)
 {
     struct test_server server = { .cb_called = false };
     pid_t pid;
@@ -154,9 +155,56 @@ test_surface_create_and_destroy(void)
     test_server_finish(&server.base);
 }
 
+static void
+test_ds_surface_get_buffer_source_box(void)
+{
+    struct ds_surface surface = {
+        .current = {
+            .buffer_width = 1920,
+            .buffer_height = 1080,
+            .scale = 1,
+            .transform = WL_OUTPUT_TRANSFORM_NORMAL,
+            .viewport = {
+                .has_src = false,
+                .src = {
+                    .x = 100,
+                    .y = 100,
+                    .width = 800,
+                    .height = 600,
+                }
+            }
+        }
+    };
+
+    struct ds_fbox box;
+
+    ds_surface_get_buffer_source_box(&surface, &box);
+    assert(box.x == 0.0 && box.y == 0.0 && box.width == 1920.0 && box.height == 1080.0);
+
+    surface.current.viewport.has_src = true;
+    surface.current.transform = WL_OUTPUT_TRANSFORM_90;
+    ds_surface_get_buffer_source_box(&surface, &box);
+    assert(box.x == 100.0 && box.y == 180.0 && box.width == 600.0 && box.height == 800.0);
+
+    surface.current.scale = 2;
+    surface.current.buffer_width *= surface.current.scale;
+    surface.current.buffer_height *= surface.current.scale;
+    ds_surface_get_buffer_source_box(&surface, &box);
+    assert(box.x == 200.0 && box.y == 360.0 && box.width == 1200.0 && box.height == 1600.0);
+
+    surface.current.transform = WL_OUTPUT_TRANSFORM_270;
+    ds_surface_get_buffer_source_box(&surface, &box);
+    assert(box.x == 2440.0 && box.y == 200.0 && box.width == 1200.0 && box.height == 1600.0);
+
+    surface.current.transform = WL_OUTPUT_TRANSFORM_180;
+    ds_surface_get_buffer_source_box(&surface, &box);
+    assert(box.x == 2040.0 && box.y == 760.0 && box.width == 1600.0 && box.height == 1200.0);
+}
+
 int
 main(void)
 {
-    test_surface_create_and_destroy();
+    test_ds_surface_create_and_destroy();
+    test_ds_surface_get_buffer_source_box();
     return 0;
 }