Add CTS_ARB_gl_spirv test implementation
[platform/upstream/VK-GL-CTS.git] / modules / internal / ditImageIOTests.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Internal Test Module
3  * ---------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief Image IO tests.
22  *//*--------------------------------------------------------------------*/
23
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"
31 #include "deString.h"
32
33 namespace dit
34 {
35
36 using tcu::TestLog;
37
38 // \todo [2013-05-28 pyry] Image output cases!
39
40 class ImageReadCase : public tcu::TestCase
41 {
42 public:
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)
47         {
48         }
49
50         IterateResult iterate (void)
51         {
52                 m_testCtx.getLog() << TestLog::Message << "Loading image from file '" << m_filename << "'" << TestLog::EndMessage;
53
54                 tcu::TextureLevel texture;
55                 tcu::ImageIO::loadImage(texture, m_testCtx.getArchive(), m_filename.c_str());
56
57                 m_testCtx.getLog() << TestLog::Message << "Loaded " << texture.getWidth() << "x" << texture.getHeight() << "x" << texture.getDepth() << " image with format " << texture.getFormat() << TestLog::EndMessage;
58
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());
62
63                 const int               imageSize       = texture.getAccess().getSlicePitch()*texture.getDepth();
64                 const deUint32  hash            = deMemoryHash(texture.getAccess().getDataPtr(), imageSize);
65
66                 if (hash != m_expectedHash)
67                 {
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");
71                 }
72                 else
73                         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
74
75                 return STOP;
76         }
77
78 private:
79         const std::string               m_filename;
80         const deUint32                  m_expectedHash;
81 };
82
83 class ImageReadTests : public tcu::TestCaseGroup
84 {
85 public:
86         ImageReadTests (tcu::TestContext& testCtx)
87                 : TestCaseGroup(testCtx, "read", "Image read tests")
88         {
89         }
90
91         void init (void)
92         {
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));
97         }
98 };
99
100 ImageIOTests::ImageIOTests(tcu::TestContext& testCtx)
101         : TestCaseGroup(testCtx, "image_io", "Image read and write tests")
102 {
103 }
104
105 ImageIOTests::~ImageIOTests (void)
106 {
107 }
108
109 void ImageIOTests::init (void)
110 {
111         addChild(new ImageReadTests(m_testCtx));
112 }
113
114 } // dit