1 //
2 // Copyright 2022 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // AstcDecompressor_unittest.cpp: Unit tests for AstcDecompressor
7
8 #include <gmock/gmock.h>
9 #include <vector>
10
11 #include "common/WorkerThread.h"
12 #include "image_util/AstcDecompressor.h"
13 #include "image_util/AstcDecompressorTestUtils.h"
14
15 using namespace angle;
16 using namespace testing;
17
18 namespace
19 {
20
21 // Test that we can correctly decompress an image
TEST(AstcDecompressor,Decompress)22 TEST(AstcDecompressor, Decompress)
23 {
24 const int width = 1024;
25 const int height = 1024;
26
27 auto singleThreadedPool = WorkerThreadPool::Create(1, ANGLEPlatformCurrent());
28 auto multiThreadedPool = WorkerThreadPool::Create(0, ANGLEPlatformCurrent());
29
30 auto &decompressor = AstcDecompressor::get();
31 if (!decompressor.available())
32 GTEST_SKIP() << "ASTC decompressor not available";
33
34 std::vector<Rgba> output(width * height);
35 std::vector<uint8_t> astcData = makeAstcCheckerboard(width, height);
36 int32_t status =
37 decompressor.decompress(singleThreadedPool, multiThreadedPool, width, height, 8, 8,
38 astcData.data(), astcData.size(), (uint8_t *)output.data());
39 EXPECT_EQ(status, 0);
40
41 std::vector<Rgba> expected = makeCheckerboard(width, height);
42
43 ASSERT_THAT(output, ElementsAreArray(expected));
44 }
45
46 // Test that getStatusString returns non-null even for unknown statuses
TEST(AstcDecompressor,getStatusStringAlwaysNonNull)47 TEST(AstcDecompressor, getStatusStringAlwaysNonNull)
48 {
49 EXPECT_THAT(AstcDecompressor::get().getStatusString(-10000), NotNull());
50 }
51
52 } // namespace