2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 using namespace Toolkit;
30 const char* TEST_IMAGE_FILE_NAME = "selection-popup-border.9.png";
31 const char* TEST_FONT_FAMILY = "BreezeSans";
34 void dali_textselectionpopup_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_textselectionpopup_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliToolkitTextSelectionPopupNewP(void)
46 ToolkitTestApplication application;
47 TextSelectionPopup textSelectionPopup;
49 DALI_TEST_CHECK(!textSelectionPopup);
51 textSelectionPopup = TextSelectionPopup::New(NULL);
53 DALI_TEST_CHECK(textSelectionPopup);
57 int UtcDaliToolkitTextSelectionPopupConstructorP(void)
59 TextSelectionPopup textSelectionPopup;
61 DALI_TEST_CHECK(!textSelectionPopup);
66 int UtcDaliToolkitTextSelectionPopupCopyConstructorP(void)
68 ToolkitTestApplication application;
69 TextSelectionPopup textSelectionPopup;
71 textSelectionPopup = TextSelectionPopup::New(NULL);
72 TextSelectionPopup copy(textSelectionPopup);
74 DALI_TEST_CHECK(copy == textSelectionPopup);
79 int UtcDaliToolkitTextSelectionPopupDestructorP(void)
81 ToolkitTestApplication application;
82 TextSelectionPopup* textSelectionPopup = new TextSelectionPopup;
83 delete textSelectionPopup;
85 DALI_TEST_CHECK(true);
90 int UtcDaliToolkitTextSelectionPopupAssignmentOperatorP(void)
92 ToolkitTestApplication application;
93 TextSelectionPopup textSelectionPopup;
94 textSelectionPopup = TextSelectionPopup::New(NULL);
95 TextSelectionPopup copy;
96 copy = textSelectionPopup;
98 DALI_TEST_CHECK(copy == textSelectionPopup);
102 int UtcDaliToolkitTextSelectionPopupDownCastP(void)
104 ToolkitTestApplication application;
105 TextSelectionPopup textSelectionPopup;
106 textSelectionPopup = TextSelectionPopup::New(NULL);
108 TextSelectionPopup cast = TextSelectionPopup::DownCast(textSelectionPopup);
110 DALI_TEST_CHECK(cast);
115 int UtcDaliToolkitTextSelectionPopupBackgroundBorderP(void)
117 ToolkitTestApplication application;
118 TextSelectionPopup textSelectionPopup;
119 textSelectionPopup = TextSelectionPopup::New(NULL);
121 textSelectionPopup.SetProperty(TextSelectionPopup::Property::BACKGROUND_BORDER,
122 Property::Map().Add(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME));
124 Property::Value value = textSelectionPopup.GetProperty(TextSelectionPopup::Property::BACKGROUND_BORDER);
129 Property::Value* returnValue = map.Find(Dali::Toolkit::ImageVisual::Property::URL);
130 DALI_TEST_CHECK(NULL != returnValue);
135 returnValue->Get(url);
136 DALI_TEST_EQUALS(TEST_IMAGE_FILE_NAME, url, TEST_LOCATION);
142 int UtcDaliToolkitTextSelectionPopupBackgroundP(void)
144 ToolkitTestApplication application;
145 TextSelectionPopup textSelectionPopup;
146 textSelectionPopup = TextSelectionPopup::New(NULL);
148 textSelectionPopup.SetProperty(TextSelectionPopup::Property::BACKGROUND,
149 Property::Map().Add(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME));
151 Property::Value value = textSelectionPopup.GetProperty(TextSelectionPopup::Property::BACKGROUND);
156 Property::Value* returnValue = map.Find(Dali::Toolkit::ImageVisual::Property::URL);
157 DALI_TEST_CHECK(NULL != returnValue);
162 returnValue->Get(url);
163 DALI_TEST_EQUALS(TEST_IMAGE_FILE_NAME, url, TEST_LOCATION);
169 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
171 int UtcDaliToolkitTextSelectionToolBarP(void)
173 // Creates Toolbar, adds 2 options and a divider then resizes divider
174 ToolkitTestApplication application;
176 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
178 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
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);
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);
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);
195 Size newSize = Size(3.0f, 0.0f);
196 toolbar.ResizeDividers(newSize);
198 DALI_TEST_CHECK(toolbar);
202 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
204 // Creates Toolbar, adds 2 options and a divider then resizes divider
205 ToolkitTestApplication application;
207 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
209 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
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);
217 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true);
219 bool enabled = toolbar.GetProperty<bool>(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR);
220 DALI_TEST_CHECK(enabled);
222 DALI_TEST_CHECK(toolbar);
226 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
228 // Configures the ScrollView within the TextSelectionToolbar
229 ToolkitTestApplication application;
231 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
232 DALI_TEST_CHECK(toolbar);
233 application.GetScene().Add(toolbar);
236 map["overshootEffectColor"] = Color::RED;
237 map["overshootSize"] = Vector2(50.0f, 50.f);
238 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map);
240 application.SendNotification();
241 application.Render();
243 Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
244 DALI_TEST_CHECK(actor);
246 ScrollView scrollView = ScrollView::DownCast(actor);
247 DALI_TEST_CHECK(scrollView);
249 Vector4 color = scrollView.GetProperty<Vector4>(Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR);
250 DALI_TEST_EQUALS(color, Color::RED, TEST_LOCATION);
252 Vector2 size = scrollView.GetProperty<Vector2>(Toolkit::Scrollable::Property::OVERSHOOT_SIZE);
253 DALI_TEST_EQUALS(size, Vector2(50.0f, 50.f), TEST_LOCATION);
258 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
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");
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);
281 int UtcDaliToolkitTextSelectionPopupSizeProperties(void)
283 ToolkitTestApplication application;
284 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);
306 int UtcDaliToolkitTextSelectionPopupFloatProperties(void)
308 ToolkitTestApplication application;
309 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);
325 int UtcDaliToolkitTextSelectionPopupColorProperties(void)
327 ToolkitTestApplication application;
328 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);
341 int UtcDaliToolkitTextSelectionPopupScrollBarP(void)
343 ToolkitTestApplication application;
344 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
345 DALI_TEST_CHECK(popup);
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);
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);
356 int UtcDaliToolkitTextSelectionPopupLabelTextVisualP(void)
358 ToolkitTestApplication application;
359 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
360 DALI_TEST_CHECK(popup);
362 Property::Map textVisualMapSet;
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);
368 popup.SetProperty(TextSelectionPopup::Property::LABEL_TEXT_VISUAL, textVisualMapSet);
370 Property::Map textVisualMapGet;
371 Property::Map styleMapGet;
373 textVisualMapGet = popup.GetProperty(TextSelectionPopup::Property::LABEL_TEXT_VISUAL).Get<Property::Map>();
374 DALI_TEST_EQUALS(textVisualMapGet.Count(), 3u, TEST_LOCATION);
376 Property::Value* returnValue;
378 returnValue = textVisualMapGet.Find(TextVisual::Property::FONT_FAMILY);
379 DALI_TEST_CHECK(NULL != returnValue);
383 std::string fontFamily;
384 returnValue->Get(fontFamily);
385 DALI_TEST_EQUALS(fontFamily, TEST_FONT_FAMILY, TEST_LOCATION);
388 returnValue = textVisualMapGet.Find(TextVisual::Property::POINT_SIZE);
389 DALI_TEST_CHECK(NULL != returnValue);
394 returnValue->Get(pointSize);
395 DALI_TEST_EQUALS(pointSize, 50.0f, TEST_LOCATION);
398 returnValue = textVisualMapGet.Find(TextVisual::Property::TEXT_COLOR);
399 DALI_TEST_CHECK(NULL != returnValue);
404 returnValue->Get(textColor);
405 DALI_TEST_EQUALS(textColor, Color::RED, TEST_LOCATION);
411 int UtcDaliToolkitTextSelectionPopupLabelProperties(void)
413 ToolkitTestApplication application;
414 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
415 DALI_TEST_CHECK(popup);
417 const Vector2 labelMinimumSize(100.0f, 50.0f);
418 const Vector4 labelPadding(10.0f, 20.0f, 30.0f, 40.0f);
420 popup.SetProperty(TextSelectionPopup::Property::LABEL_MINIMUM_SIZE, labelMinimumSize);
421 popup.SetProperty(TextSelectionPopup::Property::LABEL_PADDING, labelPadding);
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);