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";
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 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
144 int UtcDaliToolkitTextSelectionToolBarP(void)
146 // Creates Toolbar, adds 2 options and a divider then resizes divider
147 ToolkitTestApplication application;
149 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
151 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
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);
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);
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);
168 Size newSize = Size(3.0f, 0.0f);
169 toolbar.ResizeDividers(newSize);
171 DALI_TEST_CHECK(toolbar);
175 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
177 // Creates Toolbar, adds 2 options and a divider then resizes divider
178 ToolkitTestApplication application;
180 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
182 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size(100.0f, 60.0f));
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);
190 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true);
192 bool enabled = toolbar.GetProperty<bool>(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR);
193 DALI_TEST_CHECK(enabled);
195 DALI_TEST_CHECK(toolbar);
199 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
201 // Configures the ScrollView within the TextSelectionToolbar
202 ToolkitTestApplication application;
204 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
205 DALI_TEST_CHECK(toolbar);
206 application.GetScene().Add(toolbar);
209 map["overshootEffectColor"] = Color::RED;
210 map["overshootSize"] = Vector2(50.0f, 50.f);
211 toolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map);
213 application.SendNotification();
214 application.Render();
216 Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
217 DALI_TEST_CHECK(actor);
219 ScrollView scrollView = ScrollView::DownCast(actor);
220 DALI_TEST_CHECK(scrollView);
222 Vector4 color = scrollView.GetProperty<Vector4>(Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR);
223 DALI_TEST_EQUALS(color, Color::RED, TEST_LOCATION);
225 Vector2 size = scrollView.GetProperty<Vector2>(Toolkit::Scrollable::Property::OVERSHOOT_SIZE);
226 DALI_TEST_EQUALS(size, Vector2(50.0f, 50.f), TEST_LOCATION);
231 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
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");
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);
254 int UtcDaliToolkitTextSelectionPopupSizeProperties(void)
256 ToolkitTestApplication application;
257 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);
279 int UtcDaliToolkitTextSelectionPopupDurationProperties(void)
281 ToolkitTestApplication application;
282 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);
295 int UtcDaliToolkitTextSelectionPopupColorProperties(void)
297 ToolkitTestApplication application;
298 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
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);
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);