Reordered builder implementation ahead of rework
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-styling / utc-Dali-StyleManager.cpp
1 /*
2  * Copyright (c) 2016 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 #include <dali/devel-api/adaptor-framework/style-monitor.h>
18
19 #include <iostream>
20 #include <stdlib.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
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 namespace
33 {
34 const char* defaultTheme =
35 "{\n"
36 "  \"constants\":\n"
37 "  {\n"
38 "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"NoLogging\"\n"
39 "  },\n"
40 "  \"styles\":\n"
41 "  {\n"
42 "    \"textlabel\":\n"
43 "    {\n"
44 "      \"pointSize\":18\n"
45 "    },\n"
46 "\n"
47 "    \"textlabelFontSize0\":\n"
48 "    {\n"
49 "      \"pointSize\":8\n"
50 "    },\n"
51 "    \"textlabelFontSize1\":\n"
52 "    {\n"
53 "      \"pointSize\":10\n"
54 "    },\n"
55 "    \"textlabelFontSize2\":\n"
56 "    {\n"
57 "      \"pointSize\":15\n"
58 "    },\n"
59 "    \"textlabelFontSize3\":\n"
60 "    {\n"
61 "      \"pointSize\":19\n"
62 "    },\n"
63 "    \"textlabelFontSize4\":\n"
64 "    {\n"
65 "      \"pointSize\":25\n"
66 "    },\n"
67 "\n"
68 "    \"textfield\":\n"
69 "    {\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"
78 "    },\n"
79 "\n"
80 "    \"textfieldFontSize0\":\n"
81 "    {\n"
82 "      \"pointSize\":10\n"
83 "    },\n"
84 "    \"textfieldFontSize1\":\n"
85 "    {\n"
86 "      \"pointSize\":10\n"
87 "    },\n"
88 "    \"textfieldFontSize2\":\n"
89 "    {\n"
90 "      \"pointSize\":10\n"
91 "    },\n"
92 "    \"textfieldFontSize3\":\n"
93 "    {\n"
94 "      \"pointSize\":10\n"
95 "    },\n"
96 "    \"textfieldFontSize4\":\n"
97 "    {\n"
98 "      \"pointSize\":10\n"
99 "    },\n"
100 "    \"textselectionpopup\":\n"
101 "    {\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"
110 "        },\n"
111 "      \"popupFadeInDuration\":0.25,\n"
112 "      \"popupFadeOutDuration\":0.25\n"
113 "    },\n"
114 "    \"textselectionpopupbutton\":\n"
115 "    {\n"
116 "      \"label\":\n"
117 "      {\n"
118 "        \"pointSize\":8,\n"
119 "        \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n"
120 "      }\n"
121 "    },\n"
122 "    \"textselectiontoolbar\":\n"
123 "    {\n"
124 "      \"enableOvershoot\":true,\n"
125 "      \"scrollView\":\n"
126 "      {\n"
127 "        \"overshootAnimationSpeed\":360.0,\n"
128 "        \"overshootSize\":[720.0,130.0]\n"
129 "      }\n"
130 "    },\n"
131 "    \"scrollview\":\n"
132 "    {\n"
133 "      \"overshootEffectColor\":\"B018\",\n"
134 "      \"overshootAnimationSpeed\":360.0,\n"
135 "      \"overshootSize\":[720.0,130.0]\n"
136 "    },\n"
137 "    \"itemview\":\n"
138 "    {\n"
139 "      \"overshootEffectColor\":\"B018\",\n"
140 "      \"overshootAnimationSpeed\":360.0,\n"
141 "      \"overshootSize\":[720.0,130.0]\n"
142 "    },\n"
143 "    \"texteditor\":\n"
144 "    {\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"
153 "    }\n"
154 "  }\n"
155 "}\n";
156
157 } // anonymous namespace
158
159
160
161 void dali_style_manager_startup(void)
162 {
163   test_return_value = TET_UNDEF;
164 }
165
166 void dali_style_manager_cleanup(void)
167 {
168   test_return_value = TET_PASS;
169 }
170
171 int UtcDaliStyleManagerConstructorP(void)
172 {
173   ToolkitTestApplication application;
174
175   tet_infoline(" UtcDaliStyleManagerConstructorP");
176   StyleManager styleManager;
177   DALI_TEST_CHECK( !styleManager);
178   END_TEST;
179 }
180
181 int UtcDaliStyleManagerCopyConstructorP(void)
182 {
183   TestApplication application;
184
185   StyleManager styleManager = StyleManager::Get();
186   StyleManager copyOfStyleManager( styleManager );
187
188   DALI_TEST_CHECK( copyOfStyleManager );
189   END_TEST;
190 }
191
192 int UtcDaliStyleManagerAssignmentOperatorP(void)
193 {
194   TestApplication application;
195
196   StyleManager styleManager = StyleManager::Get();
197   StyleManager copyOfStyleManager = styleManager;
198
199   DALI_TEST_CHECK( copyOfStyleManager );
200   DALI_TEST_CHECK( copyOfStyleManager == styleManager );
201   END_TEST;
202 }
203
204 int UtcDaliStyleManagerGet(void)
205 {
206   ToolkitTestApplication application;
207
208   tet_infoline(" UtcDaliStyleManagerGet");
209
210   // Register Type
211   TypeInfo type;
212   type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
213   DALI_TEST_CHECK( type );
214   BaseHandle handle = type.CreateInstance();
215   DALI_TEST_CHECK( handle );
216
217   StyleManager manager;
218
219   manager = StyleManager::Get();
220   DALI_TEST_CHECK(manager);
221
222   StyleManager newManager = StyleManager::Get();
223   DALI_TEST_CHECK(newManager);
224
225   // Check that focus manager is a singleton
226   DALI_TEST_CHECK(manager == newManager);
227   END_TEST;
228 }
229
230
231 namespace
232 {
233 class StyleChangedSignalChecker : public ConnectionTracker
234 {
235 public:
236   StyleChangedSignalChecker()
237   : signalCount(0)
238   {
239   }
240
241   void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
242   {
243     signalCount++;
244   }
245
246   void Reset()
247   {
248     signalCount =0;
249   }
250
251 public:
252   int signalCount;
253 };
254
255 } // anonymous namespace
256
257 int UtcDaliStyleManagerApplyTheme(void)
258 {
259   ToolkitTestApplication application;
260
261   tet_infoline( "Testing StyleManager ApplyTheme" );
262
263   const char* json1 =
264     "{\n"
265     "  \"constants\":\n"
266     "  {\n"
267     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Verbose\"\n"
268     "  },\n"
269     "  \"styles\":\n"
270     "  {\n"
271     "    \"testbutton\":\n"
272     "    {\n"
273     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
274     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
275     "    }\n"
276     "  }\n"
277     "}\n";
278
279   const char* json2 =
280     "{\n"
281     "  \"styles\":\n"
282     "  {\n"
283     "    \"testbutton\":\n"
284     "    {\n"
285     "      \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
286     "      \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
287     "    }\n"
288     "  }\n"
289     "}\n";
290
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();
299
300   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
301
302   // Render and notify
303   application.SendNotification();
304   application.Render();
305
306   tet_infoline("Apply the style");
307
308   std::string themeFile("ThemeOne");
309   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
310   StyleManager::Get().ApplyTheme(themeFile);
311
312   Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
313   Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
314
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 );
317
318   tet_infoline("Testing that the signal handler is called only once");
319   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
320
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 );
327
328   // Render and notify
329   application.SendNotification();
330   application.Render();
331
332   tet_infoline("Apply the style again");
333
334   styleChangedSignalHandler.signalCount = 0;
335   StyleManager::Get().ApplyTheme(themeFile);
336
337   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
338   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
339
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 );
345
346   tet_infoline( "Load a different stylesheet");
347
348   tet_infoline("Apply the new style");
349   std::string themeFile2("ThemeTwo");
350   Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
351
352   styleChangedSignalHandler.signalCount = 0;
353   StyleManager::Get().ApplyTheme(themeFile2);
354
355   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
356   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
357
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 );
362
363   END_TEST;
364 }
365
366
367 int UtcDaliStyleManagerApplyDefaultTheme(void)
368 {
369   tet_infoline( "Testing StyleManager ApplyTheme" );
370
371   const char* defaultTheme =
372     "{\n"
373     "  \"constants\":\n"
374     "  {\n"
375     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Concise\"\n"
376     "  },\n"
377     "  \"styles\":\n"
378     "  {\n"
379     "    \"testbutton\":\n"
380     "    {\n"
381     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
382     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
383     "    }\n"
384     "  }\n"
385     "}\n";
386   // Bg: Yellow, Fg: Blue
387
388   const char* appTheme =
389     "{\n"
390     "  \"styles\":\n"
391     "  {\n"
392     "    \"testbutton\":\n"
393     "    {\n"
394     "      \"backgroundColor\":[1.0,0.0,1.0,1.0],\n"
395     "      \"foregroundColor\":[0.0,1.0,0.0,1.0]\n"
396     "    }\n"
397     "  }\n"
398     "}\n";
399   // Bg::Magenta, Fg:Green
400
401   std::string filepath(TEST_RESOURCE_DIR "");
402
403   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
404                                           defaultTheme);
405   ToolkitTestApplication application;
406
407   Test::TestButton testButton = Test::TestButton::New();
408   Stage::GetCurrent().Add( testButton );
409   StyleChangedSignalChecker styleChangedSignalHandler;
410   StyleManager styleManager = StyleManager::Get();
411
412   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
413
414   // Render and notify
415   application.SendNotification();
416   application.Render();
417
418   // Get the default:
419   Property::Value defaultBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
420   Property::Value defaultFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
421
422   tet_infoline("Apply the style");
423
424   std::string themeFile("ThemeOne");
425   Test::StyleMonitor::SetThemeFileOutput(themeFile, appTheme);
426   StyleManager::Get().ApplyTheme(themeFile);
427
428   Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
429   Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
430
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 );
433
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");
437
438   styleChangedSignalHandler.signalCount = 0;
439   StyleManager::Get().ApplyDefaultTheme();
440
441   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
442   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
443
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 );
451
452   END_TEST;
453 }
454
455
456 int UtcDaliStyleManagerSetStyleConstantP(void)
457 {
458   ToolkitTestApplication application;
459
460   tet_infoline( " UtcDaliStyleManagerSetStyleConstantP" );
461
462   StyleManager manager = StyleManager::Get();
463
464   std::string key( "key" );
465   Property::Value value( 100 );
466
467   manager.SetStyleConstant( key, value );
468
469   Property::Value returnedValue;
470   manager.GetStyleConstant( key, returnedValue );
471
472   DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
473   END_TEST;
474 }
475
476
477 int UtcDaliStyleManagerGetStyleConstantP(void)
478 {
479   ToolkitTestApplication application;
480
481   tet_infoline( " UtcDaliStyleManagerGetStyleConstantP" );
482
483   StyleManager manager = StyleManager::Get();
484
485   std::string key( "key" );
486   Property::Value value( 100 );
487
488   manager.SetStyleConstant( key, value );
489
490   Property::Value returnedValue;
491   manager.GetStyleConstant( key, returnedValue );
492
493   DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
494   END_TEST;
495 }
496
497 int UtcDaliStyleManagerGetStyleConstantN(void)
498 {
499   ToolkitTestApplication application;
500
501   tet_infoline( " UtcDaliStyleManagerGetStyleConstantN" );
502
503   StyleManager manager = StyleManager::Get();
504
505   std::string key2( "key2" );
506   Property::Value returnedValue2;
507   DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
508
509   END_TEST;
510 }
511
512 int UtcDaliStyleManagerApplyStyle(void)
513 {
514   ToolkitTestApplication application;
515
516   tet_infoline( "UtcDaliStyleManagerApplyStyle - test that a style can be applied to a single button" );
517
518   const char* json1 =
519     "{\n"
520     "  \"constants\":\n"
521     "  {\n"
522     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"General\"\n"
523     "  },\n"
524     "  \"styles\":\n"
525     "  {\n"
526     "    \"testbutton\":\n"
527     "    {\n"
528     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
529     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
530     "    }\n"
531     "  }\n"
532     "}\n";
533
534   const char* json2 =
535     "{\n"
536     "  \"styles\":\n"
537     "  {\n"
538     "    \"testbutton\":\n"
539     "    {\n"
540     "      \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
541     "      \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
542     "    }\n"
543     "  }\n"
544     "}\n";
545
546   // Add 2 buttons
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();
553
554   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
555
556   tet_infoline("Apply the style");
557
558   std::string themeFile("ThemeOne");
559   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
560   styleManager.ApplyTheme(themeFile);
561
562   // Render and notify
563   application.SendNotification();
564   application.Render();
565
566   Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
567   Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
568
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" );
573
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 );
579
580   DALI_TEST_NOT_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
581   DALI_TEST_NOT_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
582
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 );
588
589   END_TEST;
590 }
591
592
593 int UtcDaliStyleManagerIncludeStyleP(void)
594 {
595   ToolkitTestApplication application;
596
597   tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works" );
598
599   const char* json1 =
600     "{\n"
601     "  \"includes\":\n"
602     "  [\n"
603     "     \"src/dali-toolkit-styling/theme2.json\"\n"
604     "  ],\n"
605     "  \"styles\":\n"
606     "  {\n"
607     "    \"testbutton\":\n"
608     "    {\n"
609     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
610     "    }\n"
611     "  }\n"
612     "}\n";
613
614   // Add 2 buttons
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();
621
622   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
623
624   tet_infoline("Apply the style");
625
626   std::string themeFile("ThemeOne");
627   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
628
629   styleManager.ApplyTheme(themeFile);
630
631   // Render and notify
632   application.SendNotification();
633   application.Render();
634
635   Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
636   Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
637
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 );
640
641   END_TEST;
642 }
643
644
645 int UtcDaliStyleManagerIncludeStyleN(void)
646 {
647   ToolkitTestApplication application;
648
649   tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works, but included stylesheet is bad json" );
650
651   const char* json1 =
652     "{\n"
653     "  \"includes\":\n"
654     "  [\n"
655     "     \"src/dali-toolkit-styling/theme3.json\"\n"
656     "  ],\n"
657     "  \"styles\":\n"
658     "  {\n"
659     "    \"testbutton\":\n"
660     "    {\n"
661     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
662     "    }\n"
663     "  }\n"
664     "}\n";
665
666   // Add 2 buttons
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();
673
674   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
675
676   tet_infoline("Apply the style");
677
678   std::string themeFile("ThemeOne");
679   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
680
681   try
682   {
683     styleManager.ApplyTheme(themeFile);
684   }
685   catch( Dali::DaliException& e )
686   {
687     DALI_TEST_ASSERT( e, "!\"Cannot parse JSON\"", TEST_LOCATION );
688   }
689
690   END_TEST;
691 }
692
693
694 int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
695 {
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",
698                                           defaultTheme );
699
700   ToolkitTestApplication application;
701
702   std::string labelStr("Label");
703   Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
704   Stage::GetCurrent().Add( label );
705
706   Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
707   Stage::GetCurrent().Add( label2 );
708
709   StyleChangedSignalChecker styleChangedSignalHandler;
710   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
711   StyleManager styleManager = StyleManager::Get();
712
713   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
714
715   Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
716
717   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_CHANGE);
718
719   tet_infoline("Test that the StyleChanged signal is received only once");
720
721   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
722
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 );
727
728   DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
729
730   END_TEST;
731 }
732
733 int UtcDaliStyleManagerStyleChangedSignalFontSize(void)
734 {
735   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
736
737   const char* defaultTheme =
738     "{\n"
739     "  \"styles\":\n"
740     "  {\n"
741     "    \"textlabelFontSize0\":\n"
742     "    {\n"
743     "      \"pointSize\":10\n"
744     "    },\n"
745     "    \"textlabelFontSize1\":\n"
746     "    {\n"
747     "      \"pointSize\":10\n"
748     "    },\n"
749     "    \"textlabelFontSize2\":\n"
750     "    {\n"
751     "      \"pointSize\":12\n"
752     "    },\n"
753     "    \"textlabelFontSize3\":\n"
754     "    {\n"
755     "      \"pointSize\":14\n"
756     "    },\n"
757     "    \"textlabelFontSize4\":\n"
758     "    {\n"
759     "      \"pointSize\":16\n"
760     "    }\n"
761     "  }\n"
762     "}\n";
763
764   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
765
766   ToolkitTestApplication application;
767
768   std::string labelStr("Label");
769   Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
770   Stage::GetCurrent().Add( label );
771
772   Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
773   Stage::GetCurrent().Add( label2 );
774
775   StyleChangedSignalChecker styleChangedSignalHandler;
776   StyleMonitor styleMonitor = StyleMonitor::Get();
777   StyleManager styleManager = StyleManager::Get();
778
779   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.0f);
780
781   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
782
783   Test::StyleMonitor::SetDefaultFontSize(2);
784   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
785
786   tet_infoline("Test that the StyleChanged signal is received only once");
787   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
788
789   tet_infoline("Test that the label's font size has been altered\n");
790   Property::Value pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
791   float pointSize;
792   pointSizeValue.Get( pointSize );
793
794   DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
795
796   styleChangedSignalHandler.signalCount = 0;
797
798   Test::StyleMonitor::SetDefaultFontSize(4);
799   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
800
801   tet_infoline("Test that the StyleChanged signal is received only once");
802   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
803
804   // Check that the label's font style has been altered
805   pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
806   pointSizeValue.Get( pointSize );
807
808   DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
809
810
811   END_TEST;
812 }
813
814
815 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextField(void)
816 {
817   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
818
819   const char* defaultTheme =
820     "{\n"
821     "  \"styles\":\n"
822     "  {\n"
823     "    \"textfieldFontSize0\":\n"
824     "    {\n"
825     "      \"pointSize\":8\n"
826     "    },\n"
827     "    \"textfieldFontSize1\":\n"
828     "    {\n"
829     "      \"pointSize\":10\n"
830     "    },\n"
831     "    \"textfieldFontSize2\":\n"
832     "    {\n"
833     "      \"pointSize\":12\n"
834     "    },\n"
835     "    \"textfieldFontSize3\":\n"
836     "    {\n"
837     "      \"pointSize\":14\n"
838     "    },\n"
839     "    \"textfieldFontSize4\":\n"
840     "    {\n"
841     "      \"pointSize\":16\n"
842     "    }\n"
843     "  }\n"
844     "}\n";
845
846   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
847
848   ToolkitTestApplication application;
849
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 );
854
855   Toolkit::TextField field2 = Toolkit::TextField::New();
856   Stage::GetCurrent().Add( field2 );
857   field2.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
858
859   StyleChangedSignalChecker styleChangedSignalHandler;
860   StyleMonitor styleMonitor = StyleMonitor::Get();
861   StyleManager styleManager = StyleManager::Get();
862
863   field.SetProperty(TextField::Property::POINT_SIZE, 10.0f);
864
865   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
866
867   Test::StyleMonitor::SetDefaultFontSize(2);
868   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
869
870   tet_infoline("Test that the StyleChanged signal is received only once");
871   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
872
873   tet_infoline("Test that the field's font size has been altered\n");
874   Property::Value pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
875   float pointSize;
876   pointSizeValue.Get( pointSize );
877
878   DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
879
880   styleChangedSignalHandler.signalCount = 0;
881
882   Test::StyleMonitor::SetDefaultFontSize(4);
883   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
884
885   tet_infoline("Test that the StyleChanged signal is received only once");
886   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
887
888   // Check that the field's font style has been altered
889   pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
890   pointSizeValue.Get( pointSize );
891
892   DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
893
894
895   END_TEST;
896 }
897
898 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
899 {
900   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
901
902   const char* defaultTheme =
903     "{\n"
904     "  \"styles\":\n"
905     "  {\n"
906     "    \"texteditorFontSize0\":\n"
907     "    {\n"
908     "      \"pointSize\":10\n"
909     "    },\n"
910     "    \"texteditorFontSize1\":\n"
911     "    {\n"
912     "      \"pointSize\":12\n"
913     "    },\n"
914     "    \"texteditorFontSize2\":\n"
915     "    {\n"
916     "      \"pointSize\":14\n"
917     "    },\n"
918     "    \"texteditorFontSize3\":\n"
919     "    {\n"
920     "      \"pointSize\":18\n"
921     "    },\n"
922     "    \"texteditorFontSize4\":\n"
923     "    {\n"
924     "      \"pointSize\":25\n"
925     "    }\n"
926     "  }\n"
927     "}\n";
928
929   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
930
931   ToolkitTestApplication application;
932
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 );
937
938   Toolkit::TextEditor editor2 = Toolkit::TextEditor::New();
939   Stage::GetCurrent().Add( editor2 );
940   editor2.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
941
942   StyleChangedSignalChecker styleChangedSignalHandler;
943   StyleMonitor styleMonitor = StyleMonitor::Get();
944   StyleManager styleManager = StyleManager::Get();
945
946   editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.0f);
947
948   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
949
950   Test::StyleMonitor::SetDefaultFontSize(2);
951   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
952
953   tet_infoline("Test that the StyleChanged signal is received only once");
954   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
955
956   tet_infoline("Test that the editor's font size has been altered\n");
957   Property::Value pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
958   float pointSize;
959   pointSizeValue.Get( pointSize );
960
961   DALI_TEST_EQUALS( pointSize, 14.0f, 0.001, TEST_LOCATION );
962
963   styleChangedSignalHandler.signalCount = 0;
964
965   Test::StyleMonitor::SetDefaultFontSize(4);
966   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
967
968   tet_infoline("Test that the StyleChanged signal is received only once");
969   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
970
971   // Check that the editor's font style has been altered
972   pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
973   pointSizeValue.Get( pointSize );
974
975   DALI_TEST_EQUALS( pointSize, 25.0f, 0.001, TEST_LOCATION );
976
977
978   END_TEST;
979 }