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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/common/expanded_value_base_unittest.cc
diff --git a/media/cast/common/expanded_value_base_unittest.cc b/media/cast/common/expanded_value_base_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..58563aa24efeb503a02bf04f8ed2cfed0eae3a43
--- /dev/null
+++ b/media/cast/common/expanded_value_base_unittest.cc
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cast/common/expanded_value_base.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+namespace cast {
+
+namespace {
+
+// A basic subclass of ExpandedValueBase to use for testing.
+class TestValue : public ExpandedValueBase<int64_t, TestValue> {
+ public:
+ explicit TestValue(int64_t value) : ExpandedValueBase(value) {}
+};
+
+} // namespace
+
+// Tests the various scenarios of truncating and then re-expanding values, and
+// confirming the correct behavior. Note that, while the code below just tests
+// truncation/expansion to/from 8 bits, the 16- and 32-bit cases are implicitly
+// confirmed because the Expand() method uses the compiler to derive all of its
+// constants (based on the type of its argument).
+TEST(ExpandedValueBaseTest, TruncationAndExpansion) {
+ // Test that expansion works when the reference is always equal to the value
+ // that was truncated.
+ for (int64_t i = -512; i <= 512; ++i) {
+ const TestValue original_value(i);
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(i);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i;
+ }
+
+ // Test that expansion works when the reference is always one less than the
+ // value that was truncated.
+ for (int64_t i = -512; i <= 512; ++i) {
+ const TestValue original_value(i);
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(i - 1);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i;
+ }
+
+ // Test that expansion works when the reference is always one greater than the
+ // value that was truncated.
+ for (int64_t i = -512; i <= 512; ++i) {
+ const TestValue original_value(i);
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(i + 1);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "i=" << i;
+ }
+
+ // Test the cases where a difference of [-128,+127] around a fixed refererence
+ // does not trigger any wrap-around adjustments during expansion.
+ for (int64_t bias = -5; bias <= 5; ++bias) {
+ for (int64_t i = -128; i <= 127; ++i) {
+ const TestValue original_value(bias + i);
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(bias);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias
+ << ", i=" << i;
+ }
+ }
+
+ // Test the cases where a difference of [+128,+255] around a fixed reference
+ // always triggers backwards wrap-around adjustments.
+ for (int64_t bias = -5; bias <= 5; ++bias) {
+ for (int64_t i = 128; i <= 255; ++i) {
+ 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.
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(bias);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias
+ << ", i=" << i;
+ }
+ }
+
+ // Test the cases where a difference of [-256,-129] around a fixed reference
+ // always triggers forwards wrap-around adjustments.
+ for (int64_t bias = -5; bias <= 5; ++bias) {
+ for (int64_t i = -256; i <= -129; ++i) {
+ const TestValue original_value(bias + i + 256);
+ const uint8_t truncated = original_value.lower_8_bits();
+ const TestValue reference(bias);
+ ASSERT_EQ(original_value, reference.Expand(truncated)) << "bias=" << bias
+ << ", i=" << i;
+ }
+ }
+}
+
+} // namespace cast
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698