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