efl
718 строк · 21.2 Кб
1#ifdef HAVE_CONFIG_H2# include "elementary_config.h"3#endif4
5#include "elm_suite.h"6#include "Elementary.h"7#include "elm_code_widget_private.h"8#include "elm_code_widget_selection.h"9
10EFL_START_TEST(elm_code_test_widget_selection_set)11{
12Elm_Code *code;13Elm_Code_File *file;14Elm_Code_Widget *widget;15Evas_Object *win;16
17char *args[] = { "exe" };18elm_init(1, args);19code = elm_code_create();20file = elm_code_file_new(code);21elm_code_file_line_append(file, "test", 4, NULL);22
23win = win_add(NULL, "entry", ELM_WIN_BASIC);24widget = elm_code_widget_add(win, code);25
26elm_code_widget_selection_start(widget, 1, 2);27elm_code_widget_selection_end(widget, 1, 3);28elm_code_widget_selection_clear(widget);29
30elm_code_free(code);31elm_shutdown();32}
33EFL_END_TEST
34
35EFL_START_TEST(elm_code_test_widget_selection_normalized_get)36{
37Elm_Code *code;38Elm_Code_File *file;39Elm_Code_Widget *widget;40Elm_Code_Widget_Selection_Data *selection;41Evas_Object *win;42
43char *args[] = { "exe" };44elm_init(1, args);45code = elm_code_create();46file = elm_code_file_new(code);47elm_code_file_line_append(file, "test", 4, NULL);48
49win = win_add(NULL, "entry", ELM_WIN_BASIC);50widget = elm_code_widget_add(win, code);51
52elm_code_widget_selection_start(widget, 1, 3);53elm_code_widget_selection_end(widget, 1, 2);54selection = elm_code_widget_selection_normalized_get(widget);55
56ck_assert_int_eq(selection->start_col, 2);57ck_assert_int_eq(selection->end_col, 3);58elm_code_widget_selection_clear(widget);59free(selection);60
61elm_code_file_line_append(file, "another", 7, NULL);62elm_code_widget_selection_start(widget, 2, 2);63elm_code_widget_selection_end(widget, 1, 3);64selection = elm_code_widget_selection_normalized_get(widget);65
66ck_assert_int_eq(selection->start_line, 1);67ck_assert_int_eq(selection->start_col, 3);68ck_assert_int_eq(selection->end_line, 2);69ck_assert_int_eq(selection->end_col, 2);70elm_code_widget_selection_clear(widget);71free(selection);72
73elm_code_free(code);74elm_shutdown();75}
76EFL_END_TEST
77
78EFL_START_TEST(elm_code_test_widget_selection_text_get)79{
80Elm_Code *code;81Elm_Code_File *file;82Elm_Code_Widget *widget;83Evas_Object *win;84char *selection;85
86char *args[] = { "exe" };87elm_init(1, args);88code = elm_code_create();89file = elm_code_file_new(code);90elm_code_file_line_append(file, "test", 4, NULL);91
92win = win_add(NULL, "entry", ELM_WIN_BASIC);93widget = elm_code_widget_add(win, code);94
95ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));96
97elm_code_widget_selection_start(widget, 1, 2);98elm_code_widget_selection_end(widget, 1, 3);99
100selection = elm_code_widget_selection_text_get(widget);101ck_assert_str_eq("es", selection);102free(selection);103
104elm_code_widget_selection_clear(widget);105ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));106
107elm_code_free(code);108elm_shutdown();109}
110EFL_END_TEST
111
112EFL_START_TEST(elm_code_test_widget_selection_reverse_text_get)113{
114Elm_Code *code;115Elm_Code_File *file;116Elm_Code_Widget *widget;117Evas_Object *win;118char *selection;119
120char *args[] = { "exe" };121elm_init(1, args);122code = elm_code_create();123file = elm_code_file_new(code);124elm_code_file_line_append(file, "test", 4, NULL);125
126win = win_add(NULL, "entry", ELM_WIN_BASIC);127widget = elm_code_widget_add(win, code);128
129ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));130
131elm_code_widget_selection_start(widget, 1, 3);132elm_code_widget_selection_end(widget, 1, 2);133
134selection = elm_code_widget_selection_text_get(widget);135ck_assert_str_eq("es", selection);136free(selection);137
138elm_code_widget_selection_clear(widget);139ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));140
141elm_code_free(code);142elm_shutdown();143}
144EFL_END_TEST
145
146EFL_START_TEST(elm_code_test_widget_selection_text_get_twoline)147{
148Elm_Code *code;149Elm_Code_File *file;150Elm_Code_Widget *widget;151Evas_Object *win;152char *selection;153
154char *args[] = { "exe" };155elm_init(1, args);156code = elm_code_create();157file = elm_code_file_new(code);158elm_code_file_line_append(file, "test", 4, NULL);159elm_code_file_line_append(file, "test", 4, NULL);160
161win = win_add(NULL, "entry", ELM_WIN_BASIC);162widget = elm_code_widget_add(win, code);163
164elm_code_widget_selection_start(widget, 1, 3);165elm_code_widget_selection_end(widget, 2, 2);166
167selection = elm_code_widget_selection_text_get(widget);168ck_assert_str_eq("st\nte", selection);169free(selection);170
171elm_code_free(code);172elm_shutdown();173}
174EFL_END_TEST
175
176EFL_START_TEST(elm_code_test_widget_selection_reverse_text_get_twoline)177{
178Elm_Code *code;179Elm_Code_File *file;180Elm_Code_Widget *widget;181Evas_Object *win;182char *selection;183
184char *args[] = { "exe" };185elm_init(1, args);186code = elm_code_create();187file = elm_code_file_new(code);188elm_code_file_line_append(file, "test", 4, NULL);189elm_code_file_line_append(file, "test", 4, NULL);190
191win = win_add(NULL, "entry", ELM_WIN_BASIC);192widget = elm_code_widget_add(win, code);193
194elm_code_widget_selection_start(widget, 2, 2);195elm_code_widget_selection_end(widget, 1, 3);196
197selection = elm_code_widget_selection_text_get(widget);198ck_assert_str_eq("st\nte", selection);199free(selection);200
201elm_code_free(code);202elm_shutdown();203}
204EFL_END_TEST
205
206EFL_START_TEST(elm_code_test_widget_selection_text_get_multiline)207{
208Elm_Code *code;209Elm_Code_File *file;210Elm_Code_Widget *widget;211Evas_Object *win;212char *selection;213
214char *args[] = { "exe" };215elm_init(1, args);216code = elm_code_create();217file = elm_code_file_new(code);218elm_code_file_line_append(file, "test", 4, NULL);219elm_code_file_line_append(file, "test", 4, NULL);220elm_code_file_line_append(file, "test", 4, NULL);221
222win = win_add(NULL, "entry", ELM_WIN_BASIC);223widget = elm_code_widget_add(win, code);224
225elm_code_widget_selection_start(widget, 1, 3);226elm_code_widget_selection_end(widget, 3, 2);227
228selection = elm_code_widget_selection_text_get(widget);229ck_assert_str_eq("st\ntest\nte", selection);230free(selection);231
232elm_code_free(code);233elm_shutdown();234}
235EFL_END_TEST
236
237EFL_START_TEST(elm_code_test_widget_selection_reverse_text_get_multiline)238{
239Elm_Code *code;240Elm_Code_File *file;241Elm_Code_Widget *widget;242Evas_Object *win;243char *selection;244
245char *args[] = { "exe" };246elm_init(1, args);247code = elm_code_create();248file = elm_code_file_new(code);249elm_code_file_line_append(file, "test", 4, NULL);250elm_code_file_line_append(file, "test", 4, NULL);251elm_code_file_line_append(file, "test", 4, NULL);252
253win = win_add(NULL, "entry", ELM_WIN_BASIC);254widget = elm_code_widget_add(win, code);255
256elm_code_widget_selection_start(widget, 3, 2);257elm_code_widget_selection_end(widget, 1, 3);258
259selection = elm_code_widget_selection_text_get(widget);260ck_assert_str_eq("st\ntest\nte", selection);261free(selection);262
263elm_code_free(code);264elm_shutdown();265}
266EFL_END_TEST
267
268EFL_START_TEST(elm_code_test_widget_selection_delete)269{
270Elm_Code *code;271Elm_Code_File *file;272Elm_Code_Line *line;273Elm_Code_Widget *widget;274Evas_Object *win;275const char *text;276unsigned int length;277
278char *args[] = { "exe" };279elm_init(1, args);280code = elm_code_create();281file = elm_code_file_new(code);282elm_code_file_line_append(file, "text", 4, NULL);283
284win = win_add(NULL, "code", ELM_WIN_BASIC);285widget = elm_code_widget_add(win, code);286line = elm_code_file_line_get(file, 1);287text = elm_code_line_text_get(line, &length);288ck_assert_int_eq(4, length);289ck_assert_strn_eq("text", text, length);290
291elm_code_widget_selection_start(widget, 1, 2);292elm_code_widget_selection_end(widget, 1, 3);293elm_code_widget_selection_delete(widget);294
295line = elm_code_file_line_get(file, 1);296text = elm_code_line_text_get(line, &length);297ck_assert_int_eq(2, length);298ck_assert_strn_eq("tt", text, length);299
300elm_code_free(code);301elm_shutdown();302}
303EFL_END_TEST
304
305EFL_START_TEST(elm_code_test_widget_selection_reverse_delete)306{
307Elm_Code *code;308Elm_Code_File *file;309Elm_Code_Line *line;310Elm_Code_Widget *widget;311Evas_Object *win;312const char *text;313unsigned int length;314
315char *args[] = { "exe" };316elm_init(1, args);317code = elm_code_create();318file = elm_code_file_new(code);319elm_code_file_line_append(file, "text", 4, NULL);320
321win = win_add(NULL, "code", ELM_WIN_BASIC);322widget = elm_code_widget_add(win, code);323line = elm_code_file_line_get(file, 1);324text = elm_code_line_text_get(line, &length);325ck_assert_int_eq(4, length);326ck_assert_strn_eq("text", text, length);327
328elm_code_widget_selection_start(widget, 1, 3);329elm_code_widget_selection_end(widget, 1, 2);330elm_code_widget_selection_delete(widget);331
332line = elm_code_file_line_get(file, 1);333text = elm_code_line_text_get(line, &length);334ck_assert_int_eq(2, length);335ck_assert_strn_eq("tt", text, length);336
337elm_code_free(code);338elm_shutdown();339}
340EFL_END_TEST
341
342EFL_START_TEST(elm_code_test_widget_selection_delete_twoline)343{
344Elm_Code *code;345Elm_Code_File *file;346Elm_Code_Line *line;347Elm_Code_Widget *widget;348Evas_Object *win;349const char *text;350unsigned int length;351
352char *args[] = { "exe" };353elm_init(1, args);354code = elm_code_create();355file = elm_code_file_new(code);356elm_code_file_line_append(file, "text", 4, NULL);357elm_code_file_line_append(file, "TEXT", 4, NULL);358elm_code_file_line_append(file, "remove", 6, NULL);359
360win = win_add(NULL, "code", ELM_WIN_BASIC);361widget = elm_code_widget_add(win, code);362line = elm_code_file_line_get(file, 1);363text = elm_code_line_text_get(line, NULL);364ck_assert_str_eq("text", text);365ck_assert_int_eq(3, elm_code_file_lines_get(file));366
367elm_code_widget_selection_start(widget, 1, 3);368elm_code_widget_selection_end(widget, 2, 2);369elm_code_widget_selection_delete(widget);370
371line = elm_code_file_line_get(file, 1);372text = elm_code_line_text_get(line, &length);373ck_assert_strn_eq("teXT", text, length);374ck_assert_int_eq(2, elm_code_file_lines_get(file));375
376elm_code_widget_selection_start(widget, 1, 5);377elm_code_widget_selection_end(widget, 2, 1);378elm_code_widget_selection_delete(widget);379
380line = elm_code_file_line_get(file, 1);381text = elm_code_line_text_get(line, &length);382ck_assert_strn_eq("teXTemove", text, length);383ck_assert_int_eq(1, elm_code_file_lines_get(file));384
385elm_code_free(code);386elm_shutdown();387}
388EFL_END_TEST
389
390EFL_START_TEST(elm_code_test_widget_selection_reverse_delete_twoline)391{
392Elm_Code *code;393Elm_Code_File *file;394Elm_Code_Line *line;395Elm_Code_Widget *widget;396Evas_Object *win;397const char *text;398unsigned int length;399
400char *args[] = { "exe" };401elm_init(1, args);402code = elm_code_create();403file = elm_code_file_new(code);404elm_code_file_line_append(file, "text", 4, NULL);405elm_code_file_line_append(file, "TEXT", 4, NULL);406elm_code_file_line_append(file, "remove", 6, NULL);407
408win = win_add(NULL, "code", ELM_WIN_BASIC);409widget = elm_code_widget_add(win, code);410line = elm_code_file_line_get(file, 1);411text = elm_code_line_text_get(line, NULL);412ck_assert_str_eq("text", text);413ck_assert_int_eq(3, elm_code_file_lines_get(file));414
415elm_code_widget_selection_start(widget, 2, 2);416elm_code_widget_selection_end(widget, 1, 3);417elm_code_widget_selection_delete(widget);418
419line = elm_code_file_line_get(file, 1);420text = elm_code_line_text_get(line, &length);421ck_assert_strn_eq("teXT", text, length);422ck_assert_int_eq(2, elm_code_file_lines_get(file));423
424elm_code_widget_selection_start(widget, 2, 1);425elm_code_widget_selection_end(widget, 1, 5);426elm_code_widget_selection_delete(widget);427
428line = elm_code_file_line_get(file, 1);429text = elm_code_line_text_get(line, &length);430ck_assert_strn_eq("teXTemove", text, length);431ck_assert_int_eq(1, elm_code_file_lines_get(file));432
433elm_code_free(code);434elm_shutdown();435}
436EFL_END_TEST
437
438EFL_START_TEST(elm_code_test_widget_selection_delete_multiline)439{
440Elm_Code *code;441Elm_Code_File *file;442Elm_Code_Line *line;443Elm_Code_Widget *widget;444Evas_Object *win;445const char *text;446unsigned int length;447
448char *args[] = { "exe" };449elm_init(1, args);450code = elm_code_create();451file = elm_code_file_new(code);452elm_code_file_line_append(file, "text", 4, NULL);453elm_code_file_line_append(file, "remove", 6, NULL);454elm_code_file_line_append(file, "TEXT", 4, NULL);455elm_code_file_line_append(file, "delete", 6, NULL);456elm_code_file_line_append(file, "REMOVE", 6, NULL);457
458win = win_add(NULL, "code", ELM_WIN_BASIC);459widget = elm_code_widget_add(win, code);460line = elm_code_file_line_get(file, 1);461text = elm_code_line_text_get(line, NULL);462ck_assert_str_eq("text", text);463ck_assert_int_eq(5, elm_code_file_lines_get(file));464
465elm_code_widget_selection_start(widget, 1, 3);466elm_code_widget_selection_end(widget, 3, 2);467elm_code_widget_selection_delete(widget);468
469line = elm_code_file_line_get(file, 1);470text = elm_code_line_text_get(line, &length);471ck_assert_strn_eq("teXT", text, length);472ck_assert_int_eq(3, elm_code_file_lines_get(file));473
474elm_code_widget_selection_start(widget, 1, 5);475elm_code_widget_selection_end(widget, 3, 1);476elm_code_widget_selection_delete(widget);477
478line = elm_code_file_line_get(file, 1);479text = elm_code_line_text_get(line, &length);480ck_assert_strn_eq("teXTEMOVE", text, length);481ck_assert_int_eq(1, elm_code_file_lines_get(file));482
483elm_code_free(code);484elm_shutdown();485}
486EFL_END_TEST
487
488EFL_START_TEST(elm_code_test_widget_selection_reverse_delete_multiline)489{
490Elm_Code *code;491Elm_Code_File *file;492Elm_Code_Line *line;493Elm_Code_Widget *widget;494Evas_Object *win;495const char *text;496unsigned int length;497
498char *args[] = { "exe" };499elm_init(1, args);500code = elm_code_create();501file = elm_code_file_new(code);502elm_code_file_line_append(file, "text", 4, NULL);503elm_code_file_line_append(file, "remove", 6, NULL);504elm_code_file_line_append(file, "TEXT", 4, NULL);505elm_code_file_line_append(file, "delete", 6, NULL);506elm_code_file_line_append(file, "REMOVE", 6, NULL);507
508win = win_add(NULL, "code", ELM_WIN_BASIC);509widget = elm_code_widget_add(win, code);510line = elm_code_file_line_get(file, 1);511text = elm_code_line_text_get(line, NULL);512ck_assert_str_eq("text", text);513ck_assert_int_eq(5, elm_code_file_lines_get(file));514
515elm_code_widget_selection_start(widget, 3, 2);516elm_code_widget_selection_end(widget, 1, 3);517elm_code_widget_selection_delete(widget);518
519line = elm_code_file_line_get(file, 1);520text = elm_code_line_text_get(line, &length);521ck_assert_strn_eq("teXT", text, length);522ck_assert_int_eq(3, elm_code_file_lines_get(file));523
524elm_code_widget_selection_start(widget, 3, 1);525elm_code_widget_selection_end(widget, 1, 5);526elm_code_widget_selection_delete(widget);527
528line = elm_code_file_line_get(file, 1);529text = elm_code_line_text_get(line, &length);530ck_assert_strn_eq("teXTEMOVE", text, length);531ck_assert_int_eq(1, elm_code_file_lines_get(file));532
533elm_code_free(code);534elm_shutdown();535}
536EFL_END_TEST
537
538EFL_START_TEST(elm_code_test_widget_selection_select_line)539{
540Elm_Code *code;541Elm_Code_File *file;542Elm_Code_Widget *widget;543Evas_Object *win;544char *selection;545
546char *args[] = { "exe" };547elm_init(1, args);548code = elm_code_create();549file = elm_code_file_new(code);550elm_code_file_line_append(file, "line selection", 14, NULL);551elm_code_file_line_append(file, "line2", 5, NULL);552elm_code_file_line_append(file, "\ttab", 4, NULL);553
554win = win_add(NULL, "entry", ELM_WIN_BASIC);555widget = elm_code_widget_add(win, code);556
557elm_code_widget_selection_select_line(widget, 1);558selection = elm_code_widget_selection_text_get(widget);559ck_assert_str_eq("line selection", selection);560free(selection);561
562elm_code_widget_selection_select_line(widget, 2);563selection = elm_code_widget_selection_text_get(widget);564ck_assert_str_eq("line2", selection);565free(selection);566
567elm_code_widget_selection_select_line(widget, 3);568selection = elm_code_widget_selection_text_get(widget);569ck_assert_str_eq("\ttab", selection);570free(selection);571
572elm_shutdown();573}
574EFL_END_TEST
575
576EFL_START_TEST(elm_code_test_widget_selection_select_word)577{
578Elm_Code *code;579Elm_Code_File *file;580Elm_Code_Widget *widget;581Evas_Object *win;582char *selection;583
584char *args[] = { "exe" };585elm_init(1, args);586code = elm_code_create();587file = elm_code_file_new(code);588elm_code_file_line_append(file, "word selection test", 19, NULL);589elm_code_file_line_append(file, "more stuff\tto test", 18, NULL);590elm_code_file_line_append(file, "word \"symbols\" test", 19, NULL);591
592win = win_add(NULL, "entry", ELM_WIN_BASIC);593widget = elm_code_widget_add(win, code);594
595elm_code_widget_selection_select_word(widget, 1, 3);596selection = elm_code_widget_selection_text_get(widget);597ck_assert_str_eq("word", selection);598free(selection);599
600elm_code_widget_selection_select_word(widget, 1, 16);601selection = elm_code_widget_selection_text_get(widget);602ck_assert_str_eq("test", selection);603free(selection);604
605elm_code_widget_selection_select_word(widget, 2, 9);606selection = elm_code_widget_selection_text_get(widget);607ck_assert_str_eq("stuff", selection);608free(selection);609
610elm_code_widget_selection_select_word(widget, 3, 9);611selection = elm_code_widget_selection_text_get(widget);612ck_assert_str_eq("symbols", selection);613free(selection);614elm_shutdown();615}
616EFL_END_TEST
617
618EFL_START_TEST(elm_code_test_widget_selection_select_word_punctuation)619{
620Elm_Code *code;621Elm_Code_File *file;622Elm_Code_Widget *widget;623Evas_Object *win;624char *selection;625
626char *args[] = { "exe" };627elm_init(1, args);628code = elm_code_create();629file = elm_code_file_new(code);630elm_code_file_line_append(file, "comma, stop. question? mark!", 38, NULL);631
632win = win_add(NULL, "entry", ELM_WIN_BASIC);633widget = elm_code_widget_add(win, code);634
635elm_code_widget_selection_select_word(widget, 1, 3);636selection = elm_code_widget_selection_text_get(widget);637ck_assert_str_eq("comma", selection);638free(selection);639
640elm_code_widget_selection_select_word(widget, 1, 10);641selection = elm_code_widget_selection_text_get(widget);642ck_assert_str_eq("stop", selection);643free(selection);644
645elm_code_widget_selection_select_word(widget, 1, 20);646selection = elm_code_widget_selection_text_get(widget);647ck_assert_str_eq("question", selection);648free(selection);649
650elm_code_widget_selection_select_word(widget, 1, 25);651selection = elm_code_widget_selection_text_get(widget);652ck_assert_str_eq("mark", selection);653free(selection);654elm_shutdown();655}
656EFL_END_TEST
657
658EFL_START_TEST(elm_code_test_widget_selection_select_word_symbols)659{
660Elm_Code *code;661Elm_Code_File *file;662Elm_Code_Widget *widget;663Evas_Object *win;664char *selection;665
666char *args[] = { "exe" };667elm_init(1, args);668code = elm_code_create();669file = elm_code_file_new(code);670elm_code_file_line_append(file, "colon: [array] (brackets) {braces}", 38, NULL);671
672win = win_add(NULL, "entry", ELM_WIN_BASIC);673widget = elm_code_widget_add(win, code);674
675elm_code_widget_selection_select_word(widget, 1, 3);676selection = elm_code_widget_selection_text_get(widget);677ck_assert_str_eq("colon", selection);678free(selection);679
680elm_code_widget_selection_select_word(widget, 1, 10);681selection = elm_code_widget_selection_text_get(widget);682ck_assert_str_eq("array", selection);683free(selection);684
685elm_code_widget_selection_select_word(widget, 1, 20);686selection = elm_code_widget_selection_text_get(widget);687ck_assert_str_eq("brackets", selection);688free(selection);689
690elm_code_widget_selection_select_word(widget, 1, 30);691selection = elm_code_widget_selection_text_get(widget);692ck_assert_str_eq("braces", selection);693free(selection);694elm_shutdown();695}
696EFL_END_TEST
697
698void elm_code_test_widget_selection(TCase *tc)699{
700tcase_add_test(tc, elm_code_test_widget_selection_set);701tcase_add_test(tc, elm_code_test_widget_selection_normalized_get);702tcase_add_test(tc, elm_code_test_widget_selection_text_get);703tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get);704tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline);705tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_twoline);706tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline);707tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_multiline);708tcase_add_test(tc, elm_code_test_widget_selection_delete);709tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete);710tcase_add_test(tc, elm_code_test_widget_selection_delete_twoline);711tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_twoline);712tcase_add_test(tc, elm_code_test_widget_selection_delete_multiline);713tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline);714tcase_add_test(tc, elm_code_test_widget_selection_select_line);715tcase_add_test(tc, elm_code_test_widget_selection_select_word);716tcase_add_test(tc, elm_code_test_widget_selection_select_word_punctuation);717tcase_add_test(tc, elm_code_test_widget_selection_select_word_symbols);718}
719