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/builder/builder.h>
23 #include <test-button.h>
24 #include <test-animation-data.h>
25 #include <toolkit-style-monitor.h>
28 using namespace Dali::Toolkit;
32 const char* defaultTheme =
41 " \"textlabelFontSize0\":\n"
45 " \"textlabelFontSize1\":\n"
49 " \"textlabelFontSize2\":\n"
53 " \"textlabelFontSize3\":\n"
57 " \"textlabelFontSize4\":\n"
64 " \"pointSize\":18,\n"
65 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
66 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
67 " \"cursorWidth\":3,\n"
68 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
69 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
70 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
71 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
74 " \"textfieldFontSize0\":\n"
78 " \"textfieldFontSize1\":\n"
82 " \"textfieldFontSize2\":\n"
86 " \"textfieldFontSize3\":\n"
90 " \"textfieldFontSize4\":\n"
94 " \"textselectionpopup\":\n"
96 " \"popupMaxSize\":[656,72],\n"
97 " \"optionDividerSize\":[2,0],\n"
98 " \"popupDividerColor\":[0.23,0.72,0.8,0.11],\n"
99 " \"popupIconColor\":[1.0,1.0,1.0,1.0],\n"
100 " \"popupPressedColor\":[0.24,0.72,0.8,0.11],\n"
101 " \"background\": {\n"
102 " \"rendererType\": \"nPatch\",\n"
103 " \"imageUrl\": \"{DALI_IMAGE_DIR}selection-popup-bg.9.png\"\n"
105 " \"popupFadeInDuration\":0.25,\n"
106 " \"popupFadeOutDuration\":0.25\n"
108 " \"textselectionpopupbutton\":\n"
112 " \"pointSize\":8,\n"
113 " \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n"
116 " \"textselectiontoolbar\":\n"
118 " \"enableOvershoot\":true,\n"
121 " \"overshootAnimationSpeed\":360.0,\n"
122 " \"overshootSize\":[720.0,130.0]\n"
127 " \"overshootEffectColor\":\"B018\",\n"
128 " \"overshootAnimationSpeed\":360.0,\n"
129 " \"overshootSize\":[720.0,130.0]\n"
133 " \"overshootEffectColor\":\"B018\",\n"
134 " \"overshootAnimationSpeed\":360.0,\n"
135 " \"overshootSize\":[720.0,130.0]\n"
139 " \"pointSize\":18,\n"
140 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
141 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
142 " \"cursorWidth\":3,\n"
143 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
144 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
145 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
146 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
151 } // anonymous namespace
155 void dali_style_manager_startup(void)
157 test_return_value = TET_UNDEF;
160 void dali_style_manager_cleanup(void)
162 test_return_value = TET_PASS;
166 int UtcDaliStyleManagerConstructorP(void)
168 ToolkitTestApplication application;
170 tet_infoline(" UtcDaliStyleManagerConstructorP");
171 StyleManager styleManager;
172 DALI_TEST_CHECK( !styleManager);
176 int UtcDaliStyleManagerCopyConstructorP(void)
178 TestApplication application;
180 StyleManager styleManager = StyleManager::Get();
181 StyleManager copyOfStyleManager( styleManager );
183 DALI_TEST_CHECK( copyOfStyleManager );
187 int UtcDaliStyleManagerAssignmentOperatorP(void)
189 TestApplication application;
191 StyleManager styleManager = StyleManager::Get();
192 StyleManager copyOfStyleManager = styleManager;
194 DALI_TEST_CHECK( copyOfStyleManager );
195 DALI_TEST_CHECK( copyOfStyleManager == styleManager );
199 int UtcDaliStyleManagerGet(void)
201 ToolkitTestApplication application;
203 tet_infoline(" UtcDaliStyleManagerGet");
207 type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
208 DALI_TEST_CHECK( type );
209 BaseHandle handle = type.CreateInstance();
210 DALI_TEST_CHECK( handle );
212 StyleManager manager;
214 manager = StyleManager::Get();
215 DALI_TEST_CHECK(manager);
217 StyleManager newManager = StyleManager::Get();
218 DALI_TEST_CHECK(newManager);
220 // Check that focus manager is a singleton
221 DALI_TEST_CHECK(manager == newManager);
228 class StyleChangedSignalChecker : public ConnectionTracker
231 StyleChangedSignalChecker()
236 void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
250 } // anonymous namespace
252 int UtcDaliStyleManagerApplyTheme(void)
254 ToolkitTestApplication application;
256 tet_infoline( "Testing StyleManager ApplyTheme" );
264 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
265 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
276 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
277 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
282 // Add 2 buttons to test how many times the signal is sent
283 Test::TestButton testButton = Test::TestButton::New();
284 Test::TestButton testButton2 = Test::TestButton::New();
285 Stage::GetCurrent().Add( testButton );
286 Stage::GetCurrent().Add( testButton2 );
287 StyleChangedSignalChecker styleChangedSignalHandler;
288 StyleChangedSignalChecker styleChangedSignalHandler2;
289 StyleManager styleManager = StyleManager::Get();
291 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
294 application.SendNotification();
295 application.Render();
297 tet_infoline("Apply the style");
299 std::string themeFile("ThemeOne");
300 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
301 StyleManager::Get().ApplyTheme(themeFile);
303 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
304 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
306 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
307 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
309 tet_infoline("Testing that the signal handler is called only once");
310 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
312 tet_infoline("Override the background property");
313 testButton.SetProperty( Test::TestButton::Property::BACKGROUND_COLOR, Color::GREEN );
314 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
315 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
316 DALI_TEST_EQUALS( bgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
317 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
320 application.SendNotification();
321 application.Render();
323 tet_infoline("Apply the style again");
325 styleChangedSignalHandler.signalCount = 0;
326 StyleManager::Get().ApplyTheme(themeFile);
328 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
329 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
331 tet_infoline("Check that the property is changed");
332 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
333 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
334 tet_infoline("Testing that the signal handler is called only once");
335 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
337 tet_infoline( "Load a different stylesheet");
339 tet_infoline("Apply the new style");
340 std::string themeFile2("ThemeTwo");
341 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
343 styleChangedSignalHandler.signalCount = 0;
344 StyleManager::Get().ApplyTheme(themeFile2);
346 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
347 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
349 tet_infoline("Check that the properties change, but the signal gets sent only once");
350 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
351 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
352 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
358 int UtcDaliStyleManagerApplyDefaultTheme(void)
360 tet_infoline( "Testing StyleManager ApplyTheme" );
362 const char* defaultTheme =
368 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
369 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
373 // Bg: Yellow, Fg: Blue
375 const char* appTheme =
381 " \"backgroundColor\":[1.0,0.0,1.0,1.0],\n"
382 " \"foregroundColor\":[0.0,1.0,0.0,1.0]\n"
386 // Bg::Magenta, Fg:Green
388 std::string filepath(TEST_RESOURCE_DIR "");
390 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
392 ToolkitTestApplication application;
394 Test::TestButton testButton = Test::TestButton::New();
395 Stage::GetCurrent().Add( testButton );
396 StyleChangedSignalChecker styleChangedSignalHandler;
397 StyleManager styleManager = StyleManager::Get();
399 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
402 application.SendNotification();
403 application.Render();
406 Property::Value defaultBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
407 Property::Value defaultFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
409 tet_infoline("Apply the style");
411 std::string themeFile("ThemeOne");
412 Test::StyleMonitor::SetThemeFileOutput(themeFile, appTheme);
413 StyleManager::Get().ApplyTheme(themeFile);
415 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
416 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
418 DALI_TEST_EQUALS( bgColor, Property::Value(Color::MAGENTA), 0.001, TEST_LOCATION );
419 DALI_TEST_EQUALS( fgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
421 tet_infoline("Testing that the signal handler is called only once");
422 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
423 tet_infoline("Revert the style");
425 styleChangedSignalHandler.signalCount = 0;
426 StyleManager::Get().ApplyDefaultTheme();
428 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
429 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
431 tet_infoline("Check that the property is reverted");
432 DALI_TEST_EQUALS( bgColor, defaultBgColor, 0.001, TEST_LOCATION );
433 DALI_TEST_EQUALS( fgColor, defaultFgColor, 0.001, TEST_LOCATION );
434 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
435 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
436 tet_infoline("Testing that the signal handler is called only once");
437 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
443 int UtcDaliStyleManagerSetStyleConstantP(void)
445 ToolkitTestApplication application;
447 tet_infoline( " UtcDaliStyleManagerSetStyleConstantP" );
449 StyleManager manager = StyleManager::Get();
451 std::string key( "key" );
452 Property::Value value( 100 );
454 manager.SetStyleConstant( key, value );
456 Property::Value returnedValue;
457 manager.GetStyleConstant( key, returnedValue );
459 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
464 int UtcDaliStyleManagerGetStyleConstantP(void)
466 ToolkitTestApplication application;
468 tet_infoline( " UtcDaliStyleManagerGetStyleConstantP" );
470 StyleManager manager = StyleManager::Get();
472 std::string key( "key" );
473 Property::Value value( 100 );
475 manager.SetStyleConstant( key, value );
477 Property::Value returnedValue;
478 manager.GetStyleConstant( key, returnedValue );
480 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
484 int UtcDaliStyleManagerGetStyleConstantN(void)
486 ToolkitTestApplication application;
488 tet_infoline( " UtcDaliStyleManagerGetStyleConstantN" );
490 StyleManager manager = StyleManager::Get();
492 std::string key2( "key2" );
493 Property::Value returnedValue2;
494 DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
499 int UtcDaliStyleManagerApplyStyle(void)
501 ToolkitTestApplication application;
503 tet_infoline( "UtcDaliStyleManagerApplyStyle - test that a style can be applied to a single button" );
511 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
512 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
523 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
524 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
530 Test::TestButton testButton = Test::TestButton::New();
531 Test::TestButton testButton2 = Test::TestButton::New();
532 Stage::GetCurrent().Add( testButton );
533 Stage::GetCurrent().Add( testButton2 );
534 StyleChangedSignalChecker styleChangedSignalHandler;
535 StyleManager styleManager = StyleManager::Get();
537 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
539 tet_infoline("Apply the style");
541 std::string themeFile("ThemeOne");
542 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
543 styleManager.ApplyTheme(themeFile);
546 application.SendNotification();
547 application.Render();
549 Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
550 Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
552 // Apply the style to the test button:
553 std::string themeFile2("ThemeTwo");
554 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
555 styleManager.ApplyStyle( testButton, themeFile2, "testbutton" );
557 tet_infoline("Check that the properties change for the first button");
558 Property::Value bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
559 Property::Value fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
560 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
561 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
563 DALI_TEST_NOT_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
564 DALI_TEST_NOT_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
566 tet_infoline("Check that the properties remain the same for the second button");
567 bgColor = testButton2.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
568 fgColor = testButton2.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
569 DALI_TEST_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
570 DALI_TEST_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
576 int UtcDaliStyleManagerStyleChangedSignal(void)
578 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
579 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
582 ToolkitTestApplication application;
584 std::string labelStr("Label");
585 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
586 Stage::GetCurrent().Add( label );
588 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
589 Stage::GetCurrent().Add( label2 );
591 StyleChangedSignalChecker styleChangedSignalHandler;
592 StyleMonitor styleMonitor = StyleMonitor::Get();
593 StyleManager styleManager = StyleManager::Get();
595 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
597 Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
599 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_CHANGE);
601 tet_infoline("Test that the StyleChanged signal is received only once");
603 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
605 // Check that the label's font style has been altered
606 Property::Value family = label.GetProperty(TextLabel::Property::FONT_FAMILY);
607 std::string familyStr;
608 family.Get( familyStr );
610 DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);