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