OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/cast/common/expanded_value_base.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | |
7 | |
8 namespace media { | |
9 namespace cast { | |
10 | |
11 namespace { | |
12 | |
13 // A basic subclass of ExpandedValueBase to use for testing. | |
14 class TestValue : public ExpandedValueBase<int64_t, TestValue> { | |
15 public: | |
16 explicit TestValue(int64_t value) : ExpandedValueBase(value) {} | |
17 }; | |
18 | |
19 } // namespace | |
20 | |
21 // Tests the various scenarios of truncating and then re-expanding values, and | |
22 // confirming the correct behavior. Note that, while the code below just tests | |
23 // truncation/expansion to/from 8 bits, the 16- and 32-bit cases are implicitly | |
24 // confirmed because the Expand() method uses the compiler to derive all of its | |
25 // constants (based on the type of its argument). | |
26 TEST(ExpandedValueBaseTest, TruncationAndExpansion) { | |
27 // Test that expansion works when the reference is always equal to the value | |
28 // that was truncated. | |
29 for (int64_t i = -512; i <= 512; ++i) { | |
30 const TestValue original_value(i); | |
31 const uint8_t truncated = original_value.lower_8_bits(); | |
32 const TestValue reference(i); | |
33 ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i; | |
34 } | |
35 | |
36 // Test that expansion works when the reference is always one less than the | |
37 // value that was truncated. | |
38 for (int64_t i = -512; i <= 512; ++i) { | |
39 const TestValue original_value(i); | |
40 const uint8_t truncated = original_value.lower_8_bits(); | |
41 const TestValue reference(i - 1); | |
42 ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i; | |
43 } | |
44 | |
45 // Test that expansion works when the reference is always one greater than the | |
46 // value that was truncated. | |
47 for (int64_t i = -512; i <= 512; ++i) { | |
48 const TestValue original_value(i); | |
49 const uint8_t truncated = original_value.lower_8_bits(); | |
50 const TestValue reference(i + 1); | |
51 ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i; | |
52 } | |
53 | |
54 // Test the cases where a difference of [-128,+127] around a fixed refererence | |
55 // does not trigger any wrap-around adjustments during expansion. | |
56 for (int64_t bias = -5; bias <= 5; ++bias) { | |
57 for (int64_t i = -128; i <= 127; ++i) { | |
58 const TestValue original_value(bias + i); | |
59 const uint8_t truncated = original_value.lower_8_bits(); | |
60 const TestValue reference(bias); | |
61 ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias | |
62 << ", i=" << i; | |
63 } | |
64 } | |
65 | |
66 // Test the cases where a difference of [+128,+255] around a fixed reference | |
67 // always triggers backwards wrap-around adjustments. | |
68 for (int64_t bias = -5; bias <= 5; ++bias) { | |
69 for (int64_t i = 128; i <= 255; ++i) { | |
70 const TestValue original_value(bias + i - 256); | |
Irfan
2015/12/09 21:24:27
am a little confused by the need for -256. perhaps
miu
2015/12/10 00:38:36
I clarified with comments and a little extra code.
| |
71 const uint8_t truncated = original_value.lower_8_bits(); | |
72 const TestValue reference(bias); | |
73 ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias | |
74 << ", i=" << i; | |
75 } | |
76 } | |
77 | |
78 // Test the cases where a difference of [-256,-129] around a fixed reference | |
79 // always triggers forwards wrap-around adjustments. | |
80 for (int64_t bias = -5; bias <= 5; ++bias) { | |
81 for (int64_t i = -256; i <= -129; ++i) { | |
82 const TestValue original_value(bias + i + 256); | |
83 const uint8_t truncated = original_value.lower_8_bits(); | |
84 const TestValue reference(bias); | |
85 ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias | |
86 << ", i=" << i; | |
87 } | |
88 } | |
89 } | |
90 | |
91 } // namespace cast | |
92 } // namespace media | |
OLD | NEW |