2 * Copyright (c) 2020 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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
25 void propertyBuffer_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void propertyBuffer_test_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliPropertyBufferNew01(void)
37 TestApplication application;
39 Property::Map texturedQuadVertexFormat;
40 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
41 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
43 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
45 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
49 int UtcDaliPropertyBufferNew02(void)
51 TestApplication application;
52 PropertyBuffer propertyBuffer;
53 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
57 int UtcDaliPropertyBufferDownCast01(void)
59 TestApplication application;
61 Property::Map texturedQuadVertexFormat;
62 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
63 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
65 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
67 BaseHandle handle(propertyBuffer);
68 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
69 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
73 int UtcDaliPropertyBufferDownCast02(void)
75 TestApplication application;
77 Handle handle = Handle::New(); // Create a custom object
78 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
79 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
83 int UtcDaliPropertyBufferCopyConstructor(void)
85 TestApplication application;
87 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
89 PropertyBuffer propertyBufferCopy(propertyBuffer);
91 DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
92 DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 0u, TEST_LOCATION );
97 int UtcDaliPropertyBufferAssignmentOperator(void)
99 TestApplication application;
101 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
103 PropertyBuffer propertyBuffer2;
104 DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
106 propertyBuffer2 = propertyBuffer;
107 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
108 DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 0u, TEST_LOCATION );
113 int UtcDaliPropertyBufferMoveConstructor(void)
115 TestApplication application;
117 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
118 DALI_TEST_CHECK( propertyBuffer );
119 DALI_TEST_EQUALS( 1, propertyBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
120 DALI_TEST_EQUALS( 0u, propertyBuffer.GetSize(), TEST_LOCATION );
122 PropertyBuffer move = std::move( propertyBuffer );
123 DALI_TEST_CHECK( move );
124 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
125 DALI_TEST_EQUALS( 0u, move.GetSize(), TEST_LOCATION );
126 DALI_TEST_CHECK( !propertyBuffer );
131 int UtcDaliPropertyBufferMoveAssignment(void)
133 TestApplication application;
135 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
136 DALI_TEST_CHECK( propertyBuffer );
137 DALI_TEST_EQUALS( 1, propertyBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
138 DALI_TEST_EQUALS( 0u, propertyBuffer.GetSize(), TEST_LOCATION );
141 move = std::move( propertyBuffer );
142 DALI_TEST_CHECK( move );
143 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
144 DALI_TEST_EQUALS( 0u, move.GetSize(), TEST_LOCATION );
145 DALI_TEST_CHECK( !propertyBuffer );
150 int UtcDaliPropertyBufferSetData01(void)
152 TestApplication application;
154 Property::Map texturedQuadVertexFormat;
155 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
156 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
159 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
160 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
162 const float halfQuadSize = .5f;
163 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
164 TexturedQuadVertex texturedQuadVertexData[4] = {
165 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
166 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
167 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
168 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
170 propertyBuffer.SetData( texturedQuadVertexData, 4 );
172 Geometry geometry = Geometry::New();
173 geometry.AddVertexBuffer( propertyBuffer );
175 Shader shader = CreateShader();
176 Renderer renderer = Renderer::New(geometry, shader);
177 Actor actor = Actor::New();
178 actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f);
179 actor.AddRenderer(renderer);
180 application.GetScene().Add(actor);
182 application.SendNotification();
183 application.Render(0);
184 application.Render();
185 application.SendNotification();
187 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
188 application.GetGlAbstraction().GetBufferDataCalls();
190 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
192 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
195 // end of scope to let the buffer and geometry die; do another notification and render to get the deletion processed
196 application.SendNotification();
197 application.Render(0);
202 int UtcDaliPropertyBufferSetData02(void)
204 TestApplication application;
206 Property::Map texturedQuadVertexFormat;
207 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
208 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
210 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
211 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
213 const float halfQuadSize = .5f;
214 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
215 TexturedQuadVertex texturedQuadVertexData[4] = {
216 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
217 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
218 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
219 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
221 propertyBuffer.SetData( texturedQuadVertexData, 4 );
223 Geometry geometry = Geometry::New();
224 geometry.AddVertexBuffer( propertyBuffer );
226 Shader shader = CreateShader();
227 Renderer renderer = Renderer::New(geometry, shader);
228 Actor actor = Actor::New();
229 actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f);
230 actor.AddRenderer(renderer);
231 application.GetScene().Add(actor);
233 application.SendNotification();
234 application.Render(0);
235 application.Render();
236 application.SendNotification();
239 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
240 application.GetGlAbstraction().GetBufferDataCalls();
242 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
244 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
247 // Re-upload the data on the propertyBuffer
248 propertyBuffer.SetData( texturedQuadVertexData, 4 );
250 application.SendNotification();
251 application.Render(0);
252 application.Render();
253 application.SendNotification();
256 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
257 application.GetGlAbstraction().GetBufferSubDataCalls();
259 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
260 application.GetGlAbstraction().GetBufferDataCalls();
262 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
263 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
265 if ( bufferSubDataCalls.size() )
267 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
274 int UtcDaliPropertyBufferInvalidTypeN(void)
276 TestApplication application;
278 Property::Map texturedQuadVertexFormat;
279 texturedQuadVertexFormat["aPosition"] = Property::MAP;
280 texturedQuadVertexFormat["aVertexCoord"] = Property::STRING;
284 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
285 tet_result(TET_FAIL);
287 catch ( Dali::DaliException& e )
289 DALI_TEST_ASSERT( e, "Property::Type not supported in PropertyBuffer", TEST_LOCATION );