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;
121 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
122 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
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) } };
132 propertyBuffer.SetData( texturedQuadVertexData, 4 );
134 Geometry geometry = Geometry::New();
135 geometry.AddVertexBuffer( propertyBuffer );
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);
144 application.SendNotification();
145 application.Render(0);
146 application.Render();
147 application.SendNotification();
149 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
150 application.GetGlAbstraction().GetBufferDataCalls();
152 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
154 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
159 int UtcDaliPropertyBufferSetData02(void)
161 TestApplication application;
163 Property::Map texturedQuadVertexFormat;
164 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
165 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
167 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
168 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
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) } };
178 propertyBuffer.SetData( texturedQuadVertexData, 4 );
180 Geometry geometry = Geometry::New();
181 geometry.AddVertexBuffer( propertyBuffer );
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);
190 application.SendNotification();
191 application.Render(0);
192 application.Render();
193 application.SendNotification();
196 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
197 application.GetGlAbstraction().GetBufferDataCalls();
199 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
201 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
204 // Re-upload the data on the propertyBuffer
205 propertyBuffer.SetData( texturedQuadVertexData, 4 );
207 application.SendNotification();
208 application.Render(0);
209 application.Render();
210 application.SendNotification();
213 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
214 application.GetGlAbstraction().GetBufferSubDataCalls();
216 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
217 application.GetGlAbstraction().GetBufferDataCalls();
219 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
220 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
222 if ( bufferSubDataCalls.size() )
224 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
231 int UtcDaliPropertyBufferInvalidTypeN(void)
233 TestApplication application;
235 Property::Map texturedQuadVertexFormat;
236 texturedQuadVertexFormat["aPosition"] = Property::MAP;
237 texturedQuadVertexFormat["aVertexCoord"] = Property::STRING;
241 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
242 tet_result(TET_FAIL);
244 catch ( Dali::DaliException& e )
246 DALI_TEST_ASSERT( e, "Property::Type not supported in PropertyBuffer", TEST_LOCATION );