[dali_2.0.15] 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 <iostream>
19 #include <stdlib.h>
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>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 namespace
29 {
30
31 const char* TEST_IMAGE_FILE_NAME = "selection-popup-border.9.png";
32
33 }
34
35 void dali_textselectionpopup_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void dali_textselectionpopup_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 int UtcDaliToolkitTextSelectionPopupNewP(void)
46 {
47   ToolkitTestApplication application;
48   TextSelectionPopup textSelectionPopup;
49
50   DALI_TEST_CHECK( !textSelectionPopup );
51
52   textSelectionPopup = TextSelectionPopup::New( NULL );
53
54   DALI_TEST_CHECK( textSelectionPopup );
55   END_TEST;
56 }
57
58 int UtcDaliToolkitTextSelectionPopupConstructorP(void)
59 {
60   TextSelectionPopup textSelectionPopup;
61
62   DALI_TEST_CHECK( !textSelectionPopup );
63
64   END_TEST;
65 }
66
67 int UtcDaliToolkitTextSelectionPopupCopyConstructorP(void)
68 {
69   ToolkitTestApplication application;
70   TextSelectionPopup textSelectionPopup;
71
72   textSelectionPopup = TextSelectionPopup::New( NULL );
73   TextSelectionPopup copy( textSelectionPopup );
74
75   DALI_TEST_CHECK( copy == textSelectionPopup );
76
77   END_TEST;
78 }
79
80
81 int UtcDaliToolkitTextSelectionPopupDestructorP(void)
82 {
83   ToolkitTestApplication application;
84   TextSelectionPopup* textSelectionPopup = new TextSelectionPopup;
85   delete textSelectionPopup;
86
87   DALI_TEST_CHECK( true );
88
89   END_TEST;
90 }
91
92 int UtcDaliToolkitTextSelectionPopupAssignmentOperatorP(void)
93 {
94   ToolkitTestApplication application;
95   TextSelectionPopup textSelectionPopup;
96   textSelectionPopup = TextSelectionPopup::New(  NULL );
97   TextSelectionPopup copy;
98   copy = textSelectionPopup;
99
100   DALI_TEST_CHECK( copy == textSelectionPopup );
101   END_TEST;
102 }
103
104 int UtcDaliToolkitTextSelectionPopupDownCastP(void)
105 {
106   ToolkitTestApplication application;
107   TextSelectionPopup textSelectionPopup;
108   textSelectionPopup = TextSelectionPopup::New( NULL );
109
110   TextSelectionPopup cast = TextSelectionPopup::DownCast( textSelectionPopup );
111
112   DALI_TEST_CHECK( cast );
113
114   END_TEST;
115 }
116
117 int UtcDaliToolkitTextSelectionPopupBackgroundBorderP(void)
118 {
119   ToolkitTestApplication application;
120   TextSelectionPopup textSelectionPopup;
121   textSelectionPopup = TextSelectionPopup::New( NULL );
122
123   textSelectionPopup.SetProperty( TextSelectionPopup::Property::BACKGROUND_BORDER,
124                                   Property::Map().Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ) );
125
126   Property::Value value = textSelectionPopup.GetProperty( TextSelectionPopup::Property::BACKGROUND_BORDER );
127
128   Property::Map map;
129   value.Get( map );
130
131   Property::Value* returnValue = map.Find( Dali::Toolkit::ImageVisual::Property::URL );
132   DALI_TEST_CHECK( NULL != returnValue );
133
134   if( returnValue )
135   {
136     std::string url;
137     returnValue->Get( url );
138     DALI_TEST_EQUALS( TEST_IMAGE_FILE_NAME, url, TEST_LOCATION );
139   }
140
141   END_TEST;
142 }
143
144 // TextSelectionToolBar is used TextSelectionPopup, below tests it individually
145
146 int UtcDaliToolkitTextSelectionToolBarP(void)
147 {
148   // Creates Toolbar, adds 2 options and a divider then resizes divider
149   ToolkitTestApplication application;
150
151   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
152
153   toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size( 100.0f, 60.0f) );
154
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 );
159
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 );
164
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 );
169
170   Size newSize =  Size(3.0f, 0.0f);
171   toolbar.ResizeDividers( newSize );
172
173   DALI_TEST_CHECK( toolbar );
174   END_TEST;
175 }
176
177 int UtcDaliToolkitTextSelectionToolBarScrollBarP(void)
178 {
179   // Creates Toolbar, adds 2 options and a divider then resizes divider
180   ToolkitTestApplication application;
181
182   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
183
184   toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, Size( 100.0f, 60.0f) );
185
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 );
190
191   // Add a scroll-bar
192   toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, true );
193
194   bool enabled = toolbar.GetProperty<bool>( Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR );
195   DALI_TEST_CHECK( enabled );
196
197   DALI_TEST_CHECK( toolbar );
198   END_TEST;
199 }
200
201 int UtcDaliToolkitTextSelectionToolBarScrollView(void)
202 {
203   // Configures the ScrollView within the TextSelectionToolbar
204   ToolkitTestApplication application;
205
206   TextSelectionToolbar toolbar = TextSelectionToolbar::New();
207   DALI_TEST_CHECK( toolbar );
208   application.GetScene().Add( toolbar );
209
210   Property::Map map;
211   map["overshootEffectColor"] = Color::RED;
212   map["overshootSize"] = Vector2(50.0f, 50.f);
213   toolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::SCROLL_VIEW, map );
214
215   application.SendNotification();
216   application.Render();
217
218   Actor actor = toolbar.FindChildByName("TextSelectionScrollView");
219   DALI_TEST_CHECK( actor );
220
221   ScrollView scrollView = ScrollView::DownCast( actor );
222   DALI_TEST_CHECK( scrollView );
223
224   Vector4 color = scrollView.GetProperty<Vector4>( Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR );
225   DALI_TEST_EQUALS( color, Color::RED, TEST_LOCATION );
226
227   Vector2 size = scrollView.GetProperty<Vector2>( Toolkit::Scrollable::Property::OVERSHOOT_SIZE );
228   DALI_TEST_EQUALS( size, Vector2(50.0f, 50.f), TEST_LOCATION );
229
230   END_TEST;
231 }
232
233 int UtcDaliToolkitTextSelectionPopupIconProperties(void)
234 {
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");
243
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);
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   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);
267
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);
272
273   END_TEST;
274 }