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