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 = "cell-padding";
43 const char* const PROPERTY_NAME_LAYOUT_ROWS = "layout-rows";
44 const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layout-columns";
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, 4u );
600 DALI_TEST_CHECK( tableView.GetRows() == 4u );
601 DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::ROWS).Get<unsigned int>() == 4u );
603 // Test "columns" property
604 DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::Property::COLUMNS );
606 tableView.SetProperty( TableView::Property::COLUMNS, 5u );
608 DALI_TEST_CHECK( tableView.GetColumns() == 5u );
609 DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::COLUMNS).Get<unsigned int>() == 5u );
611 // Test "cell-padding" 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 "layout-rows" 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 "layout-columns" 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 UtcDaliTableViewCustomProperties(void)
691 ToolkitTestApplication application;
692 tet_infoline("UtcDaliTableViewCustomProperties");
694 // Create a 10x10 table-view
695 TableView tableView = TableView::New(10,10);
696 Constraint constraint = Constraint::New<Vector3>( tableView, Actor::Property::SIZE, Constraint100() );
698 DALI_TEST_CHECK( tableView );
700 // Create a child actor with the custom properties
701 Actor child1 = Actor::New();
702 child1.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 3, 4 ) );
703 tableView.Add( child1 );
704 // Check for actors at actual positions.
705 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1);
707 // Create a second child actor with the custom properties
708 Actor child2 = Actor::New();
710 float columnSpan = 2.f;
711 child2.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 6, 1 ) );
712 child2.RegisterProperty( TableView::ROW_SPAN_PROPERTY_NAME, rowSpan );
713 child2.RegisterProperty( TableView::COLUMN_SPAN_PROPERTY_NAME, columnSpan );
714 tableView.Add( child2 );
715 // Check for actors at actual positions.
716 for( int i=0; i<rowSpan; i++ )
718 for(int j=0; j<columnSpan; j++)
720 DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(6+i,1+j)) == child2);
727 int UtcDaliTableViewGetChildAtN(void)
729 ToolkitTestApplication application;
731 TableView tableView = TableView::New(10,10);
733 Actor actor = tableView.GetChildAt( TableView::CellPosition( 200, 200 ) );
734 DALI_TEST_CHECK( !actor );
739 int UtcDaliTableViewAddChildN(void)
741 ToolkitTestApplication application;
743 TableView tableView = TableView::New(10,10);
744 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
745 DALI_TEST_CHECK( ! tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
750 int UtcDaliTableViewInsertRowAtZero(void)
752 ToolkitTestApplication application;
754 TableView tableView = TableView::New(10,10);
755 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
756 tableView.InsertRow(0);
758 DALI_TEST_CHECK( tableView.GetRows() == 11 );
763 int UtcDaliTableViewDeleteRowAtZero(void)
765 ToolkitTestApplication application;
767 TableView tableView = TableView::New(10,10);
768 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
769 tableView.DeleteRow(0);
771 DALI_TEST_CHECK( tableView.GetRows() == 9 );
776 int UtcDaliTableViewInsertColumnAtZero(void)
778 ToolkitTestApplication application;
780 TableView tableView = TableView::New(10,10);
781 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
782 tableView.InsertColumn(0);
784 DALI_TEST_CHECK( tableView.GetColumns() == 11 );
789 int UtcDaliTableViewDeleteColumnAtZero(void)
791 ToolkitTestApplication application;
793 TableView tableView = TableView::New(10,10);
794 DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
795 tableView.DeleteColumn(0);
797 DALI_TEST_CHECK( tableView.GetColumns() == 9 );
802 int UtcDaliTableViewTypeRegistry(void)
804 ToolkitTestApplication application;
806 TypeRegistry typeRegistry = TypeRegistry::Get();
807 DALI_TEST_CHECK( typeRegistry );
809 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "TableView" );
810 DALI_TEST_CHECK( typeInfo );
812 BaseHandle handle = typeInfo.CreateInstance();
813 DALI_TEST_CHECK( handle );
815 TableView view = TableView::DownCast( handle );
816 DALI_TEST_CHECK( view );
821 int UtcDaliTableViewKeyboardFocus(void)
823 ToolkitTestApplication application;
825 TableView tableView = TableView::New(4,4);
826 tableView.SetKeyboardFocusable( true );
827 tableView.SetName( "TableView");
829 for ( int row = 0; row < 4; ++row )
831 for ( int col = 0; col < 4; ++col )
833 Control control = Control::New();
834 std::ostringstream str;
835 str << row << "-" << col;
836 control.SetName( str.str() );
837 control.SetKeyboardFocusable( true );
838 tableView.AddChild( control, TableView::CellPosition( row, col ) );
842 Stage::GetCurrent().Add( tableView );
844 application.SendNotification();
845 application.Render();
847 Actor firstFocusActor = Toolkit::Internal::GetImplementation( tableView ).GetNextKeyboardFocusableActor( Actor(), Control::KeyboardFocus::RIGHT, true );
848 DALI_TEST_CHECK( firstFocusActor );
849 DALI_TEST_CHECK( firstFocusActor.GetName() == "0-0" );
851 KeyboardFocusManager manager = KeyboardFocusManager::Get();
852 manager.SetFocusGroupLoop( true );
853 manager.SetCurrentFocusActor( firstFocusActor );
855 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
856 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
857 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
858 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
859 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
860 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
861 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
862 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
863 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-0" );
865 manager.MoveFocus( Control::KeyboardFocus::LEFT );
866 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
867 manager.MoveFocus( Control::KeyboardFocus::LEFT );
868 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
869 manager.MoveFocus( Control::KeyboardFocus::LEFT );
870 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
871 manager.MoveFocus( Control::KeyboardFocus::LEFT );
872 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
873 manager.MoveFocus( Control::KeyboardFocus::LEFT );
874 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-3" );
876 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
877 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
878 manager.MoveFocus( Control::KeyboardFocus::RIGHT );
879 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
881 manager.MoveFocus( Control::KeyboardFocus::DOWN );
882 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
883 manager.MoveFocus( Control::KeyboardFocus::DOWN );
884 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
885 manager.MoveFocus( Control::KeyboardFocus::DOWN );
886 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
887 manager.MoveFocus( Control::KeyboardFocus::DOWN );
888 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
890 manager.MoveFocus( Control::KeyboardFocus::UP );
891 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
892 manager.MoveFocus( Control::KeyboardFocus::UP );
893 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
894 manager.MoveFocus( Control::KeyboardFocus::UP );
895 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
896 manager.MoveFocus( Control::KeyboardFocus::UP );
897 DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );