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

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: Added CONTENT_EXPORT to fix compilation issues on win bots. Created 8 years, 7 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
« no previous file with comments | « content/browser/speech/chunked_byte_buffer.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <vector>
7
8 #include "content/browser/speech/chunked_byte_buffer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace speech {
12
13 typedef std::vector<uint8> ByteVector;
14
15 TEST(ChunkedByteBufferTest, BasicTest) {
16 ChunkedByteBuffer buffer;
17
18 const uint8 kChunks[] = {
19 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, // Chunk 1: 4 bytes
20 0x00, 0x00, 0x00, 0x02, 0x05, 0x06, // Chunk 2: 2 bytes
21 0x00, 0x00, 0x00, 0x01, 0x07 // Chunk 3: 1 bytes
22 };
23
24 EXPECT_EQ(0U, buffer.GetTotalLength());
25 EXPECT_FALSE(buffer.HasChunks());
26
27 // Append partially chunk 1.
28 buffer.Append(kChunks, 2);
29 EXPECT_EQ(2U, buffer.GetTotalLength());
30 EXPECT_FALSE(buffer.HasChunks());
31
32 // Complete chunk 1.
33 buffer.Append(kChunks + 2, 6);
34 EXPECT_EQ(8U, buffer.GetTotalLength());
35 EXPECT_TRUE(buffer.HasChunks());
36
37 // Append fully chunk 2.
38 buffer.Append(kChunks + 8, 6);
39 EXPECT_EQ(14U, buffer.GetTotalLength());
40 EXPECT_TRUE(buffer.HasChunks());
41
42 // Remove and check chunk 1.
43 scoped_ptr<ByteVector> chunk;
44 chunk = buffer.PopChunk();
45 EXPECT_TRUE(chunk != NULL);
46 EXPECT_EQ(4U, chunk->size());
47 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 4,
48 &(*chunk)[0],
49 chunk->size()));
50 EXPECT_EQ(6U, buffer.GetTotalLength());
51 EXPECT_TRUE(buffer.HasChunks());
52
53 // Read and check chunk 2.
54 chunk = buffer.PopChunk();
55 EXPECT_TRUE(chunk != NULL);
56 EXPECT_EQ(2U, chunk->size());
57 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 12,
58 &(*chunk)[0],
59 chunk->size()));
60 EXPECT_EQ(0U, buffer.GetTotalLength());
61 EXPECT_FALSE(buffer.HasChunks());
62
63 // Append fully chunk 3.
64 buffer.Append(kChunks + 14, 5);
65 EXPECT_EQ(5U, buffer.GetTotalLength());
66
67 // Remove and check chunk 3.
68 chunk = buffer.PopChunk();
69 EXPECT_TRUE(chunk != NULL);
70 EXPECT_EQ(1U, chunk->size());
71 EXPECT_EQ((*chunk)[0], kChunks[18]);
72 EXPECT_EQ(0U, buffer.GetTotalLength());
73 EXPECT_FALSE(buffer.HasChunks());
74 }
75
76 } // namespace speech
OLDNEW
« no previous file with comments | « content/browser/speech/chunked_byte_buffer.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698