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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 <string>
6
7 #include "content/browser/speech/chunked_byte_buffer.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace speech {
11
12 TEST(ChunkedByteBufferTest, BasicTest) {
13 ChunkedByteBuffer buffer;
14 const uint8 kChunks[] = {
15 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, // Chunk 1: 4 bytes
16 0x00, 0x00, 0x00, 0x02, 0x05, 0x06, // Chunk 2: 2 bytes
17 0x00, 0x00, 0x00, 0x01, 0x07 // Chunk 3: 1 bytes
18 };
19
20 EXPECT_EQ(0U, buffer.GetTotalLength());
21 EXPECT_EQ(0U, buffer.GetNextChunkLength());
22
23 // Append partially chunk 1.
24 buffer.Append(kChunks, 2);
25 EXPECT_EQ(2U, buffer.GetTotalLength());
26 EXPECT_EQ(0U, buffer.GetNextChunkLength());
27
28 // Complete chunk 1.
29 size_t first_chunk_length = 0;
30 buffer.Append(kChunks + 2, 6);
31 EXPECT_EQ(8U, buffer.GetTotalLength());
32 EXPECT_EQ(4U, buffer.GetNextChunkLength());
33
34 // Append fully chunk 2.
35 first_chunk_length = 0;
36 buffer.Append(kChunks + 8, 6);
37 EXPECT_EQ(14U, buffer.GetTotalLength());
38 EXPECT_EQ(4U, buffer.GetNextChunkLength());
39
40 // Read and check chunk 1.
41 const uint8* first_chunk_start = NULL;
42 first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
43 EXPECT_TRUE(first_chunk_start != NULL);
44 EXPECT_EQ(4U, first_chunk_length);
45 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 4,
46 first_chunk_start,
47 first_chunk_length));
48
49 // Remove chunk 1. Only chunk 2 should remain in the buffer.
50 buffer.RemoveNextChunk();
51 EXPECT_EQ(6U, buffer.GetTotalLength());
52 EXPECT_EQ(2U, buffer.GetNextChunkLength());
53
54 // Read and check chunk 2.
55 first_chunk_start = NULL;
56 first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
57 EXPECT_TRUE(first_chunk_start != NULL);
58 EXPECT_EQ(2U, first_chunk_length);
59 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 12,
60 first_chunk_start,
61 first_chunk_length));
62
63 // Remove chunk 2. Buffer should be empty.
64 buffer.RemoveNextChunk();
65 EXPECT_EQ(0U, buffer.GetTotalLength());
66 EXPECT_EQ(0U, buffer.GetNextChunkLength());
67
68 // Append fully chunk 3.
69 first_chunk_length = 42; // Anything, but not 0.
70 buffer.Append(kChunks + 14, 5);
71 EXPECT_EQ(5U, buffer.GetTotalLength());
72 EXPECT_EQ(1U, buffer.GetNextChunkLength());
73
74 // Read and check chunk 3.
75 first_chunk_start = NULL;
76 first_chunk_length = buffer.GetNextChunk(&first_chunk_start);
77 EXPECT_TRUE(first_chunk_start != NULL);
78 EXPECT_EQ(1U, first_chunk_length);
79 EXPECT_EQ(*first_chunk_start, kChunks[18]);
80
81 // Remove chunk 3. Buffer should be empty.
82 buffer.RemoveNextChunk();
83 EXPECT_EQ(0U, buffer.GetTotalLength());
84 EXPECT_EQ(0U, buffer.GetNextChunkLength());
85 }
86
87 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698