6d7b2bf517562d8b9e5650144ab2696204b3474a
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TableView.cpp
1 /*
2  * Copyright (c) 2014 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 #include <iostream>
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
23
24 using namespace Dali;
25 using namespace Toolkit;
26
27 void dali_tableview_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_tableview_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
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
46 static bool gObjectCreatedCallBackCalled;
47
48 static void TestCallback(BaseHandle handle)
49 {
50   gObjectCreatedCallBackCalled = true;
51 }
52
53 struct Constraint100
54 {
55   Constraint100( )
56   {
57   }
58
59   /**
60    * function operator to apply the parent size
61    */
62   void operator()( Dali::Vector3& current, const PropertyInputContainer& /* inputs */ )
63   {
64     current.x = current.y = current.z = 100.0f;
65   }
66 };
67
68 // Convenience function to quickly set up a 10x10 table with each cell being 10x10 pixels in size by default.
69 static void SetupTableViewAndActors(TableView& tableView, Actor& actor1, Actor& actor2, Actor& actor3)
70 {
71   tableView = TableView::New( 10, 10 ); // 10 by 10 grid.
72   DALI_TEST_CHECK( tableView );
73
74   Stage::GetCurrent().Add( tableView );
75   tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );
76
77   actor1 = Actor::New();
78   actor2 = Actor::New();
79   actor3 = Actor::New();
80
81   actor1.SetSize( Dali::Vector2( 10, 10 ) );
82   actor2.SetSize( Dali::Vector2( 10, 10 ) );
83   actor3.SetSize( Dali::Vector2( 10, 10 ) );
84
85   tableView.AddChild( actor1, TableView::CellPosition( 0, 0 ) );
86   tableView.AddChild( actor2, TableView::CellPosition( 0, 1 ) );
87   tableView.AddChild( actor3, TableView::CellPosition( 1, 0 ) );
88 }
89
90 } // namespace
91
92 int UtcDaliTableViewNew(void)
93 {
94   ToolkitTestApplication application;
95
96   TableView tableView = TableView::New(10,10);
97   DALI_TEST_CHECK(tableView);
98
99   //Additional check to ensure object is created by checking if it's registered
100   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
101   DALI_TEST_CHECK( registry );
102
103   gObjectCreatedCallBackCalled = false;
104   registry.ObjectCreatedSignal().Connect(&TestCallback);
105   {
106     TableView tableView = TableView::New(10,10);
107   }
108   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
109   END_TEST;
110 }
111
112 // Test adjusting the metric values for the cell.
113 int UtcDaliTableViewMetricsPadding(void)
114 {
115   ToolkitTestApplication application;
116
117   tet_infoline("UtcDaliTableViewMetricsPadding");
118
119   TableView tableView;
120   Actor actor1;
121   Actor actor2;
122   Actor actor3;
123
124   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
125
126   // 1. check that padding works. no padding:
127   tableView.SetCellPadding(Size(0.0f, 0.0f));
128   application.SendNotification();
129   application.Render();
130
131   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(0.0f, 0.0f), TEST_LOCATION );
132   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
133   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
134   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
135
136   // 1. check that padding works. some padding:
137   tableView.SetCellPadding(Size(5.0f, 10.0f));
138   application.SendNotification();
139   application.Render();
140
141   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(5.0f, 10.0f), TEST_LOCATION );
142   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(5.0f, 10.0f, 0.0f), TEST_LOCATION );
143   END_TEST;
144 }
145
146 // Test adjusting the metric values for the cell.
147 int UtcDaliTableViewMetricsFixed(void)
148 {
149   ToolkitTestApplication application;
150
151   tet_infoline("UtcDaliTableViewMetricsFixed");
152
153   TableView tableView;
154   Actor actor1;
155   Actor actor2;
156   Actor actor3;
157
158   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
159   application.SendNotification();
160   application.Render();
161
162   // 1. check that with no fixed width/heights, actors are in default position.
163   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
164   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
165   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
166
167   // 2. check that with a fixed width & height, actors to the right and below are offsetted.
168   tableView.SetFixedWidth(0, 20.0f);
169   tableView.SetFixedHeight(0, 50.0f);
170   DALI_TEST_EQUALS( tableView.GetFixedWidth(0), 20.0f, TEST_LOCATION );
171   DALI_TEST_EQUALS( tableView.GetFixedHeight(0), 50.0f, TEST_LOCATION );
172
173   application.SendNotification();
174   application.Render();
175
176   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
177   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(20.0f, 0.0f, 0.0f), TEST_LOCATION );
178   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
179   END_TEST;
180 }
181
182 // Test adjusting the metric values for the cell.
183 int UtcDaliTableViewMetricsRelative(void)
184 {
185   ToolkitTestApplication application;
186
187   tet_infoline("UtcDaliTableViewMetricsRelative");
188
189   TableView tableView;
190   Actor actor1;
191   Actor actor2;
192   Actor actor3;
193
194   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
195   application.SendNotification();
196   application.Render();
197
198   // 1. check that with no relative width/heights, actors are in default position.
199   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
200   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
201   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
202
203   // 2. check that with a relative width & height, actors to the right and below are offsetted.
204   tableView.SetRelativeWidth(0, 0.3f); // cell 0,0 occupies 30%x50% of the grid (i.e. 30x50 pixels)
205   tableView.SetRelativeHeight(0, 0.5f);
206   DALI_TEST_EQUALS( tableView.GetRelativeWidth(0), 0.3f, TEST_LOCATION );
207   DALI_TEST_EQUALS( tableView.GetRelativeHeight(0), 0.5f, TEST_LOCATION );
208
209   application.SendNotification();
210   application.Render();
211
212   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
213   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(30.0f, 0.0f, 0.0f), TEST_LOCATION );
214   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
215   END_TEST;
216 }
217
218
219 // Test Adding/Removing/Finding Children.
220 int UtcDaliTableViewChild(void)
221 {
222   ToolkitTestApplication application;
223
224   tet_infoline("UtcDaliTableViewChild");
225
226   // Create a 10x10 table-view
227   TableView tableView = TableView::New(10,10);
228   DALI_TEST_CHECK( tableView );
229
230   // Check if actor doesn't exist.
231   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
232
233   // Add an actor to it at 0,0
234   Actor actor = Actor::New();
235   tableView.AddChild(actor, TableView::CellPosition());
236
237   // Check if exists.
238   DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(0,0)) );
239
240   // Remove this actor
241   tableView.RemoveChildAt(TableView::CellPosition());
242
243   // Check if actor no longer exists.
244   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
245
246   // Add actor to it again, but at 2,5
247   tableView.AddChild(actor, TableView::CellPosition(2,5));
248
249   // Add another actor somewhere else 7,8
250   Actor actor2 = Actor::New();
251   tableView.AddChild(actor2, TableView::CellPosition(7,8));
252
253   Actor searchActor;
254
255   // Check that no actor exists in a few random places.
256   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
257   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(2,1)) );
258   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(6,3)) );
259   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(9,5)) );
260
261   // Check for actors at actual positions.
262   searchActor = tableView.GetChildAt(TableView::CellPosition(2,5));
263   DALI_TEST_CHECK( searchActor == actor);
264
265   searchActor = tableView.GetChildAt(TableView::CellPosition(7,8));
266   DALI_TEST_CHECK( searchActor == actor2);
267
268   // Create a second table, and add already added Child to new one.
269   TableView tableView2 = TableView::New(5,5);
270   tableView2.AddChild(actor, TableView::CellPosition(2,2));
271   DALI_TEST_CHECK( tableView2.GetChildAt(TableView::CellPosition(2,2)) );
272   END_TEST;
273 }
274
275 // Test calling Add on it's own (to invoke the OnChildAdd)
276 int UtcDaliTableViewAdd(void)
277 {
278   ToolkitTestApplication application;
279
280   tet_infoline("UtcDaliTableViewAdd");
281
282   // Create a 4x1 table-view, and just keep adding.
283   TableView tableView = TableView::New(1,4);
284   DALI_TEST_CHECK( tableView );
285
286   for(unsigned int i = 0;i<16;i++)
287   {
288     Actor currentActor = Actor::New();
289     TableView::CellPosition position = TableView::CellPosition();
290     tableView.Add( currentActor );
291     tableView.FindChildPosition(currentActor, position);
292     tet_printf("%dx%d (%d,%d)\n", tableView.GetColumns(), tableView.GetRows(), position.columnIndex, position.rowIndex);
293
294     DALI_TEST_EQUALS((position.rowIndex * 4 + position.columnIndex), i, TEST_LOCATION);
295   }
296   END_TEST;
297 }
298
299 // Test cell modification.
300 int UtcDaliTableViewCells(void)
301 {
302   ToolkitTestApplication application;
303   tet_infoline("UtcDaliTableViewCells");
304
305   // Create a 10x10 table-view
306   TableView tableView = TableView::New(10,10);
307   DALI_TEST_CHECK( tableView );
308
309   // Add a few actors to the table.
310   Actor actor1 = Actor::New();
311   Actor actor2 = Actor::New();
312   Actor actor3 = Actor::New();
313   actor1.SetName("Actor1");
314   actor2.SetName("Actor2");
315   actor3.SetName("Actor3");
316
317   // note: positions are specified in reversed cartesian coords - row,col (i.e. y,x)
318   tableView.AddChild(actor1, TableView::CellPosition(0,0));
319   tableView.AddChild(actor2, TableView::CellPosition(5,5));
320   tableView.AddChild(actor3, TableView::CellPosition(7,2));
321
322   DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
323
324   // Add a row between actor1 and actor2 | insert column on actor1 and see what happens...
325   tableView.InsertRow(3);
326   tableView.InsertColumn(0);
327   DALI_TEST_CHECK( tableView.GetRows() == 11 && tableView.GetColumns() == 11 );
328
329   TableView::CellPosition cellPosition;
330   bool result;
331
332   result = tableView.FindChildPosition(actor1, cellPosition);
333   DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
334   result = tableView.FindChildPosition(actor2, cellPosition);
335   DALI_TEST_CHECK( result && cellPosition.rowIndex == 6 && cellPosition.columnIndex == 6);
336   result = tableView.FindChildPosition(actor3, cellPosition);
337   DALI_TEST_CHECK( result && cellPosition.rowIndex == 8 && cellPosition.columnIndex == 3);
338
339   // Delete a row between actor2 and actor3 | delete column on actor2 and see what happens...
340   tableView.DeleteRow(7);
341   tableView.DeleteColumn(6);
342   DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
343
344   result = tableView.FindChildPosition(actor1, cellPosition);
345   DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
346   result = tableView.FindChildPosition(actor2, cellPosition);
347   DALI_TEST_CHECK( !result );
348   result = tableView.FindChildPosition(actor3, cellPosition);
349   DALI_TEST_CHECK( result && cellPosition.rowIndex == 7 && cellPosition.columnIndex == 3);
350
351   // Delete the other two remaining actors by a row delete and a column delete.
352   std::vector<Actor> actorsRemoved;
353   tableView.DeleteRow(0, actorsRemoved);
354   tet_printf("Row Delete >> Actors Removed: %d {", actorsRemoved.size());
355   for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
356   tet_printf("}\n");
357   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
358   DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
359
360   actorsRemoved.clear();
361   tableView.DeleteColumn(3, actorsRemoved);
362   tet_printf("Column Delete >> Actors Removed: %d {", actorsRemoved.size());
363   for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
364   tet_printf("}\n");
365   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
366   DALI_TEST_CHECK( actorsRemoved[0] == actor3 );
367
368   DALI_TEST_CHECK( tableView.GetRows() == 9 && tableView.GetColumns() == 9 );
369
370   tableView.AddChild(actor1, TableView::CellPosition(5,8));
371   tableView.Resize(100,100);
372   DALI_TEST_CHECK( tableView.GetRows() == 100 && tableView.GetColumns() == 100 );
373
374   tableView.AddChild(actor2, TableView::CellPosition(69,57));
375   DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && tableView.FindChildPosition(actor2, cellPosition) );
376
377   tableView.Resize(20,20);
378   DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
379
380   actorsRemoved.clear();
381   tableView.Resize(1,1, actorsRemoved);
382   DALI_TEST_CHECK( !tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
383   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
384   DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
385
386   // Add child outside table size, forcing a resize.
387   tableView.AddChild(actor1, TableView::CellPosition(100, 100, 1, 1));
388   DALI_TEST_CHECK( tableView.GetRows() == 101 && tableView.GetColumns() == 101 );
389
390   // Add child outside table size, forcing a resize.
391   tableView.AddChild(actor1, TableView::CellPosition(110, 110, 5, 5));
392   DALI_TEST_CHECK( tableView.GetRows() == 115 && tableView.GetColumns() == 115 );
393
394   DALI_TEST_CHECK( true );
395   END_TEST;
396 }
397
398 int UtcDaliTableViewChildAssert(void)
399 {
400   ToolkitTestApplication application;
401   tet_infoline("UtcDaliTableViewChildAssert");
402
403   // Create a 10x10 table-view
404   TableView tableView = TableView::New(10,10);
405   DALI_TEST_CHECK( tableView );
406   Actor childActor;
407
408   try
409   {
410     tableView.AddChild( childActor, TableView::CellPosition(0,0,5,5) );
411     // should assert
412     tet_result(TET_FAIL);
413   }
414   catch( Dali::DaliException& e )
415   {
416     DALI_TEST_PRINT_ASSERT( e );
417     DALI_TEST_EQUALS(e.condition, "child", TEST_LOCATION);
418   }
419   END_TEST;
420 }
421
422 int UtcDaliTableViewMetricsAssert(void)
423 {
424   ToolkitTestApplication application;
425   tet_infoline("UtcDaliTableViewChildAssert");
426
427   // Create a 10x10 table-view
428   TableView tableView = TableView::New(10,10);
429   DALI_TEST_CHECK( tableView );
430
431   // fixeds...
432
433   try
434   {
435     tableView.SetFixedHeight( 10, 1.0f );
436
437     tet_result(TET_FAIL);
438   }
439   catch( Dali::DaliException& e )
440   {
441     DALI_TEST_PRINT_ASSERT( e );
442     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
443   }
444
445   try
446   {
447     tableView.GetFixedHeight( 10 );
448
449     tet_result(TET_FAIL);
450   }
451   catch( Dali::DaliException& e )
452   {
453     DALI_TEST_PRINT_ASSERT( e );
454     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
455   }
456
457   try
458   {
459     tableView.SetFixedWidth( 10, 1.0f );
460
461     tet_result(TET_FAIL);
462   }
463   catch( Dali::DaliException& e )
464   {
465     DALI_TEST_PRINT_ASSERT( e );
466     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
467   }
468
469   try
470   {
471     tableView.GetFixedWidth( 10 );
472
473     tet_result(TET_FAIL);
474   }
475   catch( Dali::DaliException& e )
476   {
477     DALI_TEST_PRINT_ASSERT( e );
478     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
479   }
480
481   // relatives...
482
483   try
484   {
485     tableView.SetRelativeHeight( 10, 0.1f );
486
487     tet_result(TET_FAIL);
488   }
489   catch( Dali::DaliException& e )
490   {
491     DALI_TEST_PRINT_ASSERT( e );
492     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
493   }
494
495   try
496   {
497     tableView.GetRelativeHeight( 10 );
498
499     tet_result(TET_FAIL);
500   }
501   catch( Dali::DaliException& e )
502   {
503     DALI_TEST_PRINT_ASSERT( e );
504     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
505   }
506
507   try
508   {
509     tableView.SetRelativeWidth( 10, 0.1f );
510
511     tet_result(TET_FAIL);
512   }
513   catch( Dali::DaliException& e )
514   {
515     DALI_TEST_PRINT_ASSERT( e );
516     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
517   }
518
519   try
520   {
521     tableView.GetRelativeWidth( 10 );
522
523     tet_result(TET_FAIL);
524   }
525   catch( Dali::DaliException& e )
526   {
527     DALI_TEST_PRINT_ASSERT( e );
528     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
529   }
530   END_TEST;
531 }
532
533 int UtcDaliTableViewSetGetProperty(void)
534 {
535   ToolkitTestApplication application;
536   tet_infoline("UtcDaliTableViewSetGetProperty");
537
538   // Create a 1x1 table-view
539   TableView tableView = TableView::New(1,1);
540   tableView.SetSize( Vector2( 100.0f, 100.0f ) );
541   DALI_TEST_CHECK( tableView );
542
543   // Test "rows" property
544   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_ROWS ) == TableView::Property::ROWS );
545
546   tableView.SetProperty( TableView::Property::ROWS, 4u );
547
548   DALI_TEST_CHECK( tableView.GetRows() == 4u );
549   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::ROWS).Get<unsigned int>() == 4u );
550
551   // Test "columns" property
552   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::Property::COLUMNS );
553
554   tableView.SetProperty( TableView::Property::COLUMNS, 5u );
555
556   DALI_TEST_CHECK( tableView.GetColumns() == 5u );
557   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::COLUMNS).Get<unsigned int>() == 5u );
558
559   // Test "cell-padding" property
560   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_CELL_PADDING ) == TableView::Property::CELL_PADDING );
561
562   tableView.SetProperty( TableView::Property::CELL_PADDING, Size( 6.f, 8.f ) );
563
564   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(6.f, 8.f), TEST_LOCATION );
565   DALI_TEST_EQUALS( tableView.GetProperty(TableView::Property::CELL_PADDING).Get<Vector2>(), Vector2(6.f,8.f), TEST_LOCATION );
566
567   //{ "policy": "fixed", "value": 30.0 },
568   Property::Map item1;
569   item1[ "policy" ] = "fixed";
570   item1[ "value" ] = 30.f;
571   //{ "policy": "relative", "value": 0.2 },
572   Property::Map item2;
573   item2[ "policy" ] = "relative";
574   item2[ "value" ] = 0.2f;
575
576   // Test "layout-rows" property
577   DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::Property::LAYOUT_ROWS );
578
579   /*
580    * "layout-rows":
581    *  {
582    *    "1": { "policy": "fixed", "value": 30 },
583    *    "3": { "policy": "relative", "value": 0.2 }
584    *   }
585    */
586   Property::Map layoutRows;
587   layoutRows[ "1" ] = item1;
588   layoutRows[ "3" ] = item2;
589   tableView.SetProperty( TableView::Property::LAYOUT_ROWS, layoutRows );
590
591   DALI_TEST_EQUALS( tableView.GetFixedHeight( 1u ), 30.f, TEST_LOCATION );
592   DALI_TEST_EQUALS( tableView.GetRelativeHeight( 3u ), 0.2f, TEST_LOCATION );
593
594   Property::Map layoutRowsGet = tableView.GetProperty(TableView::Property::LAYOUT_ROWS).Get<Property::Map>();
595
596   DALI_TEST_EQUALS( layoutRowsGet.GetKey(1).compare(layoutRows.GetKey(0)), 0, TEST_LOCATION );
597   DALI_TEST_CHECK( layoutRowsGet.GetValue(1).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
598   DALI_TEST_EQUALS( layoutRowsGet.GetValue(1).GetValue( "value" ).Get<float>(), layoutRows.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
599
600   DALI_TEST_CHECK( layoutRowsGet.GetKey(3).compare(layoutRows.GetKey(1)) == 0 );
601   DALI_TEST_CHECK( layoutRowsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
602   DALI_TEST_EQUALS( layoutRowsGet.GetValue(3).GetValue( "value" ).Get<float>(), layoutRows.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
603
604   // Test "layout-columns" property
605   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_LAYOUT_COLUMNS ) == TableView::Property::LAYOUT_COLUMNS );
606
607   /*
608    * "layout-columns":
609    *  {
610    *    "2": { "policy": "relative", "value": 0.2 },
611    *    "3": { "policy": "fixed", "value": 30 }
612    *   }
613    */
614   Property::Map layoutColumns;
615   layoutColumns[ "2" ] = item2;
616   layoutColumns[ "3" ] = item1;
617   tableView.SetProperty( TableView::Property::LAYOUT_COLUMNS, layoutColumns );
618
619   DALI_TEST_EQUALS( tableView.GetRelativeWidth( 2u ), 0.2f, TEST_LOCATION );
620   DALI_TEST_EQUALS( tableView.GetFixedWidth( 3u ), 30.f, TEST_LOCATION );
621
622   Property::Map layoutColumnsGet = tableView.GetProperty(TableView::Property::LAYOUT_COLUMNS).Get<Property::Map>();
623   DALI_TEST_CHECK( layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0 );
624   DALI_TEST_CHECK( layoutColumnsGet.GetValue(2).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
625   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(2).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
626
627   DALI_TEST_CHECK( layoutColumnsGet.GetKey(3).compare(layoutColumns.GetKey(1)) == 0 );
628   DALI_TEST_CHECK( layoutColumnsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
629   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(3).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
630
631   END_TEST;
632 }
633
634 int UtcDaliTableViewCustomProperties(void)
635 {
636   ToolkitTestApplication application;
637   tet_infoline("UtcDaliTableViewCustomProperties");
638
639   // Create a 10x10 table-view
640   TableView tableView = TableView::New(10,10);
641   Constraint constraint = Constraint::New<Vector3>( tableView, Actor::Property::SIZE, Constraint100() );
642   constraint.Apply();
643   DALI_TEST_CHECK( tableView );
644
645   // Create a child actor with the custom properties
646   Actor child1 = Actor::New();
647   child1.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 3, 4 ) );
648   tableView.Add( child1 );
649   // Check for actors at actual positions.
650   DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1);
651
652   // Create a second child actor with the custom properties
653   Actor child2 = Actor::New();
654   float rowSpan = 3.f;
655   float columnSpan = 2.f;
656   child2.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 6, 1 ) );
657   child2.RegisterProperty( TableView::ROW_SPAN_PROPERTY_NAME, rowSpan );
658   child2.RegisterProperty( TableView::COLUMN_SPAN_PROPERTY_NAME, columnSpan );
659   tableView.Add( child2 );
660   // Check for actors at actual positions.
661   for( int i=0; i<rowSpan; i++ )
662   {
663     for(int j=0; j<columnSpan; j++)
664     {
665       DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(6+i,1+j)) == child2);
666     }
667   }
668
669   END_TEST;
670 }