[dali_2.1.23] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextSelectionPopup.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
21 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
22 #include <stdlib.h>
23 #include <iostream>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 namespace
29 {
30 const char* TEST_IMAGE_FILE_NAME = "selection-popup-border.9.png";
31
32 }
33
34 void dali_textselectionpopup_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void dali_textselectionpopup_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 int UtcDaliToolkitTextSelectionPopupNewP(void)
45 {
46   ToolkitTestApplication application;
47   TextSelectionPopup     textSelectionPopup;
48
49   DALI_TEST_CHECK(!textSelectionPopup);
50
51   textSelectionPopup = TextSelectionPopup::New(NULL);
52
53   DALI_TEST_CHECK(textSelectionPopup);
54   END_TEST;
55 }
56
57 int UtcDaliToolkitTextSelectionPopupConstructorP(void)
58 {
59   TextSelectionPopup textSelectionPopup;
60
61   DALI_TEST_CHECK(!textSelectionPopup);
62
63   END_TEST;
64 }
65
66 int UtcDaliToolkitTextSelectionPopupCopyConstructorP(void)
67 {
68   ToolkitTestApplication application;
69   TextSelectionPopup     textSelectionPopup;
70
71   textSelectionPopup = TextSelectionPopup::New(NULL);
72   TextSelectionPopup copy(textSelectionPopup);
73
74   DALI_TEST_CHECK(copy == textSelectionPopup);
75
76   END_TEST;
77 }
78
79 int UtcDaliToolkitTextSelectionPopupDestructorP(void)
80 {
81   ToolkitTestApplication application;
82   TextSelectionPopup*    textSelectionPopup = new TextSelectionPopup;
83   delete textSelectionPopup;
84
85   DALI_TEST_CHECK(true);
86
87   END_TEST;
88 }
89
90 int UtcDaliToolkitTextSelectionPopupAssignmentOperatorP(void)
91 {
92   ToolkitTestApplication application;
93   TextSelectionPopup     textSelectionPopup;
94   textSelectionPopup = TextSelectionPopup::New(NULL);
95   TextSelectionPopup copy;
96   copy = textSelectionPopup;
97
98   DALI_TEST_CHECK(copy == textSelectionPopup);
99   END_TEST;
100 }
101
102 int UtcDaliToolkitTextSelectionPopupDownCastP(void)
103 {
104   ToolkitTestApplication application;
105   TextSelectionPopup     textSelectionPopup;
106   textSelectionPopup = TextSelectionPopup::New(NULL);
107
108   TextSelectionPopup cast = TextSelectionPopup::DownCast(textSelectionPopup);
109
110   DALI_TEST_CHECK(cast);
111
112   END_TEST;
113 }
114
115 int UtcDaliToolkitTextSelectionPopupBackgroundBorderP(void)
116 {
117   ToolkitTestApplication application;
118   TextSelectionPopup     textSelectionPopup;
119   textSelectionPopup = TextSelectionPopup::New(NULL);
120
121   textSelectionPopup.SetProperty(TextSelectionPopup::Property::BACKGROUND_BORDER,
122                                  Property::Map().Add(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME));
123
124   Property::Value value = textSelectionPopup.GetProperty(TextSelectionPopup::Property::BACKGROUND_BORDER);
125
126   Property::Map map;
127   value.Get(map);
128
129   Property::Value* returnValue = map.Find(Dali::Toolkit::ImageVisual::Property::URL);
130   DALI_TEST_CHECK(NULL != returnValue);
131
132   if(returnValue)
133   {
134     std::string url;
135     returnValue->Get(url);
136     DALI_TEST_EQUALS(TEST_IMAGE_FILE_NAME, url, TEST_LOCATION);
137   }
138
139   END_TEST;
140 }
141
142 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
143
144 int UtcDaliToolkitTextSelectionToolBarP(void)
145 {
146   // Creates Toolbar, adds 2 options and a divider then resizes divider
147   ToolkitTestApplication application;
148
149   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
150
151   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
152
153   Toolkit::PushButton option = Toolkit::PushButton::New();
154   option.SetProperty(Dali::Actor::Property::NAME, "test-option");
155   option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
156   toolbar.AddOption(option);
157
158   Toolkit::Control divider = Toolkit::Control::New();
159   divider.SetProperty(Actor::Property::SIZE, Vector2(2.0f, 0.0f));
160   divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
161   toolbar.AddDivider(divider);
162
163   Toolkit::PushButton option2 = Toolkit::PushButton::New();
164   option2.SetProperty(Dali::Actor::Property::NAME, "test-option-2");
165   option2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
166   toolbar.AddOption(option2);
167
168   Size newSize = Size(3.0f, 0.0f);
169   toolbar.ResizeDividers(newSize);
170
171   DALI_TEST_CHECK(toolbar);
172   END_TEST;
173 }
174
175 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
176 {
177   // Creates Toolbar, adds 2 options and a divider then resizes divider
178   ToolkitTestApplication application;
179
180   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
181
182   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
183
184   Toolkit::PushButton option = Toolkit::PushButton::New();
185   option.SetProperty(Dali::Actor::Property::NAME, "test-option");
186   option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
187   toolbar.AddOption(option);
188
189   // Add a scroll-bar
190   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true);
191
192   bool enabled = toolbar.GetProperty<bool>(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR);
193   DALI_TEST_CHECK(enabled);
194
195   DALI_TEST_CHECK(toolbar);
196   END_TEST;
197 }
198
199 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
200 {
201   // Configures the ScrollView within the TextSelectionToolbar
202   ToolkitTestApplication application;
203
204   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
205   DALI_TEST_CHECK(toolbar);
206   application.GetScene().Add(toolbar);
207
208   Property::Map map;
209   map["overshootEffectColor"] = Color::RED;
210   map["overshootSize"]        = Vector2(50.0f, 50.f);
211   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map);
212
213   application.SendNotification();
214   application.Render();
215
216   Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
217   DALI_TEST_CHECK(actor);
218
219   ScrollView scrollView = ScrollView::DownCast(actor);
220   DALI_TEST_CHECK(scrollView);
221
222   Vector4 color = scrollView.GetProperty<Vector4>(Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR);
223   DALI_TEST_EQUALS(color, Color::RED, TEST_LOCATION);
224
225   Vector2 size = scrollView.GetProperty<Vector2>(Toolkit::Scrollable::Property::OVERSHOOT_SIZE);
226   DALI_TEST_EQUALS(size, Vector2(50.0f, 50.f), TEST_LOCATION);
227
228   END_TEST;
229 }
230
231 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
232 {
233   ToolkitTestApplication application;
234   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
235   popup.SetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE, "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE");
236   popup.SetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE, "POPUP_CUT_BUTTON_ICON_IMAGE");
237   popup.SetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE, "POPUP_COPY_BUTTON_ICON_IMAGE");
238   popup.SetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE, "POPUP_PASTE_BUTTON_ICON_IMAGE");
239   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE, "POPUP_SELECT_BUTTON_ICON_IMAGE");
240   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE");
241   popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE, "POPUP_PRESSED_IMAGE");
242
243   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE", TEST_LOCATION);
244   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CUT_BUTTON_ICON_IMAGE", TEST_LOCATION);
245   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_COPY_BUTTON_ICON_IMAGE", TEST_LOCATION);
246   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_PASTE_BUTTON_ICON_IMAGE", TEST_LOCATION);
247   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_BUTTON_ICON_IMAGE", TEST_LOCATION);
248   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE", TEST_LOCATION);
249   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE).Get<std::string>(), "POPUP_PRESSED_IMAGE", TEST_LOCATION);
250
251   END_TEST;
252 }
253
254 int UtcDaliToolkitTextSelectionPopupSizeProperties(void)
255 {
256   ToolkitTestApplication application;
257   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
258
259   const Vector2 popupMaxSize(200.0f, 300.0f);
260   const Vector2 optionMaxSize(50.0f, 100.0f);
261   const Vector2 optionMinSize(10.0f, 10.0f);
262   const Vector2 optionDividerSize(5.0f, 5.0f);
263   const Vector4 optionDividerPadding(20.0f, 20.0f, 10.0f, 10.0f);
264   popup.SetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE, popupMaxSize);
265   popup.SetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE, optionMaxSize);
266   popup.SetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE, optionMinSize);
267   popup.SetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, optionDividerSize);
268   popup.SetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING, optionDividerPadding);
269
270   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE).Get<Vector2>(), popupMaxSize, TEST_LOCATION);
271   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE).Get<Vector2>(), optionMaxSize, TEST_LOCATION);
272   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE).Get<Vector2>(), optionMinSize, TEST_LOCATION);
273   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE).Get<Vector2>(), optionDividerSize, TEST_LOCATION);
274   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING).Get<Vector4>(), optionDividerPadding, TEST_LOCATION);
275
276   END_TEST;
277 }
278
279 int UtcDaliToolkitTextSelectionPopupDurationProperties(void)
280 {
281   ToolkitTestApplication application;
282   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
283
284   const float popupFadeInDuration = 5.0f;
285   const float popupFadeOutDuration = 10.0f;
286   popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION, popupFadeInDuration);
287   popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION, popupFadeOutDuration);
288
289   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION).Get<float>(), popupFadeInDuration, TEST_LOCATION);
290   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION).Get<float>(), popupFadeOutDuration, TEST_LOCATION);
291
292   END_TEST;
293 }
294
295 int UtcDaliToolkitTextSelectionPopupColorProperties(void)
296 {
297   ToolkitTestApplication application;
298   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
299
300   popup.SetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR, Color::RED);
301   popup.SetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR, Color::BLUE);
302   popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR, Color::BLACK);
303
304   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR).Get<Vector4>(), Color::RED, TEST_LOCATION);
305   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR).Get<Vector4>(), Color::BLUE, TEST_LOCATION);
306   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR).Get<Vector4>(), Color::BLACK, TEST_LOCATION);
307
308   END_TEST;
309 }