Add text selection popup style
[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 const char* TEST_FONT_FAMILY = "BreezeSans";
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 int UtcDaliToolkitTextSelectionPopupBackgroundP(void)
143 {
144   ToolkitTestApplication application;
145   TextSelectionPopup     textSelectionPopup;
146   textSelectionPopup = TextSelectionPopup::New(NULL);
147
148   textSelectionPopup.SetProperty(TextSelectionPopup::Property::BACKGROUND,
149                                  Property::Map().Add(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME));
150
151   Property::Value value = textSelectionPopup.GetProperty(TextSelectionPopup::Property::BACKGROUND);
152
153   Property::Map map;
154   value.Get(map);
155
156   Property::Value* returnValue = map.Find(Dali::Toolkit::ImageVisual::Property::URL);
157   DALI_TEST_CHECK(NULL != returnValue);
158
159   if(returnValue)
160   {
161     std::string url;
162     returnValue->Get(url);
163     DALI_TEST_EQUALS(TEST_IMAGE_FILE_NAME, url, TEST_LOCATION);
164   }
165
166   END_TEST;
167 }
168
169 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
170
171 int UtcDaliToolkitTextSelectionToolBarP(void)
172 {
173   // Creates Toolbar, adds 2 options and a divider then resizes divider
174   ToolkitTestApplication application;
175
176   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
177
178   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
179
180   Toolkit::PushButton option = Toolkit::PushButton::New();
181   option.SetProperty(Dali::Actor::Property::NAME, "test-option");
182   option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
183   toolbar.AddOption(option);
184
185   Toolkit::Control divider = Toolkit::Control::New();
186   divider.SetProperty(Actor::Property::SIZE, Vector2(2.0f, 0.0f));
187   divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
188   toolbar.AddDivider(divider);
189
190   Toolkit::PushButton option2 = Toolkit::PushButton::New();
191   option2.SetProperty(Dali::Actor::Property::NAME, "test-option-2");
192   option2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
193   toolbar.AddOption(option2);
194
195   Size newSize = Size(3.0f, 0.0f);
196   toolbar.ResizeDividers(newSize);
197
198   DALI_TEST_CHECK(toolbar);
199   END_TEST;
200 }
201
202 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
203 {
204   // Creates Toolbar, adds 2 options and a divider then resizes divider
205   ToolkitTestApplication application;
206
207   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
208
209   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
210
211   Toolkit::PushButton option = Toolkit::PushButton::New();
212   option.SetProperty(Dali::Actor::Property::NAME, "test-option");
213   option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
214   toolbar.AddOption(option);
215
216   // Add a scroll-bar
217   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true);
218
219   bool enabled = toolbar.GetProperty<bool>(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR);
220   DALI_TEST_CHECK(enabled);
221
222   DALI_TEST_CHECK(toolbar);
223   END_TEST;
224 }
225
226 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
227 {
228   // Configures the ScrollView within the TextSelectionToolbar
229   ToolkitTestApplication application;
230
231   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
232   DALI_TEST_CHECK(toolbar);
233   application.GetScene().Add(toolbar);
234
235   Property::Map map;
236   map["overshootEffectColor"] = Color::RED;
237   map["overshootSize"]        = Vector2(50.0f, 50.f);
238   toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map);
239
240   application.SendNotification();
241   application.Render();
242
243   Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
244   DALI_TEST_CHECK(actor);
245
246   ScrollView scrollView = ScrollView::DownCast(actor);
247   DALI_TEST_CHECK(scrollView);
248
249   Vector4 color = scrollView.GetProperty<Vector4>(Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR);
250   DALI_TEST_EQUALS(color, Color::RED, TEST_LOCATION);
251
252   Vector2 size = scrollView.GetProperty<Vector2>(Toolkit::Scrollable::Property::OVERSHOOT_SIZE);
253   DALI_TEST_EQUALS(size, Vector2(50.0f, 50.f), TEST_LOCATION);
254
255   END_TEST;
256 }
257
258 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
259 {
260   ToolkitTestApplication application;
261   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
262   popup.SetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE, "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE");
263   popup.SetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE, "POPUP_CUT_BUTTON_ICON_IMAGE");
264   popup.SetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE, "POPUP_COPY_BUTTON_ICON_IMAGE");
265   popup.SetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE, "POPUP_PASTE_BUTTON_ICON_IMAGE");
266   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE, "POPUP_SELECT_BUTTON_ICON_IMAGE");
267   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE");
268   popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE, "POPUP_PRESSED_IMAGE");
269
270   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE", TEST_LOCATION);
271   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CUT_BUTTON_ICON_IMAGE", TEST_LOCATION);
272   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_COPY_BUTTON_ICON_IMAGE", TEST_LOCATION);
273   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_PASTE_BUTTON_ICON_IMAGE", TEST_LOCATION);
274   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_BUTTON_ICON_IMAGE", TEST_LOCATION);
275   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE", TEST_LOCATION);
276   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE).Get<std::string>(), "POPUP_PRESSED_IMAGE", TEST_LOCATION);
277
278   END_TEST;
279 }
280
281 int UtcDaliToolkitTextSelectionPopupSizeProperties(void)
282 {
283   ToolkitTestApplication application;
284   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
285
286   const Vector2 popupMaxSize(200.0f, 300.0f);
287   const Vector2 optionMaxSize(50.0f, 100.0f);
288   const Vector2 optionMinSize(10.0f, 10.0f);
289   const Vector2 optionDividerSize(5.0f, 5.0f);
290   const Vector4 optionDividerPadding(20.0f, 20.0f, 10.0f, 10.0f);
291   popup.SetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE, popupMaxSize);
292   popup.SetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE, optionMaxSize);
293   popup.SetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE, optionMinSize);
294   popup.SetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, optionDividerSize);
295   popup.SetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING, optionDividerPadding);
296
297   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE).Get<Vector2>(), popupMaxSize, TEST_LOCATION);
298   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE).Get<Vector2>(), optionMaxSize, TEST_LOCATION);
299   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE).Get<Vector2>(), optionMinSize, TEST_LOCATION);
300   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE).Get<Vector2>(), optionDividerSize, TEST_LOCATION);
301   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING).Get<Vector4>(), optionDividerPadding, TEST_LOCATION);
302
303   END_TEST;
304 }
305
306 int UtcDaliToolkitTextSelectionPopupFloatProperties(void)
307 {
308   ToolkitTestApplication application;
309   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
310
311   const float popupFadeInDuration = 5.0f;
312   const float popupFadeOutDuration = 10.0f;
313   const float popupPressedCornerRadius = 15.0f;
314   popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION, popupFadeInDuration);
315   popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION, popupFadeOutDuration);
316   popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_CORNER_RADIUS, popupPressedCornerRadius);
317
318   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION).Get<float>(), popupFadeInDuration, TEST_LOCATION);
319   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION).Get<float>(), popupFadeOutDuration, TEST_LOCATION);
320   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_CORNER_RADIUS).Get<float>(), popupPressedCornerRadius, TEST_LOCATION);
321
322   END_TEST;
323 }
324
325 int UtcDaliToolkitTextSelectionPopupColorProperties(void)
326 {
327   ToolkitTestApplication application;
328   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
329
330   popup.SetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR, Color::RED);
331   popup.SetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR, Color::BLUE);
332   popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR, Color::BLACK);
333
334   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR).Get<Vector4>(), Color::RED, TEST_LOCATION);
335   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR).Get<Vector4>(), Color::BLUE, TEST_LOCATION);
336   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR).Get<Vector4>(), Color::BLACK, TEST_LOCATION);
337
338   END_TEST;
339 }
340
341 int UtcDaliToolkitTextSelectionPopupScrollBarP(void)
342 {
343   ToolkitTestApplication application;
344   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
345   DALI_TEST_CHECK(popup);
346
347   popup.SetProperty(TextSelectionPopup::Property::ENABLE_SCROLL_BAR, true);
348   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::ENABLE_SCROLL_BAR).Get<bool>(), true, TEST_LOCATION);
349
350   popup.SetProperty(TextSelectionPopup::Property::ENABLE_SCROLL_BAR, false);
351   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::ENABLE_SCROLL_BAR).Get<bool>(), false, TEST_LOCATION);
352
353   END_TEST;
354 }
355
356 int UtcDaliToolkitTextSelectionPopupLabelTextVisualP(void)
357 {
358   ToolkitTestApplication application;
359   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
360   DALI_TEST_CHECK(popup);
361
362   Property::Map textVisualMapSet;
363
364   textVisualMapSet.Insert(TextVisual::Property::FONT_FAMILY, TEST_FONT_FAMILY);
365   textVisualMapSet.Insert(TextVisual::Property::POINT_SIZE, 50.f);
366   textVisualMapSet.Insert(TextVisual::Property::TEXT_COLOR, Color::RED);
367
368   popup.SetProperty(TextSelectionPopup::Property::LABEL_TEXT_VISUAL, textVisualMapSet);
369
370   Property::Map textVisualMapGet;
371   Property::Map styleMapGet;
372
373   textVisualMapGet = popup.GetProperty(TextSelectionPopup::Property::LABEL_TEXT_VISUAL).Get<Property::Map>();
374   DALI_TEST_EQUALS(textVisualMapGet.Count(), 3u, TEST_LOCATION);
375
376   Property::Value* returnValue;
377
378   returnValue = textVisualMapGet.Find(TextVisual::Property::FONT_FAMILY);
379   DALI_TEST_CHECK(NULL != returnValue);
380
381   if(returnValue)
382   {
383     std::string fontFamily;
384     returnValue->Get(fontFamily);
385     DALI_TEST_EQUALS(fontFamily, TEST_FONT_FAMILY, TEST_LOCATION);
386   }
387
388   returnValue = textVisualMapGet.Find(TextVisual::Property::POINT_SIZE);
389   DALI_TEST_CHECK(NULL != returnValue);
390
391   if(returnValue)
392   {
393     float pointSize;
394     returnValue->Get(pointSize);
395     DALI_TEST_EQUALS(pointSize, 50.0f, TEST_LOCATION);
396   }
397
398   returnValue = textVisualMapGet.Find(TextVisual::Property::TEXT_COLOR);
399   DALI_TEST_CHECK(NULL != returnValue);
400
401   if(returnValue)
402   {
403     Vector4 textColor;
404     returnValue->Get(textColor);
405     DALI_TEST_EQUALS(textColor, Color::RED, TEST_LOCATION);
406   }
407
408   END_TEST;
409 }
410
411 int UtcDaliToolkitTextSelectionPopupLabelProperties(void)
412 {
413   ToolkitTestApplication application;
414   TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
415   DALI_TEST_CHECK(popup);
416
417   const Vector2 labelMinimumSize(100.0f, 50.0f);
418   const Vector4 labelPadding(10.0f, 20.0f, 30.0f, 40.0f);
419
420   popup.SetProperty(TextSelectionPopup::Property::LABEL_MINIMUM_SIZE, labelMinimumSize);
421   popup.SetProperty(TextSelectionPopup::Property::LABEL_PADDING, labelPadding);
422
423   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::LABEL_MINIMUM_SIZE).Get<Vector2>(), labelMinimumSize, TEST_LOCATION);
424   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::LABEL_PADDING).Get<Vector4>(), labelPadding, TEST_LOCATION);
425
426   END_TEST;
427 }