2 * Copyright (c) 2015 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( PropertyBuffer::STATIC,
44 texturedQuadVertexFormat, 4 );
46 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
50 int UtcDaliPropertyBufferNew02(void)
52 TestApplication application;
53 PropertyBuffer propertyBuffer;
54 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
58 int UtcDaliPropertyBufferDownCast01(void)
60 TestApplication application;
62 Property::Map texturedQuadVertexFormat;
63 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
64 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
66 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
67 texturedQuadVertexFormat, 4 );
69 BaseHandle handle(propertyBuffer);
70 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
71 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
75 int UtcDaliPropertyBufferDownCast02(void)
77 TestApplication application;
79 Handle handle = Handle::New(); // Create a custom object
80 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
81 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
85 int UtcDaliPropertyBufferSetData01(void)
87 TestApplication application;
89 Property::Map texturedQuadVertexFormat;
90 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
91 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
93 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
94 texturedQuadVertexFormat, 4 );
95 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
97 const float halfQuadSize = .5f;
98 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
99 TexturedQuadVertex texturedQuadVertexData[4] = {
100 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
101 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
102 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
103 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
105 propertyBuffer.SetData( texturedQuadVertexData );
107 Geometry geometry = Geometry::New();
108 geometry.AddVertexBuffer( propertyBuffer );
110 Material material = CreateMaterial(1.f);
111 Renderer renderer = Renderer::New(geometry, material);
112 Actor actor = Actor::New();
113 actor.SetSize(Vector3::ONE * 100.f);
114 actor.AddRenderer(renderer);
115 Stage::GetCurrent().Add(actor);
117 application.SendNotification();
118 application.Render(0);
119 application.Render();
120 application.SendNotification();
122 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
123 application.GetGlAbstraction().GetBufferDataCalls();
125 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
127 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
132 int UtcDaliPropertyBufferSetData02(void)
134 TestApplication application;
136 Property::Map texturedQuadVertexFormat;
137 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
138 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
140 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
141 texturedQuadVertexFormat, 4 );
142 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
144 const float halfQuadSize = .5f;
145 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
146 TexturedQuadVertex texturedQuadVertexData[4] = {
147 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
148 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
149 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
150 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
152 propertyBuffer.SetData( texturedQuadVertexData );
154 Geometry geometry = Geometry::New();
155 geometry.AddVertexBuffer( propertyBuffer );
157 Material material = CreateMaterial(1.f);
158 Renderer renderer = Renderer::New(geometry, material);
159 Actor actor = Actor::New();
160 actor.SetSize(Vector3::ONE * 100.f);
161 actor.AddRenderer(renderer);
162 Stage::GetCurrent().Add(actor);
164 application.SendNotification();
165 application.Render(0);
166 application.Render();
167 application.SendNotification();
170 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
171 application.GetGlAbstraction().GetBufferDataCalls();
173 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
175 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
178 // Re-upload the data on the propertyBuffer
179 propertyBuffer.SetData( texturedQuadVertexData );
181 application.SendNotification();
182 application.Render(0);
183 application.Render();
184 application.SendNotification();
187 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
188 application.GetGlAbstraction().GetBufferSubDataCalls();
190 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
192 if ( bufferSubDataCalls.size() )
194 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
201 int UtcDaliPropertyBufferSetSize01(void)
203 TestApplication application;
205 Property::Map texturedQuadVertexFormat;
206 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
207 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
209 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
210 texturedQuadVertexFormat,
212 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
214 size_t size = propertyBuffer.GetSize();
215 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
217 propertyBuffer.SetSize( 10u );
218 size = propertyBuffer.GetSize();
219 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );