Merge "Prevent API generate warning log" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PropertyBuffer.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 <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 void propertyBuffer_test_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void propertyBuffer_test_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 int UtcDaliPropertyBufferNew01(void)
36 {
37   TestApplication application;
38
39   Property::Map texturedQuadVertexFormat;
40   texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
41   texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
42
43   PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
44
45   DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
46   END_TEST;
47 }
48
49 int UtcDaliPropertyBufferNew02(void)
50 {
51   TestApplication application;
52   PropertyBuffer propertyBuffer;
53   DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
54   END_TEST;
55 }
56
57 int UtcDaliPropertyBufferDownCast01(void)
58 {
59   TestApplication application;
60
61   Property::Map texturedQuadVertexFormat;
62   texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
63   texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
64
65   PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
66
67   BaseHandle handle(propertyBuffer);
68   PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
69   DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
70   END_TEST;
71 }
72
73 int UtcDaliPropertyBufferDownCast02(void)
74 {
75   TestApplication application;
76
77   Handle handle = Handle::New(); // Create a custom object
78   PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
79   DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
80   END_TEST;
81 }
82
83 int UtcDaliPropertyBufferCopyConstructor(void)
84 {
85   TestApplication application;
86
87   PropertyBuffer propertyBuffer = CreatePropertyBuffer();
88
89   PropertyBuffer propertyBufferCopy(propertyBuffer);
90
91   DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
92   DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 0u, TEST_LOCATION );
93
94   END_TEST;
95 }
96
97 int UtcDaliPropertyBufferAssignmentOperator(void)
98 {
99   TestApplication application;
100
101   PropertyBuffer propertyBuffer = CreatePropertyBuffer();
102
103   PropertyBuffer propertyBuffer2;
104   DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
105
106   propertyBuffer2 = propertyBuffer;
107   DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
108   DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 0u, TEST_LOCATION );
109
110   END_TEST;
111 }
112
113 int UtcDaliPropertyBufferSetData01(void)
114 {
115   TestApplication application;
116
117   Property::Map texturedQuadVertexFormat;
118   texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
119   texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
120
121   PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
122   DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
123
124   const float halfQuadSize = .5f;
125   struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
126   TexturedQuadVertex texturedQuadVertexData[4] = {
127     { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
128     { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
129     { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
130     { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
131
132   propertyBuffer.SetData( texturedQuadVertexData, 4 );
133
134   Geometry geometry = Geometry::New();
135   geometry.AddVertexBuffer( propertyBuffer );
136
137   Shader shader = CreateShader();
138   Renderer renderer = Renderer::New(geometry, shader);
139   Actor actor = Actor::New();
140   actor.SetSize(Vector3::ONE * 100.f);
141   actor.AddRenderer(renderer);
142   Stage::GetCurrent().Add(actor);
143
144   application.SendNotification();
145   application.Render(0);
146   application.Render();
147   application.SendNotification();
148
149   const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
150       application.GetGlAbstraction().GetBufferDataCalls();
151
152   DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
153
154   DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
155
156   END_TEST;
157 }
158
159 int UtcDaliPropertyBufferSetData02(void)
160 {
161   TestApplication application;
162
163   Property::Map texturedQuadVertexFormat;
164   texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
165   texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
166
167   PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
168   DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
169
170   const float halfQuadSize = .5f;
171   struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
172   TexturedQuadVertex texturedQuadVertexData[4] = {
173     { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
174     { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
175     { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
176     { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
177
178   propertyBuffer.SetData( texturedQuadVertexData, 4 );
179
180   Geometry geometry = Geometry::New();
181   geometry.AddVertexBuffer( propertyBuffer );
182
183   Shader shader = CreateShader();
184   Renderer renderer = Renderer::New(geometry, shader);
185   Actor actor = Actor::New();
186   actor.SetSize(Vector3::ONE * 100.f);
187   actor.AddRenderer(renderer);
188   Stage::GetCurrent().Add(actor);
189
190   application.SendNotification();
191   application.Render(0);
192   application.Render();
193   application.SendNotification();
194
195   {
196     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
197       application.GetGlAbstraction().GetBufferDataCalls();
198
199     DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
200
201     DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
202   }
203
204   // Re-upload the data on the propertyBuffer
205   propertyBuffer.SetData( texturedQuadVertexData, 4 );
206
207   application.SendNotification();
208   application.Render(0);
209   application.Render();
210   application.SendNotification();
211
212   {
213     const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
214       application.GetGlAbstraction().GetBufferSubDataCalls();
215
216     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
217           application.GetGlAbstraction().GetBufferDataCalls();
218
219     DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
220     DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
221
222     if ( bufferSubDataCalls.size() )
223     {
224       DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
225     }
226   }
227
228   END_TEST;
229 }
230
231 int UtcDaliPropertyBufferInvalidTypeN(void)
232 {
233   TestApplication application;
234
235   Property::Map texturedQuadVertexFormat;
236   texturedQuadVertexFormat["aPosition"] = Property::MAP;
237   texturedQuadVertexFormat["aVertexCoord"] = Property::STRING;
238
239   try
240   {
241     PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
242     tet_result(TET_FAIL);
243   }
244   catch ( Dali::DaliException& e )
245   {
246     DALI_TEST_ASSERT( e, "Property::Type not supported in PropertyBuffer", TEST_LOCATION );
247   }
248   END_TEST;
249 }
250