License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / item-view / 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
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.h>
24
25 #include <dali-toolkit/dali-toolkit.h>
26
27 #include <dali-toolkit-test-suite-utils.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 namespace
33 {
34 const unsigned int TOTAL_ITEM_NUMBER = 200;
35 const char* TEST_IMAGE_FILE_NAME = DALI_IMAGE_DIR "gallery_image_01.jpg";
36 } // namespace
37
38 static void Startup();
39 static void Cleanup();
40
41 extern "C" {
42   void (*tet_startup)() = Startup;
43   void (*tet_cleanup)() = Cleanup;
44 }
45
46 static void UtcDaliItemLayoutSetAndGetOrientation();
47 static void UtcDaliItemLayoutGetScrollHints();
48
49 enum {
50   POSITIVE_TC_IDX = 0x01,
51   NEGATIVE_TC_IDX,
52 };
53
54 // Add test functionality for all APIs in the class (Positive and Negative)
55 extern "C" {
56   struct tet_testlist tet_testlist[] = {
57     { UtcDaliItemLayoutSetAndGetOrientation, POSITIVE_TC_IDX },
58     { UtcDaliItemLayoutGetScrollHints, POSITIVE_TC_IDX },
59     { NULL, 0 }
60   };
61 }
62
63 // Called only once before first test is run.
64 static void Startup()
65 {
66 }
67
68 // Called only once after last test is run
69 static void Cleanup()
70 {
71 }
72
73 // Implementation of ItemFactory for providing actors to ItemView
74 class TestItemFactory : public ItemFactory
75 {
76 public:
77
78   /**
79    * Constructor
80    * @param application class, stored as reference
81    */
82   TestItemFactory()
83   {
84   }
85
86 public: // From ItemFactory
87
88   /**
89    * Query the number of items available from the factory.
90    * The maximum available item has an ID of GetNumberOfItems() - 1.
91    */
92   virtual unsigned int GetNumberOfItems()
93   {
94     return TOTAL_ITEM_NUMBER;
95   }
96
97   /**
98    * Create an Actor to represent a visible item.
99    * @param itemId
100    * @return the created actor.
101    */
102   virtual Actor NewItem(unsigned int itemId)
103   {
104     // Create an image actor for this item
105     Image image = Image::New( TEST_IMAGE_FILE_NAME );
106     Actor actor = ImageActor::New(image);
107
108     return actor;
109   }
110 };
111
112 static void UtcDaliItemLayoutSetAndGetOrientation()
113 {
114   ToolkitTestApplication application;
115
116   // Create the ItemView actor
117   TestItemFactory factory;
118   ItemView view = ItemView::New(factory);
119
120   // Create a grid layout and add it to ItemView
121   GridLayoutPtr gridLayout = GridLayout::New();
122   view.AddLayout(*gridLayout);
123
124   // Set the orientation of the layout to be horizontal from left to right
125   ItemLayoutPtr layout = view.GetLayout(0);
126   layout->SetOrientation(ControlOrientation::Left);
127
128   // Check the orientation of the layout is horizontal from left to right
129   DALI_TEST_CHECK(layout->GetOrientation() == ControlOrientation::Left);
130 }
131
132 static void UtcDaliItemLayoutGetScrollHints()
133 {
134   ToolkitTestApplication application;
135
136   // Create the ItemView actor
137   TestItemFactory factory;
138   ItemView view = ItemView::New(factory);
139
140   // Create a grid layout and add it to ItemView
141   GridLayoutPtr gridLayout = GridLayout::New();
142   view.AddLayout(*gridLayout);
143
144   // Set the orientation of the layout to be horizontal from left to right
145   ItemLayoutPtr layout = view.GetLayout(0);
146
147   Vector2 axisScrollHint;
148
149   layout->SetOrientation(ControlOrientation::Up);
150   layout->GetXAxisScrollHint(axisScrollHint);
151   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
152   layout->GetYAxisScrollHint(axisScrollHint);
153   DALI_TEST_EQUALS(axisScrollHint, Vector2::YAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
154
155   layout->SetOrientation(ControlOrientation::Down);
156   layout->GetXAxisScrollHint(axisScrollHint);
157   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
158   layout->GetYAxisScrollHint(axisScrollHint);
159   DALI_TEST_EQUALS(axisScrollHint, Vector2::YAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
160
161   layout->SetOrientation(ControlOrientation::Left);
162   layout->GetXAxisScrollHint(axisScrollHint);
163   DALI_TEST_EQUALS(axisScrollHint, Vector2::XAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
164   layout->GetYAxisScrollHint(axisScrollHint);
165   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
166
167   layout->SetOrientation(ControlOrientation::Right);
168   layout->GetXAxisScrollHint(axisScrollHint);
169   DALI_TEST_EQUALS(axisScrollHint, Vector2::XAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
170   layout->GetYAxisScrollHint(axisScrollHint);
171   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
172 }