summaryrefslogtreecommitdiffstats
path: root/media/omx
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-09 20:56:17 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-09 20:56:17 +0000
commit2559e45a158b52215534b09c4e0be13f7e3b275a (patch)
tree6e9c4ee13ff765a46a0f85d4426dd4aec101dd3a /media/omx
parenta4bbdf7a9e474e5d00d35c4abdc36f8e0ee0b72a (diff)
downloadchromium_src-2559e45a158b52215534b09c4e0be13f7e3b275a.zip
chromium_src-2559e45a158b52215534b09c4e0be13f7e3b275a.tar.gz
chromium_src-2559e45a158b52215534b09c4e0be13f7e3b275a.tar.bz2
Unit test for OmxInputBuffer
TEST=media_unittest --gtest_filter=OmxInputBuffer.* BUG=32753 Review URL: http://codereview.chromium.org/580012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/omx')
-rw-r--r--media/omx/omx_input_buffer_unittest.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/media/omx/omx_input_buffer_unittest.cc b/media/omx/omx_input_buffer_unittest.cc
new file mode 100644
index 0000000..50a2302
--- /dev/null
+++ b/media/omx/omx_input_buffer_unittest.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2010 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/omx/omx_input_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const int kSize = 256;
+
+void GenerateData(uint8** data, int size) {
+ *data = new uint8[size];
+ for (int i = 0; i < size; ++i) {
+ (*data)[i] = static_cast<uint8>(i);
+ }
+}
+
+bool VerifyData(uint8* data, int size, int offset) {
+ bool data_mismatch = false;
+ for (int i = 0; i < size; ++i) {
+ if (data[i] != static_cast<uint8>(offset + i)) {
+ data_mismatch = true;
+ break;
+ }
+ }
+ return !data_mismatch;
+}
+
+} // namespace
+
+namespace media {
+
+TEST(OmxInputBufferTest, Read) {
+ scoped_array<uint8> read_buffer(new uint8[kSize]);
+ uint8* data;
+ GenerateData(&data, kSize);
+ scoped_refptr<OmxInputBuffer> buffer(new OmxInputBuffer(data, kSize));
+ EXPECT_FALSE(buffer->Used());
+
+ // Perform the first read.
+ EXPECT_EQ(10, buffer->Read(read_buffer.get(), 10));
+ EXPECT_FALSE(buffer->Used());
+ EXPECT_TRUE(VerifyData(read_buffer.get(), 10, 0));
+
+ // Perform the second read.
+ EXPECT_EQ(10, buffer->Read(read_buffer.get(), 10));
+ EXPECT_FALSE(buffer->Used());
+ EXPECT_TRUE(VerifyData(read_buffer.get(), 10, 10));
+
+ // Perform the last read.
+ EXPECT_EQ(kSize - 20, buffer->Read(read_buffer.get(), kSize));
+ EXPECT_TRUE(buffer->Used());
+ EXPECT_TRUE(VerifyData(read_buffer.get(), kSize - 20, 20));
+
+ // This read will return nothing.
+ EXPECT_EQ(0, buffer->Read(read_buffer.get(), kSize));
+ EXPECT_TRUE(buffer->Used());
+}
+
+TEST(OmxInputBufferTest, EmptyBuffer) {
+ scoped_refptr<OmxInputBuffer> buffer(new OmxInputBuffer(NULL, 0));
+ EXPECT_TRUE(buffer->IsEndOfStream());
+ EXPECT_TRUE(buffer->Used());
+}
+
+} // namespace media