Compute min/max value if min/max is not defined.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader / utc-Dali-CubeLoader.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-scene-loader/public-api/cube-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::SceneLoader;
29
30 int UtcDaliCubeLoaderFailNonexistent(void)
31 {
32   CubeData data;
33   DALI_TEST_CHECK(!LoadCubeData("non-existent.jpg", data));
34   END_TEST;
35 }
36
37 int UtcDaliCubeLoaderFailInvalid1(void)
38 {
39   CubeData data;
40   DALI_TEST_CHECK(!LoadCubeData(TEST_RESOURCE_DIR "/gallery-small-1.jpg", data)); // Wrong sized image
41   END_TEST;
42 }
43
44 int UtcDaliCubeLoaderSuccess01(void)
45 {
46   CubeData cubeData;
47   auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";  // cross horizontal
48   DALI_TEST_CHECK(LoadCubeData(path, cubeData));
49
50   DALI_TEST_EQUAL(6u, cubeData.data.size());
51   for (auto& face: cubeData.data)
52   {
53     uint32_t size = 512;
54     DALI_TEST_EQUAL(size, face[0].GetWidth());
55     DALI_TEST_EQUAL(size, face[0].GetHeight());
56     DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
57   }
58
59   END_TEST;
60 }
61
62 int UtcDaliCubeLoaderSuccess02(void)
63 {
64   CubeData cubeData;
65   auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap_cross_vertical.png"; // cross vertical
66   DALI_TEST_CHECK(LoadCubeData(path, cubeData));
67
68   DALI_TEST_EQUAL(6u, cubeData.data.size());
69   for (auto& face: cubeData.data)
70   {
71     uint32_t size = 256;
72     DALI_TEST_EQUAL(size, face[0].GetWidth());
73     DALI_TEST_EQUAL(size, face[0].GetHeight());
74     DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
75   }
76
77   END_TEST;
78 }
79
80 int UtcDaliCubeLoaderSuccess03(void)
81 {
82   CubeData cubeData;
83   auto path = TEST_RESOURCE_DIR "/cubemap_array_horizontal.png"; // array horizontal
84   DALI_TEST_CHECK(LoadCubeData(path, cubeData));
85
86   DALI_TEST_EQUAL(6u, cubeData.data.size());
87   for (auto& face: cubeData.data)
88   {
89     uint32_t size = 100;
90     DALI_TEST_EQUAL(size, face[0].GetWidth());
91     DALI_TEST_EQUAL(size, face[0].GetHeight());
92     DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
93   }
94
95   END_TEST;
96 }
97
98 int UtcDaliCubeLoaderSuccess04(void)
99 {
100   CubeData cubeData;
101   auto path = TEST_RESOURCE_DIR "/cubemap_array_vertical.png"; // array horizontal
102   DALI_TEST_CHECK(LoadCubeData(path, cubeData));
103
104   DALI_TEST_EQUAL(6u, cubeData.data.size());
105   for (auto& face: cubeData.data)
106   {
107     uint32_t size = 100;
108     DALI_TEST_EQUAL(size, face[0].GetWidth());
109     DALI_TEST_EQUAL(size, face[0].GetHeight());
110     DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
111   }
112
113   END_TEST;
114 }
115
116 int UtcDaliCubeLoaderCubeDataCreateTexture(void)
117 {
118   CubeData cubeData;
119   auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
120   DALI_TEST_CHECK(LoadCubeData(path, cubeData));
121
122   TestApplication app;
123   auto texture = cubeData.CreateTexture();
124
125   DALI_TEST_CHECK(texture);
126   DALI_TEST_EQUAL(512u, texture.GetWidth());
127   DALI_TEST_EQUAL(512u, texture.GetHeight());
128
129   END_TEST;
130 }