2 * Copyright (c) 2020 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.
19 #include <dali-test-suite-utils.h>
20 #include <dali/internal/imaging/common/loader-astc.h>
21 #include <dali/internal/imaging/common/loader-ktx.h>
27 #include "image-loaders.h"
31 // Pre-define loader functions for each image type being tested (as they are reused in different tests).
32 static const LoadFunctions KtxLoaders(TizenPlatform::LoadKtxHeader, TizenPlatform::LoadBitmapFromKtx);
33 static const LoadFunctions AstcLoaders(TizenPlatform::LoadAstcHeader, TizenPlatform::LoadBitmapFromAstc);
36 * This class encapsulates knowledge of testing compressed files.
37 * It requires a few input parameters per test to confirm if the file was read and understood.
38 * The fixture guarantees that each test performed is setup and closed individually, therefore run order does not matter.
45 * Sets up the fixture.
59 * This struct contains any per-test parameters.
60 * This should be added to if more properties of a file/format should be tested.
64 LoadFunctions loadFunctions; ///< Used to parse the header of a given type of image.
65 std::string filename; ///< Name of the compressed texture KTX file to load.
66 int expectedWidth; ///< The width the texture should be.
67 int expectedHeight; ///< The height the KTX texture should be.
69 TestEntry(const LoadFunctions& newLoadFunctions, std::string newFilename, int newExpectedWidth, int newExpectedHeight)
70 : loadFunctions(newLoadFunctions),
71 filename(newFilename),
72 expectedWidth(newExpectedWidth),
73 expectedHeight(newExpectedHeight)
79 typedef std::vector<TestEntry> TestContainer;
83 * Adds a test to be performed.
84 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
86 void AddTest(TestEntry testEntry)
88 mTests.push_back(testEntry);
92 * Runs all tests created with "AddTest".
93 * This will create failures upon failing tests.
97 for(TestContainer::iterator testIterator = mTests.begin(); testIterator != mTests.end(); ++testIterator)
99 const TestEntry& currentTest = *testIterator;
101 RunTest(currentTest);
107 * Sets up, Runs and Closes-down an individual test.
108 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
110 void RunTest(const TestEntry& testEntry)
112 FILE* fileDescriptor = fopen(testEntry.filename.c_str(), "rb");
113 AutoCloseFile autoClose(fileDescriptor);
114 DALI_TEST_CHECK(fileDescriptor != NULL);
116 // Check the header file.
117 unsigned int width(0), height(0);
118 const Dali::ImageLoader::Input input(fileDescriptor);
120 // Use the given loader to parse the image header.
121 DALI_TEST_CHECK(testEntry.loadFunctions.header(input, width, height));
123 DALI_TEST_EQUALS(width, testEntry.expectedWidth, TEST_LOCATION);
124 DALI_TEST_EQUALS(height, testEntry.expectedHeight, TEST_LOCATION);
128 TestContainer mTests; ///< Holds all tests to be run.
131 // KTX files (KTX is a wrapper, so can contain different compressed texture types):
133 int UtcDaliKtxLoaderETC(void)
135 KtxTestFixture fixture;
137 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-ETC1_RGB8_OES-45x80.ktx", 45u, 80u));
138 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB8_ETC2-45x80.ktx", 45u, 80u));
145 int UtcDaliKtxLoaderPVRTC(void)
147 KtxTestFixture fixture;
149 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB_PVRTC_4BPPV1_IMG-32x64.ktx", 32u, 64u));
156 int UtcDaliKtxLoaderEAC(void)
158 KtxTestFixture fixture;
160 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-R11_EAC-45x80.ktx", 45u, 80u));
167 int UtcDaliKtxLoaderASTC(void)
169 KtxTestFixture fixture;
171 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.ktx", 32u, 64u));
172 fixture.AddTest(KtxTestFixture::TestEntry(KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-SRBG8_ALPHA8_ASTC_4x4_KHR-32x64.ktx", 32u, 64u));
179 // ASTC (Native) files:
180 int UtcDaliAstcLoader(void)
182 KtxTestFixture fixture;
184 fixture.AddTest(KtxTestFixture::TestEntry(AstcLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.astc", 32u, 64u));