2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
25 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Toolkit;
34 const unsigned int TOTAL_ITEM_NUMBER = 200;
35 const char* TEST_IMAGE_FILE_NAME = DALI_IMAGE_DIR "gallery_image_01.jpg";
38 static void Startup();
39 static void Cleanup();
42 void (*tet_startup)() = Startup;
43 void (*tet_cleanup)() = Cleanup;
46 static void UtcDaliItemLayoutSetAndGetOrientation();
47 static void UtcDaliItemLayoutGetScrollHints();
50 POSITIVE_TC_IDX = 0x01,
54 // Add test functionality for all APIs in the class (Positive and Negative)
56 struct tet_testlist tet_testlist[] = {
57 { UtcDaliItemLayoutSetAndGetOrientation, POSITIVE_TC_IDX },
58 { UtcDaliItemLayoutGetScrollHints, POSITIVE_TC_IDX },
63 // Called only once before first test is run.
68 // Called only once after last test is run
73 // Implementation of ItemFactory for providing actors to ItemView
74 class TestItemFactory : public ItemFactory
80 * @param application class, stored as reference
86 public: // From ItemFactory
89 * Query the number of items available from the factory.
90 * The maximum available item has an ID of GetNumberOfItems() - 1.
92 virtual unsigned int GetNumberOfItems()
94 return TOTAL_ITEM_NUMBER;
98 * Create an Actor to represent a visible item.
100 * @return the created actor.
102 virtual Actor NewItem(unsigned int itemId)
104 // Create an image actor for this item
105 Image image = Image::New( TEST_IMAGE_FILE_NAME );
106 Actor actor = ImageActor::New(image);
112 static void UtcDaliItemLayoutSetAndGetOrientation()
114 ToolkitTestApplication application;
116 // Create the ItemView actor
117 TestItemFactory factory;
118 ItemView view = ItemView::New(factory);
120 // Create a grid layout and add it to ItemView
121 GridLayoutPtr gridLayout = GridLayout::New();
122 view.AddLayout(*gridLayout);
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);
128 // Check the orientation of the layout is horizontal from left to right
129 DALI_TEST_CHECK(layout->GetOrientation() == ControlOrientation::Left);
132 static void UtcDaliItemLayoutGetScrollHints()
134 ToolkitTestApplication application;
136 // Create the ItemView actor
137 TestItemFactory factory;
138 ItemView view = ItemView::New(factory);
140 // Create a grid layout and add it to ItemView
141 GridLayoutPtr gridLayout = GridLayout::New();
142 view.AddLayout(*gridLayout);
144 // Set the orientation of the layout to be horizontal from left to right
145 ItemLayoutPtr layout = view.GetLayout(0);
147 Vector2 axisScrollHint;
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);
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);
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);
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);