Add utc test cases
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ItemLayout.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
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 namespace
32 {
33 const unsigned int TOTAL_ITEM_NUMBER = 200;
34 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
35
36
37 // Implementation of ItemFactory for providing actors to ItemView
38 class TestItemFactory : public ItemFactory
39 {
40 public:
41
42   /**
43    * Constructor
44    * @param application class, stored as reference
45    */
46   TestItemFactory()
47   {
48   }
49
50 public: // From ItemFactory
51
52   /**
53    * Query the number of items available from the factory.
54    * The maximum available item has an ID of GetNumberOfItems() - 1.
55    */
56   virtual unsigned int GetNumberOfItems()
57   {
58     return TOTAL_ITEM_NUMBER;
59   }
60
61   /**
62    * Create an Actor to represent a visible item.
63    * @param itemId
64    * @return the created actor.
65    */
66   virtual Actor NewItem(unsigned int itemId)
67   {
68     // Create an image actor for this item
69     Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
70     Actor actor = ImageActor::New(image);
71
72     return actor;
73   }
74 };
75 } // namespace
76
77 int UtcDaliItemLayoutSetAndGetOrientation(void)
78 {
79   ToolkitTestApplication application;
80
81   // Create the ItemView actor
82   TestItemFactory factory;
83   ItemView view = ItemView::New(factory);
84
85   // Create a grid layout and add it to ItemView
86   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
87   view.AddLayout(*gridLayout);
88
89   // Set the orientation of the layout to be horizontal from left to right
90   ItemLayoutPtr layout = view.GetLayout(0);
91
92   DALI_TEST_CHECK(gridLayout == layout);
93
94   layout->SetOrientation(ControlOrientation::Left);
95
96   // Check the orientation of the layout is horizontal from left to right
97   DALI_TEST_CHECK(layout->GetOrientation() == ControlOrientation::Left);
98
99   Vector3 itemSize(100.0f, 100.0f, 100.0f);
100   layout->SetItemSize(itemSize);
101
102   Vector3 itemSize1;
103   layout->GetItemSize(0u, Vector3(Stage::GetCurrent().GetSize()), itemSize1);
104
105   DALI_TEST_CHECK(itemSize == itemSize1);
106
107   float position = layout->GetClosestOnScreenLayoutPosition(0, 0.0f, Vector3(Stage::GetCurrent().GetSize()));
108
109   DALI_TEST_EQUALS(position, 0.0f, TEST_LOCATION);
110
111   int focusItem = layout->GetNextFocusItemID(0, TOTAL_ITEM_NUMBER, Control::Left, true);
112
113   DALI_TEST_CHECK(focusItem != 0);
114
115   float flickSpeedFactor = layout->GetFlickSpeedFactor();
116
117   DALI_TEST_CHECK(flickSpeedFactor != 0.0f);
118
119   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
120   view.AddLayout(*depthLayout);
121
122   layout = view.GetLayout(1);
123   DALI_TEST_CHECK(depthLayout == layout);
124
125   ItemLayoutPtr listLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );
126   view.AddLayout(*listLayout);
127
128   layout = view.GetLayout(2);
129   DALI_TEST_CHECK(listLayout == layout);
130
131   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
132   view.AddLayout(*spiralLayout);
133
134   layout = view.GetLayout(3);
135   DALI_TEST_CHECK(spiralLayout == layout);
136   END_TEST;
137 }