Home | History | Annotate | Download | only in test
      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 
     12 extern "C" {
     13 #include "vpx_config.h"
     14 #include "vpx_rtcd.h"
     15 }
     16 #include "third_party/googletest/src/include/gtest/gtest.h"
     17 
     18 typedef void (*idct_fn_t)(short *input, unsigned char *pred_ptr,
     19                           int pred_stride, unsigned char *dst_ptr,
     20                           int dst_stride);
     21 namespace {
     22 class IDCTTest : public ::testing::TestWithParam<idct_fn_t>
     23 {
     24   protected:
     25     virtual void SetUp()
     26     {
     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++)
     33             output[i] = ((i&0xF)<4&&(i<64))?0:-1;
     34     }
     35 
     36     idct_fn_t UUT;
     37     short input[16];
     38     unsigned char output[256];
     39     unsigned char predict[256];
     40 };
     41 
     42 TEST_P(IDCTTest, TestGuardBlocks)
     43 {
     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 {
     55     int i;
     56 
     57     UUT(input, output, 16, output, 16);
     58 
     59     for(i=0; i<256; i++)
     60         if((i&0xF) < 4 && i<64)
     61             EXPECT_EQ(0, output[i]) << "i==" << i;
     62         else
     63             EXPECT_EQ(255, output[i]) << "i==" << i;
     64 }
     65 
     66 TEST_P(IDCTTest, TestAllOnes)
     67 {
     68     int i;
     69 
     70     input[0] = 4;
     71     UUT(input, output, 16, output, 16);
     72 
     73     for(i=0; i<256; i++)
     74         if((i&0xF) < 4 && i<64)
     75             EXPECT_EQ(1, output[i]) << "i==" << i;
     76         else
     77             EXPECT_EQ(255, output[i]) << "i==" << i;
     78 }
     79 
     80 TEST_P(IDCTTest, TestAddOne)
     81 {
     82     int i;
     83 
     84     for(i=0; i<256; i++)
     85         predict[i] = i;
     86 
     87     input[0] = 4;
     88     UUT(input, predict, 16, output, 16);
     89 
     90     for(i=0; i<256; i++)
     91         if((i&0xF) < 4 && i<64)
     92             EXPECT_EQ(i+1, output[i]) << "i==" << i;
     93         else
     94             EXPECT_EQ(255, output[i]) << "i==" << i;
     95 }
     96 
     97 TEST_P(IDCTTest, TestWithData)
     98 {
     99     int i;
    100 
    101     for(i=0; i<16; i++)
    102         input[i] = i;
    103 
    104     UUT(input, output, 16, output, 16);
    105 
    106     for(i=0; i<256; i++)
    107         if((i&0xF) > 3 || i>63)
    108             EXPECT_EQ(255, output[i]) << "i==" << i;
    109         else if(i == 0)
    110             EXPECT_EQ(11, output[i]) << "i==" << i;
    111         else if(i == 34)
    112             EXPECT_EQ(1, output[i]) << "i==" << i;
    113         else if(i == 2 || i == 17 || i == 32)
    114             EXPECT_EQ(3, output[i]) << "i==" << i;
    115         else
    116             EXPECT_EQ(0, output[i]) << "i==" << i;
    117 }
    118 
    119 INSTANTIATE_TEST_CASE_P(C, IDCTTest,
    120                         ::testing::Values(vp8_short_idct4x4llm_c));
    121 #if HAVE_MMX
    122 INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
    123                         ::testing::Values(vp8_short_idct4x4llm_mmx));
    124 #endif
    125 }
    126