summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWoochanlee <wc0917.lee@samsung.com>2020-01-08 07:59:11 -0500
committerChristopher Michael <cp.michael@samsung.com>2020-01-08 07:59:11 -0500
commit4ea865623df83b78830dc253bcddd7e64a7810ca (patch)
tree69642ba8ae1a1fdd7e2e60c3bcf38c17454b51d9
parent7378056116ffb35c01e47126feda61ca2e0a8ff2 (diff)
tests/ecore_wl2: Add test for ecore_wl2_window_xxx functions
Summary: Add below APIs. ecore_wl2_window_commit ecore_wl2_window_frame_callback_add, del ecore_wl2_window_free ecore_wl2_window_hide ecore_wl2_window_shell_surface_exists ecore_wl2_window_show ecore_wl2_window_update_begin + Fix ecore_wl2_activated_get() ref T8016 Reviewers: devilhorns Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8016 Differential Revision: https://phab.enlightenment.org/D11007
-rw-r--r--src/tests/ecore_wl2/ecore_wl2_test_window.c508
-rw-r--r--src/tests/ecore_wl2/meson.build10
2 files changed, 501 insertions, 17 deletions
diff --git a/src/tests/ecore_wl2/ecore_wl2_test_window.c b/src/tests/ecore_wl2/ecore_wl2_test_window.c
index bb329195ef..66b76a3eb9 100644
--- a/src/tests/ecore_wl2/ecore_wl2_test_window.c
+++ b/src/tests/ecore_wl2/ecore_wl2_test_window.c
@@ -7,26 +7,92 @@
7#include <Eina.h> 7#include <Eina.h>
8#include <Ecore.h> 8#include <Ecore.h>
9#include <Ecore_Wl2.h> 9#include <Ecore_Wl2.h>
10#include <wayland-egl.h>
11
12#ifdef GL_GLES
13#include <EGL/egl.h>
14#include <GLES2/gl2.h>
15#endif
10 16
11#include "ecore_wl2_suite.h" 17#include "ecore_wl2_suite.h"
12 18
19#define WIDTH 480
20#define HEIGHT 360
21
22typedef struct _Test_Data {
23 Ecore_Wl2_Display *display;
24 Ecore_Wl2_Window *win;
25 Ecore_Wl2_Frame_Cb_Handle *frame_callback_handler;
26 Ecore_Event_Handler *handler;
27
28 struct wl_surface *surface;
29 struct wl_egl_window *egl_window;
30
31 int width;
32 int height;
33 int frame_callback_count;
34
35#ifdef GL_GLES
36 EGLDisplay egl_display;
37 EGLConfig egl_conf;
38 EGLSurface egl_surface;
39 EGLContext egl_context;
40#endif
41} Test_Data;
42
13static Ecore_Wl2_Display * 43static Ecore_Wl2_Display *
14_display_connect(void) 44_display_connect(void)
15{ 45{
16 Ecore_Wl2_Display *disp; 46 return ecore_wl2_display_connect(NULL);
17
18 disp = ecore_wl2_display_connect(NULL);
19 return disp;
20} 47}
21 48
22static Ecore_Wl2_Window * 49static Ecore_Wl2_Window *
23_window_create(Ecore_Wl2_Display *disp) 50_window_create(Ecore_Wl2_Display *disp)
24{ 51{
25 Ecore_Wl2_Window *win; 52 return ecore_wl2_window_new(disp, NULL, 100, 100, WIDTH, HEIGHT);
53}
26 54
27 win = ecore_wl2_window_new(disp, NULL, 100, 100, 500, 500); 55static struct wl_surface *
28 return win; 56_surface_get(Ecore_Wl2_Window *win)
57{
58 return ecore_wl2_window_surface_get(win);
59}
60
61#ifdef GL_GLES
62static void
63_init_egl(Test_Data *td)
64{
65 eglBindAPI(EGL_OPENGL_API);
66 EGLint num_config;
67
68 EGLint attributes[] = {
69 EGL_RED_SIZE, 8,
70 EGL_GREEN_SIZE, 8,
71 EGL_BLUE_SIZE, 8,
72 EGL_NONE
73 };
74
75 td->egl_display = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(td->display));
76 eglInitialize(td->egl_display, NULL, NULL);
77 eglChooseConfig(td->egl_display, attributes, &td->egl_conf, 1, &num_config);
78 td->egl_context = eglCreateContext(td->egl_display, td->egl_conf, EGL_NO_CONTEXT, NULL);
79
80 td->egl_window = wl_egl_window_create(td->surface, td->width, td->height);
81 td->egl_surface = eglCreateWindowSurface(td->egl_display,
82 td->egl_conf, td->egl_window, NULL);
83
84 eglMakeCurrent(td->egl_display, td->egl_surface, td->egl_surface, td->egl_context);
85}
86
87static void
88_term_egl(Test_Data *td)
89{
90 eglDestroySurface(td->egl_display, td->egl_surface);
91 wl_egl_window_destroy(td->egl_window);
92 eglDestroyContext(td->egl_display, td->egl_context);
93 eglTerminate(td->egl_display);
29} 94}
95#endif
30 96
31EFL_START_TEST(wl2_window_new) 97EFL_START_TEST(wl2_window_new)
32{ 98{
@@ -329,23 +395,93 @@ EFL_START_TEST(wl2_window_type)
329} 395}
330EFL_END_TEST 396EFL_END_TEST
331 397
398#ifdef GL_GLES
399static void
400_test_activated_frame_cb(Ecore_Wl2_Window *win EINA_UNUSED, uint32_t timestamp EINA_UNUSED, void *data)
401{
402 Test_Data *td = data;
403
404 td->frame_callback_count++;
405 if (td->frame_callback_count % 4 == 0)
406 glClearColor(0.0, 1.0, 0.0, 0.0);
407 else if (td->frame_callback_count % 4 == 1)
408 glClearColor(0.0, 0.0, 1.0, 0.0);
409 else if (td->frame_callback_count % 4 == 2)
410 glClearColor(0.0, 0.0, 0.0, 1.0);
411 else
412 glClearColor(1.0, 0.0, 0.0, 0.0);
413 glClear(GL_COLOR_BUFFER_BIT);
414 glFlush();
415
416 eglSwapBuffers(td->egl_display, td->egl_surface);
417
418 ecore_wl2_window_commit(td->win, EINA_TRUE);
419}
420
421static Eina_Bool
422_test_activated_configure_complete(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
423{
424 Test_Data *td = data;
425
426 td->frame_callback_handler = ecore_wl2_window_frame_callback_add(td->win, _test_activated_frame_cb, td);
427 ecore_wl2_window_commit(td->win, EINA_TRUE);
428
429 return ECORE_CALLBACK_PASS_ON;
430}
431
432static Eina_Bool
433_test_activated_window_activate(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
434{
435 //TC Pass
436 ecore_main_loop_quit();
437
438 return ECORE_CALLBACK_PASS_ON;
439}
440
332EFL_START_TEST(wl2_window_activated) 441EFL_START_TEST(wl2_window_activated)
333{ 442{
334 Ecore_Wl2_Display *disp; 443 Test_Data *td;
335 Ecore_Wl2_Window *win;
336 Eina_Bool ret;
337 444
338 disp = _display_connect(); 445 ecore_wl2_init();
339 ck_assert(disp != NULL);
340 446
341 win = _window_create(disp); 447 td = calloc(1, sizeof(Test_Data));
342 ck_assert(win != NULL); 448 td->width = WIDTH;
449 td->height = HEIGHT;
450 td->frame_callback_count = 0;
343 451
344 ret = ecore_wl2_window_activated_get(win); 452 td->display = _display_connect();
453 ck_assert(td->display != NULL);
345 454
346 fail_if(ret != EINA_TRUE); 455 td->win = _window_create(td->display);
456 ck_assert(td->win != NULL);
457
458 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
459
460 td->surface = _surface_get(td->win);
461 ck_assert(td->surface != NULL);
462
463 ecore_wl2_window_show(td->win);
464
465 _init_egl(td);
466 td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE_COMPLETE,
467 _test_activated_configure_complete, td);
468 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ACTIVATE,
469 _test_activated_window_activate, NULL);
470
471 ecore_main_loop_begin();
472
473 _term_egl(td);
474 ecore_wl2_shutdown();
475 free(td);
476}
477EFL_END_TEST
478#else
479EFL_START_TEST(wl2_window_activated)
480{
481 fail_if("No GL enabled GL should be enabled for API test");
347} 482}
348EFL_END_TEST 483EFL_END_TEST
484#endif
349 485
350EFL_START_TEST(wl2_window_aspect) 486EFL_START_TEST(wl2_window_aspect)
351{ 487{
@@ -454,6 +590,339 @@ EFL_START_TEST(wl2_window_role)
454} 590}
455EFL_END_TEST 591EFL_END_TEST
456 592
593static void
594_test_commit_frame_cb(Ecore_Wl2_Window *win EINA_UNUSED, uint32_t timestamp EINA_UNUSED, void *data)
595{
596 Test_Data *td = data;
597 td->frame_callback_count++;
598 ecore_main_loop_quit();
599}
600
601static Eina_Bool
602_test_commit_configure_complete(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
603{
604 Test_Data *td = data;
605
606 td->frame_callback_handler = ecore_wl2_window_frame_callback_add(td->win, _test_commit_frame_cb, td);
607 ecore_wl2_window_commit(td->win, EINA_TRUE);
608
609 return ECORE_CALLBACK_PASS_ON;
610}
611
612EFL_START_TEST(wl2_window_commit)
613{
614 Test_Data *td;
615
616 ecore_wl2_init();
617
618 td = calloc(1, sizeof(Test_Data));
619 td->width = WIDTH;
620 td->height = HEIGHT;
621 td->frame_callback_count = 0;
622
623 td->display = _display_connect();
624 ck_assert(td->display != NULL);
625
626 td->win = _window_create(td->display);
627 ck_assert(td->win != NULL);
628
629 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
630
631 td->surface = _surface_get(td->win);
632 ck_assert(td->surface != NULL);
633
634 ecore_wl2_window_show(td->win);
635
636 td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE_COMPLETE,
637 _test_commit_configure_complete, td);
638
639 ecore_main_loop_begin();
640
641 //Check if the frame callback was called properly by ecore_wl2_window_commit().
642 fail_if(td->frame_callback_count == 0);
643
644 ecore_wl2_shutdown();
645 free(td);
646}
647EFL_END_TEST
648
649static void
650_test_frame_callback_frame_cb(Ecore_Wl2_Window *win EINA_UNUSED, uint32_t timestamp EINA_UNUSED, void *data)
651{
652 Test_Data *td = data;
653 td->frame_callback_count++;
654 if (td->frame_callback_count == 1)
655 {
656 ecore_wl2_window_frame_callback_del(td->frame_callback_handler);
657 td->frame_callback_handler = NULL;
658 ecore_main_loop_quit();
659 }
660}
661
662static Eina_Bool
663_test_frame_callback_configure_complete(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
664{
665 Test_Data *td = data;
666
667 td->frame_callback_handler = ecore_wl2_window_frame_callback_add(td->win, _test_frame_callback_frame_cb, td);
668 ecore_wl2_window_commit(td->win, EINA_TRUE);
669
670 return ECORE_CALLBACK_PASS_ON;
671}
672
673EFL_START_TEST(wl2_window_frame_callback)
674{
675 Test_Data *td;
676
677 ecore_wl2_init();
678
679 td = calloc(1, sizeof(Test_Data));
680 td->width = WIDTH;
681 td->height = HEIGHT;
682 td->frame_callback_count = 0;
683
684 td->display = _display_connect();
685 ck_assert(td->display != NULL);
686
687 td->win = _window_create(td->display);
688 ck_assert(td->win != NULL);
689
690 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
691
692 td->surface = _surface_get(td->win);
693 ck_assert(td->surface != NULL);
694
695 ecore_wl2_window_show(td->win);
696
697 td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE_COMPLETE,
698 _test_frame_callback_configure_complete, td);
699
700 ecore_main_loop_begin();
701
702 //Check if the frame callback called after then it sets NULL or not.
703 fail_if(td->frame_callback_count != 1);
704 fail_if(td->frame_callback_handler != NULL);
705
706 ecore_wl2_shutdown();
707 free(td);
708}
709EFL_END_TEST
710
711EFL_START_TEST(wl2_window_free)
712{
713 Ecore_Wl2_Window *t_win;
714 Test_Data *td;
715
716 ecore_wl2_init();
717
718 td = calloc(1, sizeof(Test_Data));
719
720 td->display = _display_connect();
721 ck_assert(td->display != NULL);
722
723 td->win = _window_create(td->display);
724 ck_assert(td->win != NULL);
725
726 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
727
728 td->surface = _surface_get(td->win);
729 ck_assert(td->surface != NULL);
730
731 ecore_wl2_window_show(td->win);
732
733 t_win = ecore_wl2_display_window_find_by_surface(td->display, td->surface);
734
735 fail_if(td->win != t_win);
736
737 ecore_wl2_window_free(td->win);
738 t_win = ecore_wl2_display_window_find_by_surface(td->display, td->surface);
739
740 //Check the returned window with freed window.
741 fail_if(td->win == t_win);
742
743 ecore_wl2_shutdown();
744 free(td);
745}
746EFL_END_TEST
747
748static Eina_Bool
749_test_hide_window_hide(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
750{
751 //TC pass
752 ecore_main_loop_quit();
753
754 return ECORE_CALLBACK_PASS_ON;
755}
756
757EFL_START_TEST(wl2_window_hide)
758{
759 Test_Data *td;
760
761 ecore_wl2_init();
762
763 td = calloc(1, sizeof(Test_Data));
764 td->width = WIDTH;
765 td->height = HEIGHT;
766 td->frame_callback_count = 0;
767
768 td->display = _display_connect();
769 ck_assert(td->display != NULL);
770
771 td->win = _window_create(td->display);
772 ck_assert(td->win != NULL);
773
774 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
775
776 td->surface = _surface_get(td->win);
777 ck_assert(td->surface != NULL);
778
779 ecore_wl2_window_show(td->win);
780
781 ecore_wl2_window_hide(td->win);
782 td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_HIDE,
783 _test_hide_window_hide, NULL);
784
785 ecore_main_loop_begin();
786
787 ecore_wl2_shutdown();
788 free(td);
789}
790EFL_END_TEST
791
792EFL_START_TEST(wl2_window_shell_surface_exists)
793{
794 Test_Data *td;
795
796 ecore_wl2_init();
797
798 td = calloc(1, sizeof(Test_Data));
799 td->width = WIDTH;
800 td->height = HEIGHT;
801 td->frame_callback_count = 0;
802
803 td->display = _display_connect();
804 ck_assert(td->display != NULL);
805
806 td->win = _window_create(td->display);
807 ck_assert(td->win != NULL);
808
809 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
810
811 td->surface = _surface_get(td->win);
812 ck_assert(td->surface != NULL);
813
814 ecore_wl2_window_show(td->win);
815
816 //window_show function will create shell surface. then checks it.
817 fail_if(ecore_wl2_window_shell_surface_exists(td->win) == EINA_FALSE);
818
819 ecore_wl2_shutdown();
820 free(td);
821}
822EFL_END_TEST
823
824static Eina_Bool
825_test_show_window_show(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
826{
827 //TC pass
828 ecore_main_loop_quit();
829
830 return ECORE_CALLBACK_PASS_ON;
831}
832
833EFL_START_TEST(wl2_window_show)
834{
835 Test_Data *td;
836
837 ecore_wl2_init();
838
839 td = calloc(1, sizeof(Test_Data));
840 td->width = WIDTH;
841 td->height = HEIGHT;
842 td->frame_callback_count = 0;
843
844 td->display = _display_connect();
845 ck_assert(td->display != NULL);
846
847 td->win = _window_create(td->display);
848 ck_assert(td->win != NULL);
849
850 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
851
852 td->surface = _surface_get(td->win);
853 ck_assert(td->surface != NULL);
854
855 ecore_wl2_window_show(td->win);
856
857 td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
858 _test_show_window_show, NULL);
859
860 ecore_main_loop_begin();
861
862 ecore_wl2_shutdown();
863 free(td);
864}
865EFL_END_TEST
866
867static Eina_Bool _window_configure_event_called = EINA_FALSE;
868
869static Eina_Bool
870_test_update_window_configure(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
871{
872 _window_configure_event_called = EINA_TRUE;
873
874 return ECORE_CALLBACK_PASS_ON;
875}
876
877static Eina_Bool
878_test_update_window_configure_complete(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
879{
880 //Checks if the configure_complete calling before configure calling
881 //when ecore_wl2_window_update_begin() called.
882 fail_if(_window_configure_event_called == EINA_TRUE);
883
884 ecore_main_loop_quit();
885
886 return ECORE_CALLBACK_PASS_ON;
887}
888
889EFL_START_TEST(wl2_window_update_begin)
890{
891 Test_Data *td;
892
893 ecore_wl2_init();
894
895 td = calloc(1, sizeof(Test_Data));
896 td->width = WIDTH;
897 td->height = HEIGHT;
898 td->frame_callback_count = 0;
899
900 td->display = _display_connect();
901 ck_assert(td->display != NULL);
902
903 td->win = _window_create(td->display);
904 ck_assert(td->win != NULL);
905
906 ecore_wl2_window_type_set(td->win, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
907
908 td->surface = _surface_get(td->win);
909 ck_assert(td->surface != NULL);
910
911 ecore_wl2_window_show(td->win);
912
913 ecore_wl2_window_update_begin(td->win);
914 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE,
915 _test_update_window_configure, NULL);
916 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE_COMPLETE,
917 _test_update_window_configure_complete, NULL);
918
919 ecore_main_loop_begin();
920
921 ecore_wl2_shutdown();
922 free(td);
923}
924EFL_END_TEST
925
457void 926void
458ecore_wl2_test_window(TCase *tc) 927ecore_wl2_test_window(TCase *tc)
459{ 928{
@@ -483,5 +952,12 @@ ecore_wl2_test_window(TCase *tc)
483 tcase_add_test(tc, wl2_window_class); 952 tcase_add_test(tc, wl2_window_class);
484 tcase_add_test(tc, wl2_window_title); 953 tcase_add_test(tc, wl2_window_title);
485 tcase_add_test(tc, wl2_window_role); 954 tcase_add_test(tc, wl2_window_role);
955 tcase_add_test(tc, wl2_window_commit);
956 tcase_add_test(tc, wl2_window_frame_callback);
957 tcase_add_test(tc, wl2_window_free);
958 tcase_add_test(tc, wl2_window_hide);
959 tcase_add_test(tc, wl2_window_shell_surface_exists);
960 tcase_add_test(tc, wl2_window_show);
961 tcase_add_test(tc, wl2_window_update_begin);
486 } 962 }
487} 963}
diff --git a/src/tests/ecore_wl2/meson.build b/src/tests/ecore_wl2/meson.build
index eb1a13db6a..2491b6d631 100644
--- a/src/tests/ecore_wl2/meson.build
+++ b/src/tests/ecore_wl2/meson.build
@@ -8,9 +8,17 @@ ecore_wl2_suite_src = [
8 'ecore_wl2_test_input.c' 8 'ecore_wl2_test_input.c'
9] 9]
10 10
11wl2_test_gl_deps = []
12
13if get_option('opengl') == 'es-egl'
14 wl2_test_gl_deps += dependency('egl')
15 wl2_test_gl_deps += dependency('gl')
16endif
17
11ecore_wl2_suite = executable('ecore_wl2_suite', 18ecore_wl2_suite = executable('ecore_wl2_suite',
12 ecore_wl2_suite_src, 19 ecore_wl2_suite_src,
13 dependencies: [ecore_wl2, ecore, check, wayland_protocol], 20 dependencies: [ecore_wl2, ecore, ecore_input, check, wayland_protocol, wayland_client, dependency('wayland-egl'), wl2_test_gl_deps],
21
14 c_args : [ 22 c_args : [
15 '-DTESTS_BUILD_DIR="'+meson.current_build_dir()+'"', 23 '-DTESTS_BUILD_DIR="'+meson.current_build_dir()+'"',
16 '-DTESTS_SRC_DIR="'+meson.current_source_dir()+'"'] 24 '-DTESTS_SRC_DIR="'+meson.current_source_dir()+'"']