]> granicus.if.org Git - libvpx/blob - test/idct_test.cc
Merge "endian_inl.h: fix mips32 android build"
[libvpx] / test / idct_test.cc
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include "./vpx_config.h"
12 #include "./vp8_rtcd.h"
13
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15
16 #include "test/clear_system_state.h"
17 #include "test/register_state_check.h"
18 #include "vpx/vpx_integer.h"
19
20 typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
21                          int pred_stride, unsigned char *dst_ptr,
22                          int dst_stride);
23 namespace {
24 class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
25  protected:
26   virtual void SetUp() {
27     int i;
28
29     UUT = GetParam();
30     memset(input, 0, sizeof(input));
31     /* Set up guard blocks */
32     for (i = 0; i < 256; i++) output[i] = ((i & 0xF) < 4 && (i < 64)) ? 0 : -1;
33   }
34
35   virtual void TearDown() { libvpx_test::ClearSystemState(); }
36
37   IdctFunc UUT;
38   int16_t input[16];
39   unsigned char output[256];
40   unsigned char predict[256];
41 };
42
43 TEST_P(IDCTTest, TestGuardBlocks) {
44   int i;
45
46   for (i = 0; i < 256; i++)
47     if ((i & 0xF) < 4 && i < 64)
48       EXPECT_EQ(0, output[i]) << i;
49     else
50       EXPECT_EQ(255, output[i]);
51 }
52
53 TEST_P(IDCTTest, TestAllZeros) {
54   int i;
55
56   ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
57
58   for (i = 0; i < 256; i++)
59     if ((i & 0xF) < 4 && i < 64)
60       EXPECT_EQ(0, output[i]) << "i==" << i;
61     else
62       EXPECT_EQ(255, output[i]) << "i==" << i;
63 }
64
65 TEST_P(IDCTTest, TestAllOnes) {
66   int i;
67
68   input[0] = 4;
69   ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
70
71   for (i = 0; i < 256; i++)
72     if ((i & 0xF) < 4 && i < 64)
73       EXPECT_EQ(1, output[i]) << "i==" << i;
74     else
75       EXPECT_EQ(255, output[i]) << "i==" << i;
76 }
77
78 TEST_P(IDCTTest, TestAddOne) {
79   int i;
80
81   for (i = 0; i < 256; i++) predict[i] = i;
82   input[0] = 4;
83   ASM_REGISTER_STATE_CHECK(UUT(input, predict, 16, output, 16));
84
85   for (i = 0; i < 256; i++)
86     if ((i & 0xF) < 4 && i < 64)
87       EXPECT_EQ(i + 1, output[i]) << "i==" << i;
88     else
89       EXPECT_EQ(255, output[i]) << "i==" << i;
90 }
91
92 TEST_P(IDCTTest, TestWithData) {
93   int i;
94
95   for (i = 0; i < 16; i++) input[i] = i;
96
97   ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
98
99   for (i = 0; i < 256; i++)
100     if ((i & 0xF) > 3 || i > 63)
101       EXPECT_EQ(255, output[i]) << "i==" << i;
102     else if (i == 0)
103       EXPECT_EQ(11, output[i]) << "i==" << i;
104     else if (i == 34)
105       EXPECT_EQ(1, output[i]) << "i==" << i;
106     else if (i == 2 || i == 17 || i == 32)
107       EXPECT_EQ(3, output[i]) << "i==" << i;
108     else
109       EXPECT_EQ(0, output[i]) << "i==" << i;
110 }
111
112 INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
113 #if HAVE_MMX
114 INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
115                         ::testing::Values(vp8_short_idct4x4llm_mmx));
116 #endif
117 #if HAVE_MSA
118 INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
119                         ::testing::Values(vp8_short_idct4x4llm_msa));
120 #endif
121 }