30f0cda82ee9965de2d258bc652178905de43130
[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   DALI_TEST_CHECK( true );
442   END_TEST;
443 }
444
445 int UtcDaliTableViewChildAssert(void)
446 {
447   ToolkitTestApplication application;
448   tet_infoline("UtcDaliTableViewChildAssert");
449
450   // Create a 10x10 table-view
451   TableView tableView = TableView::New(10,10);
452   DALI_TEST_CHECK( tableView );
453   Actor childActor;
454
455   try
456   {
457     tableView.AddChild( childActor, TableView::CellPosition(0,0,5,5) );
458     // should assert
459     tet_result(TET_FAIL);
460   }
461   catch( Dali::DaliException& e )
462   {
463     DALI_TEST_PRINT_ASSERT( e );
464     DALI_TEST_EQUALS(e.condition, "child", TEST_LOCATION);
465   }
466   END_TEST;
467 }
468
469 int UtcDaliTableViewMetricsAssert(void)
470 {
471   ToolkitTestApplication application;
472   tet_infoline("UtcDaliTableViewChildAssert");
473
474   // Create a 10x10 table-view
475   TableView tableView = TableView::New(10,10);
476   DALI_TEST_CHECK( tableView );
477
478   // fixeds...
479
480   try
481   {
482     tableView.SetFixedHeight( 10, 1.0f );
483
484     tet_result(TET_FAIL);
485   }
486   catch( Dali::DaliException& e )
487   {
488     DALI_TEST_PRINT_ASSERT( e );
489     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
490   }
491
492   try
493   {
494     tableView.GetFixedHeight( 10 );
495
496     tet_result(TET_FAIL);
497   }
498   catch( Dali::DaliException& e )
499   {
500     DALI_TEST_PRINT_ASSERT( e );
501     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
502   }
503
504   try
505   {
506     tableView.SetFixedWidth( 10, 1.0f );
507
508     tet_result(TET_FAIL);
509   }
510   catch( Dali::DaliException& e )
511   {
512     DALI_TEST_PRINT_ASSERT( e );
513     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
514   }
515
516   try
517   {
518     tableView.GetFixedWidth( 10 );
519
520     tet_result(TET_FAIL);
521   }
522   catch( Dali::DaliException& e )
523   {
524     DALI_TEST_PRINT_ASSERT( e );
525     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
526   }
527
528   // relatives...
529
530   try
531   {
532     tableView.SetRelativeHeight( 10, 0.1f );
533
534     tet_result(TET_FAIL);
535   }
536   catch( Dali::DaliException& e )
537   {
538     DALI_TEST_PRINT_ASSERT( e );
539     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
540   }
541
542   try
543   {
544     tableView.GetRelativeHeight( 10 );
545
546     tet_result(TET_FAIL);
547   }
548   catch( Dali::DaliException& e )
549   {
550     DALI_TEST_PRINT_ASSERT( e );
551     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
552   }
553
554   try
555   {
556     tableView.SetRelativeWidth( 10, 0.1f );
557
558     tet_result(TET_FAIL);
559   }
560   catch( Dali::DaliException& e )
561   {
562     DALI_TEST_PRINT_ASSERT( e );
563     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
564   }
565
566   try
567   {
568     tableView.GetRelativeWidth( 10 );
569
570     tet_result(TET_FAIL);
571   }
572   catch( Dali::DaliException& e )
573   {
574     DALI_TEST_PRINT_ASSERT( e );
575     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
576   }
577   END_TEST;
578 }
579
580 int UtcDaliTableViewSetGetProperty(void)
581 {
582   ToolkitTestApplication application;
583   tet_infoline("UtcDaliTableViewSetGetProperty");
584
585   // Create a 1x1 table-view
586   TableView tableView = TableView::New(1,1);
587   tableView.SetSize( Vector2( 100.0f, 100.0f ) );
588   DALI_TEST_CHECK( tableView );
589
590   // Test "rows" property
591   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_ROWS ) == TableView::Property::ROWS );
592
593   tableView.SetProperty( TableView::Property::ROWS, 4u );
594
595   DALI_TEST_CHECK( tableView.GetRows() == 4u );
596   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::ROWS).Get<unsigned int>() == 4u );
597
598   // Test "columns" property
599   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::Property::COLUMNS );
600
601   tableView.SetProperty( TableView::Property::COLUMNS, 5u );
602
603   DALI_TEST_CHECK( tableView.GetColumns() == 5u );
604   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::COLUMNS).Get<unsigned int>() == 5u );
605
606   // Test "cell-padding" property
607   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_CELL_PADDING ) == TableView::Property::CELL_PADDING );
608
609   tableView.SetProperty( TableView::Property::CELL_PADDING, Size( 6.f, 8.f ) );
610
611   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(6.f, 8.f), TEST_LOCATION );
612   DALI_TEST_EQUALS( tableView.GetProperty(TableView::Property::CELL_PADDING).Get<Vector2>(), Vector2(6.f,8.f), TEST_LOCATION );
613
614   //{ "policy": "fixed", "value": 30.0 },
615   Property::Map item1;
616   item1[ "policy" ] = "fixed";
617   item1[ "value" ] = 30.f;
618   //{ "policy": "relative", "value": 0.2 },
619   Property::Map item2;
620   item2[ "policy" ] = "relative";
621   item2[ "value" ] = 0.2f;
622
623   // Test "layout-rows" property
624   DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::Property::LAYOUT_ROWS );
625
626   /*
627    * "layout-rows":
628    *  {
629    *    "1": { "policy": "fixed", "value": 30 },
630    *    "3": { "policy": "relative", "value": 0.2 }
631    *   }
632    */
633   Property::Map layoutRows;
634   layoutRows[ "1" ] = item1;
635   layoutRows[ "3" ] = item2;
636   tableView.SetProperty( TableView::Property::LAYOUT_ROWS, layoutRows );
637
638   DALI_TEST_EQUALS( tableView.GetFixedHeight( 1u ), 30.f, TEST_LOCATION );
639   DALI_TEST_EQUALS( tableView.GetRelativeHeight( 3u ), 0.2f, TEST_LOCATION );
640
641   Property::Map layoutRowsGet = tableView.GetProperty(TableView::Property::LAYOUT_ROWS).Get<Property::Map>();
642
643   DALI_TEST_EQUALS( layoutRowsGet.GetKey(1).compare(layoutRows.GetKey(0)), 0, TEST_LOCATION );
644   DALI_TEST_CHECK( layoutRowsGet.GetValue(1).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
645   DALI_TEST_EQUALS( layoutRowsGet.GetValue(1).GetValue( "value" ).Get<float>(), layoutRows.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
646
647   DALI_TEST_CHECK( layoutRowsGet.GetKey(3).compare(layoutRows.GetKey(1)) == 0 );
648   DALI_TEST_CHECK( layoutRowsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
649   DALI_TEST_EQUALS( layoutRowsGet.GetValue(3).GetValue( "value" ).Get<float>(), layoutRows.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
650
651   // Test "layout-columns" property
652   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_LAYOUT_COLUMNS ) == TableView::Property::LAYOUT_COLUMNS );
653
654   /*
655    * "layout-columns":
656    *  {
657    *    "2": { "policy": "relative", "value": 0.2 },
658    *    "3": { "policy": "fixed", "value": 30 }
659    *   }
660    */
661   Property::Map layoutColumns;
662   layoutColumns[ "2" ] = item2;
663   layoutColumns[ "3" ] = item1;
664   tableView.SetProperty( TableView::Property::LAYOUT_COLUMNS, layoutColumns );
665
666   DALI_TEST_EQUALS( tableView.GetRelativeWidth( 2u ), 0.2f, TEST_LOCATION );
667   DALI_TEST_EQUALS( tableView.GetFixedWidth( 3u ), 30.f, TEST_LOCATION );
668
669   Property::Map layoutColumnsGet = tableView.GetProperty(TableView::Property::LAYOUT_COLUMNS).Get<Property::Map>();
670   DALI_TEST_CHECK( layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0 );
671   DALI_TEST_CHECK( layoutColumnsGet.GetValue(2).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
672   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(2).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
673
674   DALI_TEST_CHECK( layoutColumnsGet.GetKey(3).compare(layoutColumns.GetKey(1)) == 0 );
675   DALI_TEST_CHECK( layoutColumnsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
676   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(3).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
677
678   END_TEST;
679 }
680
681 int UtcDaliTableViewCustomProperties(void)
682 {
683   ToolkitTestApplication application;
684   tet_infoline("UtcDaliTableViewCustomProperties");
685
686   // Create a 10x10 table-view
687   TableView tableView = TableView::New(10,10);
688   Constraint constraint = Constraint::New<Vector3>( tableView, Actor::Property::SIZE, Constraint100() );
689   constraint.Apply();
690   DALI_TEST_CHECK( tableView );
691
692   // Create a child actor with the custom properties
693   Actor child1 = Actor::New();
694   child1.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 3, 4 ) );
695   tableView.Add( child1 );
696   // Check for actors at actual positions.
697   DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1);
698
699   // Create a second child actor with the custom properties
700   Actor child2 = Actor::New();
701   float rowSpan = 3.f;
702   float columnSpan = 2.f;
703   child2.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 6, 1 ) );
704   child2.RegisterProperty( TableView::ROW_SPAN_PROPERTY_NAME, rowSpan );
705   child2.RegisterProperty( TableView::COLUMN_SPAN_PROPERTY_NAME, columnSpan );
706   tableView.Add( child2 );
707   // Check for actors at actual positions.
708   for( int i=0; i<rowSpan; i++ )
709   {
710     for(int j=0; j<columnSpan; j++)
711     {
712       DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(6+i,1+j)) == child2);
713     }
714   }
715
716   END_TEST;
717 }