2 * Copyright (c) 2014 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.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
25 using namespace Toolkit;
27 void dali_tableview_startup(void)
29 test_return_value = TET_UNDEF;
32 void dali_tableview_cleanup(void)
34 test_return_value = TET_PASS;
40 const char* const PROPERTY_NAME_ROWS = "rows";
41 const char* const PROPERTY_NAME_COLUMNS = "columns";
42 const char* const PROPERTY_NAME_CELL_PADDING = "cellPadding";
43 const char* const PROPERTY_NAME_LAYOUT_ROWS = "layoutRows";
44 const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layoutColumns";
45 const Vector2 CELL_SIZE( 10, 10 );
47 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
51 gObjectCreatedCallBackCalled = true;
61 * function operator to apply the parent size
63 void operator()( Dali::Vector3& current, const PropertyInputContainer& /* inputs */ )
65 current.x = current.y = current.z = 100.0f;
69 // Convenience function to quickly set up a 10x10 table with each cell being 10x10 pixels in size by default.
70 static void SetupTableViewAndActors(TableView& tableView, Actor& actor1, Actor& actor2, Actor& actor3)
72 tableView = TableView::New( 10, 10 ); // 10 by 10 grid.
73 DALI_TEST_CHECK( tableView );
75 Stage::GetCurrent().Add( tableView );
76 tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );
78 actor1 = Actor::New();
79 actor2 = Actor::New();
80 actor3 = Actor::New();
82 actor1.SetSize( CELL_SIZE );
83 actor2.SetSize( CELL_SIZE );
84 actor3.SetSize( CELL_SIZE );
86 tableView.AddChild( actor1, TableView::CellPosition( 0, 0 ) );
87 tableView.AddChild( actor2, TableView::CellPosition( 0, 1 ) );
88 tableView.AddChild( actor3, TableView::CellPosition( 1, 0 ) );
93 int UtcDaliTableViewCtorCopyP(void)
95 TestApplication application;
97 TableView actor1 = TableView::New(10,10);
98 TableView actor2( actor1 );
100 DALI_TEST_EQUALS( actor1, actor2, TEST_LOCATION );
104 int UtcDaliTableViewNew(void)
106 ToolkitTestApplication application;
108 TableView tableView = TableView::New(10,10);
109 DALI_TEST_CHECK(tableView);
111 //Additional check to ensure object is created by checking if it's registered
112 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
113 DALI_TEST_CHECK( registry );
115 gObjectCreatedCallBackCalled = false;
116 registry.ObjectCreatedSignal().Connect(&TestCallback);
118 TableView tableView = TableView::New(10,10);
120 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
124 // Test adjusting the metric values for the cell.
125 int UtcDaliTableViewMetricsPadding(void)
127 ToolkitTestApplication application;
129 tet_infoline("UtcDaliTableViewMetricsPadding");
136 SetupTableViewAndActors(tableView, actor1, actor2, actor3);
138 // 1. check that padding works. no padding:
139 tableView.SetCellPadding(Size(0.0f, 0.0f));
140 application.SendNotification();
141 application.Render();
143 DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(0.0f, 0.0f), TEST_LOCATION );
144 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
145 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
146 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
148 // 1. check that padding works. some padding:
149 tableView.SetCellPadding(Size(5.0f, 10.0f));
150 application.SendNotification();
151 application.Render();
153 DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(5.0f, 10.0f), TEST_LOCATION );
154 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(5.0f, 10.0f, 0.0f), TEST_LOCATION );
158 // Test adjusting the metric values for the cell.
159 int UtcDaliTableViewMetricsFit(void)
161 ToolkitTestApplication application;
163 tet_infoline("UtcDaliTableViewMetricsFit");
170 SetupTableViewAndActors(tableView, actor1, actor2, actor3);
171 application.SendNotification();
172 application.Render();
174 // 1. check that with no fixed width/heights, actors are in default position.
175 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
176 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
177 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
179 // 2. check that with a fixed width & height, actors to the right and below are offsetted.
180 tableView.SetFitHeight(0);
181 tableView.SetFitWidth(0);
182 DALI_TEST_EQUALS( tableView.IsFitHeight(0), true, TEST_LOCATION );
183 DALI_TEST_EQUALS( tableView.IsFitWidth(0), true, TEST_LOCATION );
185 application.SendNotification();
186 application.Render();
188 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
189 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
190 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
194 // Test adjusting the metric values for the cell.
195 int UtcDaliTableViewMetricsFixed(void)
197 ToolkitTestApplication application;
199 tet_infoline("UtcDaliTableViewMetricsFixed");
206 SetupTableViewAndActors(tableView, actor1, actor2, actor3);
207 application.SendNotification();
208 application.Render();
210 // 1. check that with no fixed width/heights, actors are in default position.
211 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
212 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
213 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
215 // 2. check that with a fixed width & height, actors to the right and below are offsetted.
216 tableView.SetFixedWidth(0, 20.0f);
217 tableView.SetFixedHeight(0, 50.0f);
218 DALI_TEST_EQUALS( tableView.GetFixedWidth(0), 20.0f, TEST_LOCATION );
219 DALI_TEST_EQUALS( tableView.GetFixedHeight(0), 50.0f, TEST_LOCATION );
221 application.SendNotification();
222 application.Render();
224 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
225 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(20.0f, 0.0f, 0.0f), TEST_LOCATION );
226 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
230 // Test adjusting the metric values for the cell.
231 int UtcDaliTableViewMetricsRelative(void)
233 ToolkitTestApplication application;
235 tet_infoline("UtcDaliTableViewMetricsRelative");
242 SetupTableViewAndActors(tableView, actor1, actor2, actor3);
243 application.SendNotification();
244 application.Render();
246 // 1. check that with no relative width/heights, actors are in default position.
247 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
248 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
249 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
251 // 2. check that with a relative width & height, actors to the right and below are offsetted.
252 tableView.SetRelativeWidth(0, 0.3f); // cell 0,0 occupies 30%x50% of the grid (i.e. 30x50 pixels)
253 tableView.SetRelativeHeight(0, 0.5f);
254 DALI_TEST_EQUALS( tableView.GetRelativeWidth(0), 0.3f, TEST_LOCATION );
255 DALI_TEST_EQUALS( tableView.GetRelativeHeight(0), 0.5f, TEST_LOCATION );
257 application.SendNotification();
258 application.Render();
260 DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
261 DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(30.0f, 0.0f, 0.0f), TEST_LOCATION );
262 DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
267 // Test Adding/Removing/Finding Children.
268 int UtcDaliTableViewChild(void)
270 ToolkitTestApplication application;
272 tet_infoline("UtcDaliTableViewChild");
274 // Create a 10x10 table-view
275 TableView tableView = TableView::New(10,10);
276 DALI_TEST_CHECK( tableView );
278 // Check if actor doesn't exist.
279 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
281 // Add an actor to it at 0,0
282 Actor actor = Actor::New();
283 tableView.AddChild(actor, TableView::CellPosition());
286 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(0,0)) );
289 tableView.RemoveChildAt(TableView::CellPosition());
291 // Check if actor no longer exists.
292 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
294 // Add actor to it again, but at 2,5
295 tableView.AddChild(actor, TableView::CellPosition(2,5));
297 // Add another actor somewhere else 7,8
298 Actor actor2 = Actor::New();
299 tableView.AddChild(actor2, TableView::CellPosition(7,8));
303 // Check that no actor exists in a few random places.
304 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
305 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(2,1)) );
306 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(6,3)) );
307 DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(9,5)) );
309 // Check for actors at actual positions.
310 searchActor = tableView.GetChildAt(TableView::CellPosition(2,5));
311 DALI_TEST_CHECK( searchActor == actor);
313 searchActor = tableView.GetChildAt(TableView::CellPosition(7,8));
314 DALI_TEST_CHECK( searchActor == actor2);
316 // Create a second table, and add already added Child to new one.
317 TableView tableView2 = TableView::New(5,5);
318 tableView2.AddChild(actor, TableView::CellPosition(2,2));
319 DALI_TEST_CHECK( tableView2.GetChildAt(TableView::CellPosition(2,2)) );
323 // Test calling Add on it's own (to invoke the OnChildAdd)
324 int UtcDaliTableViewAdd(void)
326 ToolkitTestApplication application;
328 tet_infoline("UtcDaliTableViewAdd");
330 // Create a 4x1 table-view, and just keep adding.
331 TableView tableView = TableView::New(1,4);
332 DALI_TEST_CHECK( tableView );
334 for(unsigned int i = 0;i<16;i++)
336 Actor currentActor = Actor::New();
337 TableView::CellPosition position = TableView::CellPosition();
338 tableView.Add( currentActor );
339 tableView.FindChildPosition(currentActor, position);
340 tet_printf("%dx%d (%d,%d)\n", tableView.GetColumns(), tableView.GetRows(), position.columnIndex, position.rowIndex);
342 DALI_TEST_EQUALS((position.rowIndex * 4 + position.columnIndex), i, TEST_LOCATION);
347 // Test cell modification.
348 int UtcDaliTableViewCells(void)
350 ToolkitTestApplication application;
351 tet_infoline("UtcDaliTableViewCells");
353 // Create a 10x10 table-view
354 TableView tableView = TableView::New(10,10);
355 DALI_TEST_CHECK( tableView );
357 // Add a few actors to the table.
358 Actor actor1 = Actor::New();
359 Actor actor2 = Actor::New();
360 Actor actor3 = Actor::New();
361 actor1.SetName("Actor1");
362 actor2.SetName("Actor2");
363 actor3.SetName("Actor3");
365 // note: positions are specified in reversed cartesian coords - row,col (i.e. y,x)
366 tableView.AddChild(actor1, TableView::CellPosition(0,0));
367 tableView.AddChild(actor2, TableView::CellPosition(5,5));
368 tableView.AddChild(actor3, TableView::CellPosition(7,2));
370 DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
372 // Add a row between actor1 and actor2 | insert column on actor1 and see what happens...
373 tableView.InsertRow(3);
374 tableView.InsertColumn(0);
375 DALI_TEST_CHECK( tableView.GetRows() == 11 && tableView.GetColumns() == 11 );
377 TableView::CellPosition cellPosition;
380 result = tableView.FindChildPosition(actor1, cellPosition);
381 DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
382 result = tableView.FindChildPosition(actor2, cellPosition);
383 DALI_TEST_CHECK( result && cellPosition.rowIndex == 6 && cellPosition.columnIndex == 6);
384 result = tableView.FindChildPosition(actor3, cellPosition);
385 DALI_TEST_CHECK( result && cellPosition.rowIndex == 8 && cellPosition.columnIndex == 3);
387 // Delete a row between actor2 and actor3 | delete column on actor2 and see what happens...
388 tableView.DeleteRow(7);
389 tableView.DeleteColumn(6);
390 DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
392 result = tableView.FindChildPosition(actor1, cellPosition);
393 DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
394 result = tableView.FindChildPosition(actor2, cellPosition);
395 DALI_TEST_CHECK( !result );
396 result = tableView.FindChildPosition(actor3, cellPosition);
397 DALI_TEST_CHECK( result && cellPosition.rowIndex == 7 && cellPosition.columnIndex == 3);
399 // Delete the other two remaining actors by a row delete and a column delete.
400 std::vector<Actor> actorsRemoved;
401 tableView.DeleteRow(0, actorsRemoved);
402 tet_printf("Row Delete >> Actors Removed: %d {", actorsRemoved.size());
403 for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
405 DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
406 DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
408 actorsRemoved.clear();
409 tableView.DeleteColumn(3, actorsRemoved);
410 tet_printf("Column Delete >> Actors Removed: %d {", actorsRemoved.size());
411 for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
413 DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
414 DALI_TEST_CHECK( actorsRemoved[0] == actor3 );
416 DALI_TEST_CHECK( tableView.GetRows() == 9 && tableView.GetColumns() == 9 );
418 tableView.AddChild(actor1, TableView::CellPosition(5,8));
419 tableView.Resize(100,100);
420 DALI_TEST_CHECK( tableView.GetRows() == 100 && tableView.GetColumns() == 100 );
422 tableView.AddChild(actor2, TableView::CellPosition(69,57));
423 DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && tableView.FindChildPosition(actor2, cellPosition) );
425 tableView.Resize(20,20);
426 DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
428 actorsRemoved.clear();
429 tableView.Resize(1,1, actorsRemoved);
430 DALI_TEST_CHECK( !tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
431 DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
432 DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
434 // Add child outside table size, forcing a resize.
435 tableView.AddChild(actor1, TableView::CellPosition(100, 100, 1, 1));
436 DALI_TEST_CHECK( tableView.GetRows() == 101 && tableView.GetColumns() == 101 );
438 // Add child outside table size, forcing a resize.
439 tableView.AddChild(actor1, TableView::CellPosition(110, 110, 5, 5));
440 DALI_TEST_CHECK( tableView.GetRows() == 115 && tableView.GetColumns() == 115 );
442 // Set the alignment of the cell
443 tableView.SetCellAlignment( TableView::CellPosition(100, 100, 1, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
444 tableView.SetCellAlignment( TableView::CellPosition(110, 110, 5, 5), HorizontalAlignment::LEFT, VerticalAlignment::TOP );
446 DALI_TEST_CHECK( true );
450 int UtcDaliTableViewChildAssert(void)
452 ToolkitTestApplication application;
453 tet_infoline("UtcDaliTableViewChildAssert");
455 // Create a 10x10 table-view
456 TableView tableView = TableView::New(10,10);
457 DALI_TEST_CHECK( tableView );
462 tableView.AddChild( childActor, TableView::CellPosition(0,0,5,5) );
464 tet_result(TET_FAIL);
466 catch( Dali::DaliException& e )
468 DALI_TEST_PRINT_ASSERT( e );
469 DALI_TEST_EQUALS(e.condition, "child", TEST_LOCATION);
474 int UtcDaliTableViewMetricsAssert(void)
476 ToolkitTestApplication application;
477 tet_infoline("UtcDaliTableViewChildAssert");
479 // Create a 10x10 table-view
480 TableView tableView = TableView::New(10,10);
481 DALI_TEST_CHECK( tableView );
487 tableView.SetFixedHeight( 10, 1.0f );
489 tet_result(TET_FAIL);
491 catch( Dali::DaliException& e )
493 DALI_TEST_PRINT_ASSERT( e );
494 DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
499 tableView.GetFixedHeight( 10 );
501 tet_result(TET_FAIL);
503 catch( Dali::DaliException& e )
505 DALI_TEST_PRINT_ASSERT( e );
506 DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
511 tableView.SetFixedWidth( 10, 1.0f );
513 tet_result(TET_FAIL);
515 catch( Dali::DaliException& e )
517 DALI_TEST_PRINT_ASSERT( e );
518 DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
523 tableView.GetFixedWidth( 10 );
525 tet_result(TET_FAIL);
527 catch( Dali::DaliException& e )
529 DALI_TEST_PRINT_ASSERT( e );
530 DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
537 tableView.SetRelativeHeight( 10, 0.1f );
539 tet_result(TET_FAIL);
541 catch( Dali::DaliException& e )
543 DALI_TEST_PRINT_ASSERT( e );
544 DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
549 tableView.GetRelativeHeight( 10 );
551 tet_result(TET_FAIL);
553 catch( Dali::DaliException& e )
555 DALI_TEST_PRINT_ASSERT( e );
556 DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
561 tableView.SetRelativeWidth( 10, 0.1f );
563 tet_result(TET_FAIL);
565 catch( Dali::DaliException& e )
567 DALI_TEST_PRINT_ASSERT( e );
568 DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
573 tableView.GetRelativeWidth( 10 );
575 tet_result(TET_FAIL);
577 catch( Dali::DaliException& e )
579 DALI_TEST_PRINT_ASSERT( e );
580 DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
585 int UtcDaliTableViewSetGetProperty(void)
587 ToolkitTestApplication application;
588 tet_infoline("UtcDaliTableViewSetGetProperty");
590 // Create a 1x1 table-view
591 TableView tableView = TableView::New(1,1);
592 tableView.SetSize( Vector2( 100.0f, 100.0f ) );
593 DALI_TEST_CHECK( tableView );
595 // Test "rows" property
596 DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_ROWS ) == TableView::Property::ROWS );
598 tableView.SetProperty( TableView::Property::ROWS, 4 );
600 DALI_TEST_CHECK( tableView.GetRows() == 4u );
601 DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::ROWS).Get<int>() == 4 );
603 // Test "columns" property
604 DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::Property::COLUMNS );
606 tableView.SetProperty( TableView::Property::COLUMNS, 5 );
608 DALI_TEST_CHECK( tableView.GetColumns() == 5u );
609 DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::COLUMNS).Get<int>() == 5 );
611 // Test "cellPadding" property
612 DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_CELL_PADDING ) == TableView::Property::CELL_PADDING );
614 tableView.SetProperty( TableView::Property::CELL_PADDING, Size( 6.f, 8.f ) );
616 DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(6.f, 8.f), TEST_LOCATION );
617 DALI_TEST_EQUALS( tableView.GetProperty(TableView::Property::CELL_PADDING).Get<Vector2>(), Vector2(6.f,8.f), TEST_LOCATION );
619 //{ "policy": "fixed", "value": 30.0 },
621 item1[ "policy" ] = "fixed";
622 item1[ "value" ] = 30.f;
623 //{ "policy": "relative", "value": 0.2 },
625 item2[ "policy" ] = "relative";
626 item2[ "value" ] = 0.2f;
628 // Test "layoutRows" property
629 DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::Property::LAYOUT_ROWS );
634 * "1": { "policy": "fixed", "value": 30 },
635 * "3": { "policy": "relative", "value": 0.2 }
638 Property::Map layoutRows;
639 layoutRows[ "1" ] = item1;
640 layoutRows[ "3" ] = item2;
641 tableView.SetProperty( TableView::Property::LAYOUT_ROWS, layoutRows );
643 DALI_TEST_EQUALS( tableView.GetFixedHeight( 1u ), 30.f, TEST_LOCATION );
644 DALI_TEST_EQUALS( tableView.GetRelativeHeight( 3u ), 0.2f, TEST_LOCATION );
646 Property::Map layoutRowsGet = tableView.GetProperty(TableView::Property::LAYOUT_ROWS).Get<Property::Map>();
648 DALI_TEST_EQUALS( layoutRowsGet.GetKey(1).compare(layoutRows.GetKey(0)), 0, TEST_LOCATION );
649 Property::Map* childMap =layoutRowsGet.GetValue(1).GetMap();
650 DALI_TEST_CHECK( childMap->Find( "policy" )->Get<std::string>().compare("fixed") == 0 );
651 DALI_TEST_EQUALS( childMap->Find( "value" )->Get<float>(), 30.f, TEST_LOCATION );
653 childMap =layoutRowsGet.GetValue(3).GetMap();
654 DALI_TEST_CHECK( layoutRowsGet.GetKey(3).compare(layoutRows.GetKey(1)) == 0 );
655 DALI_TEST_CHECK( childMap->Find( "policy" )->Get<std::string>().compare("relative") == 0 );
656 DALI_TEST_EQUALS( childMap->Find( "value" )->Get<float>(), 0.2f, TEST_LOCATION );
658 // Test "layoutColumns" property
659 DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_LAYOUT_COLUMNS ) == TableView::Property::LAYOUT_COLUMNS );
664 * "2": { "policy": "relative", "value": 0.2 },
665 * "3": { "policy": "fixed", "value": 30 }
668 Property::Map layoutColumns;
669 layoutColumns[ "2" ] = item2;
670 layoutColumns[ "3" ] = item1;
671 tableView.SetProperty( TableView::Property::LAYOUT_COLUMNS, layoutColumns );
673 DALI_TEST_EQUALS( tableView.GetRelativeWidth( 2u ), 0.2f, TEST_LOCATION );
674 DALI_TEST_EQUALS( tableView.GetFixedWidth( 3u ), 30.f, TEST_LOCATION );
676 Property::Map layoutColumnsGet = tableView.GetProperty(TableView::Property::LAYOUT_COLUMNS).Get<Property::Map>();
677 DALI_TEST_CHECK( layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0 );
678 childMap =layoutColumnsGet.GetValue(2).GetMap();
679 DALI_TEST_CHECK( childMap->Find( "policy" )->Get<std::string>().compare("relative") == 0 );
680 DALI_TEST_EQUALS( childMap->Find( "value" )->Get<float>(), 0.2f, TEST_LOCATION );
681 childMap =layoutColumnsGet.GetValue(3).GetMap();
682 DALI_TEST_CHECK( layoutColumnsGet.GetKey(3).compare(layoutColumns.GetKey(1)) == 0 );
683 DALI_TEST_CHECK( childMap->Find( "policy" )->Get<std::string>().compare("fixed") == 0 );
684 DALI_TEST_EQUALS( childMap->Find( "value" )->Get<float>(),30.f, TEST_LOCATION );
689 int UtcDaliTableViewChildProperties(void)
691 ToolkitTestApplication application;
692 tet_infoline("UtcDaliTableViewChildProperties");
694 // Create a 10x10 table-view
695 TableView tableView = TableView::New(10,10);
696 Stage::GetCurrent().Add( tableView );
697 tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );
699 DALI_TEST_CHECK( tableView );
701 // Create a child actor with the custom properties
702 Actor child1 = Actor::New();
703 child1.SetProperty( TableView::ChildProperty::CELL_INDEX, Vector2( 3, 4 ) );
704 tableView.Add( child1 );
705 // Check for actors at actual positions.
706 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1);
708 // Create a second child actor with the custom properties
709 Actor child2 = Actor::New();
711 float columnSpan = 2.f;
712 child2.SetProperty( TableView::ChildProperty::CELL_INDEX, Vector2( 6, 1 ) );
713 child2.SetProperty( TableView::ChildProperty::ROW_SPAN, rowSpan );
714 child2.SetProperty( TableView::ChildProperty::COLUMN_SPAN, columnSpan );
715 tableView.Add( child2 );
716 // Check for actors at actual positions.
717 for( int i=0; i<rowSpan; i++ )
719 for(int j=0; j<columnSpan; j++)
721 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(6+i,1+j)) == child2);
725 // Create a third child actor with the cell alignment properties
726 Actor child3 = Actor::New();
727 child3.SetSize( 5.f,5.f );
728 child3.SetProperty( TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT, "center" );
729 child3.SetProperty( TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT, "bottom" );
730 tableView.Add( child3 );
732 // store the actor in the first available cell
733 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(0,0)) == child3)
734 application.SendNotification();
735 application.Render();
737 DALI_TEST_EQUALS( child3.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
738 DALI_TEST_EQUALS( child3.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
739 DALI_TEST_EQUALS( child3.GetCurrentPosition(), Vector3(2.5f, 5.0f, 0.0f), TEST_LOCATION );
744 int UtcDaliTableViewGetChildAtN(void)
746 ToolkitTestApplication application;
748 TableView tableView = TableView::New(10,10);
750 Actor actor = tableView.GetChildAt( TableView::CellPosition( 200, 200 ) );
751 DALI_TEST_CHECK( !actor );
756 int UtcDaliTableViewAddChildN(void)
758 ToolkitTestApplication application;
760 TableView tableView = TableView::New(10,10);
761 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
762 DALI_TEST_CHECK( ! tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
767 int UtcDaliTableViewInsertRowAtZero(void)
769 ToolkitTestApplication application;
771 TableView tableView = TableView::New(10,10);
772 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
773 tableView.InsertRow(0);
775 DALI_TEST_CHECK( tableView.GetRows() == 11 );
780 int UtcDaliTableViewDeleteRowAtZero(void)
782 ToolkitTestApplication application;
784 TableView tableView = TableView::New(10,10);
785 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
786 tableView.DeleteRow(0);
788 DALI_TEST_CHECK( tableView.GetRows() == 9 );
793 int UtcDaliTableViewInsertColumnAtZero(void)
795 ToolkitTestApplication application;
797 TableView tableView = TableView::New(10,10);
798 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
799 tableView.InsertColumn(0);
801 DALI_TEST_CHECK( tableView.GetColumns() == 11 );
806 int UtcDaliTableViewDeleteColumnAtZero(void)
808 ToolkitTestApplication application;
810 TableView tableView = TableView::New(10,10);
811 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
812 tableView.DeleteColumn(0);
814 DALI_TEST_CHECK( tableView.GetColumns() == 9 );
819 int UtcDaliTableViewTypeRegistry(void)
821 ToolkitTestApplication application;
823 TypeRegistry typeRegistry = TypeRegistry::Get();
824 DALI_TEST_CHECK( typeRegistry );
826 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "TableView" );
827 DALI_TEST_CHECK( typeInfo );
829 BaseHandle handle = typeInfo.CreateInstance();
830 DALI_TEST_CHECK( handle );
832 TableView view = TableView::DownCast( handle );
833 DALI_TEST_CHECK( view );
838 int UtcDaliTableViewKeyboardFocus(void)
840 ToolkitTestApplication application;
842 TableView tableView = TableView::New(4,4);
843 tableView.SetKeyboardFocusable( true );
844 tableView.SetName( "TableView");
846 for ( int row = 0; row < 4; ++row )
848 for ( int col = 0; col < 4; ++col )
850 Control control = Control::New();
851 std::ostringstream str;
852 str << row << "-" << col;
853 control.SetName( str.str() );
854 control.SetKeyboardFocusable( true );
855 tableView.AddChild( control, TableView::CellPosition( row, col ) );
859 Stage::GetCurrent().Add( tableView );
861 application.SendNotification();
862 application.Render();
864 Actor firstFocusActor = Toolkit::Internal::GetImplementation( tableView ).GetNextKeyboardFocusableActor( Actor(), Control::KeyboardFocus::RIGHT, true );
865 DALI_TEST_CHECK( firstFocusActor );
866 DALI_TEST_CHECK( firstFocusActor.GetName() == "0-0" );
868 KeyboardFocusManager manager = KeyboardFocusManager::Get();
869 manager.SetFocusGroupLoop( true );
870 manager.SetCurrentFocusActor( firstFocusActor );
872 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
873 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
874 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
875 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
876 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
877 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
878 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
879 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
880 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-0" );
882 manager.MoveFocus( Control::KeyboardFocus::LEFT );
883 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
884 manager.MoveFocus( Control::KeyboardFocus::LEFT );
885 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
886 manager.MoveFocus( Control::KeyboardFocus::LEFT );
887 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
888 manager.MoveFocus( Control::KeyboardFocus::LEFT );
889 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
890 manager.MoveFocus( Control::KeyboardFocus::LEFT );
891 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-3" );
893 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
894 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
895 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
896 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
898 manager.MoveFocus( Control::KeyboardFocus::DOWN );
899 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
900 manager.MoveFocus( Control::KeyboardFocus::DOWN );
901 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
902 manager.MoveFocus( Control::KeyboardFocus::DOWN );
903 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
904 manager.MoveFocus( Control::KeyboardFocus::DOWN );
905 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
907 manager.MoveFocus( Control::KeyboardFocus::UP );
908 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
909 manager.MoveFocus( Control::KeyboardFocus::UP );
910 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
911 manager.MoveFocus( Control::KeyboardFocus::UP );
912 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
913 manager.MoveFocus( Control::KeyboardFocus::UP );
914 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );