Revert "[Tizen] Implement partial update"
[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   delete button;
81
82   END_TEST;
83 }
84
85 int UtcConnectionTrackerDisconnectAllP(void)
86 {
87   TestApplication app; // Create core for debug logging
88
89   TestButton* button = new TestButton(1);
90   TestApp testApp;
91   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
92
93   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
94
95   testApp.DisconnectAll();
96
97   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
98
99   delete button;
100
101   END_TEST;
102 }
103
104 int UtcConnectionTrackerDisconnectAllN(void)
105 {
106   TestApplication app; // Create core for debug logging
107   TestApp testApp;
108   TestButton* button = new TestButton(1);
109
110   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
111   testApp.DisconnectAll();
112   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
113
114   delete button;
115
116   END_TEST;
117 }
118
119 int UtcConnectionTrackerSignalConnectedP(void)
120 {
121   TestApplication app; // Create core for debug logging
122
123   TestButton* button = new TestButton(1);
124   TestApp testApp;
125   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
126
127   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
128
129   delete button;
130
131   END_TEST;
132
133 }
134 int UtcConnectionTrackerSignalConnectedN(void)
135 {
136   TestApplication app; // Create core for debug logging
137
138   TestButton* button = new TestButton(1);
139   TestApp* testApp( NULL );
140
141   try
142   {
143     // connect to a null connection tracker
144     button->DownSignal().Connect( testApp, &TestApp::OnButtonPress);
145   }
146   catch (Dali::DaliException& e)
147   {
148     // Tests that a negative test of an assertion succeeds
149     DALI_TEST_PRINT_ASSERT( e );
150     tet_result(TET_PASS);
151   }
152
153   delete button;
154
155   END_TEST;
156 }
157
158
159 int UtcConnectionTrackerSignalDisconnectP(void)
160 {
161   TestApplication app; // Create core for debug logging
162
163   TestButton* button = new TestButton(1);
164   TestApp testApp;
165   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
166
167   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
168
169   button->DownSignal().Disconnect(&testApp,&TestApp::OnButtonPress);
170   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
171
172   delete button;
173
174   END_TEST;
175 }
176
177
178 int UtcConnectionTrackerSignalDisconnectN(void)
179 {
180   TestApplication app; // Create core for debug logging
181
182   TestButton* button = new TestButton(1);
183   TestApp testApp;
184   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
185
186   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
187
188   try
189   {
190     app.SignalDisconnected( NULL, NULL );
191     tet_result( TET_FAIL );
192   }
193   catch (Dali::DaliException& e)
194   {
195     tet_result( TET_PASS );
196   }
197
198   delete button;
199
200   END_TEST;
201 }
202
203
204 int UtcConnectionTrackerGetConnectionCountP(void)
205 {
206   TestApplication app; // Create core for debug logging
207
208   TestButton* button = new TestButton(1);
209   TestApp testApp;
210   button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress);
211   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 );
212
213   delete button;
214
215   END_TEST;
216 }
217
218 int UtcConnectionTrackerGetConnectionCountN(void)
219 {
220   TestApplication app; // Create core for debug logging
221
222   TestButton* button = new TestButton(1);
223   DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 0 );
224
225   delete button;
226
227   END_TEST;
228 }