1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <gmock/gmock.h>
16
17 #include "AstcCpuDecompressor.h"
18
19 namespace gfxstream {
20 namespace vk {
21 namespace {
22
23 using ::testing::ElementsAreArray;
24 using ::testing::NotNull;
25
26 // 16x16 checkerboard pattern, compressed with 8x8 block size.
27 const uint8_t kCheckerboard[] = {
28 0x44, 0x05, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
29 0x44, 0x05, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
30 0x44, 0x05, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
31 0x44, 0x05, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
32
33 struct Rgba {
34 uint8_t r, g, b, a;
operator ==gfxstream::vk::__anon9b535c640111::Rgba35 bool operator==(const Rgba& o) const { return r == o.r && g == o.g && b == o.b && a == o.a; }
36 };
37
TEST(AstcCpuDecompressor,Decompress)38 TEST(AstcCpuDecompressor, Decompress) {
39 auto& decompressor = AstcCpuDecompressor::get();
40 if (!decompressor.available()) GTEST_SKIP() << "ASTC decompressor not available";
41
42 std::vector<Rgba> output(16 * 16);
43 int32_t status = decompressor.decompress(16, 16, 8, 8, kCheckerboard, sizeof(kCheckerboard),
44 (uint8_t*)output.data());
45 EXPECT_EQ(status, 0);
46
47 const Rgba W = {0xFF, 0xFF, 0xFF, 0xFF};
48 const Rgba B = {0, 0, 0, 0xFF};
49
50 std::vector<Rgba> expected = {
51 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 0
52 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 1
53 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 2
54 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 3
55 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 4
56 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 5
57 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 6
58 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 7
59 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 8
60 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 9
61 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 10
62 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 11
63 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 12
64 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 13
65 W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, // 14
66 B, W, B, W, B, W, B, W, B, W, B, W, B, W, B, W, // 15
67 };
68
69 ASSERT_THAT(output, ElementsAreArray(expected));
70 }
71
TEST(AstcCpuDecompressor,getStatusStringAlwaysNonNull)72 TEST(AstcCpuDecompressor, getStatusStringAlwaysNonNull) {
73 EXPECT_THAT(AstcCpuDecompressor::get().getStatusString(-10000), NotNull());
74 }
75
76 } // namespace
77 } // namespace vk
78 } // namespace gfxstream