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