Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-ConnectionTracker.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 <iostream>
20 #include <stdlib.h>
21
22 // INTERNAL INCLUDES
23 #include <dali/public-api/dali-core.h>
24 #include <dali-test-suite-utils.h>
25 #include <signal-helper.h>
26
27
28 using namespace Dali;
29
30 void utc_dali_conenction_tracker_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_conenction_tracker_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace {
41
42
43 } // anon namespace
44
45
46 /*******************************************
47  *
48  * Start of Utc test cases.
49  * Test cases performed in order of API listed in dali-signal.h
50  * UtcDaliSignal + FunctionName + P=positive test, N = Negative test
51  *
52  */
53
54 int UtcConnectionTrackerConstructorP(void)
55 {
56   TestApplication app; // Create core for debug logging
57
58   ConnectionTracker tracker;
59
60   DALI_TEST_CHECK( tracker.GetConnectionCount() == 0 );
61
62   END_TEST;
63 }
64
65 int UtcConnectionTrackerDestructorP(void)
66 {
67   TestApplication app; // Create core for debug logging
68   // make sure the ConnectionTracker disconnects form a signal when it
69   // gets deleted.
70   TestButton* button = new TestButton(1);
71   {
72     TestApp testApp;
73     button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
74     DALI_TEST_CHECK( testApp.GetConnectionCount() == 1 );
75     DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( )== 1 );
76   }
77   // testApp out of scope it should have been disconnected
78   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
79
80   END_TEST;
81 }
82
83 int UtcConnectionTrackerDisconnectAllP(void)
84 {
85   TestApplication app; // Create core for debug logging
86
87   TestButton* button = new TestButton(1);
88   TestApp testApp;
89   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
90
91   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
92
93   testApp.DisconnectAll();
94
95   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
96
97   END_TEST;
98 }
99
100 int UtcConnectionTrackerDisconnectAllN(void)
101 {
102   TestApplication app; // Create core for debug logging
103   TestApp testApp;
104   TestButton* button = new TestButton(1);
105
106   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
107   testApp.DisconnectAll();
108   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
109
110   END_TEST;
111 }
112
113 int UtcConnectionTrackerSignalConnectedP(void)
114 {
115   TestApplication app; // Create core for debug logging
116
117   TestButton* button = new TestButton(1);
118   TestApp testApp;
119   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
120
121   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
122
123   END_TEST;
124
125 }
126 int UtcConnectionTrackerSignalConnectedN(void)
127 {
128   TestApplication app; // Create core for debug logging
129
130   TestButton* button = new TestButton(1);
131   TestApp* testApp( NULL );
132
133   try
134   {
135     // connect to a null connection tracker
136     button->DownSignal().Connect( testApp, &TestApp::OnButtonPress);
137   }
138   catch (Dali::DaliException& e)
139   {
140     // Tests that a negative test of an assertion succeeds
141     DALI_TEST_PRINT_ASSERT( e );
142     tet_result(TET_PASS);
143   }
144
145   END_TEST;
146 }
147
148
149 int UtcConnectionTrackerSignalDisconnectP(void)
150 {
151   TestApplication app; // Create core for debug logging
152
153   TestButton* button = new TestButton(1);
154   TestApp testApp;
155   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
156
157   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
158
159   button->DownSignal().Disconnect(&testApp,&TestApp::OnButtonPress);
160   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
161
162   END_TEST;
163
164 }
165
166
167 int UtcConnectionTrackerSignalDisconnectN(void)
168 {
169   TestApplication app; // Create core for debug logging
170
171   TestButton* button = new TestButton(1);
172   TestApp testApp;
173   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
174
175   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
176
177   try
178   {
179     app.SignalDisconnected( NULL, NULL );
180     tet_result( TET_FAIL );
181   }
182   catch (Dali::DaliException& e)
183   {
184     tet_result( TET_PASS );
185   }
186
187   END_TEST;
188
189 }
190
191
192 int UtcConnectionTrackerGetConnectionCountP(void)
193 {
194   TestApplication app; // Create core for debug logging
195
196   TestButton* button = new TestButton(1);
197   TestApp testApp;
198   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
199   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
200   END_TEST;
201 }
202
203 int UtcConnectionTrackerGetConnectionCountN(void)
204 {
205   TestApplication app; // Create core for debug logging
206
207   TestButton* button = new TestButton(1);
208   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
209   END_TEST;
210 }