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

Side by Side Diff: webrtc/base/bytebuffer_unittest.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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
« no previous file with comments | « webrtc/base/bytebuffer.cc ('k') | webrtc/base/byteorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/bytebuffer.h" 11 #include "webrtc/base/bytebuffer.h"
12 #include "webrtc/base/byteorder.h" 12 #include "webrtc/base/byteorder.h"
13 #include "webrtc/base/common.h" 13 #include "webrtc/base/common.h"
14 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
15 15
16 namespace rtc { 16 namespace rtc {
17 17
18 TEST(ByteBufferTest, TestByteOrder) { 18 TEST(ByteBufferTest, TestByteOrder) {
19 uint16 n16 = 1; 19 uint16_t n16 = 1;
20 uint32 n32 = 1; 20 uint32_t n32 = 1;
21 uint64 n64 = 1; 21 uint64_t n64 = 1;
22 22
23 EXPECT_EQ(n16, NetworkToHost16(HostToNetwork16(n16))); 23 EXPECT_EQ(n16, NetworkToHost16(HostToNetwork16(n16)));
24 EXPECT_EQ(n32, NetworkToHost32(HostToNetwork32(n32))); 24 EXPECT_EQ(n32, NetworkToHost32(HostToNetwork32(n32)));
25 EXPECT_EQ(n64, NetworkToHost64(HostToNetwork64(n64))); 25 EXPECT_EQ(n64, NetworkToHost64(HostToNetwork64(n64)));
26 26
27 if (IsHostBigEndian()) { 27 if (IsHostBigEndian()) {
28 // The host is the network (big) endian. 28 // The host is the network (big) endian.
29 EXPECT_EQ(n16, HostToNetwork16(n16)); 29 EXPECT_EQ(n16, HostToNetwork16(n16));
30 EXPECT_EQ(n32, HostToNetwork32(n32)); 30 EXPECT_EQ(n32, HostToNetwork32(n32));
31 EXPECT_EQ(n64, HostToNetwork64(n64)); 31 EXPECT_EQ(n64, HostToNetwork64(n64));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 EXPECT_TRUE(buffer.ReadString(&read, 3)); 110 EXPECT_TRUE(buffer.ReadString(&read, 3));
111 EXPECT_EQ("DEF", read); 111 EXPECT_EQ("DEF", read);
112 } 112 }
113 113
114 TEST(ByteBufferTest, TestReadWriteBuffer) { 114 TEST(ByteBufferTest, TestReadWriteBuffer) {
115 ByteBuffer::ByteOrder orders[2] = { ByteBuffer::ORDER_HOST, 115 ByteBuffer::ByteOrder orders[2] = { ByteBuffer::ORDER_HOST,
116 ByteBuffer::ORDER_NETWORK }; 116 ByteBuffer::ORDER_NETWORK };
117 for (size_t i = 0; i < ARRAY_SIZE(orders); i++) { 117 for (size_t i = 0; i < ARRAY_SIZE(orders); i++) {
118 ByteBuffer buffer(orders[i]); 118 ByteBuffer buffer(orders[i]);
119 EXPECT_EQ(orders[i], buffer.Order()); 119 EXPECT_EQ(orders[i], buffer.Order());
120 uint8 ru8; 120 uint8_t ru8;
121 EXPECT_FALSE(buffer.ReadUInt8(&ru8)); 121 EXPECT_FALSE(buffer.ReadUInt8(&ru8));
122 122
123 // Write and read uint8. 123 // Write and read uint8_t.
124 uint8 wu8 = 1; 124 uint8_t wu8 = 1;
125 buffer.WriteUInt8(wu8); 125 buffer.WriteUInt8(wu8);
126 EXPECT_TRUE(buffer.ReadUInt8(&ru8)); 126 EXPECT_TRUE(buffer.ReadUInt8(&ru8));
127 EXPECT_EQ(wu8, ru8); 127 EXPECT_EQ(wu8, ru8);
128 EXPECT_EQ(0U, buffer.Length()); 128 EXPECT_EQ(0U, buffer.Length());
129 129
130 // Write and read uint16. 130 // Write and read uint16_t.
131 uint16 wu16 = (1 << 8) + 1; 131 uint16_t wu16 = (1 << 8) + 1;
132 buffer.WriteUInt16(wu16); 132 buffer.WriteUInt16(wu16);
133 uint16 ru16; 133 uint16_t ru16;
134 EXPECT_TRUE(buffer.ReadUInt16(&ru16)); 134 EXPECT_TRUE(buffer.ReadUInt16(&ru16));
135 EXPECT_EQ(wu16, ru16); 135 EXPECT_EQ(wu16, ru16);
136 EXPECT_EQ(0U, buffer.Length()); 136 EXPECT_EQ(0U, buffer.Length());
137 137
138 // Write and read uint24. 138 // Write and read uint24.
139 uint32 wu24 = (3 << 16) + (2 << 8) + 1; 139 uint32_t wu24 = (3 << 16) + (2 << 8) + 1;
140 buffer.WriteUInt24(wu24); 140 buffer.WriteUInt24(wu24);
141 uint32 ru24; 141 uint32_t ru24;
142 EXPECT_TRUE(buffer.ReadUInt24(&ru24)); 142 EXPECT_TRUE(buffer.ReadUInt24(&ru24));
143 EXPECT_EQ(wu24, ru24); 143 EXPECT_EQ(wu24, ru24);
144 EXPECT_EQ(0U, buffer.Length()); 144 EXPECT_EQ(0U, buffer.Length());
145 145
146 // Write and read uint32. 146 // Write and read uint32_t.
147 uint32 wu32 = (4 << 24) + (3 << 16) + (2 << 8) + 1; 147 uint32_t wu32 = (4 << 24) + (3 << 16) + (2 << 8) + 1;
148 buffer.WriteUInt32(wu32); 148 buffer.WriteUInt32(wu32);
149 uint32 ru32; 149 uint32_t ru32;
150 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); 150 EXPECT_TRUE(buffer.ReadUInt32(&ru32));
151 EXPECT_EQ(wu32, ru32); 151 EXPECT_EQ(wu32, ru32);
152 EXPECT_EQ(0U, buffer.Length()); 152 EXPECT_EQ(0U, buffer.Length());
153 153
154 // Write and read uint64. 154 // Write and read uint64_t.
155 uint32 another32 = (8 << 24) + (7 << 16) + (6 << 8) + 5; 155 uint32_t another32 = (8 << 24) + (7 << 16) + (6 << 8) + 5;
156 uint64 wu64 = (static_cast<uint64>(another32) << 32) + wu32; 156 uint64_t wu64 = (static_cast<uint64_t>(another32) << 32) + wu32;
157 buffer.WriteUInt64(wu64); 157 buffer.WriteUInt64(wu64);
158 uint64 ru64; 158 uint64_t ru64;
159 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); 159 EXPECT_TRUE(buffer.ReadUInt64(&ru64));
160 EXPECT_EQ(wu64, ru64); 160 EXPECT_EQ(wu64, ru64);
161 EXPECT_EQ(0U, buffer.Length()); 161 EXPECT_EQ(0U, buffer.Length());
162 162
163 // Write and read string. 163 // Write and read string.
164 std::string write_string("hello"); 164 std::string write_string("hello");
165 buffer.WriteString(write_string); 165 buffer.WriteString(write_string);
166 std::string read_string; 166 std::string read_string;
167 EXPECT_TRUE(buffer.ReadString(&read_string, write_string.size())); 167 EXPECT_TRUE(buffer.ReadString(&read_string, write_string.size()));
168 EXPECT_EQ(write_string, read_string); 168 EXPECT_EQ(write_string, read_string);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 EXPECT_EQ(wu24, ru24); 202 EXPECT_EQ(wu24, ru24);
203 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); 203 EXPECT_TRUE(buffer.ReadUInt32(&ru32));
204 EXPECT_EQ(wu32, ru32); 204 EXPECT_EQ(wu32, ru32);
205 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); 205 EXPECT_TRUE(buffer.ReadUInt64(&ru64));
206 EXPECT_EQ(wu64, ru64); 206 EXPECT_EQ(wu64, ru64);
207 EXPECT_EQ(0U, buffer.Length()); 207 EXPECT_EQ(0U, buffer.Length());
208 } 208 }
209 } 209 }
210 210
211 } // namespace rtc 211 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/bytebuffer.cc ('k') | webrtc/base/byteorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698