Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: source/libvpx/test/vp8_boolcoder_test.cc

Issue 17009012: libvpx: Pull from upstream (Closed) Base URL: http://src.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29
30 void encrypt_buffer(uint8_t *buffer, int size, const uint8_t *key) { 30 // In a real use the 'decrypt_state' parameter will be a pointer to a struct
31 // with whatever internal state the decryptor uses. For testing we'll just
32 // xor with a constant key, and decrypt_state will point to the start of
33 // the original buffer.
34 const uint8_t secret_key[16] = {
35 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
36 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0
37 };
38
39 void encrypt_buffer(uint8_t *buffer, int size) {
31 for (int i = 0; i < size; ++i) { 40 for (int i = 0; i < size; ++i) {
32 buffer[i] ^= key[i % 32]; 41 buffer[i] ^= secret_key[i & 15];
33 } 42 }
34 } 43 }
35 44
36 const uint8_t secret_key[32] = { 45 void test_decrypt_cb(void *decrypt_state, const uint8_t *input,
37 234, 32, 2, 3, 4, 230, 6, 11, 46 uint8_t *output, int count) {
38 0, 132, 22, 23, 45, 21, 124, 255, 47 int offset = input - (uint8_t *)decrypt_state;
39 0, 43, 52, 3, 23, 63, 99, 7, 48 for (int i = 0; i < count; i++) {
40 120, 8, 252, 84, 4, 83, 6, 13 49 output[i] = input[i] ^ secret_key[(offset + i) & 15];
41 }; 50 }
51 }
42 52
43 } // namespace 53 } // namespace
44 54
45 using libvpx_test::ACMRandom; 55 using libvpx_test::ACMRandom;
46 56
47 TEST(VP8, TestBitIO) { 57 TEST(VP8, TestBitIO) {
48 ACMRandom rnd(ACMRandom::DeterministicSeed()); 58 ACMRandom rnd(ACMRandom::DeterministicSeed());
49 for (int n = 0; n < num_tests; ++n) { 59 for (int n = 0; n < num_tests; ++n) {
50 for (int method = 0; method <= 7; ++method) { // we generate various proba 60 for (int method = 0; method <= 7; ++method) { // we generate various proba
51 const int bits_to_test = 1000; 61 const int bits_to_test = 1000;
(...skipping 26 matching lines...) Expand all
78 bit = (i & 1); 88 bit = (i & 1);
79 } else if (bit_method == 3) { 89 } else if (bit_method == 3) {
80 bit = bit_rnd(2); 90 bit = bit_rnd(2);
81 } 91 }
82 vp8_encode_bool(&bw, bit, static_cast<int>(probas[i])); 92 vp8_encode_bool(&bw, bit, static_cast<int>(probas[i]));
83 } 93 }
84 94
85 vp8_stop_encode(&bw); 95 vp8_stop_encode(&bw);
86 96
87 BOOL_DECODER br; 97 BOOL_DECODER br;
88
89 #if CONFIG_DECRYPT 98 #if CONFIG_DECRYPT
90 encrypt_buffer(bw_buffer, buffer_size, secret_key); 99 encrypt_buffer(bw_buffer, buffer_size);
100 vp8dx_start_decode(&br, bw_buffer, buffer_size,
101 test_decrypt_cb, (void *)bw_buffer);
102 #else
103 vp8dx_start_decode(&br, bw_buffer, buffer_size, NULL, NULL);
91 #endif 104 #endif
92
93 vp8dx_start_decode(&br, bw_buffer, buffer_size, bw_buffer, secret_key);
94 bit_rnd.Reset(random_seed); 105 bit_rnd.Reset(random_seed);
95 for (int i = 0; i < bits_to_test; ++i) { 106 for (int i = 0; i < bits_to_test; ++i) {
96 if (bit_method == 2) { 107 if (bit_method == 2) {
97 bit = (i & 1); 108 bit = (i & 1);
98 } else if (bit_method == 3) { 109 } else if (bit_method == 3) {
99 bit = bit_rnd(2); 110 bit = bit_rnd(2);
100 } 111 }
101 GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit) 112 GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit)
102 << "pos: "<< i << " / " << bits_to_test 113 << "pos: "<< i << " / " << bits_to_test
103 << " bit_method: " << bit_method 114 << " bit_method: " << bit_method
104 << " method: " << method; 115 << " method: " << method;
105 } 116 }
106 } 117 }
107 } 118 }
108 } 119 }
109 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698