2 * Copyright (c) 2023 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-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-scene3d/public-api/model-components/material.h>
26 using namespace Dali::Toolkit;
28 void model_components_material_startup(void)
30 test_return_value = TET_UNDEF;
33 void model_components_material_cleanup(void)
35 test_return_value = TET_PASS;
42 // Positive test case for a method
43 int UtcDaliMaterialNew(void)
45 ToolkitTestApplication application;
46 tet_infoline(" UtcDaliMaterialNew");
48 Scene3D::Material material = Scene3D::Material::New();
49 DALI_TEST_CHECK(material);
53 // Positive test case for a method
54 int UtcDaliMaterialDownCast(void)
56 ToolkitTestApplication application;
57 tet_infoline(" UtcDaliMaterialDownCast");
59 Scene3D::Material material = Scene3D::Material::New();
60 BaseHandle handle(material);
62 Scene3D::Material material2 = Scene3D::Material::DownCast(handle);
63 DALI_TEST_CHECK(material);
64 DALI_TEST_CHECK(material2);
65 DALI_TEST_CHECK(material2 == material);
69 int UtcDaliMaterialTypeRegistry(void)
71 ToolkitTestApplication application;
73 TypeRegistry typeRegistry = TypeRegistry::Get();
74 DALI_TEST_CHECK(typeRegistry);
76 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Material");
77 DALI_TEST_CHECK(typeInfo);
79 BaseHandle handle = typeInfo.CreateInstance();
80 DALI_TEST_CHECK(handle);
82 Scene3D::Material mateiral = Scene3D::Material::DownCast(handle);
83 DALI_TEST_CHECK(mateiral);
88 int UtcDaliMaterialCopyAndAssignment(void)
90 ToolkitTestApplication application;
92 Scene3D::Material mateiral = Scene3D::Material::New();
93 DALI_TEST_CHECK(mateiral);
95 Scene3D::Material copy(mateiral);
96 DALI_TEST_CHECK(mateiral == copy);
98 Scene3D::Material assign;
99 DALI_TEST_CHECK(!assign);
102 DALI_TEST_CHECK(assign == mateiral);
107 int UtcDaliMaterialMoveConstructor(void)
109 ToolkitTestApplication application;
111 Scene3D::Material mateiral = Scene3D::Material::New();
112 DALI_TEST_EQUALS(1, mateiral.GetBaseObject().ReferenceCount(), TEST_LOCATION);
114 Scene3D::Material moved = std::move(mateiral);
115 DALI_TEST_CHECK(moved);
116 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
117 DALI_TEST_CHECK(!mateiral);
122 int UtcDaliMaterialMoveAssignment(void)
124 ToolkitTestApplication application;
126 Scene3D::Material mateiral = Scene3D::Material::New();
127 DALI_TEST_EQUALS(1, mateiral.GetBaseObject().ReferenceCount(), TEST_LOCATION);
129 Scene3D::Material moved;
130 moved = std::move(mateiral);
131 DALI_TEST_CHECK(moved);
132 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
133 DALI_TEST_CHECK(!mateiral);
139 int UtcDaliMaterialSetGetProperty(void)
141 tet_infoline("UtcDaliMaterialSetGetProperty.");
143 ToolkitTestApplication application;
145 Scene3D::Material material = Scene3D::Material::New();
147 std::string name = "name";
148 material.SetProperty(Scene3D::Material::Property::NAME, name);
149 DALI_TEST_EQUALS(name, material.GetProperty<std::string>(Scene3D::Material::Property::NAME), TEST_LOCATION);
151 std::string baseColorUrl = "baseColorUrl";
152 material.SetProperty(Scene3D::Material::Property::BASE_COLOR_URL, baseColorUrl);
153 DALI_TEST_EQUALS(baseColorUrl, material.GetProperty<std::string>(Scene3D::Material::Property::BASE_COLOR_URL), TEST_LOCATION);
155 Vector4 baseColorFactor(0.1f, 0.2f, 0.3f, 0.4f);
156 material.SetProperty(Scene3D::Material::Property::BASE_COLOR_FACTOR, baseColorFactor);
157 DALI_TEST_EQUALS(baseColorFactor, material.GetProperty<Vector4>(Scene3D::Material::Property::BASE_COLOR_FACTOR), TEST_LOCATION);
159 std::string metallicRoughnessUrl = "metallicRoughnessUrl";
160 material.SetProperty(Scene3D::Material::Property::METALLIC_ROUGHNESS_URL, metallicRoughnessUrl);
161 DALI_TEST_EQUALS(metallicRoughnessUrl, material.GetProperty<std::string>(Scene3D::Material::Property::METALLIC_ROUGHNESS_URL), TEST_LOCATION);
163 float metallicFactor = 0.5f;
164 material.SetProperty(Scene3D::Material::Property::METALLIC_FACTOR, metallicFactor);
165 DALI_TEST_EQUALS(metallicFactor, material.GetProperty<float>(Scene3D::Material::Property::METALLIC_FACTOR), TEST_LOCATION);
167 float roughnessFactor = 0.6f;
168 material.SetProperty(Scene3D::Material::Property::ROUGHNESS_FACTOR, roughnessFactor);
169 DALI_TEST_EQUALS(roughnessFactor, material.GetProperty<float>(Scene3D::Material::Property::ROUGHNESS_FACTOR), TEST_LOCATION);
171 std::string normalUrl = "normalUrl";
172 material.SetProperty(Scene3D::Material::Property::NORMAL_URL, normalUrl);
173 DALI_TEST_EQUALS(normalUrl, material.GetProperty<std::string>(Scene3D::Material::Property::NORMAL_URL), TEST_LOCATION);
175 float normalScale = 0.7f;
176 material.SetProperty(Scene3D::Material::Property::NORMAL_SCALE, normalScale);
177 DALI_TEST_EQUALS(normalScale, material.GetProperty<float>(Scene3D::Material::Property::NORMAL_SCALE), TEST_LOCATION);
179 std::string occlusionUrl = "occlusionUrl";
180 material.SetProperty(Scene3D::Material::Property::OCCLUSION_URL, occlusionUrl);
181 DALI_TEST_EQUALS(occlusionUrl, material.GetProperty<std::string>(Scene3D::Material::Property::OCCLUSION_URL), TEST_LOCATION);
183 float occlusionStrength = 0.8f;
184 material.SetProperty(Scene3D::Material::Property::OCCLUSION_STRENGTH, occlusionStrength);
185 DALI_TEST_EQUALS(occlusionStrength, material.GetProperty<float>(Scene3D::Material::Property::OCCLUSION_STRENGTH), TEST_LOCATION);
187 std::string emissiveUrl = "emissiveUrl";
188 material.SetProperty(Scene3D::Material::Property::EMISSIVE_URL, emissiveUrl);
189 DALI_TEST_EQUALS(emissiveUrl, material.GetProperty<std::string>(Scene3D::Material::Property::EMISSIVE_URL), TEST_LOCATION);
191 Vector3 emissiveFactor(0.9f, 0.1f, 0.2f);
192 material.SetProperty(Scene3D::Material::Property::EMISSIVE_FACTOR, emissiveFactor);
193 DALI_TEST_EQUALS(emissiveFactor, material.GetProperty<Vector3>(Scene3D::Material::Property::EMISSIVE_FACTOR), TEST_LOCATION);
196 material.SetProperty(Scene3D::Material::Property::ALPHA_MODE, alphaMode);
197 DALI_TEST_EQUALS(alphaMode, material.GetProperty<int>(Scene3D::Material ::Property ::ALPHA_MODE), TEST_LOCATION);
199 float alphaCutoff = 0.9f;
200 material.SetProperty(Scene3D ::Material ::Property ::ALPHA_CUTOFF, alphaCutoff);
201 DALI_TEST_EQUALS(alphaCutoff, material.GetProperty<float>(Scene3D ::Material ::Property ::ALPHA_CUTOFF), TEST_LOCATION);
203 bool doubleSided = true;
204 material.SetProperty(Scene3D ::Material ::Property ::DOUBLE_SIDED, doubleSided);
205 DALI_TEST_EQUALS(doubleSided, material.GetProperty<bool>(Scene3D ::Material ::Property ::DOUBLE_SIDED), TEST_LOCATION);
208 material.SetProperty(Scene3D::Material::Property::IOR, ior);
209 DALI_TEST_EQUALS(ior, material.GetProperty<float>(Scene3D::Material::Property::IOR), TEST_LOCATION);
211 std::string specularUrl = "specularUrl";
212 material.SetProperty(Scene3D::Material::Property::SPECULAR_URL, specularUrl);
213 DALI_TEST_EQUALS(specularUrl, material.GetProperty<std::string>(Scene3D::Material::Property::SPECULAR_URL), TEST_LOCATION);
215 float specularFactor = 1.0f;
216 material.SetProperty(Scene3D::Material::Property::SPECULAR_FACTOR, specularFactor);
217 DALI_TEST_EQUALS(specularFactor, material.GetProperty<float>(Scene3D::Material::Property::SPECULAR_FACTOR), TEST_LOCATION);
219 std::string specularColorUrl = "specularColorUrl";
220 material.SetProperty(Scene3D::Material::Property::SPECULAR_COLOR_URL, specularColorUrl);
221 DALI_TEST_EQUALS(specularColorUrl, material.GetProperty<std::string>(Scene3D::Material::Property::SPECULAR_COLOR_URL), TEST_LOCATION);
223 Vector3 specularColorFactor(1.0f, 1.0f, 1.0f);
224 material.SetProperty(Scene3D::Material::Property::SPECULAR_COLOR_FACTOR, specularColorFactor);
225 DALI_TEST_EQUALS(specularColorFactor, material.GetProperty<Vector3>(Scene3D::Material::Property::SPECULAR_COLOR_FACTOR), TEST_LOCATION);
230 int UtcDaliMaterialSetGetTexture(void)
232 tet_infoline("UtcDaliMaterialSetGetTexture.");
234 ToolkitTestApplication application;
236 Scene3D::Material material = Scene3D::Material::New();
238 Dali::Texture baseColor = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
239 material.SetTexture(Scene3D::Material::TextureType::BASE_COLOR, baseColor);
240 DALI_TEST_EQUALS(baseColor, material.GetTexture(Scene3D::Material::TextureType::BASE_COLOR), TEST_LOCATION);
242 Dali::Texture metallicRoughness = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
243 material.SetTexture(Scene3D::Material::TextureType::METALLIC_ROUGHNESS, metallicRoughness);
244 DALI_TEST_EQUALS(metallicRoughness, material.GetTexture(Scene3D::Material::TextureType::METALLIC_ROUGHNESS), TEST_LOCATION);
246 Dali::Texture normal = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
247 material.SetTexture(Scene3D::Material::TextureType::NORMAL, normal);
248 DALI_TEST_EQUALS(normal, material.GetTexture(Scene3D::Material::TextureType::NORMAL), TEST_LOCATION);
250 Dali::Texture occlusion = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
251 material.SetTexture(Scene3D::Material::TextureType::OCCLUSION, occlusion);
252 DALI_TEST_EQUALS(occlusion, material.GetTexture(Scene3D::Material::TextureType::OCCLUSION), TEST_LOCATION);
254 Dali::Texture emissive = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
255 material.SetTexture(Scene3D::Material::TextureType::EMISSIVE, emissive);
256 DALI_TEST_EQUALS(emissive, material.GetTexture(Scene3D::Material::TextureType::EMISSIVE), TEST_LOCATION);
258 Dali::Texture specular = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
259 material.SetTexture(Scene3D::Material::TextureType::SPECULAR, specular);
260 DALI_TEST_EQUALS(specular, material.GetTexture(Scene3D::Material::TextureType::SPECULAR), TEST_LOCATION);
262 Dali::Texture specularColor = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
263 material.SetTexture(Scene3D::Material::TextureType::SPECULAR_COLOR, specularColor);
264 DALI_TEST_EQUALS(specularColor, material.GetTexture(Scene3D::Material::TextureType::SPECULAR_COLOR), TEST_LOCATION);
266 DALI_TEST_CHECK(!material.GetTexture((Scene3D::Material::TextureType)100));
271 int UtcDaliMaterialSetGetSampler(void)
273 tet_infoline("UtcDaliMaterialSetGetSampler.");
275 ToolkitTestApplication application;
277 Scene3D::Material material = Scene3D::Material::New();
279 Dali::Sampler baseColor = Dali::Sampler::New();
280 material.SetSampler(Scene3D::Material::TextureType::BASE_COLOR, baseColor);
281 DALI_TEST_EQUALS(baseColor, material.GetSampler(Scene3D::Material::TextureType::BASE_COLOR), TEST_LOCATION);
283 Dali::Sampler metallicRoughness = Dali::Sampler::New();
284 material.SetSampler(Scene3D::Material::TextureType::METALLIC_ROUGHNESS, metallicRoughness);
285 DALI_TEST_EQUALS(metallicRoughness, material.GetSampler(Scene3D::Material::TextureType::METALLIC_ROUGHNESS), TEST_LOCATION);
287 Dali::Sampler normal = Dali::Sampler::New();
288 material.SetSampler(Scene3D::Material::TextureType::NORMAL, normal);
289 DALI_TEST_EQUALS(normal, material.GetSampler(Scene3D::Material::TextureType::NORMAL), TEST_LOCATION);
291 Dali::Sampler occlusion = Dali::Sampler::New();
292 material.SetSampler(Scene3D::Material::TextureType::OCCLUSION, occlusion);
293 DALI_TEST_EQUALS(occlusion, material.GetSampler(Scene3D::Material::TextureType::OCCLUSION), TEST_LOCATION);
295 Dali::Sampler emissive = Dali::Sampler::New();
296 material.SetSampler(Scene3D::Material::TextureType::EMISSIVE, emissive);
297 DALI_TEST_EQUALS(emissive, material.GetSampler(Scene3D::Material::TextureType::EMISSIVE), TEST_LOCATION);
299 Dali::Sampler specular = Dali::Sampler::New();
300 material.SetSampler(Scene3D::Material::TextureType::SPECULAR, specular);
301 DALI_TEST_EQUALS(specular, material.GetSampler(Scene3D::Material::TextureType::SPECULAR), TEST_LOCATION);
303 Dali::Sampler specularColor = Dali::Sampler::New();
304 material.SetSampler(Scene3D::Material::TextureType::SPECULAR_COLOR, specularColor);
305 DALI_TEST_EQUALS(specularColor, material.GetSampler(Scene3D::Material::TextureType::SPECULAR_COLOR), TEST_LOCATION);
307 DALI_TEST_CHECK(!material.GetSampler((Scene3D::Material::TextureType)100));