summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_code_test_widget_undo.c
blob: 6ef93830376a8633ea1d2bae2aa2340ed06da7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include "elm_suite.h"
#include "Elementary.h"
#include "elm_code_widget_private.h"

EFL_START_TEST(elm_code_test_widget_undo_text_insert)
{
   Elm_Code *code;
   Elm_Code_File *file;
   Elm_Code_Line *line;
   Elm_Code_Widget *widget;
   Evas_Object *win;
   unsigned int length;
   const char *content;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();
   file = elm_code_file_new(code);
   elm_code_file_line_append(file, "test", 4, NULL);

   win = win_add(NULL, "entry", ELM_WIN_BASIC);
   widget = elm_code_widget_add(win, code);

   elm_code_widget_text_at_cursor_insert(widget, "a");
   line = elm_code_file_line_get(file, 1);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("atest", content, length);

   elm_code_widget_undo(widget);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("test", content, length);

   elm_code_widget_cursor_position_set(widget, 1, 3);
   elm_code_widget_text_at_cursor_insert(widget, "r");
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("terst", content, length);

   elm_code_widget_undo(widget);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("test", content, length);

   elm_code_widget_cursor_position_set(widget, 1, 4);
   elm_code_widget_text_at_cursor_insert(widget, "\t");
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("tes\tt", content, length);

   elm_code_widget_undo(widget);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("test", content, length);

   elm_code_free(code);
   elm_shutdown();
}
EFL_END_TEST

EFL_START_TEST(elm_code_test_widget_undo_text_insert_multiple)
{
   Elm_Code *code;
   Elm_Code_File *file;
   Elm_Code_Line *line;
   Elm_Code_Widget *widget;
   Evas_Object *win;
   unsigned int length;
   const char *content;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();
   file = elm_code_file_new(code);
   elm_code_file_line_append(file, "test", 4, NULL);

   win = win_add(NULL, "entry", ELM_WIN_BASIC);
   widget = elm_code_widget_add(win, code);

   elm_code_widget_text_at_cursor_insert(widget, "a");
   elm_code_widget_text_at_cursor_insert(widget, "b");
   line = elm_code_file_line_get(file, 1);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("abtest", content, length);

   elm_code_widget_undo(widget);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("atest", content, length);

   elm_code_widget_undo(widget);
   content = elm_code_line_text_get(line, &length);
   ck_assert_strn_eq("test", content, length);

   elm_code_free(code);
   elm_shutdown();
}
EFL_END_TEST

void elm_code_test_widget_undo(TCase *tc)
{
   tcase_add_test(tc, elm_code_test_widget_undo_text_insert);
   tcase_add_test(tc, elm_code_test_widget_undo_text_insert_multiple);
}