5663d79a01dd80fa449b7f829c1183b9ba0f5947
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-ItemView-internal.cpp
1 /*
2  * Copyright (c) 2020 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 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27
28 #include <dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h>
29
30 using namespace Dali;
31 using namespace Toolkit;
32
33 namespace
34 {
35 const unsigned int TOTAL_ITEM_NUMBER = 200;
36 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
37
38
39 // Implementation of ItemFactory for providing actors to ItemView
40 class TestItemFactory : public ItemFactory
41 {
42 public:
43
44   /**
45    * Constructor
46    * @param application class, stored as reference
47    */
48   TestItemFactory()
49   {
50   }
51
52   /**
53    * Virtual destructor.
54    */
55   virtual ~TestItemFactory()
56   {
57   }
58
59 public: // From ItemFactory
60
61   /**
62    * Query the number of items available from the factory.
63    * The maximum available item has an ID of GetNumberOfItems() - 1.
64    */
65   virtual unsigned int GetNumberOfItems()
66   {
67     return TOTAL_ITEM_NUMBER;
68   }
69
70   /**
71    * Create an Actor to represent a visible item.
72    * @param itemId
73    * @return the created actor.
74    */
75   virtual Actor NewItem(unsigned int itemId)
76   {
77     // Create a renderable actor for this item
78     return ImageView::New( TEST_IMAGE_FILE_NAME );
79   }
80 };
81
82 }
83
84 int UtcDaliItemLayoutCheckPropertiesSetBeforeActivateLayout(void)
85 {
86   ToolkitTestApplication application;
87
88   TestItemFactory factory;
89   ItemView view = ItemView::New(factory);
90
91   Property::Map gridLayoutProperty;
92   gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
93
94   //Set the column of grid-layout.
95   gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(6) );
96
97   Property::Array layoutArray;
98
99   layoutArray.PushBack(gridLayoutProperty);
100
101   view.SetProperty( ItemView::Property::LAYOUT, layoutArray );
102
103   Dali::Toolkit::Internal::GridLayout* gridLayout = dynamic_cast<Dali::Toolkit::Internal::GridLayout*>(view.GetLayout(0).Get());
104
105   Dali::Stage stage = Dali::Stage::GetCurrent();
106   Vector3 stageSize(stage.GetSize());
107
108   //Check if the number of columns is equals to 6 which is set before.
109   DALI_TEST_EQUALS(gridLayout->GetNumberOfColumns(), 6, TEST_LOCATION );
110   view.ActivateLayout(0, stageSize, 0.0f);
111   END_TEST;
112
113 }