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>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
33 void propertyBuffer_test_startup(void)
35 test_return_value = TET_UNDEF;
38 void propertyBuffer_test_cleanup(void)
40 test_return_value = TET_PASS;
43 int UtcDaliPropertyBufferNew01(void)
45 TestApplication application;
47 Property::Map texturedQuadVertexFormat;
48 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
49 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
51 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
53 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
57 int UtcDaliPropertyBufferNew02(void)
59 TestApplication application;
60 PropertyBuffer propertyBuffer;
61 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
65 int UtcDaliPropertyBufferDownCast01(void)
67 TestApplication application;
69 Property::Map texturedQuadVertexFormat;
70 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
71 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
73 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
75 BaseHandle handle(propertyBuffer);
76 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
77 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
81 int UtcDaliPropertyBufferDownCast02(void)
83 TestApplication application;
85 Handle handle = Handle::New(); // Create a custom object
86 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
87 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
91 int UtcDaliPropertyBufferCopyConstructor(void)
93 TestApplication application;
95 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
97 PropertyBuffer propertyBufferCopy(propertyBuffer);
99 DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
100 DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 0u, TEST_LOCATION );
105 int UtcDaliPropertyBufferAssignmentOperator(void)
107 TestApplication application;
109 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
111 PropertyBuffer propertyBuffer2;
112 DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
114 propertyBuffer2 = propertyBuffer;
115 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
116 DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 0u, TEST_LOCATION );
121 int UtcDaliPropertyBufferSetData01(void)
123 TestApplication application;
125 Property::Map texturedQuadVertexFormat;
126 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
127 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
129 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
130 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
132 const float halfQuadSize = .5f;
133 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
134 TexturedQuadVertex texturedQuadVertexData[4] = {
135 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
136 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
137 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
138 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
140 propertyBuffer.SetData( texturedQuadVertexData, 4 );
142 Geometry geometry = Geometry::New();
143 geometry.AddVertexBuffer( propertyBuffer );
145 Shader shader = CreateShader();
146 Renderer renderer = Renderer::New(geometry, shader);
147 Actor actor = Actor::New();
148 actor.SetSize(Vector3::ONE * 100.f);
149 actor.AddRenderer(renderer);
150 Stage::GetCurrent().Add(actor);
152 application.SendNotification();
153 application.Render(0);
154 application.Render();
155 application.SendNotification();
157 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
158 application.GetGlAbstraction().GetBufferDataCalls();
160 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
162 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
167 int UtcDaliPropertyBufferSetData02(void)
169 TestApplication application;
171 Property::Map texturedQuadVertexFormat;
172 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
173 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
175 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat );
176 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
178 const float halfQuadSize = .5f;
179 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
180 TexturedQuadVertex texturedQuadVertexData[4] = {
181 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
182 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
183 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
184 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
186 propertyBuffer.SetData( texturedQuadVertexData, 4 );
188 Geometry geometry = Geometry::New();
189 geometry.AddVertexBuffer( propertyBuffer );
191 Shader shader = CreateShader();
192 Renderer renderer = Renderer::New(geometry, shader);
193 Actor actor = Actor::New();
194 actor.SetSize(Vector3::ONE * 100.f);
195 actor.AddRenderer(renderer);
196 Stage::GetCurrent().Add(actor);
198 application.SendNotification();
199 application.Render(0);
200 application.Render();
201 application.SendNotification();
204 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
205 application.GetGlAbstraction().GetBufferDataCalls();
207 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
209 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
212 // Re-upload the data on the propertyBuffer
213 propertyBuffer.SetData( texturedQuadVertexData, 4 );
215 application.SendNotification();
216 application.Render(0);
217 application.Render();
218 application.SendNotification();
221 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
222 application.GetGlAbstraction().GetBufferSubDataCalls();
224 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
225 application.GetGlAbstraction().GetBufferDataCalls();
227 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
228 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
230 if ( bufferSubDataCalls.size() )
232 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );