13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Internal Test Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * --------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Image IO tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "ditImageIOTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuResource.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageIO.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuFormatUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace dit 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2013-05-28 pyry] Image output cases! 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ImageReadCase : public tcu::TestCase 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ImageReadCase (tcu::TestContext& testCtx, const char* name, const char* filename, deUint32 expectedHash) 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, name, filename) 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_filename (filename) 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_expectedHash (expectedHash) 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void) 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Message << "Loading image from file '" << m_filename << "'" << TestLog::EndMessage; 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureLevel texture; 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ImageIO::loadImage(texture, m_testCtx.getArchive(), m_filename.c_str()); 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Message << "Loaded " << texture.getWidth() << "x" << texture.getHeight() << "x" << texture.getDepth() << " image with format " << texture.getFormat() << TestLog::EndMessage; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Check that layout is as expected 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(texture.getAccess().getRowPitch() == texture.getWidth()*texture.getFormat().getPixelSize()); 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(texture.getAccess().getSlicePitch() == texture.getAccess().getRowPitch()*texture.getAccess().getHeight()); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int imageSize = texture.getAccess().getSlicePitch()*texture.getDepth(); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 hash = deMemoryHash(texture.getAccess().getDataPtr(), imageSize); 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (hash != m_expectedHash) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Message << "ERROR: expected hash " << tcu::toHex(m_expectedHash) << ", got " << tcu::toHex(hash) << TestLog::EndMessage; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Image("Image", "Loaded image", texture.getAccess()); 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Hash check failed"); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string m_filename; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_expectedHash; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ImageReadTests : public tcu::TestCaseGroup 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ImageReadTests (tcu::TestContext& testCtx) 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(testCtx, "read", "Image read tests") 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 934e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos addChild(new ImageReadCase(m_testCtx, "rgb24_256x256", "internal/data/imageio/rgb24_256x256.png", 0x6efad777)); 944e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos addChild(new ImageReadCase(m_testCtx, "rgb24_209x181", "internal/data/imageio/rgb24_209x181.png", 0xfd6ea668)); 954e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos addChild(new ImageReadCase(m_testCtx, "rgba32_256x256", "internal/data/imageio/rgba32_256x256.png", 0xcf4883da)); 964e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos addChild(new ImageReadCase(m_testCtx, "rgba32_207x219", "internal/data/imageio/rgba32_207x219.png", 0x404ba06b)); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryImageIOTests::ImageIOTests(tcu::TestContext& testCtx) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(testCtx, "image_io", "Image read and write tests") 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryImageIOTests::~ImageIOTests (void) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ImageIOTests::init (void) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ImageReadTests(m_testCtx)); 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // dit 115