OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 extern "C" { | 11 extern "C" { |
12 #include "vp8/encoder/boolhuff.h" | 12 #include "vp8/encoder/boolhuff.h" |
13 #include "vp8/decoder/dboolhuff.h" | 13 #include "vp8/decoder/dboolhuff.h" |
14 } | 14 } |
15 | 15 |
16 #include <math.h> | 16 #include <math.h> |
17 #include <stddef.h> | 17 #include <stddef.h> |
18 #include <stdio.h> | 18 #include <stdio.h> |
19 #include <stdlib.h> | 19 #include <stdlib.h> |
20 #include <string.h> | 20 #include <string.h> |
21 #include <sys/types.h> | 21 #include <sys/types.h> |
22 | 22 |
23 #include "test/acm_random.h" | 23 #include "test/acm_random.h" |
24 #include "third_party/googletest/src/include/gtest/gtest.h" | 24 #include "third_party/googletest/src/include/gtest/gtest.h" |
25 #include "vpx/vpx_integer.h" | 25 #include "vpx/vpx_integer.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 const int num_tests = 10; | 28 const int num_tests = 10; |
| 29 |
| 30 void encrypt_buffer(uint8_t *buffer, int size, const uint8_t *key) { |
| 31 for (int i = 0; i < size; ++i) { |
| 32 buffer[i] ^= key[i % 32]; |
| 33 } |
| 34 } |
| 35 |
| 36 const uint8_t secret_key[32] = { |
| 37 234, 32, 2, 3, 4, 230, 6, 11, |
| 38 0, 132, 22, 23, 45, 21, 124, 255, |
| 39 0, 43, 52, 3, 23, 63, 99, 7, |
| 40 120, 8, 252, 84, 4, 83, 6, 13 |
| 41 }; |
| 42 |
29 } // namespace | 43 } // namespace |
30 | 44 |
31 using libvpx_test::ACMRandom; | 45 using libvpx_test::ACMRandom; |
32 | 46 |
33 TEST(VP8, TestBitIO) { | 47 TEST(VP8, TestBitIO) { |
34 ACMRandom rnd(ACMRandom::DeterministicSeed()); | 48 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
35 for (int n = 0; n < num_tests; ++n) { | 49 for (int n = 0; n < num_tests; ++n) { |
36 for (int method = 0; method <= 7; ++method) { // we generate various proba | 50 for (int method = 0; method <= 7; ++method) { // we generate various proba |
37 const int bits_to_test = 1000; | 51 const int bits_to_test = 1000; |
38 uint8_t probas[bits_to_test]; | 52 uint8_t probas[bits_to_test]; |
(...skipping 25 matching lines...) Expand all Loading... |
64 bit = (i & 1); | 78 bit = (i & 1); |
65 } else if (bit_method == 3) { | 79 } else if (bit_method == 3) { |
66 bit = bit_rnd(2); | 80 bit = bit_rnd(2); |
67 } | 81 } |
68 vp8_encode_bool(&bw, bit, static_cast<int>(probas[i])); | 82 vp8_encode_bool(&bw, bit, static_cast<int>(probas[i])); |
69 } | 83 } |
70 | 84 |
71 vp8_stop_encode(&bw); | 85 vp8_stop_encode(&bw); |
72 | 86 |
73 BOOL_DECODER br; | 87 BOOL_DECODER br; |
74 vp8dx_start_decode(&br, bw_buffer, buffer_size); | 88 |
| 89 #if CONFIG_DECRYPT |
| 90 encrypt_buffer(bw_buffer, buffer_size, secret_key); |
| 91 #endif |
| 92 |
| 93 vp8dx_start_decode(&br, bw_buffer, buffer_size, bw_buffer, secret_key); |
75 bit_rnd.Reset(random_seed); | 94 bit_rnd.Reset(random_seed); |
76 for (int i = 0; i < bits_to_test; ++i) { | 95 for (int i = 0; i < bits_to_test; ++i) { |
77 if (bit_method == 2) { | 96 if (bit_method == 2) { |
78 bit = (i & 1); | 97 bit = (i & 1); |
79 } else if (bit_method == 3) { | 98 } else if (bit_method == 3) { |
80 bit = bit_rnd(2); | 99 bit = bit_rnd(2); |
81 } | 100 } |
82 GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit) | 101 GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit) |
83 << "pos: "<< i << " / " << bits_to_test | 102 << "pos: "<< i << " / " << bits_to_test |
84 << " bit_method: " << bit_method | 103 << " bit_method: " << bit_method |
85 << " method: " << method; | 104 << " method: " << method; |
86 } | 105 } |
87 } | 106 } |
88 } | 107 } |
89 } | 108 } |
90 } | 109 } |
OLD | NEW |