Add test cases for ds_{box,fbox}_transform() 75/295975/1 accepted/tizen/unified/20230720.164642
authorSeunghun Lee <shiin.lee@samsung.com>
Mon, 17 Jul 2023 06:56:06 +0000 (15:56 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 18 Jul 2023 04:20:08 +0000 (13:20 +0900)
How to run unittests with meson

$ meson setup builddir -Dtests=true
$ meson test -C builddir

Change-Id: I3ee8626d0871fd00591187191fccb8199d177c06

tests/box-test.c [new file with mode: 0644]
tests/meson.build

diff --git a/tests/box-test.c b/tests/box-test.c
new file mode 100644 (file)
index 0000000..96e6ca7
--- /dev/null
@@ -0,0 +1,91 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <libds/util/box.h>
+
+static void
+test_box_transform(void)
+{
+    const int width = 800, height = 600;
+    struct ds_box src = { 10, 20, 300, 400 };
+    struct ds_box transform90 = { 180, 10, 400, 300 },
+                  transform180 = { 490, 180, 300, 400 },
+                  transform270 = { 20, 490, 400, 300 },
+                  transform_flipped = { 490, 20, 300, 400 },
+                  transform_flipped90 = { 20, 10, 400, 300 },
+                  transform_flipped180 = { 10, 180, 300, 400 },
+                  transform_flipped270 = { 180, 490, 400, 300 };
+    struct ds_box result;
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_NORMAL, width, height);
+    assert(memcmp(&result, &src, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_90, width, height);
+    assert(memcmp(&result, &transform90, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_180, width, height);
+    assert(memcmp(&result, &transform180, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_270, width, height);
+    assert(memcmp(&result, &transform270, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED, width, height);
+    assert(memcmp(&result, &transform_flipped, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_90, width, height);
+    assert(memcmp(&result, &transform_flipped90, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_180, width, height);
+    assert(memcmp(&result, &transform_flipped180, sizeof(struct ds_box)) == 0);
+
+    ds_box_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_270, width, height);
+    assert(memcmp(&result, &transform_flipped270, sizeof(struct ds_box)) == 0);
+}
+
+static void
+test_fbox_transform(void)
+{
+    const int width = 800, height = 600;
+    struct ds_fbox src = { 10.0, 20.0, 300.0, 400.0 };
+    struct ds_fbox transform90 = { 180.0, 10.0, 400.0, 300.0 },
+                  transform180 = { 490.0, 180.0, 300.0, 400.0 },
+                  transform270 = { 20.0, 490.0, 400.0, 300.0 },
+                  transform_flipped = { 490.0, 20.0, 300.0, 400.0 },
+                  transform_flipped90 = { 20.0, 10.0, 400.0, 300.0 },
+                  transform_flipped180 = { 10.0, 180.0, 300.0, 400.0 },
+                  transform_flipped270 = { 180.0, 490.0, 400.0, 300.0 };
+    struct ds_fbox result;
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_NORMAL, width, height);
+    assert(memcmp(&result, &src, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_90, width, height);
+    assert(memcmp(&result, &transform90, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_180, width, height);
+    assert(memcmp(&result, &transform180, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_270, width, height);
+    assert(memcmp(&result, &transform270, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED, width, height);
+    assert(memcmp(&result, &transform_flipped, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_90, width, height);
+    assert(memcmp(&result, &transform_flipped90, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_180, width, height);
+    assert(memcmp(&result, &transform_flipped180, sizeof(struct ds_box)) == 0);
+
+    ds_fbox_transform(&result, &src, WL_OUTPUT_TRANSFORM_FLIPPED_270, width, height);
+    assert(memcmp(&result, &transform_flipped270, sizeof(struct ds_box)) == 0);
+}
+
+int
+main(int argc, char *argv[])
+{
+    test_box_transform();
+    test_fbox_transform();
+
+    return 0;
+}
index 6314d8a..679252d 100644 (file)
@@ -13,3 +13,26 @@ executable('libds-tests',
   install_dir: libds_bindir,
   install : true
 )
+
+tests = [
+  'box',
+]
+
+foreach t : tests
+  source_name = t + '-test.c'
+  t_exe = executable(
+    t,
+    source_name,
+    include_directories: common_inc,
+    dependencies: [
+      dep_libds,
+    ],
+    install: false,
+  )
+
+  test(
+    t,
+    t_exe,
+    timeout: 5,
+  )
+endforeach