2 * Copyright (c) 2016 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 UtcDaliPropertyBufferSetData01(void)
115 TestApplication application;
117 Property::Map texturedQuadVertexFormat;
118 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
119 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
122 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
123 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
125 const float halfQuadSize = .5f;
126 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
127 TexturedQuadVertex texturedQuadVertexData[4] = {
128 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
129 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
130 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
131 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
133 propertyBuffer.SetData( texturedQuadVertexData, 4 );
135 Geometry geometry = Geometry::New();
136 geometry.AddVertexBuffer( propertyBuffer );
138 Shader shader = CreateShader();
139 Renderer renderer = Renderer::New(geometry, shader);
140 Actor actor = Actor::New();
141 actor.SetSize(Vector3::ONE * 100.f);
142 actor.AddRenderer(renderer);
143 Stage::GetCurrent().Add(actor);
145 application.SendNotification();
146 application.Render(0);
147 application.Render();
148 application.SendNotification();
150 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
151 application.GetGlAbstraction().GetBufferDataCalls();
153 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
155 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
158 // end of scope to let the buffer and geometry die; do another notification and render to get the deletion processed
159 application.SendNotification();
160 application.Render(0);
165 int UtcDaliPropertyBufferSetData02(void)
167 TestApplication application;
169 Property::Map texturedQuadVertexFormat;
170 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
171 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
173 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
174 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
176 const float halfQuadSize = .5f;
177 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
178 TexturedQuadVertex texturedQuadVertexData[4] = {
179 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
180 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
181 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
182 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
184 propertyBuffer.SetData( texturedQuadVertexData, 4 );
186 Geometry geometry = Geometry::New();
187 geometry.AddVertexBuffer( propertyBuffer );
189 Shader shader = CreateShader();
190 Renderer renderer = Renderer::New(geometry, shader);
191 Actor actor = Actor::New();
192 actor.SetSize(Vector3::ONE * 100.f);
193 actor.AddRenderer(renderer);
194 Stage::GetCurrent().Add(actor);
196 application.SendNotification();
197 application.Render(0);
198 application.Render();
199 application.SendNotification();
202 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
203 application.GetGlAbstraction().GetBufferDataCalls();
205 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
207 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
210 // Re-upload the data on the propertyBuffer
211 propertyBuffer.SetData( texturedQuadVertexData, 4 );
213 application.SendNotification();
214 application.Render(0);
215 application.Render();
216 application.SendNotification();
219 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
220 application.GetGlAbstraction().GetBufferSubDataCalls();
222 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
223 application.GetGlAbstraction().GetBufferDataCalls();
225 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
226 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
228 if ( bufferSubDataCalls.size() )
230 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
237 int UtcDaliPropertyBufferInvalidTypeN(void)
239 TestApplication application;
241 Property::Map texturedQuadVertexFormat;
242 texturedQuadVertexFormat["aPosition"] = Property::MAP;
243 texturedQuadVertexFormat["aVertexCoord"] = Property::STRING;
247 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
248 tet_result(TET_FAIL);
250 catch ( Dali::DaliException& e )
252 DALI_TEST_ASSERT( e, "Property::Type not supported in PropertyBuffer", TEST_LOCATION );