d1ccae32800f51fab5cc545cf6e8f4fe1ba95787
[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 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 #include <stdlib.h>
19
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
23
24 #include <dali.h>
25 #include <dali-toolkit/dali-toolkit.h>
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 namespace
31 {
32 const unsigned int TOTAL_ITEM_NUMBER = 200;
33 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
34
35
36 // Implementation of ItemFactory for providing actors to ItemView
37 class TestItemFactory : public ItemFactory
38 {
39 public:
40
41   /**
42    * Constructor
43    * @param application class, stored as reference
44    */
45   TestItemFactory()
46   {
47   }
48
49 public: // From ItemFactory
50
51   /**
52    * Query the number of items available from the factory.
53    * The maximum available item has an ID of GetNumberOfItems() - 1.
54    */
55   virtual unsigned int GetNumberOfItems()
56   {
57     return TOTAL_ITEM_NUMBER;
58   }
59
60   /**
61    * Create an Actor to represent a visible item.
62    * @param itemId
63    * @return the created actor.
64    */
65   virtual Actor NewItem(unsigned int itemId)
66   {
67     // Create an image actor for this item
68     Image image = Image::New( TEST_IMAGE_FILE_NAME );
69     Actor actor = ImageActor::New(image);
70
71     return actor;
72   }
73 };
74 } // namespace
75
76 int UtcDaliItemLayoutSetAndGetOrientation(void)
77 {
78   ToolkitTestApplication application;
79
80   // Create the ItemView actor
81   TestItemFactory factory;
82   ItemView view = ItemView::New(factory);
83
84   // Create a grid layout and add it to ItemView
85   GridLayoutPtr gridLayout = GridLayout::New();
86   view.AddLayout(*gridLayout);
87
88   // Set the orientation of the layout to be horizontal from left to right
89   ItemLayoutPtr layout = view.GetLayout(0);
90   layout->SetOrientation(ControlOrientation::Left);
91
92   // Check the orientation of the layout is horizontal from left to right
93   DALI_TEST_CHECK(layout->GetOrientation() == ControlOrientation::Left);
94   END_TEST;
95 }
96
97 int UtcDaliItemLayoutGetScrollHints(void)
98 {
99   ToolkitTestApplication application;
100
101   // Create the ItemView actor
102   TestItemFactory factory;
103   ItemView view = ItemView::New(factory);
104
105   // Create a grid layout and add it to ItemView
106   GridLayoutPtr gridLayout = GridLayout::New();
107   view.AddLayout(*gridLayout);
108
109   // Set the orientation of the layout to be horizontal from left to right
110   ItemLayoutPtr layout = view.GetLayout(0);
111
112   Vector2 axisScrollHint;
113
114   layout->SetOrientation(ControlOrientation::Up);
115   layout->GetXAxisScrollHint(axisScrollHint);
116   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
117   layout->GetYAxisScrollHint(axisScrollHint);
118   DALI_TEST_EQUALS(axisScrollHint, Vector2::YAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
119
120   layout->SetOrientation(ControlOrientation::Down);
121   layout->GetXAxisScrollHint(axisScrollHint);
122   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
123   layout->GetYAxisScrollHint(axisScrollHint);
124   DALI_TEST_EQUALS(axisScrollHint, Vector2::YAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
125
126   layout->SetOrientation(ControlOrientation::Left);
127   layout->GetXAxisScrollHint(axisScrollHint);
128   DALI_TEST_EQUALS(axisScrollHint, Vector2::XAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
129   layout->GetYAxisScrollHint(axisScrollHint);
130   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
131
132   layout->SetOrientation(ControlOrientation::Right);
133   layout->GetXAxisScrollHint(axisScrollHint);
134   DALI_TEST_EQUALS(axisScrollHint, Vector2::XAXIS, Math::MACHINE_EPSILON_1, TEST_LOCATION);
135   layout->GetYAxisScrollHint(axisScrollHint);
136   DALI_TEST_EQUALS(axisScrollHint, Vector2::ZERO, Math::MACHINE_EPSILON_1, TEST_LOCATION);
137   END_TEST;
138 }