Changed Control::SetLayout to handle empty layouts
[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.SetName( "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.SetSize( 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.SetName( "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.SetName( "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   Stage::GetCurrent().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