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