Skip to content

Commit

Permalink
test: add test_widget_event.c
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Dec 22, 2019
1 parent be745bd commit 949db38
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test/helloworld.css \
test/helloworld.xml \
test/test.c \
test/test.h \
test/test_render.c \
test/test_touch.c \
test/test_string.c \
test/test_object.c \
Expand Down Expand Up @@ -65,6 +66,7 @@ test/test_widget_inline_block_layout.c \
test/test_widget_inline_block_layout.css \
test/test_widget_inline_block_layout.xml \
test/test_widget_rect.c \
test/test_widget_event.c \
test/test_textview_resize.c \
test/test_textedit.c

Expand Down
1 change: 1 addition & 0 deletions build/windows/LCUITest/LCUITest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<ClCompile Include="..\..\..\test\test_textedit.c" />
<ClCompile Include="..\..\..\test\test_textview_resize.c" />
<ClCompile Include="..\..\..\test\test_thread.c" />
<ClCompile Include="..\..\..\test\test_widget_event.c" />
<ClCompile Include="..\..\..\test\test_widget_flex_layout.c" />
<ClCompile Include="..\..\..\test\test_widget_inline_block_layout.c" />
<ClCompile Include="..\..\..\test\test_widget_layout.c" />
Expand Down
3 changes: 3 additions & 0 deletions build/windows/LCUITest/LCUITest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClCompile Include="..\..\..\test\test_object.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\test_widget_event.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\test.h">
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ test_SOURCES = test.c test_charset.c test_css_parser.c test_xml_parser.c \
test_string.c test_font_load.c test_image_reader.c test_widget_rect.c \
test_widget_layout.c test_widget_flex_layout.c test_textview_resize.c \
test_widget_inline_block_layout.c test_thread.c test_widget_opacity.c \
test_strpool.c test_linkedlist.c test_textedit.c test_object.c
test_strpool.c test_linkedlist.c test_textedit.c test_object.c \
test_widget_event.c

test_LDADD = $(top_builddir)/src/libLCUI.la -lm $(CODE_COVERAGE_LIBS)

Expand Down
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int main(void)
ret += test_widget_layout();
ret += test_widget_flex_layout();
ret += test_widget_inline_block_layout();
ret += test_widget_event();
ret += test_widget_opacity();
ret += test_widget_rect();
ret += test_textview_resize();
Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int test_widget_flex_layout(void);
int test_widget_inline_block_layout(void);
int test_widget_rect(void);
int test_widget_opacity(void);
int test_widget_event(void);
int test_textview_resize(void);
int test_textedit(void);
int test_image_reader(void);
111 changes: 111 additions & 0 deletions test/test_widget_event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <stdio.h>
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/input.h>
#include <LCUI/gui/widget.h>
#include "test.h"

int test_widget_mouse_event(void)
{
int ret = 0;
LCUI_Widget root;
LCUI_Widget parent, child;
LCUI_SysEventRec ev;

LCUI_Init();
root = LCUIWidget_GetRoot();
parent = LCUIWidget_New("button");
child = LCUIWidget_New("textview");

Widget_Resize(root, 200, 200);
Widget_Resize(parent, 100, 100);
Widget_Resize(child, 50, 50);
Widget_Append(parent, child);
Widget_Append(root, parent);
LCUIWidget_Update();

ev.type = LCUI_MOUSEMOVE;
ev.motion.x = 150;
ev.motion.y = 150;
ev.motion.xrel = 0;
ev.motion.yrel = 0;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousemove(150, 150): root.hasStatus('hover') == true",
Widget_HasStatus(root, "hover"));
CHECK_WITH_TEXT("mousemove(150, 150): parent.hasStatus('hover') == false",
!Widget_HasStatus(parent, "hover"));
CHECK_WITH_TEXT("mousemove(150, 150): child.hasStatus('hover') == false",
!Widget_HasStatus(child, "hover"));

ev.motion.x = 80;
ev.motion.y = 80;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousemove(80, 80): root.hasStatus('hover') == true",
Widget_HasStatus(root, "hover"));
CHECK_WITH_TEXT("mousemove(80, 80): parent.hasStatus('hover') == true",
Widget_HasStatus(parent, "hover"));
CHECK_WITH_TEXT("mousemove(80, 80): child.hasStatus('hover') == false",
!Widget_HasStatus(child, "hover"));

ev.motion.x = 40;
ev.motion.y = 40;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousemove(40, 40): root.hasStatus('hover') == true",
Widget_HasStatus(root, "hover"));
CHECK_WITH_TEXT("mousemove(40, 40): parent.hasStatus('hover') == true",
Widget_HasStatus(parent, "hover"));
CHECK_WITH_TEXT("mousemove(40, 40): child.hasStatus('hover') == true",
Widget_HasStatus(child, "hover"));

ev.type = LCUI_MOUSEDOWN;
ev.button.x = 40;
ev.button.y = 40;
ev.button.button = LCUI_KEY_LEFTBUTTON;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousedown(40, 40): root.hasStatus('active') == true",
Widget_HasStatus(root, "active"));
CHECK_WITH_TEXT("mousedown(40, 40): parent.hasStatus('active') == true",
Widget_HasStatus(parent, "active"));
CHECK_WITH_TEXT("mousedown(40, 40): child.hasStatus('active') == true",
Widget_HasStatus(child, "active"));

ev.type = LCUI_MOUSEUP;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mouseup(40, 40): root.hasStatus('active') == false",
!Widget_HasStatus(root, "active"));
CHECK_WITH_TEXT("mouseup(40, 40): parent.hasStatus('active') == false",
!Widget_HasStatus(parent, "active"));
CHECK_WITH_TEXT("mouseup(40, 40): child.hasStatus('active') == false",
!Widget_HasStatus(child, "active"));

ev.type = LCUI_MOUSEMOVE;
ev.motion.x = 80;
ev.motion.y = 80;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousemove(80, 80): root.hasStatus('hover') == true",
Widget_HasStatus(root, "hover"));
CHECK_WITH_TEXT("mousemove(80, 80): parent.hasStatus('hover') == true",
Widget_HasStatus(parent, "hover"));
CHECK_WITH_TEXT("mousemove(80, 80): child.hasStatus('hover') == false",
!Widget_HasStatus(child, "hover"));

ev.motion.x = 150;
ev.motion.y = 150;
ev.motion.xrel = 0;
ev.motion.yrel = 0;
LCUI_TriggerEvent(&ev, NULL);
CHECK_WITH_TEXT("mousemove(150, 150): root.hasStatus('hover') == true",
Widget_HasStatus(root, "hover"));
CHECK_WITH_TEXT("mousemove(150, 150): parent.hasStatus('hover') == false",
!Widget_HasStatus(parent, "hover"));
CHECK_WITH_TEXT("mousemove(150, 150): child.hasStatus('hover') == false",
!Widget_HasStatus(child, "hover"));

LCUI_Destroy();
return ret;
}

int test_widget_event(void)
{
return test_widget_mouse_event();
}

0 comments on commit 949db38

Please sign in to comment.