2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
33 const unsigned int TOTAL_ITEM_NUMBER = 200;
34 const char* TEST_IMAGE_FILE_NAME = DALI_IMAGE_DIR "gallery_image_01.jpg";
37 static void Startup();
38 static void Cleanup();
41 void (*tet_startup)() = Startup;
42 void (*tet_cleanup)() = Cleanup;
45 static void UtcDaliItemLayoutSetAndGetOrientation();
46 static void UtcDaliItemLayoutGetScrollHints();
49 POSITIVE_TC_IDX = 0x01,
53 // Add test functionality for all APIs in the class (Positive and Negative)
55 struct tet_testlist tet_testlist[] = {
56 { UtcDaliItemLayoutSetAndGetOrientation, POSITIVE_TC_IDX },
57 { UtcDaliItemLayoutGetScrollHints, POSITIVE_TC_IDX },
62 // Called only once before first test is run.
67 // Called only once after last test is run
72 // Implementation of ItemFactory for providing actors to ItemView
73 class TestItemFactory : public ItemFactory
79 * @param application class, stored as reference
85 public: // From ItemFactory
88 * Query the number of items available from the factory.
89 * The maximum available item has an ID of GetNumberOfItems() - 1.
91 virtual unsigned int GetNumberOfItems()
93 return TOTAL_ITEM_NUMBER;
97 * Create an Actor to represent a visible item.
99 * @return the created actor.
101 virtual Actor NewItem(unsigned int itemId)
103 // Create an image actor for this item
104 Image image = Image::New( TEST_IMAGE_FILE_NAME );
105 Actor actor = ImageActor::New(image);
111 static void UtcDaliItemLayoutSetAndGetOrientation()
113 ToolkitTestApplication application;
115 // Create the ItemView actor
116 TestItemFactory factory;
117 ItemView view = ItemView::New(factory);
119 // Create a grid layout and add it to ItemView
120 GridLayoutPtr gridLayout = GridLayout::New();
121 view.AddLayout(*gridLayout);
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);
127 // Check the orientation of the layout is horizontal from left to right
128 DALI_TEST_CHECK(layout->GetOrientation() == ControlOrientation::Left);
131 static void UtcDaliItemLayoutGetScrollHints()
133 ToolkitTestApplication application;
135 // Create the ItemView actor
136 TestItemFactory factory;
137 ItemView view = ItemView::New(factory);
139 // Create a grid layout and add it to ItemView
140 GridLayoutPtr gridLayout = GridLayout::New();
141 view.AddLayout(*gridLayout);
143 // Set the orientation of the layout to be horizontal from left to right
144 ItemLayoutPtr layout = view.GetLayout(0);
146 Vector2 axisScrollHint;
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);
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);
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);
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);