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