Compute min/max value if min/max is not defined.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-CubeMapLoader.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include "dali-scene3d/public-api/loader/cube-map-loader.h"
22 #include <dali-test-suite-utils.h>
23 #include <string_view>
24
25 #include <fstream>
26
27 using namespace Dali;
28 using namespace Dali::Scene3D::Loader;
29
30 int UtcDaliCubeMapLoaderFailNonexistent(void)
31 {
32   CubeData data;
33   DALI_TEST_CHECK(!LoadCubeMapData("non-existent.jpg", data));
34   END_TEST;
35 }
36
37 int UtcDaliCubeMapLoaderFailInvalid1(void)
38 {
39   CubeData data;
40   DALI_TEST_CHECK(!LoadCubeMapData(TEST_RESOURCE_DIR "/gallery-small-1.jpg", data)); // Wrong sized image
41   END_TEST;
42 }
43
44 int UtcDaliCubeMapLoaderSuccess01(void)
45 {
46   CubeData cubeData;
47   auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
48   DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
49
50   DALI_TEST_EQUAL(6u, cubeData.data.size());
51   for (auto& face: cubeData.data)
52   {
53     uint32_t size = 64;
54     for (auto& mipData: face)
55     {
56       DALI_TEST_EQUAL(size, mipData.GetWidth());
57       DALI_TEST_EQUAL(size, mipData.GetHeight());
58       DALI_TEST_EQUAL(Pixel::Format::RGB888, mipData.GetPixelFormat());
59       size /= 2;
60     }
61   }
62
63   END_TEST;
64 }
65
66 int UtcDaliCubeMapLoaderSuccess02(void)
67 {
68   CubeData cubeData;
69   auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";  // cross horizontal
70   DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
71
72   DALI_TEST_EQUAL(6u, cubeData.data.size());
73   for (auto& face: cubeData.data)
74   {
75     uint32_t size = 512;
76     DALI_TEST_EQUAL(size, face[0].GetWidth());
77     DALI_TEST_EQUAL(size, face[0].GetHeight());
78     DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
79   }
80
81   END_TEST;
82 }
83
84 int UtcDaliCubeMapLoaderCubeDataCreateTexture01(void)
85 {
86   CubeData cubeData;
87   auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
88   DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
89
90   TestApplication app;
91   auto texture = cubeData.CreateTexture();
92
93   DALI_TEST_CHECK(texture);
94   DALI_TEST_EQUAL(64u, texture.GetWidth());
95   DALI_TEST_EQUAL(64u, texture.GetHeight());
96
97   END_TEST;
98 }
99
100 int UtcDaliCubeMapLoaderCubeDataCreateTexture02(void)
101 {
102   CubeData cubeData;
103   auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
104   DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
105
106   TestApplication app;
107   auto texture = cubeData.CreateTexture();
108
109   DALI_TEST_CHECK(texture);
110   DALI_TEST_EQUAL(512u, texture.GetWidth());
111   DALI_TEST_EQUAL(512u, texture.GetHeight());
112
113   END_TEST;
114 }