binary_codes_test.cc (2847B)
1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #include <math.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 #include "gtest/gtest.h" 17 18 #include "config/aom_config.h" 19 20 #include "test/acm_random.h" 21 #include "aom/aom_integer.h" 22 #include "aom_dsp/bitreader.h" 23 #include "aom_dsp/bitwriter.h" 24 #include "aom_dsp/binary_codes_reader.h" 25 #include "aom_dsp/binary_codes_writer.h" 26 27 #define ACCT_STR __func__ 28 29 using libaom_test::ACMRandom; 30 31 namespace { 32 33 // Test for Finite subexponential code with reference 34 TEST(AV1, TestPrimitiveRefsubexpfin) { 35 ACMRandom rnd(ACMRandom::DeterministicSeed()); 36 const int kBufferSize = 65536; 37 aom_writer bw; 38 uint8_t bw_buffer[kBufferSize]; 39 const uint16_t kRanges = 8; 40 const uint16_t kSubexpParams = 6; 41 const uint16_t kReferences = 8; 42 const uint16_t kValues = 16; 43 uint16_t enc_values[kRanges][kSubexpParams][kReferences][kValues][4]; 44 const uint16_t range_vals[kRanges] = { 1, 13, 64, 120, 230, 420, 1100, 8000 }; 45 aom_start_encode(&bw, bw_buffer); 46 for (int n = 0; n < kRanges; ++n) { 47 const uint16_t range = range_vals[n]; 48 for (int k = 0; k < kSubexpParams; ++k) { 49 for (int r = 0; r < kReferences; ++r) { 50 const uint16_t ref = rnd(range); 51 for (int v = 0; v < kValues; ++v) { 52 const uint16_t value = rnd(range); 53 enc_values[n][k][r][v][0] = range; 54 enc_values[n][k][r][v][1] = k; 55 enc_values[n][k][r][v][2] = ref; 56 enc_values[n][k][r][v][3] = value; 57 aom_write_primitive_refsubexpfin(&bw, range, k, ref, value); 58 } 59 } 60 } 61 } 62 GTEST_ASSERT_GE(aom_stop_encode(&bw), 0); 63 aom_reader br; 64 aom_reader_init(&br, bw_buffer, bw.pos); 65 GTEST_ASSERT_GE(aom_reader_tell(&br), 0u); 66 GTEST_ASSERT_LE(aom_reader_tell(&br), 1u); 67 for (int n = 0; n < kRanges; ++n) { 68 for (int k = 0; k < kSubexpParams; ++k) { 69 for (int r = 0; r < kReferences; ++r) { 70 for (int v = 0; v < kValues; ++v) { 71 const uint16_t range = enc_values[n][k][r][v][0]; 72 assert(k == enc_values[n][k][r][v][1]); 73 const uint16_t ref = enc_values[n][k][r][v][2]; 74 const uint16_t value = 75 aom_read_primitive_refsubexpfin(&br, range, k, ref, ACCT_STR); 76 GTEST_ASSERT_EQ(value, enc_values[n][k][r][v][3]); 77 } 78 } 79 } 80 } 81 } 82 // TODO(debargha): Adds tests for other primitives 83 } // namespace