Dali 3D User Interface Engine
utc-Dali-SignalDelegate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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
25 #include <dali-test-suite-utils.h>
26 
27 using namespace Dali;
28 
29 
31 {
33 }
34 
36 {
38 }
39 
40 // Test infrastructure:
41 
42 static bool gSignalReceived = false;
43 
48 {
49 public:
50 
51  SignalDelegateTestClass( Actor connectActor, std::string connectSignal )
52  {
53  mSignalDelegate = new SignalDelegate( connectActor, connectSignal );
54  }
55 
56  void ConnectToInternalMember()
57  {
58  mSignalDelegate->Connect( this, &SignalDelegateTestClass::SignalHandlerMemberFunction );
59  }
60 
61  bool IsConnected()
62  {
63  return mSignalDelegate->IsConnected();
64  }
65 
66 private:
67 
68  void SignalHandlerMemberFunction()
69  {
70  tet_infoline( "Got signal in member function\n" );
71  gSignalReceived = true;
72  }
73 
75 };
76 
81 {
82 };
83 
88 {
90  {
91  }
92 
93  void operator()()
94  {
95  gSignalReceived = true;
96  }
97 };
98 
99 
100 // Test cases:
101 
103 {
104  TestApplication application;
105  tet_infoline( " UtcDaliSignalDelegateIsConnectedP" );
106 
107  // Set up an actor with a signal to connect to.
108  Actor connectActor = Actor::New();
109  std::string connectSignal = "onStage";
110 
111  // Create the test class (this will create the delegate, but not connect to it yet.
112  SignalDelegateTestClass testObject( connectActor, connectSignal );
113 
114  // Tell the test class to connect the delegate to it's internal member.
115  // Note: It is at this point that the delegate internally makes the connection.
116  testObject.ConnectToInternalMember();
117 
118  DALI_TEST_CHECK( testObject.IsConnected() );
119 
120  END_TEST;
121 }
122 
124 {
125  TestApplication application;
126  tet_infoline( " UtcDaliSignalDelegateIsConnectedN" );
127 
128  // Set up an actor with a signal to connect to.
129  Actor connectActor = Actor::New();
130  std::string connectSignal = "onStage";
131 
132  // Create the test class (this will create the delegate, but not connect to it yet.
133  SignalDelegateTestClass testObject( connectActor, connectSignal );
134 
135  DALI_TEST_CHECK( !testObject.IsConnected() );
136 
137  END_TEST;
138 }
139 
141 {
142  TestApplication application;
143  tet_infoline( " UtcDaliSignalDelegateConnectToMemberP" );
144 
145  // Set up an actor with a signal to connect to.
146  Actor connectActor = Actor::New();
147  std::string connectSignal = "onStage";
148 
149  gSignalReceived = false;
150 
151  // Create the test class (this will create the delegate, but not connect to it yet.
152  SignalDelegateTestClass testObject( connectActor, connectSignal );
153 
154  // Tell the test class to connect the delegate to it's internal member.
155  // Note: It is at this point that the delegate internally makes the connection.
156  testObject.ConnectToInternalMember();
157 
158  // Add the actor to the stage to trigger it's "onStage" signal.
159  // If the delegate connected correctly, this will call the member
160  // function in the test object and set a global flag.
161  Stage::GetCurrent().Add( connectActor );
162 
163  // Check the global flag to confirm the signal was received.
165 
166  END_TEST;
167 }
168 
170 {
171  TestApplication application;
172  tet_infoline( " UtcDaliSignalDelegateConnectToMemberN" );
173 
174  // Set up an actor with a signal to connect to.
175  Actor connectActor = Actor::New();
176  std::string connectSignal = "onStage";
177 
178  gSignalReceived = false;
179 
180  // Create the test class (this will create the delegate, but not connect to it yet.
181  SignalDelegateTestClass testObject( connectActor, connectSignal );
182 
183  // Tell the test class to connect the delegate to it's internal member.
184  // Note: It is at this point that the delegate internally makes the connection.
185  testObject.ConnectToInternalMember();
186 
187  // Check the global flag to confirm the signal was not received.
189 
190  END_TEST;
191 }
192 
194 {
195  TestApplication application;
196  tet_infoline( " UtcDaliSignalDelegateConnectToFunctorP" );
197 
198  // Set up an actor with a signal to connect to.
199  Actor connectActor = Actor::New();
200  std::string connectSignal = "onStage";
201 
202  // Initialise the signal delegate with the actor to connect to and it's signal.
203  SignalDelegate signalDelegate( connectActor, connectSignal );
204 
205  // We need a connection tracker object to associated with the connection.
206  // This could normally be "this", but since we are not within a class, we pass
207  // in an external one.
209 
210  // Check the signal delegate currently has no connection.
211  DALI_TEST_CHECK( !signalDelegate.IsConnected() );
212 
213  // Tell the signal delegate to connect to the given functor (via a functor delegate).
214  // Note: It is at this point that the delegate internally makes the connection.
215  signalDelegate.Connect( testTracker, FunctorDelegate::New( SignalDelegateTestFunctor() ) );
216 
217  // Check the signal delegate has made the connection.
218  DALI_TEST_CHECK( signalDelegate.IsConnected() );
219 
220  // Add the actor to the stage to trigger it's "onStage" signal.
221  // If the delegate connected correctly, this will call the () operator of our
222  // passed-in functor, the functor will in turn set a global flag.
223  Stage::GetCurrent().Add( connectActor );
224 
225  // Check the global flag to confirm the signal was received.
227 
228  END_TEST;
229 }
230 
232 {
233  TestApplication application;
234  tet_infoline( " UtcDaliSignalDelegateConnectToFunctorN" );
235 
236  // Set up an actor with a signal to connect to.
237  Actor connectActor = Actor::New();
238  std::string connectSignal = "onStage";
239 
240  // Initialise the signal delegate with the actor to connect to and it's signal.
241  SignalDelegate signalDelegate( connectActor, connectSignal );
242 
243  // We need a connection tracker object to associated with the connection.
244  // This could normally be "this", but since we are not within a class, we pass
245  // in an external one.
247 
248  // Check the signal delegate currently has no connection.
249  DALI_TEST_CHECK( !signalDelegate.IsConnected() );
250 
251  // Tell the signal delegate to connect to the given functor (via a functor delegate).
252  // Note: It is at this point that the delegate internally makes the connection.
253  signalDelegate.Connect( testTracker, FunctorDelegate::New( SignalDelegateTestFunctor() ) );
254 
255  // Check the signal delegate has made the connection.
256  DALI_TEST_CHECK( signalDelegate.IsConnected() );
257 
258  // Check the global flag to confirm the signal was received.
260 
261  END_TEST;
262 }
Dali Docs Home
Read more about Dali