Missing ewk API tests
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_text_matches_count_func.c
1 /*
2  * WebKit2 EFL
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc., 51
18  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  */
21
22 /**
23  * @file utc_webkit2_ewk_view_text_matches_count_func.c
24  * @author Krzysztof Czech <k.czech@samsung.com>
25  * @date 2013-05-28
26  * @brief Tests EWK function ewk_view_text_matches_count
27  */
28
29 #define TESTED_FUN_NAME ewk_view_text_matches_count
30 #define POSITIVE_TEST_FUN_NUM 4
31 #define NEGATIVE_TEST_FUN_NUM 2
32
33 #include "utc_webkit2_ewk.h"
34
35 static int matchCount = -1;
36
37 static const char textHtml[] =
38         "<html>"
39         "<body>"
40         "one one Two two two three THREE twoTwo text ONE"
41         "</body>"
42         "</html>";
43
44 static void onLoadFinished(void* userData, Evas_Object* obj, void* eventInfo)
45 {
46     utc_message("=========== onLoadFinished ===========\n");
47     utc_webkit2_main_loop_quit();
48 }
49
50 static void onTextFound(void* userData, Evas_Object* obj, void* eventInfo)
51 {
52     utc_message("\n=========== onTextFound ==============\n");
53     int *result = (int*)userData;
54     unsigned *count = (unsigned*)eventInfo;
55
56     *result = *count;
57 }
58
59 /* Startup and cleanup functions */
60 static void startup(void)
61 {
62     utc_webkit2_ewk_test_init();
63     evas_object_smart_callback_add(test_view.webview, "load,finished", onLoadFinished, 0);
64     evas_object_smart_callback_add(test_view.webview, "text,found", onTextFound, &matchCount);
65 }
66
67 static void cleanup(void)
68 {
69     evas_object_smart_callback_del(test_view.webview, "load,finished", onLoadFinished);
70     evas_object_smart_callback_del(test_view.webview, "text,found", onTextFound);
71     utc_webkit2_ewk_test_end();
72 }
73
74 /**
75 * @brief Checking whether correct number of words are returned.
76 */
77 POS_TEST_FUN(1)
78 {
79     ewk_view_html_string_load(test_view.webview, textHtml, 0, 0);
80     utc_webkit2_main_loop_begin();
81
82     ewk_view_text_matches_count(test_view.webview, "one", EWK_FIND_OPTIONS_NONE, 100);
83     while (matchCount < 0)
84         ecore_main_loop_iterate();
85
86     utc_check_eq(matchCount, 2);
87 }
88
89 /**
90 * @brief Checking whether correct number of words are returned, case insensitive.
91 */
92 POS_TEST_FUN(2)
93 {
94     matchCount = -1;
95
96     ewk_view_text_matches_count(test_view.webview, "one", EWK_FIND_OPTIONS_CASE_INSENSITIVE, 100);
97     while (matchCount < 0)
98         ecore_main_loop_iterate();
99
100     utc_check_eq(matchCount, 3);
101 }
102
103 /**
104 * @brief Checking whether correct number of words are returned, first occurrence.
105 */
106 POS_TEST_FUN(3)
107 {
108     matchCount = -1;
109
110     ewk_view_text_matches_count(test_view.webview, "Two", EWK_FIND_OPTIONS_AT_WORD_STARTS, 100);
111     while (matchCount < 0)
112         ecore_main_loop_iterate();
113
114     utc_check_eq(matchCount, 1);
115 }
116
117 /**
118 * @brief Checking whether correct number of words are returned, capital letter at the beginning.
119 */
120 POS_TEST_FUN(4)
121 {
122     matchCount = -1;
123
124     ewk_view_text_matches_count(test_view.webview, "Two", EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, 100);
125     while (matchCount < 0)
126         ecore_main_loop_iterate();
127
128     utc_check_eq(matchCount, 2);
129 }
130
131 /**
132 * @brief Checking whether function works properly in case of NULL of a webview.
133 */
134 NEG_TEST_FUN(1)
135 {
136     utc_check_eq(ewk_view_text_matches_count(0, "one", EWK_FIND_OPTIONS_NONE, 100), EINA_FALSE);
137 }
138
139 /**
140 * @brief Checking whether function works properly in case of NULL of a text.
141 */
142 NEG_TEST_FUN(2)
143 {
144     utc_check_eq(ewk_view_text_matches_count(test_view.webview, 0, EWK_FIND_OPTIONS_NONE, 100), EINA_FALSE);
145 }