Merge "Add SwitchParent api in actor-devel" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-SingletonService.cpp
1 /*
2  * Copyright (c) 2014 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
18 // EXTERNAL INCLUDES
19 #include <dali-test-suite-utils.h>
20 #include <dali/devel-api/common/singleton-service.h>
21 #include <dali/public-api/dali-core.h>
22 #include <stdlib.h>
23
24 #include <iostream>
25
26 using namespace Dali;
27
28 namespace
29 {
30 class TestHandle : public BaseHandle
31 {
32 public:
33   TestHandle()
34   {
35   }
36   TestHandle(BaseObject* object)
37   : BaseHandle(object)
38   {
39   }
40 };
41
42 class TestObject : public BaseObject
43 {
44 };
45
46 } // unnamed namespace
47
48 void utc_dali_singleton_service_startup(void)
49 {
50   test_return_value = TET_UNDEF;
51 }
52
53 void utc_dali_singleton_service_cleanup(void)
54 {
55   test_return_value = TET_PASS;
56 }
57
58 int UtcDaliSingletonServiceGet(void)
59 {
60   // Attempt to retrieve SingletonService before creating application
61   SingletonService singletonService;
62   singletonService = SingletonService::Get();
63   DALI_TEST_CHECK(!singletonService);
64
65   // Create Application class, should be able to retrieve SingletonService now
66   TestApplication application;
67   singletonService = SingletonService::Get();
68   DALI_TEST_CHECK(singletonService);
69
70   END_TEST;
71 }
72
73 int UtcDaliSingletonServiceRegisterAndGetSingleton(void)
74 {
75   TestApplication  application;
76   SingletonService singletonService(SingletonService::Get());
77
78   // Attempt to register an empty handle
79   TestHandle handle;
80   singletonService.Register(typeid(handle), handle);
81   DALI_TEST_CHECK(!singletonService.GetSingleton(typeid(handle)));
82
83   // Create an actor instance and retrieve, should be valid this time
84   handle = TestHandle(new TestObject);
85   singletonService.Register(typeid(handle), handle);
86   DALI_TEST_CHECK(singletonService.GetSingleton(typeid(handle)));
87
88   END_TEST;
89 }