Dali 3D User Interface Engine
utc-Dali-ConnectionTracker.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 <iostream>
20 #include <stdlib.h>
21 
22 // INTERNAL INCLUDES
24 #include <dali-test-suite-utils.h>
25 #include <signal-helper.h>
26 
27 
28 using namespace Dali;
29 
31 {
33 }
34 
36 {
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 
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 
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 
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 
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 
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 }
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
151  }
152 
153  delete button;
154 
155  END_TEST;
156 }
157 
158 
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 
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 
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 
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 }
Dali Docs Home
Read more about Dali