Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-SignalDelegate.cpp
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
23 #include <dali/public-api/dali-core.h>
24 #include <dali/devel-api/signals/signal-delegate.h>
25 #include <dali-test-suite-utils.h>
26
27 using namespace Dali;
28
29
30 void utc_dali_signal_delegate_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_signal_delegate_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 // Test infrastructure:
41
42 static bool gSignalReceived = false;
43
44 /**
45  * This object allows us to test member function connection.
46  */
47 class SignalDelegateTestClass : public Dali::ConnectionTracker
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
74   SignalDelegate* mSignalDelegate;
75 };
76
77 /**
78  * A connection tracker is required when connecting a signal delegate to a functor.
79  */
80 class TestConnectionTrackerObject : public ConnectionTracker
81 {
82 };
83
84 /**
85  * This functor is used to test the signal delegate's connect ( to functor ) method.
86  */
87 struct SignalDelegateTestFunctor
88 {
89   SignalDelegateTestFunctor()
90   {
91   }
92
93   void operator()()
94   {
95     gSignalReceived = true;
96   }
97 };
98
99
100 // Test cases:
101
102 int UtcDaliSignalDelegateIsConnectedP(void)
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
123 int UtcDaliSignalDelegateIsConnectedN(void)
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
140 int UtcDaliSignalDelegateConnectToMemberP(void)
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.
164   DALI_TEST_CHECK( gSignalReceived );
165
166   END_TEST;
167 }
168
169 int UtcDaliSignalDelegateConnectToMemberN(void)
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.
188   DALI_TEST_CHECK( !gSignalReceived );
189
190   END_TEST;
191 }
192
193 int UtcDaliSignalDelegateConnectToFunctorP(void)
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.
208   TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
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.
226   DALI_TEST_CHECK( gSignalReceived );
227
228   END_TEST;
229 }
230
231 int UtcDaliSignalDelegateConnectToFunctorN(void)
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.
246   TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
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.
259   DALI_TEST_CHECK( !gSignalReceived );
260
261   END_TEST;
262 }