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