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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali-toolkit/devel-api/styling/style-manager.h>
23 #include <dali-toolkit/devel-api/builder/builder.h>
24 #include <test-button.h>
25 #include <test-animation-data.h>
26 #include <toolkit-style-monitor.h>
29 using namespace Dali::Toolkit;
33 const char* defaultTheme =
42 " \"textlabelFontSize0\":\n"
46 " \"textlabelFontSize1\":\n"
50 " \"textlabelFontSize2\":\n"
54 " \"textlabelFontSize3\":\n"
58 " \"textlabelFontSize4\":\n"
65 " \"pointSize\":18,\n"
66 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
67 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
68 " \"cursorWidth\":3,\n"
69 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
70 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
71 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
72 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
75 " \"textfieldFontSize0\":\n"
79 " \"textfieldFontSize1\":\n"
83 " \"textfieldFontSize2\":\n"
87 " \"textfieldFontSize3\":\n"
91 " \"textfieldFontSize4\":\n"
95 " \"textselectionpopup\":\n"
97 " \"popupMaxSize\":[656,72],\n"
98 " \"optionDividerSize\":[2,0],\n"
99 " \"popupDividerColor\":[0.23,0.72,0.8,0.11],\n"
100 " \"popupIconColor\":[1.0,1.0,1.0,1.0],\n"
101 " \"popupPressedColor\":[0.24,0.72,0.8,0.11],\n"
102 " \"background\": {\n"
103 " \"rendererType\": \"nPatch\",\n"
104 " \"imageUrl\": \"{DALI_IMAGE_DIR}selection-popup-bg.9.png\"\n"
106 " \"popupFadeInDuration\":0.25,\n"
107 " \"popupFadeOutDuration\":0.25\n"
109 " \"textselectionpopupbutton\":\n"
113 " \"pointSize\":8,\n"
114 " \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n"
117 " \"textselectiontoolbar\":\n"
119 " \"enableOvershoot\":true,\n"
122 " \"overshootAnimationSpeed\":360.0,\n"
123 " \"overshootSize\":[720.0,130.0]\n"
128 " \"overshootEffectColor\":\"B018\",\n"
129 " \"overshootAnimationSpeed\":360.0,\n"
130 " \"overshootSize\":[720.0,130.0]\n"
134 " \"overshootEffectColor\":\"B018\",\n"
135 " \"overshootAnimationSpeed\":360.0,\n"
136 " \"overshootSize\":[720.0,130.0]\n"
140 " \"pointSize\":18,\n"
141 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
142 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
143 " \"cursorWidth\":3,\n"
144 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
145 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
146 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
147 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
152 } // anonymous namespace
156 void dali_style_manager_startup(void)
158 test_return_value = TET_UNDEF;
161 void dali_style_manager_cleanup(void)
163 test_return_value = TET_PASS;
166 int UtcDaliStyleManagerGet(void)
168 ToolkitTestApplication application;
170 tet_infoline(" UtcDaliStyleManagerGet");
174 type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
175 DALI_TEST_CHECK( type );
176 BaseHandle handle = type.CreateInstance();
177 DALI_TEST_CHECK( handle );
179 StyleManager manager;
181 manager = StyleManager::Get();
182 DALI_TEST_CHECK(manager);
184 StyleManager newManager = StyleManager::Get();
185 DALI_TEST_CHECK(newManager);
187 // Check that focus manager is a singleton
188 DALI_TEST_CHECK(manager == newManager);
192 int UtcDaliStyleManagerSetOrientationValue(void)
194 ToolkitTestApplication application;
196 tet_infoline( " UtcDaliStyleManagerSetOrientationValue" );
198 StyleManager manager = StyleManager::Get();
200 int orientation1 = 0;
201 manager.SetOrientationValue( orientation1 );
202 DALI_TEST_CHECK( manager.GetOrientationValue() == orientation1 );
204 int orientation2 = 180;
205 manager.SetOrientationValue( orientation2 );
206 DALI_TEST_CHECK( manager.GetOrientationValue() == orientation2 );
211 int UtcDaliStyleManagerSetOrientation(void)
213 ToolkitTestApplication application;
215 tet_infoline( " UtcDaliStyleManagerSetOrientation" );
217 StyleManager manager = StyleManager::Get();
219 Orientation orientation;
221 manager.SetOrientation( orientation );
223 DALI_TEST_CHECK( manager.GetOrientation() == orientation );
228 int UtcDaliStyleManagerSetStyleConstant(void)
230 ToolkitTestApplication application;
232 tet_infoline( " UtcDaliStyleManagerSetStyleConstant" );
234 StyleManager manager = StyleManager::Get();
236 std::string key( "key" );
237 Property::Value value( 100 );
239 manager.SetStyleConstant( key, value );
241 Property::Value returnedValue;
242 manager.GetStyleConstant( key, returnedValue );
244 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
246 std::string key2( "key2" );
247 Property::Value returnedValue2;
248 DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
255 class StyleChangedSignalChecker : public ConnectionTracker
258 StyleChangedSignalChecker()
263 void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
277 } // anonymous namespace
279 int UtcDaliStyleManagerPropertyOverride(void)
281 ToolkitTestApplication application;
283 tet_infoline( "Testing StyleManager property overrides" );
291 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
292 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
303 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
304 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
309 // Add 2 buttons to test how many times the signal is sent
310 Test::TestButton testButton = Test::TestButton::New();
311 Test::TestButton testButton2 = Test::TestButton::New();
312 Stage::GetCurrent().Add( testButton );
313 Stage::GetCurrent().Add( testButton2 );
314 StyleChangedSignalChecker styleChangedSignalHandler;
315 StyleChangedSignalChecker styleChangedSignalHandler2;
316 StyleManager styleManager = StyleManager::Get();
318 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
321 application.SendNotification();
322 application.Render();
324 tet_infoline("Apply the style");
326 Test::StyleMonitor::SetThemeFileOutput(json1);
327 std::string themeFile("ThemeOne");
328 StyleManager::Get().RequestThemeChange(themeFile);
330 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
331 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
333 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
334 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
336 tet_infoline("Testing that the signal handler is called only once");
337 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
339 tet_infoline("Override the background property");
340 testButton.SetProperty( Test::TestButton::Property::BACKGROUND_COLOR, Color::GREEN );
341 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
342 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
343 DALI_TEST_EQUALS( bgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
344 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
347 application.SendNotification();
348 application.Render();
350 tet_infoline("Apply the style again");
352 styleChangedSignalHandler.signalCount = 0;
353 StyleManager::Get().RequestThemeChange(themeFile);
355 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
356 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
358 tet_infoline("Check that the property is changed");
359 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
360 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
361 tet_infoline("Testing that the signal handler is called only once");
362 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
364 tet_infoline( "Load a different stylesheet");
366 tet_infoline("Apply the new style");
367 Test::StyleMonitor::SetThemeFileOutput(json2);
369 styleChangedSignalHandler.signalCount = 0;
370 std::string themeFile2("ThemeTwo");
371 StyleManager::Get().RequestThemeChange(themeFile2);
373 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
374 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
376 tet_infoline("Check that the properties change, but the signal gets sent only once");
377 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
378 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
379 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
384 int UtcDaliStyleManagerFontSizeChange(void)
386 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
387 Test::StyleMonitor::SetThemeFileOutput(defaultTheme);
389 ToolkitTestApplication application;
391 std::string labelStr("Label");
392 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
393 Stage::GetCurrent().Add( label );
395 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
396 Stage::GetCurrent().Add( label2 );
398 StyleChangedSignalChecker styleChangedSignalHandler;
399 StyleMonitor styleMonitor = StyleMonitor::Get();
400 StyleManager styleManager = StyleManager::Get();
402 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
404 Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
406 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_CHANGE);
408 tet_infoline("Test that the StyleChanged signal is received only once");
410 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
412 // Check that the label's font style has been altered
413 Property::Value family = label.GetProperty(TextLabel::Property::FONT_FAMILY);
414 std::string familyStr;
415 family.Get( familyStr );
417 DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);