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

Side by Side Diff: content/browser/speech/chunked_byte_buffer_unittest.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h>
6
5 #include <string> 7 #include <string>
6 #include <vector> 8 #include <vector>
7 9
8 #include "content/browser/speech/chunked_byte_buffer.h" 10 #include "content/browser/speech/chunked_byte_buffer.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 typedef std::vector<uint8> ByteVector; 15 typedef std::vector<uint8_t> ByteVector;
14 16
15 TEST(ChunkedByteBufferTest, BasicTest) { 17 TEST(ChunkedByteBufferTest, BasicTest) {
16 ChunkedByteBuffer buffer; 18 ChunkedByteBuffer buffer;
17 19
18 const uint8 kChunks[] = { 20 const uint8_t kChunks[] = {
19 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, // Chunk 1: 4 bytes 21 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, // Chunk 1: 4 bytes
20 0x00, 0x00, 0x00, 0x02, 0x05, 0x06, // Chunk 2: 2 bytes 22 0x00, 0x00, 0x00, 0x02, 0x05, 0x06, // Chunk 2: 2 bytes
21 0x00, 0x00, 0x00, 0x01, 0x07 // Chunk 3: 1 bytes 23 0x00, 0x00, 0x00, 0x01, 0x07 // Chunk 3: 1 bytes
22 }; 24 };
23 25
24 EXPECT_EQ(0U, buffer.GetTotalLength()); 26 EXPECT_EQ(0U, buffer.GetTotalLength());
25 EXPECT_FALSE(buffer.HasChunks()); 27 EXPECT_FALSE(buffer.HasChunks());
26 28
27 // Append partially chunk 1. 29 // Append partially chunk 1.
28 buffer.Append(kChunks, 2); 30 buffer.Append(kChunks, 2);
29 EXPECT_EQ(2U, buffer.GetTotalLength()); 31 EXPECT_EQ(2U, buffer.GetTotalLength());
30 EXPECT_FALSE(buffer.HasChunks()); 32 EXPECT_FALSE(buffer.HasChunks());
31 33
32 // Complete chunk 1. 34 // Complete chunk 1.
33 buffer.Append(kChunks + 2, 6); 35 buffer.Append(kChunks + 2, 6);
34 EXPECT_EQ(8U, buffer.GetTotalLength()); 36 EXPECT_EQ(8U, buffer.GetTotalLength());
35 EXPECT_TRUE(buffer.HasChunks()); 37 EXPECT_TRUE(buffer.HasChunks());
36 38
37 // Append fully chunk 2. 39 // Append fully chunk 2.
38 buffer.Append(kChunks + 8, 6); 40 buffer.Append(kChunks + 8, 6);
39 EXPECT_EQ(14U, buffer.GetTotalLength()); 41 EXPECT_EQ(14U, buffer.GetTotalLength());
40 EXPECT_TRUE(buffer.HasChunks()); 42 EXPECT_TRUE(buffer.HasChunks());
41 43
42 // Remove and check chunk 1. 44 // Remove and check chunk 1.
43 scoped_ptr<ByteVector> chunk; 45 scoped_ptr<ByteVector> chunk;
44 chunk = buffer.PopChunk(); 46 chunk = buffer.PopChunk();
45 EXPECT_TRUE(chunk != NULL); 47 EXPECT_TRUE(chunk != NULL);
46 EXPECT_EQ(4U, chunk->size()); 48 EXPECT_EQ(4U, chunk->size());
47 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 4, 49 EXPECT_EQ(0, std::char_traits<uint8_t>::compare(kChunks + 4, &(*chunk)[0],
48 &(*chunk)[0], 50 chunk->size()));
49 chunk->size()));
50 EXPECT_EQ(6U, buffer.GetTotalLength()); 51 EXPECT_EQ(6U, buffer.GetTotalLength());
51 EXPECT_TRUE(buffer.HasChunks()); 52 EXPECT_TRUE(buffer.HasChunks());
52 53
53 // Read and check chunk 2. 54 // Read and check chunk 2.
54 chunk = buffer.PopChunk(); 55 chunk = buffer.PopChunk();
55 EXPECT_TRUE(chunk != NULL); 56 EXPECT_TRUE(chunk != NULL);
56 EXPECT_EQ(2U, chunk->size()); 57 EXPECT_EQ(2U, chunk->size());
57 EXPECT_EQ(0, std::char_traits<uint8>::compare(kChunks + 12, 58 EXPECT_EQ(0, std::char_traits<uint8_t>::compare(kChunks + 12, &(*chunk)[0],
58 &(*chunk)[0], 59 chunk->size()));
59 chunk->size()));
60 EXPECT_EQ(0U, buffer.GetTotalLength()); 60 EXPECT_EQ(0U, buffer.GetTotalLength());
61 EXPECT_FALSE(buffer.HasChunks()); 61 EXPECT_FALSE(buffer.HasChunks());
62 62
63 // Append fully chunk 3. 63 // Append fully chunk 3.
64 buffer.Append(kChunks + 14, 5); 64 buffer.Append(kChunks + 14, 5);
65 EXPECT_EQ(5U, buffer.GetTotalLength()); 65 EXPECT_EQ(5U, buffer.GetTotalLength());
66 66
67 // Remove and check chunk 3. 67 // Remove and check chunk 3.
68 chunk = buffer.PopChunk(); 68 chunk = buffer.PopChunk();
69 EXPECT_TRUE(chunk != NULL); 69 EXPECT_TRUE(chunk != NULL);
70 EXPECT_EQ(1U, chunk->size()); 70 EXPECT_EQ(1U, chunk->size());
71 EXPECT_EQ((*chunk)[0], kChunks[18]); 71 EXPECT_EQ((*chunk)[0], kChunks[18]);
72 EXPECT_EQ(0U, buffer.GetTotalLength()); 72 EXPECT_EQ(0U, buffer.GetTotalLength());
73 EXPECT_FALSE(buffer.HasChunks()); 73 EXPECT_FALSE(buffer.HasChunks());
74 } 74 }
75 75
76 } // namespace content 76 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/chunked_byte_buffer.cc ('k') | content/browser/speech/endpointer/endpointer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698