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>
30 using namespace Dali::Toolkit;
34 const char* defaultTheme =
38 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"NoLogging\"\n"
47 " \"textlabelFontSize0\":\n"
51 " \"textlabelFontSize1\":\n"
55 " \"textlabelFontSize2\":\n"
59 " \"textlabelFontSize3\":\n"
63 " \"textlabelFontSize4\":\n"
70 " \"pointSize\":18,\n"
71 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
72 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
73 " \"cursorWidth\":3,\n"
74 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
75 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
76 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
77 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
80 " \"textfieldFontSize0\":\n"
84 " \"textfieldFontSize1\":\n"
88 " \"textfieldFontSize2\":\n"
92 " \"textfieldFontSize3\":\n"
96 " \"textfieldFontSize4\":\n"
100 " \"textselectionpopup\":\n"
102 " \"popupMaxSize\":[656,72],\n"
103 " \"optionDividerSize\":[2,0],\n"
104 " \"popupDividerColor\":[0.23,0.72,0.8,0.11],\n"
105 " \"popupIconColor\":[1.0,1.0,1.0,1.0],\n"
106 " \"popupPressedColor\":[0.24,0.72,0.8,0.11],\n"
107 " \"background\": {\n"
108 " \"rendererType\": \"nPatch\",\n"
109 " \"imageUrl\": \"{DALI_IMAGE_DIR}selection-popup-bg.9.png\"\n"
111 " \"popupFadeInDuration\":0.25,\n"
112 " \"popupFadeOutDuration\":0.25\n"
114 " \"textselectionpopupbutton\":\n"
118 " \"pointSize\":8,\n"
119 " \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n"
122 " \"textselectiontoolbar\":\n"
124 " \"enableOvershoot\":true,\n"
127 " \"overshootAnimationSpeed\":360.0,\n"
128 " \"overshootSize\":[720.0,130.0]\n"
133 " \"overshootEffectColor\":\"B018\",\n"
134 " \"overshootAnimationSpeed\":360.0,\n"
135 " \"overshootSize\":[720.0,130.0]\n"
139 " \"overshootEffectColor\":\"B018\",\n"
140 " \"overshootAnimationSpeed\":360.0,\n"
141 " \"overshootSize\":[720.0,130.0]\n"
145 " \"pointSize\":18,\n"
146 " \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
147 " \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n"
148 " \"cursorWidth\":3,\n"
149 " \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n"
150 " \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
151 " \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
152 " \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
157 } // anonymous namespace
161 void dali_style_manager_startup(void)
163 test_return_value = TET_UNDEF;
166 void dali_style_manager_cleanup(void)
168 test_return_value = TET_PASS;
171 int UtcDaliStyleManagerConstructorP(void)
173 ToolkitTestApplication application;
175 tet_infoline(" UtcDaliStyleManagerConstructorP");
176 StyleManager styleManager;
177 DALI_TEST_CHECK( !styleManager);
181 int UtcDaliStyleManagerCopyConstructorP(void)
183 TestApplication application;
185 StyleManager styleManager = StyleManager::Get();
186 StyleManager copyOfStyleManager( styleManager );
188 DALI_TEST_CHECK( copyOfStyleManager );
192 int UtcDaliStyleManagerAssignmentOperatorP(void)
194 TestApplication application;
196 StyleManager styleManager = StyleManager::Get();
197 StyleManager copyOfStyleManager = styleManager;
199 DALI_TEST_CHECK( copyOfStyleManager );
200 DALI_TEST_CHECK( copyOfStyleManager == styleManager );
204 int UtcDaliStyleManagerGet(void)
206 ToolkitTestApplication application;
208 tet_infoline(" UtcDaliStyleManagerGet");
212 type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
213 DALI_TEST_CHECK( type );
214 BaseHandle handle = type.CreateInstance();
215 DALI_TEST_CHECK( handle );
217 StyleManager manager;
219 manager = StyleManager::Get();
220 DALI_TEST_CHECK(manager);
222 StyleManager newManager = StyleManager::Get();
223 DALI_TEST_CHECK(newManager);
225 // Check that focus manager is a singleton
226 DALI_TEST_CHECK(manager == newManager);
233 class StyleChangedSignalChecker : public ConnectionTracker
236 StyleChangedSignalChecker()
241 void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
255 } // anonymous namespace
257 int UtcDaliStyleManagerApplyTheme(void)
259 ToolkitTestApplication application;
261 tet_infoline( "Testing StyleManager ApplyTheme" );
267 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"Verbose\"\n"
273 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
274 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
285 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
286 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
291 // Add 2 buttons to test how many times the signal is sent
292 Test::TestButton testButton = Test::TestButton::New();
293 Test::TestButton testButton2 = Test::TestButton::New();
294 Stage::GetCurrent().Add( testButton );
295 Stage::GetCurrent().Add( testButton2 );
296 StyleChangedSignalChecker styleChangedSignalHandler;
297 StyleChangedSignalChecker styleChangedSignalHandler2;
298 StyleManager styleManager = StyleManager::Get();
300 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
303 application.SendNotification();
304 application.Render();
306 tet_infoline("Apply the style");
308 std::string themeFile("ThemeOne");
309 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
310 StyleManager::Get().ApplyTheme(themeFile);
312 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
313 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
315 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
316 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
318 tet_infoline("Testing that the signal handler is called only once");
319 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
321 tet_infoline("Override the background property");
322 testButton.SetProperty( Test::TestButton::Property::BACKGROUND_COLOR, Color::GREEN );
323 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
324 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
325 DALI_TEST_EQUALS( bgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
326 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
329 application.SendNotification();
330 application.Render();
332 tet_infoline("Apply the style again");
334 styleChangedSignalHandler.signalCount = 0;
335 StyleManager::Get().ApplyTheme(themeFile);
337 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
338 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
340 tet_infoline("Check that the property is changed");
341 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
342 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
343 tet_infoline("Testing that the signal handler is called only once");
344 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
346 tet_infoline( "Load a different stylesheet");
348 tet_infoline("Apply the new style");
349 std::string themeFile2("ThemeTwo");
350 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
352 styleChangedSignalHandler.signalCount = 0;
353 StyleManager::Get().ApplyTheme(themeFile2);
355 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
356 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
358 tet_infoline("Check that the properties change, but the signal gets sent only once");
359 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
360 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
361 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
367 int UtcDaliStyleManagerApplyDefaultTheme(void)
369 tet_infoline( "Testing StyleManager ApplyTheme" );
371 const char* defaultTheme =
375 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"Concise\"\n"
381 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
382 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
386 // Bg: Yellow, Fg: Blue
388 const char* appTheme =
394 " \"backgroundColor\":[1.0,0.0,1.0,1.0],\n"
395 " \"foregroundColor\":[0.0,1.0,0.0,1.0]\n"
399 // Bg::Magenta, Fg:Green
401 std::string filepath(TEST_RESOURCE_DIR "");
403 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
405 ToolkitTestApplication application;
407 Test::TestButton testButton = Test::TestButton::New();
408 Stage::GetCurrent().Add( testButton );
409 StyleChangedSignalChecker styleChangedSignalHandler;
410 StyleManager styleManager = StyleManager::Get();
412 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
415 application.SendNotification();
416 application.Render();
419 Property::Value defaultBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
420 Property::Value defaultFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
422 tet_infoline("Apply the style");
424 std::string themeFile("ThemeOne");
425 Test::StyleMonitor::SetThemeFileOutput(themeFile, appTheme);
426 StyleManager::Get().ApplyTheme(themeFile);
428 Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
429 Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
431 DALI_TEST_EQUALS( bgColor, Property::Value(Color::MAGENTA), 0.001, TEST_LOCATION );
432 DALI_TEST_EQUALS( fgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
434 tet_infoline("Testing that the signal handler is called only once");
435 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
436 tet_infoline("Revert the style");
438 styleChangedSignalHandler.signalCount = 0;
439 StyleManager::Get().ApplyDefaultTheme();
441 bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
442 fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
444 tet_infoline("Check that the property is reverted");
445 DALI_TEST_EQUALS( bgColor, defaultBgColor, 0.001, TEST_LOCATION );
446 DALI_TEST_EQUALS( fgColor, defaultFgColor, 0.001, TEST_LOCATION );
447 DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
448 DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
449 tet_infoline("Testing that the signal handler is called only once");
450 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
456 int UtcDaliStyleManagerSetStyleConstantP(void)
458 ToolkitTestApplication application;
460 tet_infoline( " UtcDaliStyleManagerSetStyleConstantP" );
462 StyleManager manager = StyleManager::Get();
464 std::string key( "key" );
465 Property::Value value( 100 );
467 manager.SetStyleConstant( key, value );
469 Property::Value returnedValue;
470 manager.GetStyleConstant( key, returnedValue );
472 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
477 int UtcDaliStyleManagerGetStyleConstantP(void)
479 ToolkitTestApplication application;
481 tet_infoline( " UtcDaliStyleManagerGetStyleConstantP" );
483 StyleManager manager = StyleManager::Get();
485 std::string key( "key" );
486 Property::Value value( 100 );
488 manager.SetStyleConstant( key, value );
490 Property::Value returnedValue;
491 manager.GetStyleConstant( key, returnedValue );
493 DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
497 int UtcDaliStyleManagerGetStyleConstantN(void)
499 ToolkitTestApplication application;
501 tet_infoline( " UtcDaliStyleManagerGetStyleConstantN" );
503 StyleManager manager = StyleManager::Get();
505 std::string key2( "key2" );
506 Property::Value returnedValue2;
507 DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
512 int UtcDaliStyleManagerApplyStyle(void)
514 ToolkitTestApplication application;
516 tet_infoline( "UtcDaliStyleManagerApplyStyle - test that a style can be applied to a single button" );
522 " \"CONFIG_SCRIPT_LOG_LEVEL\":\"General\"\n"
528 " \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
529 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
540 " \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
541 " \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
547 Test::TestButton testButton = Test::TestButton::New();
548 Test::TestButton testButton2 = Test::TestButton::New();
549 Stage::GetCurrent().Add( testButton );
550 Stage::GetCurrent().Add( testButton2 );
551 StyleChangedSignalChecker styleChangedSignalHandler;
552 StyleManager styleManager = StyleManager::Get();
554 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
556 tet_infoline("Apply the style");
558 std::string themeFile("ThemeOne");
559 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
560 styleManager.ApplyTheme(themeFile);
563 application.SendNotification();
564 application.Render();
566 Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
567 Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
569 // Apply the style to the test button:
570 std::string themeFile2("ThemeTwo");
571 Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
572 styleManager.ApplyStyle( testButton, themeFile2, "testbutton" );
574 tet_infoline("Check that the properties change for the first button");
575 Property::Value bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
576 Property::Value fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
577 DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
578 DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
580 DALI_TEST_NOT_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
581 DALI_TEST_NOT_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
583 tet_infoline("Check that the properties remain the same for the second button");
584 bgColor = testButton2.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
585 fgColor = testButton2.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
586 DALI_TEST_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
587 DALI_TEST_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
593 int UtcDaliStyleManagerIncludeStyleP(void)
595 ToolkitTestApplication application;
597 tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works" );
603 " \"src/dali-toolkit-styling/theme2.json\"\n"
609 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
615 Test::TestButton testButton = Test::TestButton::New();
616 Test::TestButton testButton2 = Test::TestButton::New();
617 Stage::GetCurrent().Add( testButton );
618 Stage::GetCurrent().Add( testButton2 );
619 StyleChangedSignalChecker styleChangedSignalHandler;
620 StyleManager styleManager = StyleManager::Get();
622 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
624 tet_infoline("Apply the style");
626 std::string themeFile("ThemeOne");
627 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
629 styleManager.ApplyTheme(themeFile);
632 application.SendNotification();
633 application.Render();
635 Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
636 Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
638 DALI_TEST_EQUALS( themedBgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
639 DALI_TEST_EQUALS( themedFgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
645 int UtcDaliStyleManagerIncludeStyleN(void)
647 ToolkitTestApplication application;
649 tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works, but included stylesheet is bad json" );
655 " \"src/dali-toolkit-styling/theme3.json\"\n"
661 " \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
667 Test::TestButton testButton = Test::TestButton::New();
668 Test::TestButton testButton2 = Test::TestButton::New();
669 Stage::GetCurrent().Add( testButton );
670 Stage::GetCurrent().Add( testButton2 );
671 StyleChangedSignalChecker styleChangedSignalHandler;
672 StyleManager styleManager = StyleManager::Get();
674 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
676 tet_infoline("Apply the style");
678 std::string themeFile("ThemeOne");
679 Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
683 styleManager.ApplyTheme(themeFile);
685 catch( Dali::DaliException& e )
687 DALI_TEST_ASSERT( e, "!\"Cannot parse JSON\"", TEST_LOCATION );
694 int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
696 tet_infoline("Test that the StyleChange signal is fired when the font family is altered" );
697 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
700 ToolkitTestApplication application;
702 std::string labelStr("Label");
703 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
704 Stage::GetCurrent().Add( label );
706 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
707 Stage::GetCurrent().Add( label2 );
709 StyleChangedSignalChecker styleChangedSignalHandler;
710 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
711 StyleManager styleManager = StyleManager::Get();
713 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
715 Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
717 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_CHANGE);
719 tet_infoline("Test that the StyleChanged signal is received only once");
721 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
723 // Check that the label's font style has been altered
724 Property::Value family = label.GetProperty(TextLabel::Property::FONT_FAMILY);
725 std::string familyStr;
726 family.Get( familyStr );
728 DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
733 int UtcDaliStyleManagerStyleChangedSignalFontSize(void)
735 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
737 const char* defaultTheme =
741 " \"textlabelFontSize0\":\n"
743 " \"pointSize\":10\n"
745 " \"textlabelFontSize1\":\n"
747 " \"pointSize\":10\n"
749 " \"textlabelFontSize2\":\n"
751 " \"pointSize\":12\n"
753 " \"textlabelFontSize3\":\n"
755 " \"pointSize\":14\n"
757 " \"textlabelFontSize4\":\n"
759 " \"pointSize\":16\n"
764 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
766 ToolkitTestApplication application;
768 std::string labelStr("Label");
769 Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
770 Stage::GetCurrent().Add( label );
772 Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
773 Stage::GetCurrent().Add( label2 );
775 StyleChangedSignalChecker styleChangedSignalHandler;
776 StyleMonitor styleMonitor = StyleMonitor::Get();
777 StyleManager styleManager = StyleManager::Get();
779 label.SetProperty(TextLabel::Property::POINT_SIZE, 10.0f);
781 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
783 Test::StyleMonitor::SetDefaultFontSize(2);
784 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
786 tet_infoline("Test that the StyleChanged signal is received only once");
787 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
789 tet_infoline("Test that the label's font size has been altered\n");
790 Property::Value pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
792 pointSizeValue.Get( pointSize );
794 DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
796 styleChangedSignalHandler.signalCount = 0;
798 Test::StyleMonitor::SetDefaultFontSize(4);
799 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
801 tet_infoline("Test that the StyleChanged signal is received only once");
802 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
804 // Check that the label's font style has been altered
805 pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
806 pointSizeValue.Get( pointSize );
808 DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
815 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextField(void)
817 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
819 const char* defaultTheme =
823 " \"textfieldFontSize0\":\n"
827 " \"textfieldFontSize1\":\n"
829 " \"pointSize\":10\n"
831 " \"textfieldFontSize2\":\n"
833 " \"pointSize\":12\n"
835 " \"textfieldFontSize3\":\n"
837 " \"pointSize\":14\n"
839 " \"textfieldFontSize4\":\n"
841 " \"pointSize\":16\n"
846 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
848 ToolkitTestApplication application;
850 std::string fieldStr("Field");
851 Toolkit::TextField field = Toolkit::TextField::New();
852 field.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
853 Stage::GetCurrent().Add( field );
855 Toolkit::TextField field2 = Toolkit::TextField::New();
856 Stage::GetCurrent().Add( field2 );
857 field2.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
859 StyleChangedSignalChecker styleChangedSignalHandler;
860 StyleMonitor styleMonitor = StyleMonitor::Get();
861 StyleManager styleManager = StyleManager::Get();
863 field.SetProperty(TextField::Property::POINT_SIZE, 10.0f);
865 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
867 Test::StyleMonitor::SetDefaultFontSize(2);
868 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
870 tet_infoline("Test that the StyleChanged signal is received only once");
871 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
873 tet_infoline("Test that the field's font size has been altered\n");
874 Property::Value pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
876 pointSizeValue.Get( pointSize );
878 DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
880 styleChangedSignalHandler.signalCount = 0;
882 Test::StyleMonitor::SetDefaultFontSize(4);
883 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
885 tet_infoline("Test that the StyleChanged signal is received only once");
886 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
888 // Check that the field's font style has been altered
889 pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
890 pointSizeValue.Get( pointSize );
892 DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
898 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
900 tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
902 const char* defaultTheme =
906 " \"texteditorFontSize0\":\n"
908 " \"pointSize\":10\n"
910 " \"texteditorFontSize1\":\n"
912 " \"pointSize\":12\n"
914 " \"texteditorFontSize2\":\n"
916 " \"pointSize\":14\n"
918 " \"texteditorFontSize3\":\n"
920 " \"pointSize\":18\n"
922 " \"texteditorFontSize4\":\n"
924 " \"pointSize\":25\n"
929 Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
931 ToolkitTestApplication application;
933 std::string editorStr("Editor");
934 Toolkit::TextEditor editor = Toolkit::TextEditor::New();
935 editor.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
936 Stage::GetCurrent().Add( editor );
938 Toolkit::TextEditor editor2 = Toolkit::TextEditor::New();
939 Stage::GetCurrent().Add( editor2 );
940 editor2.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
942 StyleChangedSignalChecker styleChangedSignalHandler;
943 StyleMonitor styleMonitor = StyleMonitor::Get();
944 StyleManager styleManager = StyleManager::Get();
946 editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.0f);
948 styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
950 Test::StyleMonitor::SetDefaultFontSize(2);
951 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
953 tet_infoline("Test that the StyleChanged signal is received only once");
954 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
956 tet_infoline("Test that the editor's font size has been altered\n");
957 Property::Value pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
959 pointSizeValue.Get( pointSize );
961 DALI_TEST_EQUALS( pointSize, 14.0f, 0.001, TEST_LOCATION );
963 styleChangedSignalHandler.signalCount = 0;
965 Test::StyleMonitor::SetDefaultFontSize(4);
966 styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
968 tet_infoline("Test that the StyleChanged signal is received only once");
969 DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
971 // Check that the editor's font style has been altered
972 pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
973 pointSizeValue.Get( pointSize );
975 DALI_TEST_EQUALS( pointSize, 25.0f, 0.001, TEST_LOCATION );