summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_code_test_widget.c
blob: 193f1f1f7daf0a946523eaec8a767ab5484a1e6c (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define ELM_INTERNAL_API_ARGESFSDFEFC

#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

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

#include "elm_priv.h"

#undef CRI
#define CRI(...) do { } while (0);

#undef ERR
#define ERR(...) do { } while (0);

#undef WRN
#define WRN(...) do { } while (0);

#undef INF
#define INF(...) do { } while (0);

#undef DBG
#define DBG(...) do { } while (0);

// Guard against multiple redefinitions on Windows
#define ELM_CODE_TEST

#include "elm_code_parse.c"
#include "elm_code_widget_selection.c"
#include "elm_code_widget.c"

#undef ELM_CODE_TEST

static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id)
{
   ck_assert_msg(cell.fg == type, "Wrong type for cell %d", id);
}

START_TEST (elm_code_widget_token_render_simple_test)
{
   Elm_Code_File *file;
   Elm_Code_Line *line;
   Elm_Code *code;
   Elm_Code_Widget *widget;
   Evas_Object *win;

   int length;
   unsigned int gutter;

   Evas_Textgrid_Cell cells[25];

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();

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

   file = code->file;
   elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL);
   line = elm_code_file_line_get(file, 1);
   length = line->length;

   elm_code_line_token_add(line, 5, 18, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
   elm_code_line_token_add(line, 21, 22, 1, ELM_CODE_TOKEN_TYPE_NUMBER);

   _elm_code_widget_fill_line_tokens(widget, cells, length+1, line);
   gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);

   _assert_cell_type(cells[gutter+15], ELM_CODE_TOKEN_TYPE_COMMENT, 16);
   _assert_cell_type(cells[gutter+21], ELM_CODE_TOKEN_TYPE_NUMBER, 22);

   elm_code_free(code);
   elm_shutdown();
}
END_TEST

START_TEST (elm_code_widget_construct)
{
   Elm_Code *code;
   Elm_Code_Widget *widget;
   Evas_Object *win;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();

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

   ck_assert(!!widget);
   elm_code_free(code);
   elm_shutdown();
}
END_TEST

START_TEST (elm_code_widget_construct_nocode)
{
   Elm_Code_Widget *widget;
   Evas_Object *win;

   char *args[] = { "exe" };
   elm_init(1, args);

   win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
   widget = elm_code_widget_add(win, NULL);
   ck_assert(!widget);

   elm_shutdown();
}
END_TEST

START_TEST (elm_code_widget_position)
{
   Elm_Code *code;
   Elm_Code_Widget *widget;
   Evas_Object *win;
   Evas_Coord x, y, w, h, x2, y2, w2, h2;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();

   win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
   widget = elm_code_widget_add(win, code);
   evas_object_show(widget);
   evas_object_resize(widget, 100, 100);

   elm_code_file_line_append(code->file, "some content", 12, NULL);
   elm_code_file_line_append(code->file, "more", 4, NULL);

   elm_code_widget_geometry_for_position_get(widget, 1, 1, &x, &y, &w, &h);
   elm_code_widget_geometry_for_position_get(widget, 1, 2, &x2, &y2, &w2, &h2);
   ck_assert(x2 > x);
   ck_assert(y2 == y);
   ck_assert(w2 == w);
   ck_assert(h2 == h);

   elm_code_widget_geometry_for_position_get(widget, 2, 1, &x2, &y2, &w2, &h2);
   ck_assert(x2 == x);
   ck_assert(w2 == w);
   ck_assert(h2 == h);

   elm_code_free(code);
   elm_shutdown();
}
END_TEST

void elm_code_test_widget(TCase *tc)
{
   tcase_add_test(tc, elm_code_widget_token_render_simple_test);
   tcase_add_test(tc, elm_code_widget_construct);
   tcase_add_test(tc, elm_code_widget_construct_nocode);
   tcase_add_test(tc, elm_code_widget_position);
}