2 * Copyright (c) 2016 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.
22 #include <dali-test-suite-utils.h>
23 #include "platform-abstractions/tizen/image-loaders/loader-ktx.h"
24 #include "platform-abstractions/tizen/image-loaders/loader-astc.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.
46 * Sets up the fixture.
48 KtxTestFixture( void )
60 * This struct contains any per-test parameters.
61 * This should be added to if more properties of a file/format should be tested.
65 LoadFunctions loadFunctions; ///< Used to parse the header of a given type of image.
66 std::string filename; ///< Name of the compressed texture KTX file to load.
67 int expectedWidth; ///< The width the texture should be.
68 int expectedHeight; ///< The height the KTX texture should be.
70 TestEntry( const LoadFunctions& newLoadFunctions, std::string newFilename, int newExpectedWidth, int newExpectedHeight )
71 : loadFunctions( newLoadFunctions ),
72 filename( newFilename ),
73 expectedWidth( newExpectedWidth ),
74 expectedHeight( newExpectedHeight )
81 typedef std::vector< TestEntry > TestContainer;
86 * Adds a test to be performed.
87 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
89 void AddTest( TestEntry testEntry )
91 mTests.push_back( testEntry );
95 * Runs all tests created with "AddTest".
96 * This will create failures upon failing tests.
100 for( TestContainer::iterator testIterator = mTests.begin(); testIterator != mTests.end(); ++testIterator )
102 const TestEntry& currentTest = *testIterator;
104 RunTest( currentTest );
111 * Sets up, Runs and Closes-down an individual test.
112 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
114 void RunTest( const TestEntry& testEntry )
116 FILE* fileDescriptor = fopen( testEntry.filename.c_str(), "rb" );
117 AutoCloseFile autoClose( fileDescriptor );
118 DALI_TEST_CHECK( fileDescriptor != NULL );
120 // Check the header file.
121 unsigned int width( 0 ), height( 0 );
122 const Dali::TizenPlatform::ImageLoader::Input input( fileDescriptor );
124 // Use the given loader to parse the image header.
125 DALI_TEST_CHECK( testEntry.loadFunctions.header( input, width, height ) );
127 DALI_TEST_EQUALS( width, testEntry.expectedWidth, TEST_LOCATION );
128 DALI_TEST_EQUALS( height, testEntry.expectedHeight, TEST_LOCATION );
133 TestContainer mTests; ///< Holds all tests to be run.
137 // KTX files (KTX is a wrapper, so can contain different compressed texture types):
139 int UtcDaliKtxLoaderETC(void)
141 KtxTestFixture fixture;
143 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-ETC1_RGB8_OES-45x80.ktx", 45u, 80u ) );
144 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB8_ETC2-45x80.ktx", 45u, 80u ) );
151 int UtcDaliKtxLoaderPVRTC(void)
153 KtxTestFixture fixture;
155 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB_PVRTC_4BPPV1_IMG-32x64.ktx", 32u, 64u ) );
162 int UtcDaliKtxLoaderEAC(void)
164 KtxTestFixture fixture;
166 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-R11_EAC-45x80.ktx", 45u, 80u ) );
173 int UtcDaliKtxLoaderASTC(void)
175 KtxTestFixture fixture;
177 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );
178 fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-SRBG8_ALPHA8_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );
186 // ASTC (Native) files:
187 int UtcDaliAstcLoader(void)
189 KtxTestFixture fixture;
191 fixture.AddTest( KtxTestFixture::TestEntry( AstcLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.astc", 32u, 64u ) );