Dali 3D User Interface Engine
utc-Dali-SingletonService.cpp
Go to the documentation of this file.
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:
34  TestHandle( BaseObject* object ) : BaseHandle( object ) {}
35 };
36 
37 class TestObject : public BaseObject
38 {
39 };
40 
41 } // unnamed namespace
42 
44 {
46 }
47 
49 {
51 }
52 
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 
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 }
Dali Docs Home
Read more about Dali