idct_test.cc 3.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

11 12
#include "./vpx_config.h"
#include "./vp8_rtcd.h"
13
#include "test/clear_system_state.h"
14
#include "test/register_state_check.h"
15
#include "third_party/googletest/src/include/gtest/gtest.h"
16

17 18
#include "vpx/vpx_integer.h"

19 20 21
typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
                         int pred_stride, unsigned char *dst_ptr,
                         int dst_stride);
22
namespace {
23
class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
24 25 26 27 28 29 30 31 32 33 34 35
 protected:
  virtual void SetUp() {
    int i;

    UUT = GetParam();
    memset(input, 0, sizeof(input));
    /* Set up guard blocks */
    for (i = 0; i < 256; i++) output[i] = ((i & 0xF) < 4 && (i < 64)) ? 0 : -1;
  }

  virtual void TearDown() { libvpx_test::ClearSystemState(); }

36
  IdctFunc UUT;
Yaowu Xu's avatar
Yaowu Xu committed
37
  int16_t input[16];
38 39
  unsigned char output[256];
  unsigned char predict[256];
40 41
};

42
TEST_P(IDCTTest, TestGuardBlocks) {
43
  int i;
44

45 46 47 48 49
  for (i = 0; i < 256; i++)
    if ((i & 0xF) < 4 && i < 64)
      EXPECT_EQ(0, output[i]) << i;
    else
      EXPECT_EQ(255, output[i]);
50 51
}

52
TEST_P(IDCTTest, TestAllZeros) {
53
  int i;
54

55
  ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
56

57 58 59 60 61
  for (i = 0; i < 256; i++)
    if ((i & 0xF) < 4 && i < 64)
      EXPECT_EQ(0, output[i]) << "i==" << i;
    else
      EXPECT_EQ(255, output[i]) << "i==" << i;
62 63
}

64
TEST_P(IDCTTest, TestAllOnes) {
65
  int i;
66

67
  input[0] = 4;
68
  ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
69

70 71 72 73 74
  for (i = 0; i < 256; i++)
    if ((i & 0xF) < 4 && i < 64)
      EXPECT_EQ(1, output[i]) << "i==" << i;
    else
      EXPECT_EQ(255, output[i]) << "i==" << i;
75 76
}

77
TEST_P(IDCTTest, TestAddOne) {
78
  int i;
79

80 81
  for (i = 0; i < 256; i++) predict[i] = i;
  input[0] = 4;
82
  ASM_REGISTER_STATE_CHECK(UUT(input, predict, 16, output, 16));
83

84 85 86 87 88
  for (i = 0; i < 256; i++)
    if ((i & 0xF) < 4 && i < 64)
      EXPECT_EQ(i + 1, output[i]) << "i==" << i;
    else
      EXPECT_EQ(255, output[i]) << "i==" << i;
89 90
}

91
TEST_P(IDCTTest, TestWithData) {
92 93 94 95
  int i;

  for (i = 0; i < 16; i++) input[i] = i;

96
  ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
97 98 99 100 101 102 103 104 105 106 107 108

  for (i = 0; i < 256; i++)
    if ((i & 0xF) > 3 || i > 63)
      EXPECT_EQ(255, output[i]) << "i==" << i;
    else if (i == 0)
      EXPECT_EQ(11, output[i]) << "i==" << i;
    else if (i == 34)
      EXPECT_EQ(1, output[i]) << "i==" << i;
    else if (i == 2 || i == 17 || i == 32)
      EXPECT_EQ(3, output[i]) << "i==" << i;
    else
      EXPECT_EQ(0, output[i]) << "i==" << i;
109 110
}

111
INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
112 113 114 115
#if HAVE_MMX
INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
                        ::testing::Values(vp8_short_idct4x4llm_mmx));
#endif
116
}