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

Unified Diff: media/filters/h264_bitstream_buffer_unittest.cc

Issue 356903002: Revert "Revert 279650 "Add VaapiVideoEncodeAccelerator for HW-accelerate..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/h264_bitstream_buffer.cc ('k') | media/filters/h264_parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/h264_bitstream_buffer_unittest.cc
diff --git a/media/filters/h264_bitstream_buffer_unittest.cc b/media/filters/h264_bitstream_buffer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c959427cb39958526480f95baef8ca40b68cbc58
--- /dev/null
+++ b/media/filters/h264_bitstream_buffer_unittest.cc
@@ -0,0 +1,56 @@
+// Copyright 2014 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/filters/h264_bitstream_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+namespace {
+const uint64 kTestPattern = 0xfedcba0987654321;
+}
+
+class H264BitstreamBufferAppendBitsTest
+ : public ::testing::TestWithParam<size_t> {};
+
+// TODO(posciak): More tests!
+
+TEST_P(H264BitstreamBufferAppendBitsTest, AppendAndVerifyBits) {
+ H264BitstreamBuffer b;
+ uint64 num_bits = GetParam();
+ // TODO(posciak): Tests for >64 bits.
+ ASSERT_LE(num_bits, 64u);
+ uint64 num_bytes = (num_bits + 7) / 8;
+
+ b.AppendBits(num_bits, kTestPattern);
+ b.FlushReg();
+
+ EXPECT_EQ(b.BytesInBuffer(), num_bytes);
+
+ uint8* ptr = b.data();
+ uint64 got = 0;
+ uint64 expected = kTestPattern;
+
+ if (num_bits < 64)
+ expected &= ((1ull << num_bits) - 1);
+
+ while (num_bits > 8) {
+ got |= (*ptr & 0xff);
+ num_bits -= 8;
+ got <<= (num_bits > 8 ? 8 : num_bits);
+ ptr++;
+ }
+ if (num_bits > 0) {
+ uint64 temp = (*ptr & 0xff);
+ temp >>= (8 - num_bits);
+ got |= temp;
+ }
+ EXPECT_EQ(got, expected) << std::hex << "0x" << got << " vs 0x" << expected;
+}
+
+INSTANTIATE_TEST_CASE_P(AppendNumBits,
+ H264BitstreamBufferAppendBitsTest,
+ ::testing::Range(static_cast<uint64>(1),
+ static_cast<uint64>(65)));
+} // namespace media
« no previous file with comments | « media/filters/h264_bitstream_buffer.cc ('k') | media/filters/h264_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698