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