2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/devel-api/signals/signal-delegate.h>
25 #include <dali-test-suite-utils.h>
30 void utc_dali_signal_delegate_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_signal_delegate_cleanup(void)
37 test_return_value = TET_PASS;
40 // Test infrastructure:
42 static bool gSignalReceived = false;
45 * This object allows us to test member function connection.
47 class SignalDelegateTestClass : public Dali::ConnectionTracker
51 SignalDelegateTestClass( Actor connectActor, std::string connectSignal )
53 mSignalDelegate = new SignalDelegate( connectActor, connectSignal );
56 void ConnectToInternalMember()
58 mSignalDelegate->Connect( this, &SignalDelegateTestClass::SignalHandlerMemberFunction );
63 return mSignalDelegate->IsConnected();
68 void SignalHandlerMemberFunction()
70 tet_infoline( "Got signal in member function\n" );
71 gSignalReceived = true;
74 SignalDelegate* mSignalDelegate;
78 * A connection tracker is required when connecting a signal delegate to a functor.
80 class TestConnectionTrackerObject : public ConnectionTracker
85 * This functor is used to test the signal delegate's connect ( to functor ) method.
87 struct SignalDelegateTestFunctor
89 SignalDelegateTestFunctor()
95 gSignalReceived = true;
102 int UtcDaliSignalDelegateIsConnectedP(void)
104 TestApplication application;
105 tet_infoline( " UtcDaliSignalDelegateIsConnectedP" );
107 // Set up an actor with a signal to connect to.
108 Actor connectActor = Actor::New();
109 std::string connectSignal = "onStage";
111 // Create the test class (this will create the delegate, but not connect to it yet.
112 SignalDelegateTestClass testObject( connectActor, connectSignal );
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();
118 DALI_TEST_CHECK( testObject.IsConnected() );
123 int UtcDaliSignalDelegateIsConnectedN(void)
125 TestApplication application;
126 tet_infoline( " UtcDaliSignalDelegateIsConnectedN" );
128 // Set up an actor with a signal to connect to.
129 Actor connectActor = Actor::New();
130 std::string connectSignal = "onStage";
132 // Create the test class (this will create the delegate, but not connect to it yet.
133 SignalDelegateTestClass testObject( connectActor, connectSignal );
135 DALI_TEST_CHECK( !testObject.IsConnected() );
140 int UtcDaliSignalDelegateConnectToMemberP(void)
142 TestApplication application;
143 tet_infoline( " UtcDaliSignalDelegateConnectToMemberP" );
145 // Set up an actor with a signal to connect to.
146 Actor connectActor = Actor::New();
147 std::string connectSignal = "onStage";
149 gSignalReceived = false;
151 // Create the test class (this will create the delegate, but not connect to it yet.
152 SignalDelegateTestClass testObject( connectActor, connectSignal );
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();
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 );
163 // Check the global flag to confirm the signal was received.
164 DALI_TEST_CHECK( gSignalReceived );
169 int UtcDaliSignalDelegateConnectToMemberN(void)
171 TestApplication application;
172 tet_infoline( " UtcDaliSignalDelegateConnectToMemberN" );
174 // Set up an actor with a signal to connect to.
175 Actor connectActor = Actor::New();
176 std::string connectSignal = "onStage";
178 gSignalReceived = false;
180 // Create the test class (this will create the delegate, but not connect to it yet.
181 SignalDelegateTestClass testObject( connectActor, connectSignal );
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();
187 // Check the global flag to confirm the signal was not received.
188 DALI_TEST_CHECK( !gSignalReceived );
193 int UtcDaliSignalDelegateConnectToFunctorP(void)
195 TestApplication application;
196 tet_infoline( " UtcDaliSignalDelegateConnectToFunctorP" );
198 // Set up an actor with a signal to connect to.
199 Actor connectActor = Actor::New();
200 std::string connectSignal = "onStage";
202 // Initialise the signal delegate with the actor to connect to and it's signal.
203 SignalDelegate signalDelegate( connectActor, connectSignal );
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.
208 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
210 // Check the signal delegate currently has no connection.
211 DALI_TEST_CHECK( !signalDelegate.IsConnected() );
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() ) );
217 // Check the signal delegate has made the connection.
218 DALI_TEST_CHECK( signalDelegate.IsConnected() );
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 );
225 // Check the global flag to confirm the signal was received.
226 DALI_TEST_CHECK( gSignalReceived );
231 int UtcDaliSignalDelegateConnectToFunctorN(void)
233 TestApplication application;
234 tet_infoline( " UtcDaliSignalDelegateConnectToFunctorN" );
236 // Set up an actor with a signal to connect to.
237 Actor connectActor = Actor::New();
238 std::string connectSignal = "onStage";
240 // Initialise the signal delegate with the actor to connect to and it's signal.
241 SignalDelegate signalDelegate( connectActor, connectSignal );
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.
246 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
248 // Check the signal delegate currently has no connection.
249 DALI_TEST_CHECK( !signalDelegate.IsConnected() );
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() ) );
255 // Check the signal delegate has made the connection.
256 DALI_TEST_CHECK( signalDelegate.IsConnected() );
258 // Check the global flag to confirm the signal was received.
259 DALI_TEST_CHECK( !gSignalReceived );