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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
23 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
26 using namespace Toolkit;
31 const char* TEST_IMAGE_FILE_NAME = "selection-popup-border.9.png";
35 void dali_textselectionpopup_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_textselectionpopup_cleanup(void)
42 test_return_value = TET_PASS;
45 int UtcDaliToolkitTextSelectionPopupNewP(void)
47 ToolkitTestApplication application;
48 TextSelectionPopup textSelectionPopup;
50 DALI_TEST_CHECK( !textSelectionPopup );
52 textSelectionPopup = TextSelectionPopup::New( NULL );
54 DALI_TEST_CHECK( textSelectionPopup );
58 int UtcDaliToolkitTextSelectionPopupConstructorP(void)
60 TextSelectionPopup textSelectionPopup;
62 DALI_TEST_CHECK( !textSelectionPopup );
67 int UtcDaliToolkitTextSelectionPopupCopyConstructorP(void)
69 ToolkitTestApplication application;
70 TextSelectionPopup textSelectionPopup;
72 textSelectionPopup = TextSelectionPopup::New( NULL );
73 TextSelectionPopup copy( textSelectionPopup );
75 DALI_TEST_CHECK( copy == textSelectionPopup );
81 int UtcDaliToolkitTextSelectionPopupDestructorP(void)
83 ToolkitTestApplication application;
84 TextSelectionPopup* textSelectionPopup = new TextSelectionPopup;
85 delete textSelectionPopup;
87 DALI_TEST_CHECK( true );
92 int UtcDaliToolkitTextSelectionPopupAssignmentOperatorP(void)
94 ToolkitTestApplication application;
95 TextSelectionPopup textSelectionPopup;
96 textSelectionPopup = TextSelectionPopup::New( NULL );
97 TextSelectionPopup copy;
98 copy = textSelectionPopup;
100 DALI_TEST_CHECK( copy == textSelectionPopup );
104 int UtcDaliToolkitTextSelectionPopupDownCastP(void)
106 ToolkitTestApplication application;
107 TextSelectionPopup textSelectionPopup;
108 textSelectionPopup = TextSelectionPopup::New( NULL );
110 TextSelectionPopup cast = TextSelectionPopup::DownCast( textSelectionPopup );
112 DALI_TEST_CHECK( cast );
117 int UtcDaliToolkitTextSelectionPopupBackgroundBorderP(void)
119 ToolkitTestApplication application;
120 TextSelectionPopup textSelectionPopup;
121 textSelectionPopup = TextSelectionPopup::New( NULL );
123 textSelectionPopup.SetProperty( TextSelectionPopup::Property::BACKGROUND_BORDER,
124 Property::Map().Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ) );
126 Property::Value value = textSelectionPopup.GetProperty( TextSelectionPopup::Property::BACKGROUND_BORDER );
131 Property::Value* returnValue = map.Find( Dali::Toolkit::ImageVisual::Property::URL );
132 DALI_TEST_CHECK( NULL != returnValue );
137 returnValue->Get( url );
138 DALI_TEST_EQUALS( TEST_IMAGE_FILE_NAME, url, TEST_LOCATION );
144 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
146 int UtcDaliToolkitTextSelectionToolBarP(void)
148 // Creates Toolbar, adds 2 options and a divider then resizes divider
149 ToolkitTestApplication application;
151 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
153 toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size( 100.0f, 60.0f) );
155 Toolkit::PushButton option = Toolkit::PushButton::New();
156 option.SetProperty( Dali::Actor::Property::NAME, "test-option" );
157 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
158 toolbar.AddOption( option );
160 Toolkit::Control divider = Toolkit::Control::New();
161 divider.SetProperty( Actor::Property::SIZE, Vector2( 2.0f, 0.0f ) );
162 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
163 toolbar.AddDivider( divider );
165 Toolkit::PushButton option2 = Toolkit::PushButton::New();
166 option2.SetProperty( Dali::Actor::Property::NAME, "test-option-2" );
167 option2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
168 toolbar.AddOption( option2 );
170 Size newSize = Size(3.0f, 0.0f);
171 toolbar.ResizeDividers( newSize );
173 DALI_TEST_CHECK( toolbar );
177 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
179 // Creates Toolbar, adds 2 options and a divider then resizes divider
180 ToolkitTestApplication application;
182 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
184 toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size( 100.0f, 60.0f) );
186 Toolkit::PushButton option = Toolkit::PushButton::New();
187 option.SetProperty( Dali::Actor::Property::NAME, "test-option" );
188 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
189 toolbar.AddOption( option );
192 toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true );
194 bool enabled = toolbar.GetProperty<bool>( Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR );
195 DALI_TEST_CHECK( enabled );
197 DALI_TEST_CHECK( toolbar );
201 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
203 // Configures the ScrollView within the TextSelectionToolbar
204 ToolkitTestApplication application;
206 TextSelectionToolbar toolbar = TextSelectionToolbar::New();
207 DALI_TEST_CHECK( toolbar );
208 Stage::GetCurrent().Add( toolbar );
211 map["overshootEffectColor"] = Color::RED;
212 map["overshootSize"] = Vector2(50.0f, 50.f);
213 toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map );
215 application.SendNotification();
216 application.Render();
218 Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
219 DALI_TEST_CHECK( actor );
221 ScrollView scrollView = ScrollView::DownCast( actor );
222 DALI_TEST_CHECK( scrollView );
224 Vector4 color = scrollView.GetProperty<Vector4>( Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR );
225 DALI_TEST_EQUALS( color, Color::RED, TEST_LOCATION );
227 Vector2 size = scrollView.GetProperty<Vector2>( Toolkit::Scrollable::Property::OVERSHOOT_SIZE );
228 DALI_TEST_EQUALS( size, Vector2(50.0f, 50.f), TEST_LOCATION );
233 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
235 ToolkitTestApplication application;
236 TextSelectionPopup popup = TextSelectionPopup::New(nullptr);
237 popup.SetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE, "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE");
238 popup.SetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE, "POPUP_CUT_BUTTON_ICON_IMAGE");
239 popup.SetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE, "POPUP_COPY_BUTTON_ICON_IMAGE");
240 popup.SetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE, "POPUP_PASTE_BUTTON_ICON_IMAGE");
241 popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE, "POPUP_SELECT_BUTTON_ICON_IMAGE");
242 popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE");
244 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE", TEST_LOCATION);
245 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CUT_BUTTON_ICON_IMAGE", TEST_LOCATION);
246 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_COPY_BUTTON_ICON_IMAGE", TEST_LOCATION);
247 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_PASTE_BUTTON_ICON_IMAGE", TEST_LOCATION);
248 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_BUTTON_ICON_IMAGE", TEST_LOCATION);
249 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_ALL_BUTTON_ICON_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 popup.SetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE, popupMaxSize);
264 popup.SetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE, optionMaxSize);
265 popup.SetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE, optionMinSize);
266 popup.SetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, optionDividerSize);
268 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::POPUP_MAX_SIZE).Get<Vector2>(), popupMaxSize, TEST_LOCATION);
269 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::OPTION_MAX_SIZE).Get<Vector2>(), optionMaxSize, TEST_LOCATION);
270 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::OPTION_MIN_SIZE).Get<Vector2>(), optionMinSize, TEST_LOCATION);
271 DALI_TEST_EQUALS( popup.GetProperty(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE).Get<Vector2>(), optionDividerSize, TEST_LOCATION);