1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Image IO tests.
22 *//*--------------------------------------------------------------------*/
24 #include "ditImageIOTests.hpp"
25 #include "tcuResource.hpp"
26 #include "tcuImageIO.hpp"
27 #include "tcuTexture.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "deUniquePtr.hpp"
38 // \todo [2013-05-28 pyry] Image output cases!
40 class ImageReadCase : public tcu::TestCase
43 ImageReadCase (tcu::TestContext& testCtx, const char* name, const char* filename, deUint32 expectedHash)
44 : TestCase (testCtx, name, filename)
45 , m_filename (filename)
46 , m_expectedHash (expectedHash)
50 IterateResult iterate (void)
52 m_testCtx.getLog() << TestLog::Message << "Loading image from file '" << m_filename << "'" << TestLog::EndMessage;
54 tcu::TextureLevel texture;
55 tcu::ImageIO::loadImage(texture, m_testCtx.getArchive(), m_filename.c_str());
57 m_testCtx.getLog() << TestLog::Message << "Loaded " << texture.getWidth() << "x" << texture.getHeight() << "x" << texture.getDepth() << " image with format " << texture.getFormat() << TestLog::EndMessage;
59 // Check that layout is as expected
60 TCU_CHECK(texture.getAccess().getRowPitch() == texture.getWidth()*texture.getFormat().getPixelSize());
61 TCU_CHECK(texture.getAccess().getSlicePitch() == texture.getAccess().getRowPitch()*texture.getAccess().getHeight());
63 const int imageSize = texture.getAccess().getSlicePitch()*texture.getDepth();
64 const deUint32 hash = deMemoryHash(texture.getAccess().getDataPtr(), imageSize);
66 if (hash != m_expectedHash)
68 m_testCtx.getLog() << TestLog::Message << "ERROR: expected hash " << tcu::toHex(m_expectedHash) << ", got " << tcu::toHex(hash) << TestLog::EndMessage;
69 m_testCtx.getLog() << TestLog::Image("Image", "Loaded image", texture.getAccess());
70 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Hash check failed");
73 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
79 const std::string m_filename;
80 const deUint32 m_expectedHash;
83 class ImageReadTests : public tcu::TestCaseGroup
86 ImageReadTests (tcu::TestContext& testCtx)
87 : TestCaseGroup(testCtx, "read", "Image read tests")
93 addChild(new ImageReadCase(m_testCtx, "rgb24_256x256", "internal/data/imageio/rgb24_256x256.png", 0x6efad777));
94 addChild(new ImageReadCase(m_testCtx, "rgb24_209x181", "internal/data/imageio/rgb24_209x181.png", 0xfd6ea668));
95 addChild(new ImageReadCase(m_testCtx, "rgba32_256x256", "internal/data/imageio/rgba32_256x256.png", 0xcf4883da));
96 addChild(new ImageReadCase(m_testCtx, "rgba32_207x219", "internal/data/imageio/rgba32_207x219.png", 0x404ba06b));
100 ImageIOTests::ImageIOTests(tcu::TestContext& testCtx)
101 : TestCaseGroup(testCtx, "image_io", "Image read and write tests")
105 ImageIOTests::~ImageIOTests (void)
109 void ImageIOTests::init (void)
111 addChild(new ImageReadTests(m_testCtx));