Merge "Implemented basic CPU image masking" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-ActorDepth.cpp
1 /*
2  * Copyright (c) 2017 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 #include <iostream>
17
18 #include <stdlib.h>
19 #include <dali/public-api/dali-core.h>
20
21 #include <dali-test-suite-utils.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23
24 // Internal headers are allowed here
25 #define protected public
26 #include <dali/internal/event/actors/actor-impl.h>
27
28 using namespace Dali;
29
30 void utc_dali_internal_actor_depth_startup()
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_internal_actor_depth_cleanup()
36 {
37   test_return_value = TET_PASS;
38 }
39
40 Actor CreateActor( Actor parent, int siblingOrder, const char* name )
41 {
42   Actor actor = Actor::New();
43   actor.SetProperty( DevelActor::Property::SIBLING_ORDER, siblingOrder);
44   actor.SetName( name );
45   parent.Add(actor);
46   return actor;
47 }
48
49 void PrintActor(Dali::Actor a, int depth)
50 {
51   int siblingOrder;
52   Dali::Property::Value v = a.GetProperty( Dali::DevelActor::Property::SIBLING_ORDER );
53   v.Get(siblingOrder);
54
55   Dali::Internal::Actor& actorImpl = GetImplementation(a);
56   for( int i=0; i<depth; ++i)
57     std::cout << "  ";
58   std::cout << "Actor: " << a.GetName() << "(" << a.GetId() << ") siblingOrder: " <<
59     siblingOrder << " depthOrder: " << actorImpl.GetSortingDepth() << std::endl;
60 }
61
62 void PrintActorTree( Dali::Actor a, int depth )
63 {
64   PrintActor( a, depth );
65   for( unsigned int i=0; i<a.GetChildCount(); ++i )
66   {
67     PrintActorTree( a.GetChildAt(i), depth+1 );
68   }
69 }
70
71 void PrintNode( Dali::Internal::ActorDepthTreeNode& node, int depth )
72 {
73   for( int i=0; i<depth; ++i)
74     std::cout << "  ";
75   std::cout << "Node: " << &node << "  siblingOrder:" << node.mSiblingOrder << " Actors:";
76   for( std::vector<Internal::Actor*>::iterator iter = node.mActors.begin() ;
77        iter != node.mActors.end(); ++iter )
78   {
79     std::cout << (*iter)->GetName() << ", ";
80   }
81   std::cout << std::endl;
82
83   if( node.mFirstChildNode )
84     PrintNode( *node.mFirstChildNode, depth+1);
85
86   if( node.mNextSiblingNode )
87   {
88     PrintNode( *node.mNextSiblingNode, depth );
89   }
90 }
91
92 void CheckNodeForActor( Dali::Internal::ActorDepthTreeNode*node, Actor actor, const char* loc )
93 {
94   bool found = false;
95   Dali::Internal::Actor& actorImpl = Dali::GetImplementation(actor);
96
97   for( std::vector<Internal::Actor*>::iterator iter = node->mActors.begin(); iter != node->mActors.end(); ++iter )
98   {
99     if( *iter == &actorImpl )
100     {
101       found = true;
102       break;
103     }
104   }
105   DALI_TEST_EQUALS( found, true, loc );
106 }
107
108 unsigned int GetActorCount( Dali::Internal::ActorDepthTreeNode*node )
109 {
110   unsigned int size = node->mActors.size();
111
112   for( Dali::Internal::ActorDepthTreeNode* childNode = node->mFirstChildNode;
113        childNode != NULL;
114        childNode = childNode->mNextSiblingNode )
115   {
116     size += GetActorCount( childNode );
117   }
118
119   return size;
120 }
121
122 int UtcDaliActorDepthTreeTest01(void)
123 {
124   TestApplication application;
125   tet_infoline("Testing Actor tree depth");
126
127   Stage stage = Stage::GetCurrent();
128
129   Actor Root = CreateActor(stage.GetRootLayer(), 0, "ROOT" );
130   Actor A = CreateActor( Root, 0, "A");
131   Actor B = CreateActor( Root, 2, "B");
132   Actor C = CreateActor( Root, 0, "C");
133   Actor D = CreateActor( Root, 1, "D");
134
135   Actor E = CreateActor(A, 0, "E");
136   Actor F = CreateActor(A, 2, "F");
137   Actor G = CreateActor(A, 1, "G");
138
139   Actor H = CreateActor(B, 2, "H");
140   Actor I = CreateActor(B, 1, "I");
141   Actor J = CreateActor(B, 0, "J");
142
143   Actor K = CreateActor(C, 1, "K");
144   Actor L = CreateActor(C, 2, "L");
145   Actor M = CreateActor(C, 0, "M");
146
147   Actor N = CreateActor(D, 2, "N");
148   Actor O = CreateActor(D, 2, "O");
149   Actor P = CreateActor(D, 1, "P");
150
151   PrintActorTree( Root, 0 );
152
153   Internal::Actor& rootLayerImpl = GetImplementation(Root);
154
155   Internal::DepthNodeMemoryPool nodeMemoryPool;
156   Internal::ActorDepthTreeNode* rootNode = new (nodeMemoryPool.AllocateRaw()) Internal::ActorDepthTreeNode( &rootLayerImpl, 0 );
157   rootLayerImpl.BuildDepthTree( nodeMemoryPool, rootNode ) ;
158
159   int depth=0;
160   PrintNode( *rootNode, depth );
161
162   // Check that first child node contains actors A and C
163   // check that first grand child node contains actors E, M
164   // check that it's sibling node contains actors G, K
165   // check that it's sibling node contains actors F, L
166   // Check that tree only contains 16 actors.
167   CheckNodeForActor( rootNode->mFirstChildNode, A, TEST_LOCATION );
168   CheckNodeForActor( rootNode->mFirstChildNode, C, TEST_LOCATION );
169   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, E, TEST_LOCATION );
170   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, M, TEST_LOCATION );
171   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode->mNextSiblingNode, G, TEST_LOCATION );
172   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode->mNextSiblingNode, K, TEST_LOCATION );
173   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode->mNextSiblingNode->mNextSiblingNode, F, TEST_LOCATION );
174   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode->mNextSiblingNode->mNextSiblingNode, L, TEST_LOCATION );
175   CheckNodeForActor( rootNode->mFirstChildNode->mNextSiblingNode->mNextSiblingNode, B, TEST_LOCATION );
176
177   unsigned int actorCount = GetActorCount( rootNode );
178   DALI_TEST_EQUALS( actorCount, 17, TEST_LOCATION );
179
180   END_TEST;
181 }
182
183
184
185 int UtcDaliActorDepthTreeTest02(void)
186 {
187   TestApplication application;
188   tet_infoline("Testing Actor tree depth");
189
190   Stage stage = Stage::GetCurrent();
191
192   Actor Root = CreateActor(stage.GetRootLayer(), 0, "ROOT" );
193   Actor A = CreateActor( Root, 0, "A");
194   Actor B = CreateActor( Root, 0, "B");
195   Actor C = CreateActor( Root, 0, "C");
196   Actor D = CreateActor( Root, 0, "D");
197
198   Actor E = CreateActor(A, 0, "E");
199   Actor F = CreateActor(A, 0, "F");
200   Actor G = CreateActor(A, 0, "G");
201
202   Actor H = CreateActor(B, 0, "H");
203   Actor I = CreateActor(B, 0, "I");
204   Actor J = CreateActor(B, 0, "J");
205
206   Actor K = CreateActor(C, 0, "K");
207   Actor L = CreateActor(C, 0, "L");
208   Actor M = CreateActor(C, 0, "M");
209
210   Actor N = CreateActor(D, 0, "N");
211   Actor O = CreateActor(D, 0, "O");
212   Actor P = CreateActor(D, 0, "P");
213
214   PrintActorTree( Root, 0 );
215
216   Internal::Actor& rootLayerImpl = GetImplementation(Root);
217
218   Internal::DepthNodeMemoryPool nodeMemoryPool;
219   Internal::ActorDepthTreeNode* rootNode = new (nodeMemoryPool.AllocateRaw()) Internal::ActorDepthTreeNode( &rootLayerImpl, 0 );
220   rootLayerImpl.BuildDepthTree( nodeMemoryPool, rootNode ) ;
221
222   int depth=0;
223   PrintNode( *rootNode, depth );
224
225   CheckNodeForActor( rootNode->mFirstChildNode, A, TEST_LOCATION );
226   CheckNodeForActor( rootNode->mFirstChildNode, C, TEST_LOCATION );
227   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, E, TEST_LOCATION );
228   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, M, TEST_LOCATION );
229   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, G, TEST_LOCATION );
230   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, K, TEST_LOCATION );
231   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, F, TEST_LOCATION );
232   CheckNodeForActor( rootNode->mFirstChildNode->mFirstChildNode, L, TEST_LOCATION );
233   CheckNodeForActor( rootNode->mFirstChildNode, B, TEST_LOCATION );
234
235   unsigned int actorCount = GetActorCount( rootNode );
236   DALI_TEST_EQUALS( actorCount, 17, TEST_LOCATION );
237
238   END_TEST;
239 }