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"
26 #include "image-loaders.h"
31 * This class encapsulates knowledge of testing compressed files.
32 * It requires a few input parameters per test to confirm if the file was read and understood.
33 * The fixture guarantees that each test performed is setup and closed individually, therefore run order does not matter.
43 * This struct contains any per-test parameters.
44 * This should be added to if more properties of a file/format should be tested.
48 std::string filename; ///< Name of the compressed texture KTX file to load.
49 int expectedWidth; ///< The width the texture should be.
50 int expectedHeight; ///< The height the KTX texture should be.
52 TestEntry( std::string newFilename, int newExpectedWidth, int newExpectedHeight )
53 : filename( newFilename ),
54 expectedWidth( newExpectedWidth ),
55 expectedHeight( newExpectedHeight )
62 typedef std::vector< TestEntry > TestContainer;
67 * Adds a test to be performed.
68 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
70 void AddTest( TestEntry testEntry )
72 mTests.push_back( testEntry );
76 * Runs all tests created with "AddTest".
77 * This will create failures upon failing tests.
81 for( TestContainer::iterator testIterator = mTests.begin(); testIterator != mTests.end(); ++testIterator )
83 const TestEntry& currentTest = *testIterator;
85 RunTest( currentTest );
92 * Sets up, Runs and Closes-down an individual test.
93 * @param[in] testEntry A TestEntry struct containing all the details to perform one test.
95 void RunTest( const TestEntry& testEntry )
97 FILE* fileDescriptor = fopen( testEntry.filename.c_str(), "rb" );
98 AutoCloseFile autoClose( fileDescriptor );
99 DALI_TEST_CHECK( fileDescriptor != NULL );
101 // Check the header file.
102 unsigned int width( 0 ), height( 0 );
103 const Dali::TizenPlatform::ImageLoader::Input input( fileDescriptor );
105 DALI_TEST_CHECK( TizenPlatform::LoadKtxHeader( input, width, height ) );
107 DALI_TEST_EQUALS( width, testEntry.expectedWidth, TEST_LOCATION );
108 DALI_TEST_EQUALS( height, testEntry.expectedHeight, TEST_LOCATION );
113 TestContainer mTests; ///< Holds all tests to be run.
118 int UtcDaliKtxLoaderETC(void)
120 KtxTestFixture fixture;
122 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-ETC1_RGB8_OES-45x80.ktx", 45u, 80u ) );
123 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-RGB8_ETC2-45x80.ktx", 45u, 80u ) );
130 int UtcDaliKtxLoaderPVRTC(void)
132 KtxTestFixture fixture;
134 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-RGB_PVRTC_4BPPV1_IMG-32x64.ktx", 32u, 64u ) );
141 int UtcDaliKtxLoaderEAC(void)
143 KtxTestFixture fixture;
145 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-R11_EAC-45x80.ktx", 45u, 80u ) );
152 int UtcDaliKtxLoaderASTC(void)
154 KtxTestFixture fixture;
156 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );
157 fixture.AddTest( KtxTestFixture::TestEntry( TEST_IMAGE_DIR "/fractal-compressed-SRBG8_ALPHA8_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );