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

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: Refactored according to Satish indications. 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_FALSE(buffer.HasChunks());
22
23 // Append partially chunk 1.
24 buffer.Append(kChunks, 2);
25 EXPECT_EQ(2U, buffer.GetTotalLength());
26 EXPECT_FALSE(buffer.HasChunks());
27
28 // Complete chunk 1.
29 buffer.Append(kChunks + 2, 6);
30 EXPECT_EQ(8U, buffer.GetTotalLength());
31 EXPECT_TRUE(buffer.HasChunks());
32 EXPECT_EQ(4U, buffer.GetFirstChunk().GetLength());
33
34 // Append fully chunk 2.
35 buffer.Append(kChunks + 8, 6);
36 EXPECT_EQ(14U, buffer.GetTotalLength());
37 EXPECT_TRUE(buffer.HasChunks());
38 EXPECT_EQ(4U, buffer.GetFirstChunk().GetLength());
39
40 // Remove and check chunk 1.
41 scoped_ptr<ByteBufferChunk> chunk;
42 chunk = buffer.PopChunk();
43 EXPECT_TRUE(chunk != NULL);
44 EXPECT_EQ(4U, chunk->GetLength());
45 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 4,
46 chunk->GetData(),
47 chunk->GetLength()));
48 EXPECT_EQ(6U, buffer.GetTotalLength());
49 EXPECT_TRUE(buffer.HasChunks());
50 EXPECT_EQ(2U, buffer.GetFirstChunk().GetLength());
51
52 // Read and check chunk 2.
53 chunk = buffer.PopChunk();
54 EXPECT_TRUE(chunk != NULL);
55 EXPECT_EQ(2U, chunk->GetLength());
56 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 12,
57 chunk->GetData(),
58 chunk->GetLength()));
59 EXPECT_EQ(0U, buffer.GetTotalLength());
60 EXPECT_FALSE(buffer.HasChunks());
61 EXPECT_EQ(0U, buffer.GetFirstChunk().GetLength());
62
63 // Append fully chunk 3.
64 buffer.Append(kChunks + 14, 5);
65 EXPECT_EQ(5U, buffer.GetTotalLength());
66 EXPECT_EQ(1U, buffer.GetFirstChunk().GetLength());
67
68 // Remove and check chunk 3.
69 chunk = buffer.PopChunk();
70 EXPECT_TRUE(chunk != NULL);
71 EXPECT_EQ(1U, chunk->GetLength());
72 EXPECT_EQ(chunk->GetData()[0], kChunks[18]);
73 EXPECT_EQ(0U, buffer.GetTotalLength());
74 EXPECT_EQ(0U, buffer.GetFirstChunk().GetLength());
75 }
76
77 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698