2 * Copyright (c) 2016 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.
17 #include <dali/devel-api/adaptor-framework/style-monitor.h>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/devel-api/builder/builder.h>
25 #include <test-button.h>
26 #include <test-animation-data.h>
27 #include <toolkit-style-monitor.h>
28 #include <dummy-control.h>
29 #include <dali-toolkit/devel-api/controls/control-devel.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
33 using namespace Dali::Toolkit;
37 const char* defaultTheme =
41 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"NoLogging\"\n"
50 " \"textlabelFontSize0\":\n"
54 " \"textlabelFontSize1\":\n"
58 " \"textlabelFontSize2\":\n"
62 " \"textlabelFontSize3\":\n"
66 " \"textlabelFontSize4\":\n"
73 " \"pointSize\":18,\n"
74 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
75 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
76 " \"cursorWidth\":3,\n"
77 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
78 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
79 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
80 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
83 " \"textfieldFontSize0\":\n"
87 " \"textfieldFontSize1\":\n"
91 " \"textfieldFontSize2\":\n"
95 " \"textfieldFontSize3\":\n"
99 " \"textfieldFontSize4\":\n"
101 " \"pointSize\":10\n"
103 " \"textselectionpopup\":\n"
105 " \"popupMaxSize\":[656,72],\n"
106 " \"optionDividerSize\":[2,0],\n"
107 " \"popupDividerColor\":[0.23,0.72,0.8,0.11],\n"
108 " \"popupIconColor\":[1.0,1.0,1.0,1.0],\n"
109 " \"popupPressedColor\":[0.24,0.72,0.8,0.11],\n"
110 " \"background\": {\n"
111 " \"rendererType\": \"nPatch\",\n"
112 " \"imageUrl\": \"{DALI_IMAGE_DIR}selection-popup-bg.9.png\"\n"
114 " \"popupFadeInDuration\":0.25,\n"
115 " \"popupFadeOutDuration\":0.25\n"
117 " \"textselectionpopupbutton\":\n"
121 " \"pointSize\":8,\n"
122 " \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n"
125 " \"textselectiontoolbar\":\n"
127 " \"enableOvershoot\":true,\n"
130 " \"overshootAnimationSpeed\":360.0,\n"
131 " \"overshootSize\":[720.0,130.0]\n"
136 " \"overshootEffectColor\":\"B018\",\n"
137 " \"overshootAnimationSpeed\":360.0,\n"
138 " \"overshootSize\":[720.0,130.0]\n"
142 " \"overshootEffectColor\":\"B018\",\n"
143 " \"overshootAnimationSpeed\":360.0,\n"
144 " \"overshootSize\":[720.0,130.0]\n"
148 " \"pointSize\":18,\n"
149 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
150 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
151 " \"cursorWidth\":3,\n"
152 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
153 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
154 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
155 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
157 " \"ComplexControl\":\n"
169 " \"foregroundVisual\":\n"
171 " \"visualType\":\"GRADIENT\",\n"
172 " \"startPosition\": [-1, -1],\n"
173 " \"endPosition\": [1, 1],\n"
174 " \"spreadMethod\": \"REPEAT\",\n"
175 " \"stopOffset\": [0.2, 0.8],\n"
176 " \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n"
184 " \"foregroundVisual\":\n"
186 " \"visualType\":\"COLOR\",\n"
187 " \"mixColor\": [ 1,0,0,1]\n"
192 " \"transitions\":\n"
194 " \"visualName\":\"*\",\n"
195 " \"effect\":\"CROSSFADE\",\n"
198 " \"alphaFunction\":\"EASE_IN_OUT\",\n"
199 " \"duration\":0.3\n"
207 " \"foregroundVisual\":\n"
209 " \"visualType\":\"GRADIENT\",\n"
210 " \"startPosition\": [-1, -1],\n"
211 " \"endPosition\": [1, 1],\n"
212 " \"spreadMethod\": \"REPEAT\",\n"
213 " \"stopOffset\": [0.3, 0.9],\n"
214 " \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n"
216 " \"focusVisual\":\n"
218 " \"visualType\":\"IMAGE\",\n"
219 " \"url\": \"focus.png\"\n"
222 " \"entryTransition\":\n"
224 " \"target\":\"focusVisual\",\n"
225 " \"property\":\"mixColor\",\n"
226 " \"initialValue\":[0,0,0,0],\n"
227 " \"targetValue\":[1,1,1,1],\n"
230 " \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
231 " \"timePeriod\": \n"
233 " \"duration\":0.5,\n"
238 " \"exitTransition\":\n"
240 " \"target\":\"focusVisual\",\n"
241 " \"property\":\"mixColor\",\n"
242 " \"initialValue\":[1,1,1,1],\n"
243 " \"targetValue\":[0,0,0,0],\n"
246 " \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
247 " \"timePeriod\": \n"
249 " \"duration\":0.5,\n"
259 " \"foregroundVisual\":\n"
261 " \"visualType\":\"COLOR\",\n"
262 " \"mixColor\": [1,0,0,1]\n"
267 " \"transitions\":\n"
270 " \"effect\":\"CROSSFADE\",\n"
273 " \"alphaFunction\":\"EASE_IN_OUT\",\n"
274 " \"duration\":0.3\n"
279 " \"BasicControl\":\n"
287 " \"foregroundVisual\":\n"
289 " \"visualType\":\"GRADIENT\",\n"
290 " \"startPosition\": [-1, -1],\n"
291 " \"endPosition\": [1, 1],\n"
292 " \"spreadMethod\": \"REPEAT\",\n"
293 " \"stopOffset\": [0.2, 0.8],\n"
294 " \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n"
302 " \"foregroundVisual\":\n"
304 " \"visualType\":\"GRADIENT\",\n"
305 " \"startPosition\": [-1, -1],\n"
306 " \"endPosition\": [1, 1],\n"
307 " \"spreadMethod\": \"REPEAT\",\n"
308 " \"stopOffset\": [0.3, 0.9],\n"
309 " \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n"
311 " \"focusVisual\":\n"
313 " \"visualType\":\"IMAGE\",\n"
314 " \"url\": \"focus.png\"\n"
317 " \"entryTransition\":\n"
319 " \"target\":\"focusVisual\",\n"
320 " \"property\":\"mixColor\",\n"
321 " \"initialValue\":[0,0,0,0],\n"
322 " \"targetValue\":[1,1,1,1],\n"
325 " \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
326 " \"timePeriod\": \n"
328 " \"duration\":0.5,\n"
333 " \"exitTransition\":\n"
335 " \"target\":\"focusVisual\",\n"
336 " \"property\":\"mixColor\",\n"
337 " \"initialValue\":[1,1,1,1],\n"
338 " \"targetValue\":[0,0,0,0],\n"
341 " \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
342 " \"timePeriod\": \n"
344 " \"duration\":0.5,\n"
354 " \"foregroundVisual\":\n"
356 " \"visualType\":\"COLOR\",\n"
357 " \"mixColor\": [1,0,0,1]\n"
362 " \"transitions\":\n"
365 " \"effect\":\"CROSSFADE\",\n"
368 " \"alphaFunction\":\"EASE_IN_OUT\",\n"
369 " \"duration\":0.3\n"
377 } // anonymous namespace
382 void dali_style_manager_startup(void)
384 test_return_value = TET_UNDEF;
387 void dali_style_manager_cleanup(void)
389 test_return_value = TET_PASS;
392 int UtcDaliStyleManagerConstructorP(void)
394 ToolkitTestApplication application;
396 tet_infoline(" UtcDaliStyleManagerConstructorP");
397 StyleManager styleManager;
398 DALI_TEST_CHECK( !styleManager);
402 int UtcDaliStyleManagerCopyConstructorP(void)
404 TestApplication application;
406 StyleManager styleManager = StyleManager::Get();
407 StyleManager copyOfStyleManager( styleManager );
409 DALI_TEST_CHECK( copyOfStyleManager );
413 int UtcDaliStyleManagerAssignmentOperatorP(void)
415 TestApplication application;
417 StyleManager styleManager = StyleManager::Get();
418 StyleManager copyOfStyleManager = styleManager;
420 DALI_TEST_CHECK( copyOfStyleManager );
421 DALI_TEST_CHECK( copyOfStyleManager == styleManager );
425 int UtcDaliStyleManagerGet(void)
427 ToolkitTestApplication application;
429 tet_infoline(" UtcDaliStyleManagerGet");
433 type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
434 DALI_TEST_CHECK( type );
435 BaseHandle handle = type.CreateInstance();
436 DALI_TEST_CHECK( handle );
438 StyleManager manager;
440 manager = StyleManager::Get();
441 DALI_TEST_CHECK(manager);
443 StyleManager newManager = StyleManager::Get();
444 DALI_TEST_CHECK(newManager);
446 // Check that focus manager is a singleton
447 DALI_TEST_CHECK(manager == newManager);
454 class StyleChangedSignalChecker : public ConnectionTracker
457 StyleChangedSignalChecker()
462 void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
476 } // anonymous namespace
478 int UtcDaliStyleManagerApplyTheme(void)
480 ToolkitTestApplication application;
482 tet_infoline( "Testing StyleManager ApplyTheme" );
488 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"Verbose\"\n"
494 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
495 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
506 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
507 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
512 // Add 2 buttons to test how many times the signal is sent
513 Test::TestButton testButton = Test::TestButton::New();
514 Test::TestButton testButton2 = Test::TestButton::New();
515 Stage::GetCurrent().Add( testButton );
516 Stage::GetCurrent().Add( testButton2 );
517 StyleChangedSignalChecker styleChangedSignalHandler;
518 StyleChangedSignalChecker styleChangedSignalHandler2;
519 StyleManager styleManager = StyleManager::Get();
521 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
524 application.SendNotification();
525 application.Render();
527 tet_infoline("Apply the style");
529 std::string themeFile("ThemeOne");
530 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
531 StyleManager::Get().ApplyTheme(themeFile);
533 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
534 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
536 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
537 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
539 tet_infoline("Testing that the signal handler is called only once");
540 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
542 tet_infoline("Override the background property");
543 testButton.SetProperty( Test::TestButton::Property::BACKGROUND_COLOR, Color::GREEN );
544 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
545 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
546 DALI_TEST_EQUALS( bgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
547 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
550 application.SendNotification();
551 application.Render();
553 tet_infoline("Apply the style again");
555 styleChangedSignalHandler.signalCount = 0;
556 StyleManager::Get().ApplyTheme(themeFile);
558 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
559 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
561 tet_infoline("Check that the property is changed");
562 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
563 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
564 tet_infoline("Testing that the signal handler is called only once");
565 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
567 tet_infoline( "Load a different stylesheet");
569 tet_infoline("Apply the new style");
570 std::string themeFile2("ThemeTwo");
571 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
573 styleChangedSignalHandler.signalCount = 0;
574 StyleManager::Get().ApplyTheme(themeFile2);
576 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
577 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
579 tet_infoline("Check that the properties change, but the signal gets sent only once");
580 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
581 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
582 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
588 int UtcDaliStyleManagerApplyDefaultTheme(void)
590 tet_infoline( "Testing StyleManager ApplyTheme" );
592 const char* defaultTheme =
596 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"Concise\"\n"
602 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
603 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
607 // Bg: Yellow, Fg: Blue
609 const char* appTheme =
615 " \"backgroundColor\":[1.0,0.0,1.0,1.0],\n"
616 " \"foregroundColor\":[0.0,1.0,0.0,1.0]\n"
620 // Bg::Magenta, Fg:Green
622 std::string filepath(TEST_RESOURCE_DIR "");
624 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
626 ToolkitTestApplication application;
628 Test::TestButton testButton = Test::TestButton::New();
629 Stage::GetCurrent().Add( testButton );
630 StyleChangedSignalChecker styleChangedSignalHandler;
631 StyleManager styleManager = StyleManager::Get();
633 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
636 application.SendNotification();
637 application.Render();
640 Property::Value defaultBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
641 Property::Value defaultFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
643 tet_infoline("Apply the style");
645 std::string themeFile("ThemeOne");
646 Test::StyleMonitor::SetThemeFileOutput(themeFile, appTheme);
647 StyleManager::Get().ApplyTheme(themeFile);
649 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
650 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
652 DALI_TEST_EQUALS( bgColor, Property::Value(Color::MAGENTA), 0.001, TEST_LOCATION );
653 DALI_TEST_EQUALS( fgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
655 tet_infoline("Testing that the signal handler is called only once");
656 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
657 tet_infoline("Revert the style");
659 styleChangedSignalHandler.signalCount = 0;
660 StyleManager::Get().ApplyDefaultTheme();
662 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
663 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
665 tet_infoline("Check that the property is reverted");
666 DALI_TEST_EQUALS( bgColor, defaultBgColor, 0.001, TEST_LOCATION );
667 DALI_TEST_EQUALS( fgColor, defaultFgColor, 0.001, TEST_LOCATION );
668 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
669 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
670 tet_infoline("Testing that the signal handler is called only once");
671 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
677 int UtcDaliStyleManagerSetStyleConstantP(void)
679 ToolkitTestApplication application;
681 tet_infoline( " UtcDaliStyleManagerSetStyleConstantP" );
683 StyleManager manager = StyleManager::Get();
685 std::string key( "key" );
686 Property::Value value( 100 );
688 manager.SetStyleConstant( key, value );
690 Property::Value returnedValue;
691 manager.GetStyleConstant( key, returnedValue );
693 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
698 int UtcDaliStyleManagerGetStyleConstantP(void)
700 ToolkitTestApplication application;
702 tet_infoline( " UtcDaliStyleManagerGetStyleConstantP" );
704 StyleManager manager = StyleManager::Get();
706 std::string key( "key" );
707 Property::Value value( 100 );
709 manager.SetStyleConstant( key, value );
711 Property::Value returnedValue;
712 manager.GetStyleConstant( key, returnedValue );
714 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
718 int UtcDaliStyleManagerGetStyleConstantN(void)
720 ToolkitTestApplication application;
722 tet_infoline( " UtcDaliStyleManagerGetStyleConstantN" );
724 StyleManager manager = StyleManager::Get();
726 std::string key2( "key2" );
727 Property::Value returnedValue2;
728 DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
733 int UtcDaliStyleManagerApplyStyle(void)
735 ToolkitTestApplication application;
737 tet_infoline( "UtcDaliStyleManagerApplyStyle - test that a style can be applied to a single button" );
743 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"General\"\n"
749 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
750 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
761 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
762 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
768 Test::TestButton testButton = Test::TestButton::New();
769 Test::TestButton testButton2 = Test::TestButton::New();
770 Stage::GetCurrent().Add( testButton );
771 Stage::GetCurrent().Add( testButton2 );
772 StyleChangedSignalChecker styleChangedSignalHandler;
773 StyleManager styleManager = StyleManager::Get();
775 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
777 tet_infoline("Apply the style");
779 std::string themeFile("ThemeOne");
780 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
781 styleManager.ApplyTheme(themeFile);
784 application.SendNotification();
785 application.Render();
787 Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
788 Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
790 // Apply the style to the test button:
791 std::string themeFile2("ThemeTwo");
792 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
793 styleManager.ApplyStyle( testButton, themeFile2, "testbutton" );
795 tet_infoline("Check that the properties change for the first button");
796 Property::Value bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
797 Property::Value fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
798 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
799 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
801 DALI_TEST_NOT_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
802 DALI_TEST_NOT_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
804 tet_infoline("Check that the properties remain the same for the second button");
805 bgColor = testButton2.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
806 fgColor = testButton2.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
807 DALI_TEST_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
808 DALI_TEST_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
814 int UtcDaliStyleManagerIncludeStyleP(void)
816 ToolkitTestApplication application;
818 tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works" );
824 " \"src/dali-toolkit-styling/theme2.json\"\n"
830 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
836 Test::TestButton testButton = Test::TestButton::New();
837 Test::TestButton testButton2 = Test::TestButton::New();
838 Stage::GetCurrent().Add( testButton );
839 Stage::GetCurrent().Add( testButton2 );
840 StyleChangedSignalChecker styleChangedSignalHandler;
841 StyleManager styleManager = StyleManager::Get();
843 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
845 tet_infoline("Apply the style");
847 std::string themeFile("ThemeOne");
848 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
850 styleManager.ApplyTheme(themeFile);
853 application.SendNotification();
854 application.Render();
856 Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
857 Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
859 DALI_TEST_EQUALS( themedBgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
860 DALI_TEST_EQUALS( themedFgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
866 int UtcDaliStyleManagerIncludeStyleN(void)
868 ToolkitTestApplication application;
870 tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works, but included stylesheet is bad json" );
876 " \"src/dali-toolkit-styling/theme3.json\"\n"
882 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
888 Test::TestButton testButton = Test::TestButton::New();
889 Test::TestButton testButton2 = Test::TestButton::New();
890 Stage::GetCurrent().Add( testButton );
891 Stage::GetCurrent().Add( testButton2 );
892 StyleChangedSignalChecker styleChangedSignalHandler;
893 StyleManager styleManager = StyleManager::Get();
895 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
897 tet_infoline("Apply the style");
899 std::string themeFile("ThemeOne");
900 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
904 styleManager.ApplyTheme(themeFile);
906 catch( Dali::DaliException& e )
908 DALI_TEST_ASSERT( e, "!\"Cannot parse JSON\"", TEST_LOCATION );
915 int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
917 tet_infoline("Test that the StyleChange signal is fired when the font family is altered" );
918 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
921 ToolkitTestApplication application;
923 std::string labelStr("Label");
924 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
925 Stage::GetCurrent().Add( label );
927 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
928 Stage::GetCurrent().Add( label2 );
930 StyleChangedSignalChecker styleChangedSignalHandler;
931 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
932 StyleManager styleManager = StyleManager::Get();
934 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
936 Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
938 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_CHANGE);
940 tet_infoline("Test that the StyleChanged signal is received only once");
942 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
944 // Check that the label's font style has been altered
945 Property::Value family = label.GetProperty(TextLabel::Property::FONT_FAMILY);
946 std::string familyStr;
947 family.Get( familyStr );
949 DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
954 int UtcDaliStyleManagerStyleChangedSignalFontSize(void)
956 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
958 const char* defaultTheme =
962 " \"textlabelFontSize0\":\n"
964 " \"pointSize\":10\n"
966 " \"textlabelFontSize1\":\n"
968 " \"pointSize\":10\n"
970 " \"textlabelFontSize2\":\n"
972 " \"pointSize\":12\n"
974 " \"textlabelFontSize3\":\n"
976 " \"pointSize\":14\n"
978 " \"textlabelFontSize4\":\n"
980 " \"pointSize\":16\n"
985 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
987 ToolkitTestApplication application;
989 std::string labelStr("Label");
990 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
991 Stage::GetCurrent().Add( label );
993 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
994 Stage::GetCurrent().Add( label2 );
996 StyleChangedSignalChecker styleChangedSignalHandler;
997 StyleMonitor styleMonitor = StyleMonitor::Get();
998 StyleManager styleManager = StyleManager::Get();
1000 label.SetProperty(TextLabel::Property::POINT_SIZE, 10.0f);
1002 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
1004 Test::StyleMonitor::SetDefaultFontSize(2);
1005 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1007 tet_infoline("Test that the StyleChanged signal is received only once");
1008 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1010 tet_infoline("Test that the label's font size has been altered\n");
1011 Property::Value pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
1013 pointSizeValue.Get( pointSize );
1015 DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
1017 styleChangedSignalHandler.signalCount = 0;
1019 Test::StyleMonitor::SetDefaultFontSize(4);
1020 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1022 tet_infoline("Test that the StyleChanged signal is received only once");
1023 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1025 // Check that the label's font style has been altered
1026 pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
1027 pointSizeValue.Get( pointSize );
1029 DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
1036 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextField(void)
1038 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
1040 const char* defaultTheme =
1044 " \"textfieldFontSize0\":\n"
1046 " \"pointSize\":8\n"
1048 " \"textfieldFontSize1\":\n"
1050 " \"pointSize\":10\n"
1052 " \"textfieldFontSize2\":\n"
1054 " \"pointSize\":12\n"
1056 " \"textfieldFontSize3\":\n"
1058 " \"pointSize\":14\n"
1060 " \"textfieldFontSize4\":\n"
1062 " \"pointSize\":16\n"
1067 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
1069 ToolkitTestApplication application;
1071 std::string fieldStr("Field");
1072 Toolkit::TextField field = Toolkit::TextField::New();
1073 field.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
1074 Stage::GetCurrent().Add( field );
1076 Toolkit::TextField field2 = Toolkit::TextField::New();
1077 Stage::GetCurrent().Add( field2 );
1078 field2.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
1080 StyleChangedSignalChecker styleChangedSignalHandler;
1081 StyleMonitor styleMonitor = StyleMonitor::Get();
1082 StyleManager styleManager = StyleManager::Get();
1084 field.SetProperty(TextField::Property::POINT_SIZE, 10.0f);
1086 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
1088 Test::StyleMonitor::SetDefaultFontSize(2);
1089 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1091 tet_infoline("Test that the StyleChanged signal is received only once");
1092 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1094 tet_infoline("Test that the field's font size has been altered\n");
1095 Property::Value pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
1097 pointSizeValue.Get( pointSize );
1099 DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
1101 styleChangedSignalHandler.signalCount = 0;
1103 Test::StyleMonitor::SetDefaultFontSize(4);
1104 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1106 tet_infoline("Test that the StyleChanged signal is received only once");
1107 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1109 // Check that the field's font style has been altered
1110 pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
1111 pointSizeValue.Get( pointSize );
1113 DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
1119 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
1121 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
1123 const char* defaultTheme =
1127 " \"texteditorFontSize0\":\n"
1129 " \"pointSize\":10\n"
1131 " \"texteditorFontSize1\":\n"
1133 " \"pointSize\":12\n"
1135 " \"texteditorFontSize2\":\n"
1137 " \"pointSize\":14\n"
1139 " \"texteditorFontSize3\":\n"
1141 " \"pointSize\":18\n"
1143 " \"texteditorFontSize4\":\n"
1145 " \"pointSize\":25\n"
1150 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
1152 ToolkitTestApplication application;
1154 std::string editorStr("Editor");
1155 Toolkit::TextEditor editor = Toolkit::TextEditor::New();
1156 editor.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
1157 Stage::GetCurrent().Add( editor );
1159 Toolkit::TextEditor editor2 = Toolkit::TextEditor::New();
1160 Stage::GetCurrent().Add( editor2 );
1161 editor2.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
1163 StyleChangedSignalChecker styleChangedSignalHandler;
1164 StyleMonitor styleMonitor = StyleMonitor::Get();
1165 StyleManager styleManager = StyleManager::Get();
1167 editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.0f);
1169 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
1171 Test::StyleMonitor::SetDefaultFontSize(2);
1172 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1174 tet_infoline("Test that the StyleChanged signal is received only once");
1175 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1177 tet_infoline("Test that the editor's font size has been altered\n");
1178 Property::Value pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
1180 pointSizeValue.Get( pointSize );
1182 DALI_TEST_EQUALS( pointSize, 14.0f, 0.001, TEST_LOCATION );
1184 styleChangedSignalHandler.signalCount = 0;
1186 Test::StyleMonitor::SetDefaultFontSize(4);
1187 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1189 tet_infoline("Test that the StyleChanged signal is received only once");
1190 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
1192 // Check that the editor's font style has been altered
1193 pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
1194 pointSizeValue.Get( pointSize );
1196 DALI_TEST_EQUALS( pointSize, 25.0f, 0.001, TEST_LOCATION );
1203 int UtcDaliStyleManagerVisualTransitionParsing(void)
1205 tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
1206 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1209 ToolkitTestApplication application;
1211 StyleChangedSignalChecker styleChangedSignalHandler;
1212 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1213 StyleManager styleManager = StyleManager::Get();
1215 DummyControl actor = DummyControl::New(true);
1216 actor.SetStyleName("BasicControl");
1217 Stage::GetCurrent().Add(actor);
1219 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1221 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1222 Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1224 actor.SetProperty( DevelControl::Property::STATE, DevelControl::FOCUSED );
1226 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1227 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), true, TEST_LOCATION);
1229 Visual::Base visual2 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1230 DALI_TEST_CHECK( visual1 != visual2 );
1232 actor.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
1234 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1236 Visual::Base visual3 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1237 Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1238 DALI_TEST_CHECK( !focusVisual );
1239 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION);
1241 DALI_TEST_CHECK( visual1 != visual3 );
1242 DALI_TEST_CHECK( visual2 != visual3 );
1248 int UtcDaliStyleManagerVisualTransitionParsing02(void)
1250 tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
1251 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1254 ToolkitTestApplication application;
1256 StyleChangedSignalChecker styleChangedSignalHandler;
1257 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1258 StyleManager styleManager = StyleManager::Get();
1260 DummyControl actor = DummyControl::New(true);
1261 actor.SetProperty(DevelControl::Property::STATE, "FOCUSED");
1263 actor.SetStyleName("ComplexControl");
1264 Stage::GetCurrent().Add(actor);
1266 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1268 DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1269 Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1270 DALI_TEST_CHECK( visual1 );
1272 visual1.CreatePropertyMap( map );
1273 Property::Value* value = map.Find( Visual::Property::TYPE );
1274 DALI_TEST_CHECK( value );
1277 value->Get( visualType );
1279 DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::GRADIENT, TEST_LOCATION );