[dali_2.2.3] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-styling / utc-Dali-StyleManager.cpp
1  /*
2  * Copyright (c) 2022 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 <fstream>
21 #include <sstream>
22 #include <stdlib.h>
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali-toolkit/devel-api/builder/builder.h>
27 #include <test-button.h>
28 #include <test-animation-data.h>
29 #include <toolkit-style-monitor.h>
30 #include <dummy-control.h>
31 #include <dali-toolkit/devel-api/controls/control-devel.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
34 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
35 #include <dali/integration-api/events/key-event-integ.h>
36
37 // for Internal::StyleManager
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
39
40 using namespace Dali;
41 using namespace Dali::Toolkit;
42
43 namespace
44 {
45 std::string defaultTheme;
46
47 } // anonymous namespace
48
49
50
51
52 void dali_style_manager_startup(void)
53 {
54   test_return_value = TET_UNDEF;
55
56   std::ifstream t("src/dali-toolkit-styling/default-theme.json");
57   defaultTheme = std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
58 }
59
60 void dali_style_manager_cleanup(void)
61 {
62   test_return_value = TET_PASS;
63 }
64
65
66 Visual::Base CheckVisual( Impl::DummyControl& dummyImpl, Property::Index visualId, int type, const char* location )
67 {
68     DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(visualId), true, location);
69     Visual::Base visual = dummyImpl.GetVisual(visualId);
70     DALI_TEST_EQUALS( (bool)visual, true, location );
71     Property::Map map;
72     visual.CreatePropertyMap( map );
73     Property::Value* value = map.Find( Toolkit::Visual::Property::TYPE );
74     DALI_TEST_EQUALS( value != NULL, true, location );
75
76     int visualType;
77     value->Get( visualType );
78     DALI_TEST_EQUALS( visualType, type, location );
79     return visual;
80 }
81
82
83 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
84 {
85   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
86   Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
87   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
88
89   memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
90
91   return bitmap;
92 }
93
94 Integration::ResourcePointer CustomizeNinePatch( ToolkitTestApplication& application,
95                                                  unsigned int ninePatchImageWidth,
96                                                  unsigned int ninePatchImageHeight)
97 {
98   TestPlatformAbstraction& platform = application.GetPlatform();
99
100   Pixel::Format pixelFormat = Pixel::RGBA8888;
101
102   tet_infoline("Create Bitmap");
103   platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
104   Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
105
106   tet_infoline("Getting resource");
107   Integration::ResourcePointer resourcePtr(bitmap);
108   platform.SetSynchronouslyLoadedResource( resourcePtr);
109
110   return resourcePtr;
111 }
112
113 int UtcDaliStyleManagerConstructorP(void)
114 {
115   ToolkitTestApplication application;
116
117   tet_infoline(" UtcDaliStyleManagerConstructorP");
118   StyleManager styleManager;
119   DALI_TEST_CHECK( !styleManager);
120   END_TEST;
121 }
122
123 int UtcDaliStyleManagerCopyConstructorP(void)
124 {
125   ToolkitTestApplication application;
126
127   StyleManager styleManager = StyleManager::Get();
128   StyleManager copyOfStyleManager( styleManager );
129
130   DALI_TEST_CHECK( copyOfStyleManager );
131   END_TEST;
132 }
133
134 int UtcDaliStyleManagerAssignmentOperatorP(void)
135 {
136   ToolkitTestApplication application;
137
138   StyleManager styleManager = StyleManager::Get();
139   StyleManager copyOfStyleManager = styleManager;
140
141   DALI_TEST_CHECK( copyOfStyleManager );
142   DALI_TEST_CHECK( copyOfStyleManager == styleManager );
143   END_TEST;
144 }
145
146 int UtcDaliStyleManagerGet(void)
147 {
148   ToolkitTestApplication application;
149
150   tet_infoline(" UtcDaliStyleManagerGet");
151
152   // Register Type
153   TypeInfo type;
154   type = TypeRegistry::Get().GetTypeInfo( "StyleManager" );
155   DALI_TEST_CHECK( type );
156   BaseHandle handle = type.CreateInstance();
157   DALI_TEST_CHECK( handle );
158
159   StyleManager manager;
160
161   manager = StyleManager::Get();
162   DALI_TEST_CHECK(manager);
163
164   StyleManager newManager = StyleManager::Get();
165   DALI_TEST_CHECK(newManager);
166
167   // Check that focus manager is a singleton
168   DALI_TEST_CHECK(manager == newManager);
169   END_TEST;
170 }
171
172
173 namespace
174 {
175 class StyleChangedSignalChecker : public ConnectionTracker
176 {
177 public:
178   StyleChangedSignalChecker()
179   : signalCount(0)
180   {
181   }
182
183   void OnStyleChanged(StyleManager styleManager, StyleChange::Type type)
184   {
185     signalCount++;
186   }
187
188   void Reset()
189   {
190     signalCount =0;
191   }
192
193 public:
194   int signalCount;
195 };
196
197 } // anonymous namespace
198
199 int UtcDaliStyleManagerApplyTheme(void)
200 {
201   ToolkitTestApplication application;
202
203   tet_infoline( "Testing StyleManager ApplyTheme" );
204
205   const char* json1 =
206     "{\n"
207     "  \"constants\":\n"
208     "  {\n"
209     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Verbose\"\n"
210     "  },\n"
211     "  \"styles\":\n"
212     "  {\n"
213     "    \"testbutton\":\n"
214     "    {\n"
215     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
216     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
217     "    }\n"
218     "  }\n"
219     "}\n";
220
221   const char* json2 =
222     "{\n"
223     "  \"styles\":\n"
224     "  {\n"
225     "    \"testbutton\":\n"
226     "    {\n"
227     "      \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
228     "      \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
229     "    }\n"
230     "  }\n"
231     "}\n";
232
233   // Add 2 buttons to test how many times the signal is sent
234   Test::TestButton testButton = Test::TestButton::New();
235   Test::TestButton testButton2 = Test::TestButton::New();
236   application.GetScene().Add( testButton );
237   application.GetScene().Add( testButton2 );
238   StyleChangedSignalChecker styleChangedSignalHandler;
239   StyleChangedSignalChecker styleChangedSignalHandler2;
240   StyleManager styleManager = StyleManager::Get();
241
242   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
243
244   // To ensure we make VisualFactory
245   VisualFactory factory = VisualFactory::Get();
246   Property::Map propertyMap;
247   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT );
248   Visual::Base textVisual = factory.CreateVisual( propertyMap );
249
250   // Render and notify
251   application.SendNotification();
252   application.Render();
253
254   tet_infoline("Apply the style");
255
256   std::string themeFile("ThemeOne");
257   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
258   StyleManager::Get().ApplyTheme(themeFile);
259
260   Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
261   Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
262
263   DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
264   DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
265
266   tet_infoline("Testing that the signal handler is called only once");
267   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
268
269   tet_infoline("Override the background property");
270   testButton.SetProperty( Test::TestButton::Property::BACKGROUND_COLOR, Color::GREEN );
271   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
272   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
273   DALI_TEST_EQUALS( bgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
274   DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
275
276   // Render and notify
277   application.SendNotification();
278   application.Render();
279
280   tet_infoline("Apply the style again");
281
282   styleChangedSignalHandler.signalCount = 0;
283   StyleManager::Get().ApplyTheme(themeFile);
284
285   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
286   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
287
288   tet_infoline("Check that the property is changed");
289   DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
290   DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
291   tet_infoline("Testing that the signal handler is called only once");
292   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
293
294   tet_infoline( "Load a different stylesheet");
295
296   tet_infoline("Apply the new style");
297   std::string themeFile2("ThemeTwo");
298   Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
299
300   styleChangedSignalHandler.signalCount = 0;
301   StyleManager::Get().ApplyTheme(themeFile2);
302
303   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
304   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
305
306   tet_infoline("Check that the properties change, but the signal gets sent only once");
307   DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
308   DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
309   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
310
311   END_TEST;
312 }
313
314
315 int UtcDaliStyleManagerApplyDefaultTheme(void)
316 {
317   tet_infoline( "Testing StyleManager ApplyTheme" );
318
319   const char* defaultTheme =
320     "{\n"
321     "  \"constants\":\n"
322     "  {\n"
323     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Concise\"\n"
324     "  },\n"
325     "  \"styles\":\n"
326     "  {\n"
327     "    \"testbutton\":\n"
328     "    {\n"
329     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
330     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
331     "    }\n"
332     "  }\n"
333     "}\n";
334   // Bg: Yellow, Fg: Blue
335
336   const char* appTheme =
337     "{\n"
338     "  \"styles\":\n"
339     "  {\n"
340     "    \"testbutton\":\n"
341     "    {\n"
342     "      \"backgroundColor\":[1.0,0.0,1.0,1.0],\n"
343     "      \"foregroundColor\":[0.0,1.0,0.0,1.0]\n"
344     "    }\n"
345     "  }\n"
346     "}\n";
347   // Bg::Magenta, Fg:Green
348
349   std::string filepath(TEST_RESOURCE_DIR "");
350
351   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
352                                           defaultTheme);
353   ToolkitTestApplication application;
354
355   Test::TestButton testButton = Test::TestButton::New();
356   application.GetScene().Add( testButton );
357   StyleChangedSignalChecker styleChangedSignalHandler;
358   StyleManager styleManager = StyleManager::Get();
359
360   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
361
362   // Render and notify
363   application.SendNotification();
364   application.Render();
365
366   // Get the default:
367   Property::Value defaultBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
368   Property::Value defaultFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
369
370   tet_infoline("Apply the style");
371
372   std::string themeFile("ThemeOne");
373   Test::StyleMonitor::SetThemeFileOutput(themeFile, appTheme);
374   StyleManager::Get().ApplyTheme(themeFile);
375
376   Property::Value bgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
377   Property::Value fgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
378
379   DALI_TEST_EQUALS( bgColor, Property::Value(Color::MAGENTA), 0.001, TEST_LOCATION );
380   DALI_TEST_EQUALS( fgColor, Property::Value(Color::GREEN), 0.001, TEST_LOCATION );
381
382   tet_infoline("Testing that the signal handler is called only once");
383   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
384   tet_infoline("Revert the style");
385
386   styleChangedSignalHandler.signalCount = 0;
387   StyleManager::Get().ApplyDefaultTheme();
388
389   bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
390   fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
391
392   tet_infoline("Check that the property is reverted");
393   DALI_TEST_EQUALS( bgColor, defaultBgColor, 0.001, TEST_LOCATION );
394   DALI_TEST_EQUALS( fgColor, defaultFgColor, 0.001, TEST_LOCATION );
395   DALI_TEST_EQUALS( bgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
396   DALI_TEST_EQUALS( fgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
397   tet_infoline("Testing that the signal handler is called only once");
398   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
399
400   END_TEST;
401 }
402
403
404 int UtcDaliStyleManagerSetStyleConstantP(void)
405 {
406   ToolkitTestApplication application;
407
408   tet_infoline( " UtcDaliStyleManagerSetStyleConstantP" );
409
410   StyleManager manager = StyleManager::Get();
411
412   std::string key( "key" );
413   Property::Value value( 100 );
414
415   manager.SetStyleConstant( key, value );
416
417   Property::Value returnedValue;
418   manager.GetStyleConstant( key, returnedValue );
419
420   DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
421   END_TEST;
422 }
423
424
425 int UtcDaliStyleManagerGetStyleConstantP(void)
426 {
427   ToolkitTestApplication application;
428
429   tet_infoline( " UtcDaliStyleManagerGetStyleConstantP" );
430
431   StyleManager manager = StyleManager::Get();
432
433   std::string key( "key" );
434   Property::Value value( 100 );
435
436   manager.SetStyleConstant( key, value );
437
438   Property::Value returnedValue;
439   manager.GetStyleConstant( key, returnedValue );
440
441   DALI_TEST_CHECK( value.Get<int>() == returnedValue.Get<int>() );
442   END_TEST;
443 }
444
445 int UtcDaliStyleManagerGetStyleConstantN(void)
446 {
447   ToolkitTestApplication application;
448
449   tet_infoline( " UtcDaliStyleManagerGetStyleConstantN" );
450
451   StyleManager manager = StyleManager::Get();
452
453   std::string key2( "key2" );
454   Property::Value returnedValue2;
455   DALI_TEST_CHECK( !manager.GetStyleConstant( key2, returnedValue2 ) );
456
457   END_TEST;
458 }
459
460 int UtcDaliStyleManagerApplyStyle(void)
461 {
462   ToolkitTestApplication application;
463
464   tet_infoline( "UtcDaliStyleManagerApplyStyle - test that a style can be applied to a single button" );
465
466   const char* json1 =
467     "{\n"
468     "  \"constants\":\n"
469     "  {\n"
470     "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"General\"\n"
471     "  },\n"
472     "  \"styles\":\n"
473     "  {\n"
474     "    \"testbutton\":\n"
475     "    {\n"
476     "      \"backgroundColor\":[1.0,1.0,0.0,1.0],\n"
477     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
478     "    }\n"
479     "  }\n"
480     "}\n";
481
482   const char* json2 =
483     "{\n"
484     "  \"styles\":\n"
485     "  {\n"
486     "    \"testbutton\":\n"
487     "    {\n"
488     "      \"backgroundColor\":[1.0,0.0,0.0,1.0],\n"
489     "      \"foregroundColor\":[0.0,1.0,1.0,1.0]\n"
490     "    }\n"
491     "  }\n"
492     "}\n";
493
494   // Add 2 buttons
495   Test::TestButton testButton = Test::TestButton::New();
496   Test::TestButton testButton2 = Test::TestButton::New();
497   application.GetScene().Add( testButton );
498   application.GetScene().Add( testButton2 );
499   StyleChangedSignalChecker styleChangedSignalHandler;
500   StyleManager styleManager = StyleManager::Get();
501
502   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
503
504   tet_infoline("Apply the style");
505
506   std::string themeFile("ThemeOne");
507   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
508   styleManager.ApplyTheme(themeFile);
509
510   // Render and notify
511   application.SendNotification();
512   application.Render();
513
514   Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
515   Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
516
517   // Apply the style to the test button:
518   std::string themeFile2("ThemeTwo");
519   Test::StyleMonitor::SetThemeFileOutput(themeFile2, json2);
520   styleManager.ApplyStyle( testButton, themeFile2, "testbutton" );
521
522   tet_infoline("Check that the properties change for the first button");
523   Property::Value bgColor = testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
524   Property::Value fgColor = testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
525   DALI_TEST_EQUALS( bgColor, Property::Value(Color::RED), 0.001, TEST_LOCATION );
526   DALI_TEST_EQUALS( fgColor, Property::Value(Color::CYAN), 0.001, TEST_LOCATION );
527
528   DALI_TEST_NOT_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
529   DALI_TEST_NOT_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
530
531   tet_infoline("Check that the properties remain the same for the second button");
532   bgColor = testButton2.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR);
533   fgColor = testButton2.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR);
534   DALI_TEST_EQUALS( bgColor, themedBgColor, 0.001, TEST_LOCATION );
535   DALI_TEST_EQUALS( fgColor, themedFgColor, 0.001, TEST_LOCATION );
536
537   END_TEST;
538 }
539
540
541 int UtcDaliStyleManagerIncludeStyleP(void)
542 {
543   ToolkitTestApplication application;
544
545   tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works" );
546
547   const char* json1 =
548     "{\n"
549     "  \"includes\":\n"
550     "  [\n"
551     "     \"src/dali-toolkit-styling/theme2.json\"\n"
552     "  ],\n"
553     "  \"styles\":\n"
554     "  {\n"
555     "    \"testbutton\":\n"
556     "    {\n"
557     "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
558     "    }\n"
559     "  }\n"
560     "}\n";
561
562   // Add 2 buttons
563   Test::TestButton testButton = Test::TestButton::New();
564   Test::TestButton testButton2 = Test::TestButton::New();
565   application.GetScene().Add( testButton );
566   application.GetScene().Add( testButton2 );
567   StyleChangedSignalChecker styleChangedSignalHandler;
568   StyleManager styleManager = StyleManager::Get();
569
570   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
571
572   tet_infoline("Apply the style");
573
574   std::string themeFile("ThemeOne");
575   Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
576
577   styleManager.ApplyTheme(themeFile);
578
579   // Render and notify
580   application.SendNotification();
581   application.Render();
582
583   Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
584   Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
585
586   DALI_TEST_EQUALS( themedBgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
587   DALI_TEST_EQUALS( themedFgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
588
589   END_TEST;
590 }
591
592
593 int UtcDaliStyleManagerIncludeStyleN(void)
594 {
595   ToolkitTestApplication application;
596
597   tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works, but included stylesheet is bad json" );
598
599   const char* json1 =
600     "{\n"
601     "  \"includes\":\n"
602     "  [\n"
603     "     \"src/dali-toolkit-styling/theme3.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   application.GetScene().Add( testButton );
618   application.GetScene().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   try
630   {
631     styleManager.ApplyTheme(themeFile);
632   }
633   catch( Dali::DaliException& e )
634   {
635     DALI_TEST_ASSERT( e, "!\"Cannot parse JSON\"", TEST_LOCATION );
636   }
637
638   END_TEST;
639 }
640
641
642 int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
643 {
644   tet_infoline("Test that the StyleChange signal is fired when the font family is altered" );
645   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
646                                           defaultTheme );
647
648   ToolkitTestApplication application;
649
650   std::string labelStr("Label");
651   Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
652   application.GetScene().Add( label );
653
654   Toolkit::TextField field = Toolkit::TextField::New();
655   application.GetScene().Add( field );
656
657   Toolkit::TextEditor editor = Toolkit::TextEditor::New();
658   application.GetScene().Add( editor );
659
660   StyleChangedSignalChecker styleChangedSignalHandler;
661   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
662   StyleManager styleManager = StyleManager::Get();
663
664   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
665
666   Test::StyleMonitor::SetDefaultFontFamily("Times New Roman");
667
668   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_CHANGE);
669
670   tet_infoline("Test that the StyleChanged signal is received only once");
671
672   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
673
674   // Check that the label's font style has been altered
675   Property::Value family = label.GetProperty(TextLabel::Property::FONT_FAMILY);
676   std::string familyStr;
677   family.Get( familyStr );
678
679   DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
680
681   // Check that the field's font style has been altered
682   family = field.GetProperty(TextField::Property::FONT_FAMILY);
683   family.Get( familyStr );
684
685   DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
686
687   // Check that the editor's font style has been altered
688   family = editor.GetProperty(TextEditor::Property::FONT_FAMILY);
689   family.Get( familyStr );
690
691   DALI_TEST_EQUALS( familyStr, "Times New Roman", TEST_LOCATION);
692
693   END_TEST;
694 }
695
696 int UtcDaliStyleManagerStyleChangedSignalFontSize(void)
697 {
698   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
699
700   const char* defaultTheme =
701     "{\n"
702     "  \"styles\":\n"
703     "  {\n"
704     "    \"textlabelFontSize0\":\n"
705     "    {\n"
706     "      \"pointSize\":10\n"
707     "    },\n"
708     "    \"textlabelFontSize1\":\n"
709     "    {\n"
710     "      \"pointSize\":10\n"
711     "    },\n"
712     "    \"textlabelFontSize2\":\n"
713     "    {\n"
714     "      \"pointSize\":12\n"
715     "    },\n"
716     "    \"textlabelFontSize3\":\n"
717     "    {\n"
718     "      \"pointSize\":14\n"
719     "    },\n"
720     "    \"textlabelFontSize4\":\n"
721     "    {\n"
722     "      \"pointSize\":16\n"
723     "    }\n"
724     "  }\n"
725     "}\n";
726
727   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
728
729   ToolkitTestApplication application;
730
731   std::string labelStr("Label");
732   Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
733   application.GetScene().Add( label );
734
735   Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
736   application.GetScene().Add( label2 );
737
738   StyleChangedSignalChecker styleChangedSignalHandler;
739   StyleMonitor styleMonitor = StyleMonitor::Get();
740   StyleManager styleManager = StyleManager::Get();
741
742   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.0f);
743
744   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
745
746   Test::StyleMonitor::SetDefaultFontSize(2);
747   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
748
749   tet_infoline("Test that the StyleChanged signal is received only once");
750   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
751
752   tet_infoline("Test that the label's font size has been altered\n");
753   Property::Value pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
754   float pointSize;
755   pointSizeValue.Get( pointSize );
756
757   DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
758
759   styleChangedSignalHandler.signalCount = 0;
760
761   Test::StyleMonitor::SetDefaultFontSize(4);
762   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
763
764   tet_infoline("Test that the StyleChanged signal is received only once");
765   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
766
767   // Check that the label's font style has been altered
768   pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
769   pointSizeValue.Get( pointSize );
770
771   DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
772
773
774   END_TEST;
775 }
776
777
778 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextField(void)
779 {
780   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
781
782   const char* defaultTheme =
783     "{\n"
784     "  \"styles\":\n"
785     "  {\n"
786     "    \"textfieldFontSize0\":\n"
787     "    {\n"
788     "      \"pointSize\":8\n"
789     "    },\n"
790     "    \"textfieldFontSize1\":\n"
791     "    {\n"
792     "      \"pointSize\":10\n"
793     "    },\n"
794     "    \"textfieldFontSize2\":\n"
795     "    {\n"
796     "      \"pointSize\":12\n"
797     "    },\n"
798     "    \"textfieldFontSize3\":\n"
799     "    {\n"
800     "      \"pointSize\":14\n"
801     "    },\n"
802     "    \"textfieldFontSize4\":\n"
803     "    {\n"
804     "      \"pointSize\":16\n"
805     "    }\n"
806     "  }\n"
807     "}\n";
808
809   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
810
811   ToolkitTestApplication application;
812
813   std::string fieldStr("Field");
814   Toolkit::TextField field = Toolkit::TextField::New();
815   field.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
816   application.GetScene().Add( field );
817
818   Toolkit::TextField field2 = Toolkit::TextField::New();
819   application.GetScene().Add( field2 );
820   field2.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
821
822   StyleChangedSignalChecker styleChangedSignalHandler;
823   StyleMonitor styleMonitor = StyleMonitor::Get();
824   StyleManager styleManager = StyleManager::Get();
825
826   field.SetProperty(TextField::Property::POINT_SIZE, 10.0f);
827
828   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
829
830   Test::StyleMonitor::SetDefaultFontSize(2);
831   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
832
833   tet_infoline("Test that the StyleChanged signal is received only once");
834   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
835
836   tet_infoline("Test that the field's font size has been altered\n");
837   Property::Value pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
838   float pointSize;
839   pointSizeValue.Get( pointSize );
840
841   DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
842
843   styleChangedSignalHandler.signalCount = 0;
844
845   Test::StyleMonitor::SetDefaultFontSize(4);
846   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
847
848   tet_infoline("Test that the StyleChanged signal is received only once");
849   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
850
851   // Check that the field's font style has been altered
852   pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
853   pointSizeValue.Get( pointSize );
854
855   DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
856
857
858   END_TEST;
859 }
860
861 int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
862 {
863   tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
864
865   const char* defaultTheme =
866     "{\n"
867     "  \"styles\":\n"
868     "  {\n"
869     "    \"texteditorFontSize0\":\n"
870     "    {\n"
871     "      \"pointSize\":10\n"
872     "    },\n"
873     "    \"texteditorFontSize1\":\n"
874     "    {\n"
875     "      \"pointSize\":12\n"
876     "    },\n"
877     "    \"texteditorFontSize2\":\n"
878     "    {\n"
879     "      \"pointSize\":14\n"
880     "    },\n"
881     "    \"texteditorFontSize3\":\n"
882     "    {\n"
883     "      \"pointSize\":18\n"
884     "    },\n"
885     "    \"texteditorFontSize4\":\n"
886     "    {\n"
887     "      \"pointSize\":25\n"
888     "    }\n"
889     "  }\n"
890     "}\n";
891
892   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
893
894   ToolkitTestApplication application;
895
896   std::string editorStr("Editor");
897   Toolkit::TextEditor editor = Toolkit::TextEditor::New();
898   editor.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
899   application.GetScene().Add( editor );
900
901   Toolkit::TextEditor editor2 = Toolkit::TextEditor::New();
902   application.GetScene().Add( editor2 );
903   editor2.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
904
905   StyleChangedSignalChecker styleChangedSignalHandler;
906   StyleMonitor styleMonitor = StyleMonitor::Get();
907   StyleManager styleManager = StyleManager::Get();
908
909   editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.0f);
910
911   styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
912
913   Test::StyleMonitor::SetDefaultFontSize(2);
914   styleMonitor.StyleChangeSignal().Emit( styleMonitor,  StyleChange::DEFAULT_FONT_SIZE_CHANGE);
915
916   tet_infoline("Test that the StyleChanged signal is received only once");
917   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
918
919   tet_infoline("Test that the editor's font size has been altered\n");
920   Property::Value pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
921   float pointSize;
922   pointSizeValue.Get( pointSize );
923
924   DALI_TEST_EQUALS( pointSize, 14.0f, 0.001, TEST_LOCATION );
925
926   styleChangedSignalHandler.signalCount = 0;
927
928   Test::StyleMonitor::SetDefaultFontSize(4);
929   styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
930
931   tet_infoline("Test that the StyleChanged signal is received only once");
932   DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
933
934   // Check that the editor's font style has been altered
935   pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
936   pointSizeValue.Get( pointSize );
937
938   DALI_TEST_EQUALS( pointSize, 25.0f, 0.001, TEST_LOCATION );
939
940
941   END_TEST;
942 }
943
944
945 int UtcDaliStyleManagerSetState01(void)
946 {
947   tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
948   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
949                                           defaultTheme );
950
951   ToolkitTestApplication application;
952
953   StyleChangedSignalChecker styleChangedSignalHandler;
954   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
955   StyleManager styleManager = StyleManager::Get();
956
957   DummyControl actor = DummyControl::New(true);
958   actor.SetStyleName("BasicControl");
959   application.GetScene().Add(actor);
960
961   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
962   Integration::ResourcePointer ninePatch = CustomizeNinePatch( application, 30, 30 );
963
964   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
965   Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
966   Visual::Base labelVisual1 = dummyImpl.GetVisual(DummyControl::Property::LABEL_VISUAL);
967   Property::Map labelMap;
968   labelVisual1.CreatePropertyMap( labelMap );
969   labelMap[TextVisual::Property::TEXT] = "New text";
970   VisualFactory factory = VisualFactory::Get();
971   labelVisual1 = factory.CreateVisual(labelMap);
972   dummyImpl.UnregisterVisual(DummyControl::Property::LABEL_VISUAL );
973   dummyImpl.RegisterVisual(DummyControl::Property::LABEL_VISUAL, labelVisual1 );
974
975   actor.SetProperty( DevelControl::Property::STATE, DevelControl::FOCUSED );
976
977   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
978   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), true, TEST_LOCATION);
979   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::LABEL_VISUAL), true, TEST_LOCATION);
980
981   Visual::Base visual2 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
982   Visual::Base labelVisual2 = dummyImpl.GetVisual(DummyControl::Property::LABEL_VISUAL);
983   DALI_TEST_CHECK( visual1 != visual2 );
984   DALI_TEST_CHECK( labelVisual1 != labelVisual2 );
985   labelMap.Clear();
986   labelVisual2.CreatePropertyMap( labelMap );
987   Property::Value* textValue = labelMap.Find( Toolkit::TextVisual::Property::TEXT, "text");
988   DALI_TEST_CHECK( textValue );
989   Property::Value* pointSizeValue = labelMap.Find( Toolkit::TextVisual::Property::POINT_SIZE, "pointSize");
990   tet_infoline( "Check that the instance data has been copied to the new text visual\n");
991   DALI_TEST_EQUALS( textValue->Get<std::string>(), "New text", TEST_LOCATION );
992   DALI_TEST_EQUALS( pointSizeValue->Get<int>(), 10, TEST_LOCATION );
993
994
995   actor.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
996
997   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
998
999   Visual::Base visual3 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1000   Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1001   DALI_TEST_CHECK( !focusVisual );
1002   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION);
1003
1004   DALI_TEST_CHECK( visual1 != visual3 );
1005   DALI_TEST_CHECK( visual2 != visual3 );
1006
1007   Visual::Base labelVisual3 = dummyImpl.GetVisual(DummyControl::Property::LABEL_VISUAL);
1008   DALI_TEST_CHECK( labelVisual2 != labelVisual3 );
1009
1010   labelVisual2.CreatePropertyMap( labelMap );
1011   textValue = labelMap.Find(Toolkit::TextVisual::Property::TEXT, "text");
1012   DALI_TEST_CHECK( textValue );
1013   pointSizeValue = labelMap.Find(Toolkit::TextVisual::Property::POINT_SIZE, "pointSize");
1014   tet_infoline( "Check that the instance data has been copied to the new text visual\n");
1015   DALI_TEST_EQUALS( textValue->Get<std::string>(), "New text", TEST_LOCATION );
1016   DALI_TEST_EQUALS( pointSizeValue->Get<int>(), 10, TEST_LOCATION );
1017
1018   END_TEST;
1019 }
1020
1021 int UtcDaliStyleManagerSetState02(void)
1022 {
1023   tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
1024   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1025                                           defaultTheme );
1026
1027   ToolkitTestApplication application;
1028
1029   StyleChangedSignalChecker styleChangedSignalHandler;
1030   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1031   StyleManager styleManager = StyleManager::Get();
1032
1033   DummyControl actor = DummyControl::New(true);
1034   actor.SetStyleName("BasicControl");
1035   application.GetScene().Add(actor);
1036
1037   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1038   Integration::ResourcePointer ninePatch = CustomizeNinePatch( application, 30, 30 );
1039
1040   int state = actor.GetProperty<int>( DevelControl::Property::STATE );
1041   DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION );
1042
1043   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1044   Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1045
1046   actor.SetProperty( DevelControl::Property::STATE,
1047                      Property::Map().Add( "state", "FOCUSED" ).Add("withTransitions", false));
1048
1049   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1050   DALI_TEST_EQUALS( state, (int) DevelControl::FOCUSED, TEST_LOCATION );
1051
1052   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1053   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), true, TEST_LOCATION);
1054
1055   Visual::Base visual2 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1056   DALI_TEST_CHECK( visual1 != visual2 );
1057
1058   actor.SetProperty( DevelControl::Property::STATE,
1059                      Property::Map().Add( "state", "DISABLED" ).Add("withTransitions", false));
1060
1061   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1062   DALI_TEST_EQUALS( state, (int) DevelControl::DISABLED, TEST_LOCATION );
1063
1064   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1065
1066   Visual::Base visual3 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1067
1068   Visual::Base testVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1069   DALI_TEST_CHECK( !testVisual );
1070   testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL);
1071   DALI_TEST_CHECK( !testVisual );
1072   testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL2);
1073   DALI_TEST_CHECK( !testVisual );
1074   testVisual = dummyImpl.GetVisual(DummyControl::Property::LABEL_VISUAL);
1075   DALI_TEST_CHECK( testVisual );
1076
1077
1078   DALI_TEST_CHECK( visual1 != visual3 );
1079   DALI_TEST_CHECK( visual2 != visual3 );
1080
1081   actor.SetProperty( DevelControl::Property::STATE,
1082                      Property::Map().Add( "state", "NORMAL" ).Add("withTransitions", false));
1083
1084   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1085   DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION );
1086
1087   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
1088
1089   visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
1090   DALI_TEST_CHECK( visual1 );
1091
1092   Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1093   DALI_TEST_CHECK( !focusVisual );
1094   DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION);
1095
1096
1097   END_TEST;
1098 }
1099
1100
1101 int UtcDaliStyleManagerSetState03N(void)
1102 {
1103   tet_infoline("Instantiate dummy control and test state transition without state style" );
1104   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1105                                           defaultTheme );
1106
1107   ToolkitTestApplication application;
1108
1109   StyleChangedSignalChecker styleChangedSignalHandler;
1110   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1111   StyleManager styleManager = StyleManager::Get();
1112
1113   DummyControl actor = DummyControl::New(true);
1114   actor.SetStyleName("NoStyles");
1115   application.GetScene().Add(actor);
1116
1117   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1118   Property::Map propertyMap;
1119   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1120   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
1121   VisualFactory factory = VisualFactory::Get();
1122   Visual::Base visual = factory.CreateVisual( propertyMap );
1123   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1124
1125   int state = actor.GetProperty<int>( DevelControl::Property::STATE );
1126   DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION );
1127
1128   actor.SetProperty( DevelControl::Property::STATE,
1129                      Property::Map().Add( "state", "FOCUSED" ).Add("withTransitions", false));
1130
1131   Visual::Base testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL);
1132   DALI_TEST_CHECK( testVisual = visual );
1133
1134   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1135   DALI_TEST_EQUALS( state, (int) DevelControl::FOCUSED, TEST_LOCATION );
1136
1137   actor.SetProperty( DevelControl::Property::STATE,
1138                      Property::Map().Add( "state", "DISABLED" ).Add("withTransitions", false));
1139
1140   testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL);
1141   DALI_TEST_CHECK( testVisual = visual );
1142
1143   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1144   DALI_TEST_EQUALS( state, (int) DevelControl::DISABLED, TEST_LOCATION );
1145
1146   END_TEST;
1147 }
1148
1149
1150 int UtcDaliStyleManagerSetState04N(void)
1151 {
1152   tet_infoline("Instantiate dummy control and test state transition with style without state" );
1153   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1154                                           defaultTheme );
1155
1156   ToolkitTestApplication application;
1157
1158   StyleChangedSignalChecker styleChangedSignalHandler;
1159   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1160   StyleManager styleManager = StyleManager::Get();
1161
1162   DummyControl actor = DummyControl::New(true);
1163   actor.SetStyleName("NoStateStyle");
1164   application.GetScene().Add(actor);
1165
1166   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1167   Property::Map propertyMap;
1168   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1169   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
1170   VisualFactory factory = VisualFactory::Get();
1171   Visual::Base visual = factory.CreateVisual( propertyMap );
1172   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1173
1174   int state = actor.GetProperty<int>( DevelControl::Property::STATE );
1175   DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION );
1176
1177   actor.SetProperty( DevelControl::Property::STATE,
1178                      Property::Map().Add( "state", "FOCUSED" ).Add("withTransitions", false));
1179
1180   Visual::Base testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL);
1181   DALI_TEST_CHECK( testVisual = visual );
1182
1183   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1184   DALI_TEST_EQUALS( state, (int) DevelControl::FOCUSED, TEST_LOCATION );
1185
1186   actor.SetProperty( DevelControl::Property::STATE,
1187                      Property::Map().Add( "state", "DISABLED" ).Add("withTransitions", false));
1188
1189   testVisual = dummyImpl.GetVisual(DummyControl::Property::TEST_VISUAL);
1190   DALI_TEST_CHECK( testVisual = visual );
1191
1192   state = actor.GetProperty<int>( DevelControl::Property::STATE );
1193   DALI_TEST_EQUALS( state, (int) DevelControl::DISABLED, TEST_LOCATION );
1194
1195   END_TEST;
1196 }
1197
1198 int UtcDaliStyleManagerSetSubState01(void)
1199 {
1200   tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
1201   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1202                                           defaultTheme );
1203
1204   ToolkitTestApplication application;
1205
1206   StyleChangedSignalChecker styleChangedSignalHandler;
1207   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1208   StyleManager styleManager = StyleManager::Get();
1209
1210   DummyControl actor = DummyControl::New(true);
1211   actor.SetProperty(DevelControl::Property::STATE, "NORMAL");
1212   actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED");
1213   actor.SetStyleName("ComplexControl");
1214   application.GetScene().Add(actor);
1215
1216   Integration::ResourcePointer ninePatch = CustomizeNinePatch( application, 30, 30 );
1217
1218   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1219
1220   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1221   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1222   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1223
1224   actor.SetProperty(DevelControl::Property::SUB_STATE, "UNSELECTED");
1225
1226   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1227   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1228   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::COLOR, TEST_LOCATION);
1229
1230   actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED");
1231
1232   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1233   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1234   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1235
1236   END_TEST;
1237 }
1238
1239
1240 int UtcDaliStyleManagerSetSubState02(void)
1241 {
1242   tet_infoline("Instantiate complex control and test state/substate change" );
1243   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
1244                                           defaultTheme );
1245
1246   ToolkitTestApplication application;
1247
1248   StyleChangedSignalChecker styleChangedSignalHandler;
1249   Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
1250   StyleManager styleManager = StyleManager::Get();
1251
1252   DummyControl actor = DummyControl::New(true);
1253   actor.SetProperty(DevelControl::Property::STATE, "NORMAL");
1254   actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED");
1255   tet_infoline( "Setting state to NORMAL/SELECTED before re-styling\n");
1256
1257   actor.SetStyleName("ComplexControl");
1258   application.GetScene().Add(actor);
1259
1260   Integration::ResourcePointer ninePatch = CustomizeNinePatch( application, 30, 30 );
1261
1262   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1263
1264   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1265   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1266
1267   actor.SetProperty(DevelControl::Property::SUB_STATE, "UNSELECTED");
1268   tet_infoline( "Changing substate to UNSELECTED - check visual changes\n");
1269
1270   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1271   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::COLOR, TEST_LOCATION);
1272
1273   actor.SetProperty(DevelControl::Property::STATE, "FOCUSED");
1274   tet_infoline( "Changing state to FOCUSED - check visual changes\n");
1275
1276   Visual::Base fgVisual1 = CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1277   Visual::Base focusVisual1 = CheckVisual( dummyImpl, DummyControl::Property::FOCUS_VISUAL, Toolkit::Visual::N_PATCH, TEST_LOCATION);
1278
1279   actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED");
1280   tet_infoline( "Changing  substate to SELECTED - Expect no change\n");
1281
1282   Visual::Base fgVisual2 = CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1283   Visual::Base focusVisual2 = CheckVisual( dummyImpl, DummyControl::Property::FOCUS_VISUAL, Toolkit::Visual::N_PATCH, TEST_LOCATION);
1284
1285   DALI_TEST_CHECK( fgVisual1 == fgVisual2 );
1286   DALI_TEST_CHECK( focusVisual1 == focusVisual2 );
1287
1288   actor.SetProperty(DevelControl::Property::STATE, "NORMAL");
1289   tet_infoline( "Changing state to NORMAL - Expect to change to NORMAL/SELECTED \n");
1290
1291   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1292   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, Toolkit::Visual::GRADIENT, TEST_LOCATION);
1293
1294   Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1295   DALI_TEST_CHECK( ! focusVisual );
1296
1297   actor.SetProperty(DevelControl::Property::STATE, "DISABLED");
1298   tet_infoline( "Changing state to DISABLED - Expect to change to DISABLED/SELECTED \n");
1299
1300   CheckVisual( dummyImpl, DummyControl::Property::FOREGROUND_VISUAL, Toolkit::Visual::COLOR, TEST_LOCATION);
1301   CheckVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, Toolkit::Visual::IMAGE, TEST_LOCATION);
1302
1303   Visual::Base testVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
1304   DALI_TEST_CHECK( ! testVisual );
1305   testVisual = dummyImpl.GetVisual(DummyControl::Property::LABEL_VISUAL);
1306   DALI_TEST_CHECK( ! testVisual );
1307
1308   END_TEST;
1309 }
1310
1311
1312 int UtcDaliStyleManagerConfigSectionTest(void)
1313 {
1314   tet_infoline("Test that the properties in config section are works" );
1315
1316   const char* defaultTheme =
1317     "{\n"
1318     "  \"constants\":\n"
1319     "  {\n"
1320     "    \"TEST\":\"broken\"\n"
1321     "  },\n"
1322     "  \"config\":\n"
1323     "  {\n"
1324     "    \"brokenImageUrl\":\"{TEST}|{TEST}|{TEST|TEST.png\",\n"
1325     "    \"alwaysShowFocus\":false,\n"
1326     "    \"clearFocusOnEscape\":false\n"
1327     "  },\n"
1328     "  \"styles\":\n"
1329     "  {\n"
1330     "  }\n"
1331     "}\n";
1332
1333   Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
1334
1335   ToolkitTestApplication application;
1336
1337   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1338
1339   Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
1340   bool alwaysShowFocus = config["alwaysShowFocus"].Get<bool>();
1341   DALI_TEST_CHECK( !alwaysShowFocus );
1342   bool clearFocusOnEscape = config["clearFocusOnEscape"].Get<bool>();
1343   DALI_TEST_CHECK( !clearFocusOnEscape );
1344   std::string brokenImageUrl = config["brokenImageUrl"].Get<std::string>();
1345   DALI_TEST_CHECK( brokenImageUrl.compare( "broken|broken|{TEST|TEST.png" ) == 0 );
1346
1347   // For coverage
1348   Toolkit::TextEditor editor = Toolkit::TextEditor::New();
1349   editor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1350   application.GetScene().Add( editor );
1351
1352   Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( editor );
1353
1354   application.ProcessEvent( Integration::KeyEvent( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", "", Device::Class::NONE, Device::Subclass::NONE ) );
1355   application.SendNotification();
1356   application.Render();
1357
1358   END_TEST;
1359 }
1360
1361
1362 int UtcDaliStyleManagerNewWithAdditionalBehavior(void)
1363 {
1364   ToolkitTestApplication application;
1365
1366   Toolkit::StyleManager            styleManager     = StyleManager::Get();
1367   Toolkit::Internal::StyleManager& styleManagerImpl = GetImpl(styleManager);
1368
1369   auto checkup = [&styleManagerImpl](int enableStyleChangeSignal, const Control& control){
1370     DALI_TEST_EQUALS( enableStyleChangeSignal, styleManagerImpl.ControlStyleChangeSignal().GetConnectionCount(), TEST_LOCATION );
1371   };
1372
1373   // Default New
1374   tet_infoline( "Check whether ControlStyleChangeSignal connected in default New\n");
1375   checkup(1, Control::New());
1376   checkup(1, ImageView::New());
1377   checkup(1, ImageView::New("url"));
1378   checkup(1, ImageView::New("url", Dali::ImageDimensions(32u, 32u)));
1379   checkup(1, TextLabel::New());
1380   checkup(1, TextLabel::New("text"));
1381
1382   // New with additional behaviour, but enable style change signals
1383   tet_infoline( "Check whether ControlStyleChangeSignal connected in non-disable style change signals\n");
1384   checkup(1, Control::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT));
1385   checkup(1, Control::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION));
1386   checkup(1, Control::New(Toolkit::Control::ControlBehaviour::REQUIRES_KEYBOARD_NAVIGATION_SUPPORT));
1387   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT));
1388   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "url"));
1389   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "url", Dali::ImageDimensions(32u, 32u)));
1390   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION));
1391   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "url"));
1392   checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "url", Dali::ImageDimensions(32u, 32u)));
1393   checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT));
1394   checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "text"));
1395   checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION));
1396   checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "text"));
1397
1398   // New with additional behaviour, so disable style change signals
1399   tet_infoline( "Check whether ControlStyleChangeSignal did not connected\n");
1400   checkup(0, Control::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS));
1401   checkup(0, Control::New(Toolkit::Control::ControlBehaviour(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS | Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION)));
1402   checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS));
1403   checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "url"));
1404   checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "url", Dali::ImageDimensions(32u, 32u)));
1405   checkup(0, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS));
1406   checkup(0, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "text"));
1407
1408   END_TEST;
1409 }