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