UTC added for Text, Multi-language.
[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 <sstream>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
24 using namespace Dali;
25 using namespace Toolkit;
26
27 void dali_tableview_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_tableview_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 const char* const PROPERTY_NAME_ROWS = "rows";
41 const char* const PROPERTY_NAME_COLUMNS = "columns";
42 const char* const PROPERTY_NAME_CELL_PADDING = "cell-padding";
43 const char* const PROPERTY_NAME_LAYOUT_ROWS = "layout-rows";
44 const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layout-columns";
45 const Vector2 CELL_SIZE( 10, 10 );
46
47 static bool gObjectCreatedCallBackCalled;
48
49 static void TestCallback(BaseHandle handle)
50 {
51   gObjectCreatedCallBackCalled = true;
52 }
53
54 struct Constraint100
55 {
56   Constraint100( )
57   {
58   }
59
60   /**
61    * function operator to apply the parent size
62    */
63   void operator()( Dali::Vector3& current, const PropertyInputContainer& /* inputs */ )
64   {
65     current.x = current.y = current.z = 100.0f;
66   }
67 };
68
69 // Convenience function to quickly set up a 10x10 table with each cell being 10x10 pixels in size by default.
70 static void SetupTableViewAndActors(TableView& tableView, Actor& actor1, Actor& actor2, Actor& actor3)
71 {
72   tableView = TableView::New( 10, 10 ); // 10 by 10 grid.
73   DALI_TEST_CHECK( tableView );
74
75   Stage::GetCurrent().Add( tableView );
76   tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );
77
78   actor1 = Actor::New();
79   actor2 = Actor::New();
80   actor3 = Actor::New();
81
82   actor1.SetSize( CELL_SIZE );
83   actor2.SetSize( CELL_SIZE );
84   actor3.SetSize( CELL_SIZE );
85
86   tableView.AddChild( actor1, TableView::CellPosition( 0, 0 ) );
87   tableView.AddChild( actor2, TableView::CellPosition( 0, 1 ) );
88   tableView.AddChild( actor3, TableView::CellPosition( 1, 0 ) );
89 }
90
91 } // namespace
92
93 int UtcDaliTableViewCtorCopyP(void)
94 {
95   TestApplication application;
96
97   TableView actor1 = TableView::New(10,10);
98   TableView actor2( actor1 );
99
100   DALI_TEST_EQUALS( actor1, actor2, TEST_LOCATION );
101   END_TEST;
102 }
103
104 int UtcDaliTableViewNew(void)
105 {
106   ToolkitTestApplication application;
107
108   TableView tableView = TableView::New(10,10);
109   DALI_TEST_CHECK(tableView);
110
111   //Additional check to ensure object is created by checking if it's registered
112   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
113   DALI_TEST_CHECK( registry );
114
115   gObjectCreatedCallBackCalled = false;
116   registry.ObjectCreatedSignal().Connect(&TestCallback);
117   {
118     TableView tableView = TableView::New(10,10);
119   }
120   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
121   END_TEST;
122 }
123
124 // Test adjusting the metric values for the cell.
125 int UtcDaliTableViewMetricsPadding(void)
126 {
127   ToolkitTestApplication application;
128
129   tet_infoline("UtcDaliTableViewMetricsPadding");
130
131   TableView tableView;
132   Actor actor1;
133   Actor actor2;
134   Actor actor3;
135
136   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
137
138   // 1. check that padding works. no padding:
139   tableView.SetCellPadding(Size(0.0f, 0.0f));
140   application.SendNotification();
141   application.Render();
142
143   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(0.0f, 0.0f), TEST_LOCATION );
144   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
145   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
146   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
147
148   // 1. check that padding works. some padding:
149   tableView.SetCellPadding(Size(5.0f, 10.0f));
150   application.SendNotification();
151   application.Render();
152
153   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(5.0f, 10.0f), TEST_LOCATION );
154   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(5.0f, 10.0f, 0.0f), TEST_LOCATION );
155   END_TEST;
156 }
157
158 // Test adjusting the metric values for the cell.
159 int UtcDaliTableViewMetricsFit(void)
160 {
161   ToolkitTestApplication application;
162
163   tet_infoline("UtcDaliTableViewMetricsFit");
164
165   TableView tableView;
166   Actor actor1;
167   Actor actor2;
168   Actor actor3;
169
170   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
171   application.SendNotification();
172   application.Render();
173
174   // 1. check that with no fixed width/heights, actors are in default position.
175   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
176   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
177   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
178
179   // 2. check that with a fixed width & height, actors to the right and below are offsetted.
180   tableView.SetFitHeight(0);
181   tableView.SetFitWidth(0);
182   DALI_TEST_EQUALS( tableView.IsFitHeight(0), true, TEST_LOCATION );
183   DALI_TEST_EQUALS( tableView.IsFitWidth(0), true, TEST_LOCATION );
184
185   application.SendNotification();
186   application.Render();
187
188   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
189   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
190   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
191   END_TEST;
192 }
193
194 // Test adjusting the metric values for the cell.
195 int UtcDaliTableViewMetricsFixed(void)
196 {
197   ToolkitTestApplication application;
198
199   tet_infoline("UtcDaliTableViewMetricsFixed");
200
201   TableView tableView;
202   Actor actor1;
203   Actor actor2;
204   Actor actor3;
205
206   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
207   application.SendNotification();
208   application.Render();
209
210   // 1. check that with no fixed width/heights, actors are in default position.
211   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
212   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
213   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
214
215   // 2. check that with a fixed width & height, actors to the right and below are offsetted.
216   tableView.SetFixedWidth(0, 20.0f);
217   tableView.SetFixedHeight(0, 50.0f);
218   DALI_TEST_EQUALS( tableView.GetFixedWidth(0), 20.0f, TEST_LOCATION );
219   DALI_TEST_EQUALS( tableView.GetFixedHeight(0), 50.0f, TEST_LOCATION );
220
221   application.SendNotification();
222   application.Render();
223
224   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
225   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(20.0f, 0.0f, 0.0f), TEST_LOCATION );
226   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
227   END_TEST;
228 }
229
230 // Test adjusting the metric values for the cell.
231 int UtcDaliTableViewMetricsRelative(void)
232 {
233   ToolkitTestApplication application;
234
235   tet_infoline("UtcDaliTableViewMetricsRelative");
236
237   TableView tableView;
238   Actor actor1;
239   Actor actor2;
240   Actor actor3;
241
242   SetupTableViewAndActors(tableView, actor1, actor2, actor3);
243   application.SendNotification();
244   application.Render();
245
246   // 1. check that with no relative width/heights, actors are in default position.
247   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
248   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
249   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
250
251   // 2. check that with a relative width & height, actors to the right and below are offsetted.
252   tableView.SetRelativeWidth(0, 0.3f); // cell 0,0 occupies 30%x50% of the grid (i.e. 30x50 pixels)
253   tableView.SetRelativeHeight(0, 0.5f);
254   DALI_TEST_EQUALS( tableView.GetRelativeWidth(0), 0.3f, TEST_LOCATION );
255   DALI_TEST_EQUALS( tableView.GetRelativeHeight(0), 0.5f, TEST_LOCATION );
256
257   application.SendNotification();
258   application.Render();
259
260   DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
261   DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(30.0f, 0.0f, 0.0f), TEST_LOCATION );
262   DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 50.0f, 0.0f), TEST_LOCATION );
263   END_TEST;
264 }
265
266
267 // Test Adding/Removing/Finding Children.
268 int UtcDaliTableViewChild(void)
269 {
270   ToolkitTestApplication application;
271
272   tet_infoline("UtcDaliTableViewChild");
273
274   // Create a 10x10 table-view
275   TableView tableView = TableView::New(10,10);
276   DALI_TEST_CHECK( tableView );
277
278   // Check if actor doesn't exist.
279   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
280
281   // Add an actor to it at 0,0
282   Actor actor = Actor::New();
283   tableView.AddChild(actor, TableView::CellPosition());
284
285   // Check if exists.
286   DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(0,0)) );
287
288   // Remove this actor
289   tableView.RemoveChildAt(TableView::CellPosition());
290
291   // Check if actor no longer exists.
292   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
293
294   // Add actor to it again, but at 2,5
295   tableView.AddChild(actor, TableView::CellPosition(2,5));
296
297   // Add another actor somewhere else 7,8
298   Actor actor2 = Actor::New();
299   tableView.AddChild(actor2, TableView::CellPosition(7,8));
300
301   Actor searchActor;
302
303   // Check that no actor exists in a few random places.
304   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(0,0)) );
305   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(2,1)) );
306   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(6,3)) );
307   DALI_TEST_CHECK( !tableView.GetChildAt(TableView::CellPosition(9,5)) );
308
309   // Check for actors at actual positions.
310   searchActor = tableView.GetChildAt(TableView::CellPosition(2,5));
311   DALI_TEST_CHECK( searchActor == actor);
312
313   searchActor = tableView.GetChildAt(TableView::CellPosition(7,8));
314   DALI_TEST_CHECK( searchActor == actor2);
315
316   // Create a second table, and add already added Child to new one.
317   TableView tableView2 = TableView::New(5,5);
318   tableView2.AddChild(actor, TableView::CellPosition(2,2));
319   DALI_TEST_CHECK( tableView2.GetChildAt(TableView::CellPosition(2,2)) );
320   END_TEST;
321 }
322
323 // Test calling Add on it's own (to invoke the OnChildAdd)
324 int UtcDaliTableViewAdd(void)
325 {
326   ToolkitTestApplication application;
327
328   tet_infoline("UtcDaliTableViewAdd");
329
330   // Create a 4x1 table-view, and just keep adding.
331   TableView tableView = TableView::New(1,4);
332   DALI_TEST_CHECK( tableView );
333
334   for(unsigned int i = 0;i<16;i++)
335   {
336     Actor currentActor = Actor::New();
337     TableView::CellPosition position = TableView::CellPosition();
338     tableView.Add( currentActor );
339     tableView.FindChildPosition(currentActor, position);
340     tet_printf("%dx%d (%d,%d)\n", tableView.GetColumns(), tableView.GetRows(), position.columnIndex, position.rowIndex);
341
342     DALI_TEST_EQUALS((position.rowIndex * 4 + position.columnIndex), i, TEST_LOCATION);
343   }
344   END_TEST;
345 }
346
347 // Test cell modification.
348 int UtcDaliTableViewCells(void)
349 {
350   ToolkitTestApplication application;
351   tet_infoline("UtcDaliTableViewCells");
352
353   // Create a 10x10 table-view
354   TableView tableView = TableView::New(10,10);
355   DALI_TEST_CHECK( tableView );
356
357   // Add a few actors to the table.
358   Actor actor1 = Actor::New();
359   Actor actor2 = Actor::New();
360   Actor actor3 = Actor::New();
361   actor1.SetName("Actor1");
362   actor2.SetName("Actor2");
363   actor3.SetName("Actor3");
364
365   // note: positions are specified in reversed cartesian coords - row,col (i.e. y,x)
366   tableView.AddChild(actor1, TableView::CellPosition(0,0));
367   tableView.AddChild(actor2, TableView::CellPosition(5,5));
368   tableView.AddChild(actor3, TableView::CellPosition(7,2));
369
370   DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
371
372   // Add a row between actor1 and actor2 | insert column on actor1 and see what happens...
373   tableView.InsertRow(3);
374   tableView.InsertColumn(0);
375   DALI_TEST_CHECK( tableView.GetRows() == 11 && tableView.GetColumns() == 11 );
376
377   TableView::CellPosition cellPosition;
378   bool result;
379
380   result = tableView.FindChildPosition(actor1, cellPosition);
381   DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
382   result = tableView.FindChildPosition(actor2, cellPosition);
383   DALI_TEST_CHECK( result && cellPosition.rowIndex == 6 && cellPosition.columnIndex == 6);
384   result = tableView.FindChildPosition(actor3, cellPosition);
385   DALI_TEST_CHECK( result && cellPosition.rowIndex == 8 && cellPosition.columnIndex == 3);
386
387   // Delete a row between actor2 and actor3 | delete column on actor2 and see what happens...
388   tableView.DeleteRow(7);
389   tableView.DeleteColumn(6);
390   DALI_TEST_CHECK( tableView.GetRows() == 10 && tableView.GetColumns() == 10 );
391
392   result = tableView.FindChildPosition(actor1, cellPosition);
393   DALI_TEST_CHECK( result && cellPosition.rowIndex == 0 && cellPosition.columnIndex == 1);
394   result = tableView.FindChildPosition(actor2, cellPosition);
395   DALI_TEST_CHECK( !result );
396   result = tableView.FindChildPosition(actor3, cellPosition);
397   DALI_TEST_CHECK( result && cellPosition.rowIndex == 7 && cellPosition.columnIndex == 3);
398
399   // Delete the other two remaining actors by a row delete and a column delete.
400   std::vector<Actor> actorsRemoved;
401   tableView.DeleteRow(0, actorsRemoved);
402   tet_printf("Row Delete >> Actors Removed: %d {", actorsRemoved.size());
403   for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
404   tet_printf("}\n");
405   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
406   DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
407
408   actorsRemoved.clear();
409   tableView.DeleteColumn(3, actorsRemoved);
410   tet_printf("Column Delete >> Actors Removed: %d {", actorsRemoved.size());
411   for(size_t i = 0;i<actorsRemoved.size();i++) tet_printf("%d => %s, ", i, actorsRemoved[i].GetName().c_str());
412   tet_printf("}\n");
413   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
414   DALI_TEST_CHECK( actorsRemoved[0] == actor3 );
415
416   DALI_TEST_CHECK( tableView.GetRows() == 9 && tableView.GetColumns() == 9 );
417
418   tableView.AddChild(actor1, TableView::CellPosition(5,8));
419   tableView.Resize(100,100);
420   DALI_TEST_CHECK( tableView.GetRows() == 100 && tableView.GetColumns() == 100 );
421
422   tableView.AddChild(actor2, TableView::CellPosition(69,57));
423   DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && tableView.FindChildPosition(actor2, cellPosition) );
424
425   tableView.Resize(20,20);
426   DALI_TEST_CHECK( tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
427
428   actorsRemoved.clear();
429   tableView.Resize(1,1, actorsRemoved);
430   DALI_TEST_CHECK( !tableView.FindChildPosition(actor1, cellPosition) && !tableView.FindChildPosition(actor2, cellPosition) );
431   DALI_TEST_EQUALS( static_cast<int>(actorsRemoved.size()), 1, TEST_LOCATION );
432   DALI_TEST_CHECK( actorsRemoved[0] == actor1 );
433
434   // Add child outside table size, forcing a resize.
435   tableView.AddChild(actor1, TableView::CellPosition(100, 100, 1, 1));
436   DALI_TEST_CHECK( tableView.GetRows() == 101 && tableView.GetColumns() == 101 );
437
438   // Add child outside table size, forcing a resize.
439   tableView.AddChild(actor1, TableView::CellPosition(110, 110, 5, 5));
440   DALI_TEST_CHECK( tableView.GetRows() == 115 && tableView.GetColumns() == 115 );
441
442   // Set the alignment of the cell
443   tableView.SetCellAlignment( TableView::CellPosition(100, 100, 1, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
444   tableView.SetCellAlignment( TableView::CellPosition(110, 110, 5, 5), HorizontalAlignment::LEFT, VerticalAlignment::TOP );
445
446   DALI_TEST_CHECK( true );
447   END_TEST;
448 }
449
450 int UtcDaliTableViewChildAssert(void)
451 {
452   ToolkitTestApplication application;
453   tet_infoline("UtcDaliTableViewChildAssert");
454
455   // Create a 10x10 table-view
456   TableView tableView = TableView::New(10,10);
457   DALI_TEST_CHECK( tableView );
458   Actor childActor;
459
460   try
461   {
462     tableView.AddChild( childActor, TableView::CellPosition(0,0,5,5) );
463     // should assert
464     tet_result(TET_FAIL);
465   }
466   catch( Dali::DaliException& e )
467   {
468     DALI_TEST_PRINT_ASSERT( e );
469     DALI_TEST_EQUALS(e.condition, "child", TEST_LOCATION);
470   }
471   END_TEST;
472 }
473
474 int UtcDaliTableViewMetricsAssert(void)
475 {
476   ToolkitTestApplication application;
477   tet_infoline("UtcDaliTableViewChildAssert");
478
479   // Create a 10x10 table-view
480   TableView tableView = TableView::New(10,10);
481   DALI_TEST_CHECK( tableView );
482
483   // fixeds...
484
485   try
486   {
487     tableView.SetFixedHeight( 10, 1.0f );
488
489     tet_result(TET_FAIL);
490   }
491   catch( Dali::DaliException& e )
492   {
493     DALI_TEST_PRINT_ASSERT( e );
494     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
495   }
496
497   try
498   {
499     tableView.GetFixedHeight( 10 );
500
501     tet_result(TET_FAIL);
502   }
503   catch( Dali::DaliException& e )
504   {
505     DALI_TEST_PRINT_ASSERT( e );
506     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
507   }
508
509   try
510   {
511     tableView.SetFixedWidth( 10, 1.0f );
512
513     tet_result(TET_FAIL);
514   }
515   catch( Dali::DaliException& e )
516   {
517     DALI_TEST_PRINT_ASSERT( e );
518     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
519   }
520
521   try
522   {
523     tableView.GetFixedWidth( 10 );
524
525     tet_result(TET_FAIL);
526   }
527   catch( Dali::DaliException& e )
528   {
529     DALI_TEST_PRINT_ASSERT( e );
530     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
531   }
532
533   // relatives...
534
535   try
536   {
537     tableView.SetRelativeHeight( 10, 0.1f );
538
539     tet_result(TET_FAIL);
540   }
541   catch( Dali::DaliException& e )
542   {
543     DALI_TEST_PRINT_ASSERT( e );
544     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
545   }
546
547   try
548   {
549     tableView.GetRelativeHeight( 10 );
550
551     tet_result(TET_FAIL);
552   }
553   catch( Dali::DaliException& e )
554   {
555     DALI_TEST_PRINT_ASSERT( e );
556     DALI_TEST_EQUALS(e.condition, "rowIndex < mRowData.Size()", TEST_LOCATION);
557   }
558
559   try
560   {
561     tableView.SetRelativeWidth( 10, 0.1f );
562
563     tet_result(TET_FAIL);
564   }
565   catch( Dali::DaliException& e )
566   {
567     DALI_TEST_PRINT_ASSERT( e );
568     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
569   }
570
571   try
572   {
573     tableView.GetRelativeWidth( 10 );
574
575     tet_result(TET_FAIL);
576   }
577   catch( Dali::DaliException& e )
578   {
579     DALI_TEST_PRINT_ASSERT( e );
580     DALI_TEST_EQUALS(e.condition, "columnIndex < mColumnData.Size()", TEST_LOCATION);
581   }
582   END_TEST;
583 }
584
585 int UtcDaliTableViewSetGetProperty(void)
586 {
587   ToolkitTestApplication application;
588   tet_infoline("UtcDaliTableViewSetGetProperty");
589
590   // Create a 1x1 table-view
591   TableView tableView = TableView::New(1,1);
592   tableView.SetSize( Vector2( 100.0f, 100.0f ) );
593   DALI_TEST_CHECK( tableView );
594
595   // Test "rows" property
596   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_ROWS ) == TableView::Property::ROWS );
597
598   tableView.SetProperty( TableView::Property::ROWS, 4u );
599
600   DALI_TEST_CHECK( tableView.GetRows() == 4u );
601   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::ROWS).Get<unsigned int>() == 4u );
602
603   // Test "columns" property
604   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::Property::COLUMNS );
605
606   tableView.SetProperty( TableView::Property::COLUMNS, 5u );
607
608   DALI_TEST_CHECK( tableView.GetColumns() == 5u );
609   DALI_TEST_CHECK( tableView.GetProperty(TableView::Property::COLUMNS).Get<unsigned int>() == 5u );
610
611   // Test "cell-padding" property
612   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_CELL_PADDING ) == TableView::Property::CELL_PADDING );
613
614   tableView.SetProperty( TableView::Property::CELL_PADDING, Size( 6.f, 8.f ) );
615
616   DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(6.f, 8.f), TEST_LOCATION );
617   DALI_TEST_EQUALS( tableView.GetProperty(TableView::Property::CELL_PADDING).Get<Vector2>(), Vector2(6.f,8.f), TEST_LOCATION );
618
619   //{ "policy": "fixed", "value": 30.0 },
620   Property::Map item1;
621   item1[ "policy" ] = "fixed";
622   item1[ "value" ] = 30.f;
623   //{ "policy": "relative", "value": 0.2 },
624   Property::Map item2;
625   item2[ "policy" ] = "relative";
626   item2[ "value" ] = 0.2f;
627
628   // Test "layout-rows" property
629   DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::Property::LAYOUT_ROWS );
630
631   /*
632    * "layout-rows":
633    *  {
634    *    "1": { "policy": "fixed", "value": 30 },
635    *    "3": { "policy": "relative", "value": 0.2 }
636    *   }
637    */
638   Property::Map layoutRows;
639   layoutRows[ "1" ] = item1;
640   layoutRows[ "3" ] = item2;
641   tableView.SetProperty( TableView::Property::LAYOUT_ROWS, layoutRows );
642
643   DALI_TEST_EQUALS( tableView.GetFixedHeight( 1u ), 30.f, TEST_LOCATION );
644   DALI_TEST_EQUALS( tableView.GetRelativeHeight( 3u ), 0.2f, TEST_LOCATION );
645
646   Property::Map layoutRowsGet = tableView.GetProperty(TableView::Property::LAYOUT_ROWS).Get<Property::Map>();
647
648   DALI_TEST_EQUALS( layoutRowsGet.GetKey(1).compare(layoutRows.GetKey(0)), 0, TEST_LOCATION );
649   DALI_TEST_CHECK( layoutRowsGet.GetValue(1).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
650   DALI_TEST_EQUALS( layoutRowsGet.GetValue(1).GetValue( "value" ).Get<float>(), layoutRows.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
651
652   DALI_TEST_CHECK( layoutRowsGet.GetKey(3).compare(layoutRows.GetKey(1)) == 0 );
653   DALI_TEST_CHECK( layoutRowsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutRows.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
654   DALI_TEST_EQUALS( layoutRowsGet.GetValue(3).GetValue( "value" ).Get<float>(), layoutRows.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
655
656   // Test "layout-columns" property
657   DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_LAYOUT_COLUMNS ) == TableView::Property::LAYOUT_COLUMNS );
658
659   /*
660    * "layout-columns":
661    *  {
662    *    "2": { "policy": "relative", "value": 0.2 },
663    *    "3": { "policy": "fixed", "value": 30 }
664    *   }
665    */
666   Property::Map layoutColumns;
667   layoutColumns[ "2" ] = item2;
668   layoutColumns[ "3" ] = item1;
669   tableView.SetProperty( TableView::Property::LAYOUT_COLUMNS, layoutColumns );
670
671   DALI_TEST_EQUALS( tableView.GetRelativeWidth( 2u ), 0.2f, TEST_LOCATION );
672   DALI_TEST_EQUALS( tableView.GetFixedWidth( 3u ), 30.f, TEST_LOCATION );
673
674   Property::Map layoutColumnsGet = tableView.GetProperty(TableView::Property::LAYOUT_COLUMNS).Get<Property::Map>();
675   DALI_TEST_CHECK( layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0 );
676   DALI_TEST_CHECK( layoutColumnsGet.GetValue(2).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(0).GetValue( "policy" ).Get<std::string>()) == 0 );
677   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(2).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(0).GetValue( "value" ).Get<float>(), TEST_LOCATION );
678
679   DALI_TEST_CHECK( layoutColumnsGet.GetKey(3).compare(layoutColumns.GetKey(1)) == 0 );
680   DALI_TEST_CHECK( layoutColumnsGet.GetValue(3).GetValue( "policy" ).Get<std::string>().compare(layoutColumns.GetValue(1).GetValue( "policy" ).Get<std::string>()) == 0 );
681   DALI_TEST_EQUALS( layoutColumnsGet.GetValue(3).GetValue( "value" ).Get<float>(),layoutColumns.GetValue(1).GetValue( "value" ).Get<float>(), TEST_LOCATION );
682
683   END_TEST;
684 }
685
686 int UtcDaliTableViewCustomProperties(void)
687 {
688   ToolkitTestApplication application;
689   tet_infoline("UtcDaliTableViewCustomProperties");
690
691   // Create a 10x10 table-view
692   TableView tableView = TableView::New(10,10);
693   Constraint constraint = Constraint::New<Vector3>( tableView, Actor::Property::SIZE, Constraint100() );
694   constraint.Apply();
695   DALI_TEST_CHECK( tableView );
696
697   // Create a child actor with the custom properties
698   Actor child1 = Actor::New();
699   child1.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 3, 4 ) );
700   tableView.Add( child1 );
701   // Check for actors at actual positions.
702   DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1);
703
704   // Create a second child actor with the custom properties
705   Actor child2 = Actor::New();
706   float rowSpan = 3.f;
707   float columnSpan = 2.f;
708   child2.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 6, 1 ) );
709   child2.RegisterProperty( TableView::ROW_SPAN_PROPERTY_NAME, rowSpan );
710   child2.RegisterProperty( TableView::COLUMN_SPAN_PROPERTY_NAME, columnSpan );
711   tableView.Add( child2 );
712   // Check for actors at actual positions.
713   for( int i=0; i<rowSpan; i++ )
714   {
715     for(int j=0; j<columnSpan; j++)
716     {
717       DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(6+i,1+j)) == child2);
718     }
719   }
720
721   END_TEST;
722 }
723
724 int UtcDaliTableViewGetChildAtN(void)
725 {
726   ToolkitTestApplication application;
727
728   TableView tableView = TableView::New(10,10);
729
730   Actor actor = tableView.GetChildAt( TableView::CellPosition( 200, 200 ) );
731   DALI_TEST_CHECK( !actor );
732
733   END_TEST;
734 }
735
736 int UtcDaliTableViewAddChildN(void)
737 {
738   ToolkitTestApplication application;
739
740   TableView tableView = TableView::New(10,10);
741   DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
742   DALI_TEST_CHECK( ! tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 ) ) );
743
744   END_TEST;
745 }
746
747 int UtcDaliTableViewInsertRowAtZero(void)
748 {
749   ToolkitTestApplication application;
750
751   TableView tableView = TableView::New(10,10);
752   DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
753   tableView.InsertRow(0);
754
755   DALI_TEST_CHECK( tableView.GetRows() == 11 );
756
757   END_TEST;
758 }
759
760 int UtcDaliTableViewDeleteRowAtZero(void)
761 {
762   ToolkitTestApplication application;
763
764   TableView tableView = TableView::New(10,10);
765   DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
766   tableView.DeleteRow(0);
767
768   DALI_TEST_CHECK( tableView.GetRows() == 9 );
769
770   END_TEST;
771 }
772
773 int UtcDaliTableViewInsertColumnAtZero(void)
774 {
775   ToolkitTestApplication application;
776
777   TableView tableView = TableView::New(10,10);
778   DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
779   tableView.InsertColumn(0);
780
781   DALI_TEST_CHECK( tableView.GetColumns() == 11 );
782
783   END_TEST;
784 }
785
786 int UtcDaliTableViewDeleteColumnAtZero(void)
787 {
788   ToolkitTestApplication application;
789
790   TableView tableView = TableView::New(10,10);
791   DALI_TEST_CHECK( tableView.AddChild( Actor::New(), TableView::CellPosition( 0, 0 , 10, 10 ) ) );
792   tableView.DeleteColumn(0);
793
794   DALI_TEST_CHECK( tableView.GetColumns() == 9 );
795
796   END_TEST;
797 }
798
799 int UtcDaliTableViewTypeRegistry(void)
800 {
801   ToolkitTestApplication application;
802
803   TypeRegistry typeRegistry = TypeRegistry::Get();
804   DALI_TEST_CHECK( typeRegistry );
805
806   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "TableView" );
807   DALI_TEST_CHECK( typeInfo );
808
809   BaseHandle handle = typeInfo.CreateInstance();
810   DALI_TEST_CHECK( handle );
811
812   TableView view = TableView::DownCast( handle );
813   DALI_TEST_CHECK( view );
814
815   END_TEST;
816 }
817
818 int UtcDaliTableViewKeyboardFocus(void)
819 {
820   ToolkitTestApplication application;
821
822   TableView tableView = TableView::New(4,4);
823   tableView.SetKeyboardFocusable( true );
824   tableView.SetName( "TableView");
825
826   for ( int row = 0; row < 4; ++row )
827   {
828     for ( int col = 0; col < 4; ++col )
829     {
830       Control control = Control::New();
831       std::ostringstream str;
832       str << row << "-" << col;
833       control.SetName( str.str() );
834       control.SetKeyboardFocusable( true );
835       tableView.AddChild( control, TableView::CellPosition( row, col ) );
836     }
837   }
838
839   Stage::GetCurrent().Add( tableView );
840
841   application.SendNotification();
842   application.Render();
843
844   Actor firstFocusActor = Toolkit::Internal::GetImplementation( tableView ).GetNextKeyboardFocusableActor( Actor(), Control::KeyboardFocus::RIGHT, true );
845   DALI_TEST_CHECK( firstFocusActor );
846   DALI_TEST_CHECK( firstFocusActor.GetName() == "0-0" );
847
848   KeyboardFocusManager manager = KeyboardFocusManager::Get();
849   manager.SetFocusGroupLoop( true );
850   manager.SetCurrentFocusActor( firstFocusActor );
851
852   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
853   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
854   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
855   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
856   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
857   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
858   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
859   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
860   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-0" );
861
862   manager.MoveFocus( Control::KeyboardFocus::LEFT );
863   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-3" );
864   manager.MoveFocus( Control::KeyboardFocus::LEFT );
865   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-2" );
866   manager.MoveFocus( Control::KeyboardFocus::LEFT );
867   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
868   manager.MoveFocus( Control::KeyboardFocus::LEFT );
869   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
870   manager.MoveFocus( Control::KeyboardFocus::LEFT );
871   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-3" );
872
873   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
874   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-0" );
875   manager.MoveFocus( Control::KeyboardFocus::RIGHT );
876   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
877
878   manager.MoveFocus( Control::KeyboardFocus::DOWN );
879   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
880   manager.MoveFocus( Control::KeyboardFocus::DOWN );
881   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
882   manager.MoveFocus( Control::KeyboardFocus::DOWN );
883   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
884   manager.MoveFocus( Control::KeyboardFocus::DOWN );
885   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
886
887   manager.MoveFocus( Control::KeyboardFocus::UP );
888   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "3-1" );
889   manager.MoveFocus( Control::KeyboardFocus::UP );
890   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "2-1" );
891   manager.MoveFocus( Control::KeyboardFocus::UP );
892   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "1-1" );
893   manager.MoveFocus( Control::KeyboardFocus::UP );
894   DALI_TEST_CHECK( manager.GetCurrentFocusActor().GetName() == "0-1" );
895
896   END_TEST;
897 }