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