2 * Copyright (c) 2017 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.
19 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <dali/devel-api/actors/actor-devel.h>
24 // Internal headers are allowed here
25 #define protected public
26 #include <dali/internal/event/actors/actor-impl.h>
30 void utc_dali_internal_actor_depth_startup()
32 test_return_value = TET_UNDEF;
35 void utc_dali_internal_actor_depth_cleanup()
37 test_return_value = TET_PASS;
40 Actor CreateActor( Actor parent, int siblingOrder, const char* name )
42 Actor actor = Actor::New();
43 actor.SetProperty( DevelActor::Property::SIBLING_ORDER, siblingOrder);
44 actor.SetName( name );
49 void PrintActor(Dali::Actor a, int depth)
52 Dali::Property::Value v = a.GetProperty( Dali::DevelActor::Property::SIBLING_ORDER );
55 Dali::Internal::Actor& actorImpl = GetImplementation(a);
56 for( int i=0; i<depth; ++i)
58 std::cout << "Actor: " << a.GetName() << "(" << a.GetId() << ") siblingOrder: " <<
59 siblingOrder << " depthOrder: " << actorImpl.GetSortingDepth() << std::endl;
62 void PrintActorTree( Dali::Actor a, int depth )
64 PrintActor( a, depth );
65 for( unsigned int i=0; i<a.GetChildCount(); ++i )
67 PrintActorTree( a.GetChildAt(i), depth+1 );
71 void PrintNode( Dali::Internal::ActorDepthTreeNode& node, int depth )
73 for( int i=0; i<depth; ++i)
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 )
79 std::cout << (*iter)->GetName() << ", ";
81 std::cout << std::endl;
83 if( node.mFirstChildNode )
84 PrintNode( *node.mFirstChildNode, depth+1);
86 if( node.mNextSiblingNode )
88 PrintNode( *node.mNextSiblingNode, depth );
92 void CheckNodeForActor( Dali::Internal::ActorDepthTreeNode*node, Actor actor, const char* loc )
95 Dali::Internal::Actor& actorImpl = Dali::GetImplementation(actor);
97 for( std::vector<Internal::Actor*>::iterator iter = node->mActors.begin(); iter != node->mActors.end(); ++iter )
99 if( *iter == &actorImpl )
105 DALI_TEST_EQUALS( found, true, loc );
108 unsigned int GetActorCount( Dali::Internal::ActorDepthTreeNode*node )
110 unsigned int size = node->mActors.size();
112 for( Dali::Internal::ActorDepthTreeNode* childNode = node->mFirstChildNode;
114 childNode = childNode->mNextSiblingNode )
116 size += GetActorCount( childNode );
122 int UtcDaliActorDepthTreeTest01(void)
124 TestApplication application;
125 tet_infoline("Testing Actor tree depth");
127 Stage stage = Stage::GetCurrent();
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");
135 Actor E = CreateActor(A, 0, "E");
136 Actor F = CreateActor(A, 2, "F");
137 Actor G = CreateActor(A, 1, "G");
139 Actor H = CreateActor(B, 2, "H");
140 Actor I = CreateActor(B, 1, "I");
141 Actor J = CreateActor(B, 0, "J");
143 Actor K = CreateActor(C, 1, "K");
144 Actor L = CreateActor(C, 2, "L");
145 Actor M = CreateActor(C, 0, "M");
147 Actor N = CreateActor(D, 2, "N");
148 Actor O = CreateActor(D, 2, "O");
149 Actor P = CreateActor(D, 1, "P");
151 PrintActorTree( Root, 0 );
153 Internal::Actor& rootLayerImpl = GetImplementation(Root);
155 Internal::DepthNodeMemoryPool nodeMemoryPool;
156 Internal::ActorDepthTreeNode* rootNode = new (nodeMemoryPool.AllocateRaw()) Internal::ActorDepthTreeNode( &rootLayerImpl, 0 );
157 rootLayerImpl.BuildDepthTree( nodeMemoryPool, rootNode ) ;
160 PrintNode( *rootNode, depth );
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 );
177 unsigned int actorCount = GetActorCount( rootNode );
178 DALI_TEST_EQUALS( actorCount, 17, TEST_LOCATION );
185 int UtcDaliActorDepthTreeTest02(void)
187 TestApplication application;
188 tet_infoline("Testing Actor tree depth");
190 Stage stage = Stage::GetCurrent();
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");
198 Actor E = CreateActor(A, 0, "E");
199 Actor F = CreateActor(A, 0, "F");
200 Actor G = CreateActor(A, 0, "G");
202 Actor H = CreateActor(B, 0, "H");
203 Actor I = CreateActor(B, 0, "I");
204 Actor J = CreateActor(B, 0, "J");
206 Actor K = CreateActor(C, 0, "K");
207 Actor L = CreateActor(C, 0, "L");
208 Actor M = CreateActor(C, 0, "M");
210 Actor N = CreateActor(D, 0, "N");
211 Actor O = CreateActor(D, 0, "O");
212 Actor P = CreateActor(D, 0, "P");
214 PrintActorTree( Root, 0 );
216 Internal::Actor& rootLayerImpl = GetImplementation(Root);
218 Internal::DepthNodeMemoryPool nodeMemoryPool;
219 Internal::ActorDepthTreeNode* rootNode = new (nodeMemoryPool.AllocateRaw()) Internal::ActorDepthTreeNode( &rootLayerImpl, 0 );
220 rootLayerImpl.BuildDepthTree( nodeMemoryPool, rootNode ) ;
223 PrintNode( *rootNode, depth );
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 );
235 unsigned int actorCount = GetActorCount( rootNode );
236 DALI_TEST_EQUALS( actorCount, 17, TEST_LOCATION );