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

Side by Side Diff: media/cast/common/expanded_value_base_unittest.cc

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot to include a comment change in cast_messages.h. Created 5 years 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
« no previous file with comments | « media/cast/common/expanded_value_base.h ('k') | media/cast/common/rtp_time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 cases where the difference between the original value and the fixed
55 // reference is within the range [-128,+127]. The truncated value should
56 // always be re-expanded to the original value.
57 for (int64_t bias = -5; bias <= 5; ++bias) {
58 for (int64_t i = -128; i <= 127; ++i) {
59 const TestValue original_value(bias + i);
60 const uint8_t truncated = original_value.lower_8_bits();
61 const TestValue reference(bias);
62 ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias
63 << ", i=" << i;
64 }
65 }
66
67 // Test cases where the difference between the original value and the fixed
68 // reference is within the range [+128,+255]. When the truncated value is
69 // re-expanded, it should be 256 less than the original value.
70 for (int64_t bias = -5; bias <= 5; ++bias) {
71 for (int64_t i = 128; i <= 255; ++i) {
72 // Example: Let |original_value| be 192. Then, the truncated 8-bit value
73 // will be 0xc0. When a |reference| of zero is asked to expand 0xc0 back
74 // to the original value, it should produce -64 since -64 is closer to
75 // |reference| than 192.
76 const TestValue original_value(bias + i);
77 const uint8_t truncated = original_value.lower_8_bits();
78 const TestValue reexpanded_value(bias + i - 256);
79 ASSERT_EQ(reexpanded_value.lower_8_bits(), truncated);
80 const TestValue reference(bias);
81 ASSERT_EQ(reexpanded_value, reference.Expand(truncated))
82 << "bias=" << bias << ", i=" << i;
83 }
84 }
85
86 // Test cases where the difference between the original value and the fixed
87 // reference is within the range [-256,-129]. When the truncated value is
88 // re-expanded, it should be 256 more than the original value.
89 for (int64_t bias = -5; bias <= 5; ++bias) {
90 for (int64_t i = -256; i <= -129; ++i) {
91 // Example: Let |original_value| be -192. Then, the truncated 8-bit value
92 // will be 0x40. When a |reference| of zero is asked to expand 0x40 back
93 // to the original value, it should produce 64 since 64 is closer to the
94 // |reference| than -192.
Irfan 2015/12/10 01:40:38 Really good explanation, thanks!
95 const TestValue original_value(bias + i);
96 const uint8_t truncated = original_value.lower_8_bits();
97 const TestValue reexpanded_value(bias + i + 256);
98 ASSERT_EQ(reexpanded_value.lower_8_bits(), truncated);
99 const TestValue reference(bias);
100 ASSERT_EQ(reexpanded_value, reference.Expand(truncated))
101 << "bias=" << bias << ", i=" << i;
102 }
103 }
104 }
105
106 } // namespace cast
107 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/common/expanded_value_base.h ('k') | media/cast/common/rtp_time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698