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

Unified Diff: content/browser/speech/chunked_byte_buffer_unittest.cc

Issue 10123008: Introduced ChunkedByteBuffer class which will be needed by next speech recognition CLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reimplemented according to Satish suggestions. Created 8 years, 8 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
Index: content/browser/speech/chunked_byte_buffer_unittest.cc
diff --git a/content/browser/speech/chunked_byte_buffer_unittest.cc b/content/browser/speech/chunked_byte_buffer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..644cc30cf88d3946ea9e4f3a8c1a54cbfe1f5445
--- /dev/null
+++ b/content/browser/speech/chunked_byte_buffer_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 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 <string>
+
+#include "content/browser/speech/chunked_byte_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace speech {
+
+TEST(ChunkedByteBufferTest, BasicTest) {
+ ChunkedByteBuffer buffer;
+ const uint8 kChunks[] = {
+ 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, // Chunk 1: 4 bytes
+ 0x00, 0x00, 0x00, 0x02, 0x05, 0x06, // Chunk 2: 2 bytes
+ 0x00, 0x00, 0x00, 0x01, 0x07 // Chunk 3: 1 bytes
+ };
+
+ EXPECT_EQ(0U, buffer.GetTotalLength());
+ EXPECT_EQ(0U, buffer.GetNextChunkLength());
+
+ // Append partially chunk 1.
+ buffer.Append(kChunks, 2);
+ EXPECT_EQ(2U, buffer.GetTotalLength());
+ EXPECT_EQ(0U, buffer.GetNextChunkLength());
+
+ // Complete chunk 1.
+ size_t first_chunk_length = 0;
+ buffer.Append(kChunks + 2, 6);
+ EXPECT_EQ(8U, buffer.GetTotalLength());
+ EXPECT_EQ(4U, buffer.GetNextChunkLength());
+
+ // Append fully chunk 2.
+ first_chunk_length = 0;
+ buffer.Append(kChunks + 8, 6);
+ EXPECT_EQ(14U, buffer.GetTotalLength());
+ EXPECT_EQ(4U, buffer.GetNextChunkLength());
+
+ // Read and check chunk 1.
+ const uint8* first_chunk_start = NULL;
+ first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
+ EXPECT_TRUE(first_chunk_start != NULL);
+ EXPECT_EQ(4U, first_chunk_length);
+ EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 4,
+ first_chunk_start,
+ first_chunk_length));
+
+ // Remove chunk 1. Only chunk 2 should remain in the buffer.
+ buffer.RemoveNextChunk();
+ EXPECT_EQ(6U, buffer.GetTotalLength());
+ EXPECT_EQ(2U, buffer.GetNextChunkLength());
+
+ // Read and check chunk 2.
+ first_chunk_start = NULL;
+ first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
+ EXPECT_TRUE(first_chunk_start != NULL);
+ EXPECT_EQ(2U, first_chunk_length);
+ EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 12,
+ first_chunk_start,
+ first_chunk_length));
+
+ // Remove chunk 2. Buffer should be empty.
+ buffer.RemoveNextChunk();
+ EXPECT_EQ(0U, buffer.GetTotalLength());
+ EXPECT_EQ(0U, buffer.GetNextChunkLength());
+
+ // Append fully chunk 3.
+ first_chunk_length = 42; // Anything, but not 0.
+ buffer.Append(kChunks + 14, 5);
+ EXPECT_EQ(5U, buffer.GetTotalLength());
+ EXPECT_EQ(1U, buffer.GetNextChunkLength());
+
+ // Read and check chunk 3.
+ first_chunk_start = NULL;
+ first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
+ EXPECT_TRUE(first_chunk_start != NULL);
+ EXPECT_EQ(1U, first_chunk_length);
+ EXPECT_EQ(*first_chunk_start, kChunks[18]);
+
+ // Remove chunk 3. Buffer should be empty.
+ buffer.RemoveNextChunk();
+ EXPECT_EQ(0U, buffer.GetTotalLength());
+ EXPECT_EQ(0U, buffer.GetNextChunkLength());
+}
+
+} // namespace speech

Powered by Google App Engine
This is Rietveld 408576698