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

Side by Side Diff: import/cross/memory_stream_test.cc

Issue 147129: Adding in most of the unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 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 | « core/win/d3d9/effect_d3d9.cc ('k') | import/import.gyp » ('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 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 // Basic sanity check for endian writing/reading 228 // Basic sanity check for endian writing/reading
229 TEST_F(MemoryStreamTest, EndianSanityFloat32) { 229 TEST_F(MemoryStreamTest, EndianSanityFloat32) {
230 // Sanity check int32 230 // Sanity check int32
231 MemoryBuffer<float> buffer32(2); 231 MemoryBuffer<float> buffer32(2);
232 float *p = buffer32; 232 float *p = buffer32;
233 uint8 *p8 = reinterpret_cast<uint8*>(p); 233 uint8 *p8 = reinterpret_cast<uint8*>(p);
234 MemoryWriteStream write_stream(p8, sizeof(int32) * 2); 234 MemoryWriteStream write_stream(p8, sizeof(int32) * 2);
235 235
236 float value = 3.14159; 236 float value = 3.14159f;
237 write_stream.WriteLittleEndianFloat32(value); 237 write_stream.WriteLittleEndianFloat32(value);
238 write_stream.WriteBigEndianFloat32(value); 238 write_stream.WriteBigEndianFloat32(value);
239 239
240 // Verify that the bytes are in the correct order 240 // Verify that the bytes are in the correct order
241 int32 ivalue = *reinterpret_cast<int32*>(&value); // interpret float as int32 241 int32 ivalue = *reinterpret_cast<int32*>(&value); // interpret float as int32
242 uint8 byte1 = ivalue & 0xff; 242 uint8 byte1 = ivalue & 0xff;
243 uint8 byte2 = (ivalue >> 8) & 0xff; 243 uint8 byte2 = (ivalue >> 8) & 0xff;
244 uint8 byte3 = (ivalue >> 16) & 0xff; 244 uint8 byte3 = (ivalue >> 16) & 0xff;
245 uint8 byte4 = (ivalue >> 24) & 0xff; 245 uint8 byte4 = (ivalue >> 24) & 0xff;
246 246
247 // validate little-endian 247 // validate little-endian
248 EXPECT_EQ(byte1, p8[0]); 248 EXPECT_EQ(byte1, p8[0]);
249 EXPECT_EQ(byte2, p8[1]); 249 EXPECT_EQ(byte2, p8[1]);
250 EXPECT_EQ(byte3, p8[2]); 250 EXPECT_EQ(byte3, p8[2]);
251 EXPECT_EQ(byte4, p8[3]); 251 EXPECT_EQ(byte4, p8[3]);
252 252
253 // validate big-endian 253 // validate big-endian
254 EXPECT_EQ(byte4, p8[4]); 254 EXPECT_EQ(byte4, p8[4]);
255 EXPECT_EQ(byte3, p8[5]); 255 EXPECT_EQ(byte3, p8[5]);
256 EXPECT_EQ(byte2, p8[6]); 256 EXPECT_EQ(byte2, p8[6]);
257 EXPECT_EQ(byte1, p8[7]); 257 EXPECT_EQ(byte1, p8[7]);
258 } 258 }
259 259
260 // Write then read int16, int32, and float32 little/big endian values 260 // Write then read int16, int32, and float32 little/big endian values
261 TEST_F(MemoryStreamTest, Endian) { 261 TEST_F(MemoryStreamTest, Endian) {
262 const int16 kValue1 = 13243; 262 const int16 kValue1 = 13243;
263 const int32 kValue2 = 2393043; 263 const int32 kValue2 = 2393043;
264 const float kValue3 = -0.039483; 264 const float kValue3 = -0.039483f;
265 const int16 kValue4 = -3984; 265 const int16 kValue4 = -3984;
266 const float kValue5 = 1234.5678; 266 const float kValue5 = 1234.5678f;
267 const uint8 kValue6 = 5; // write a single byte to make things interesting 267 const uint8 kValue6 = 5; // write a single byte to make things interesting
268 const int32 kValue7 = -3920393; 268 const int32 kValue7 = -3920393;
269 269
270 size_t total_size = sizeof(kValue1) + 270 size_t total_size = sizeof(kValue1) +
271 sizeof(kValue2) + 271 sizeof(kValue2) +
272 sizeof(kValue3) + 272 sizeof(kValue3) +
273 sizeof(kValue4) + 273 sizeof(kValue4) +
274 sizeof(kValue5) + 274 sizeof(kValue5) +
275 sizeof(kValue6) + 275 sizeof(kValue6) +
276 sizeof(kValue7); 276 sizeof(kValue7);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 EXPECT_EQ(read_value1, kValue1); 311 EXPECT_EQ(read_value1, kValue1);
312 EXPECT_EQ(read_value2, kValue2); 312 EXPECT_EQ(read_value2, kValue2);
313 EXPECT_EQ(read_value3, kValue3); 313 EXPECT_EQ(read_value3, kValue3);
314 EXPECT_EQ(read_value4, kValue4); 314 EXPECT_EQ(read_value4, kValue4);
315 EXPECT_EQ(read_value5, kValue5); 315 EXPECT_EQ(read_value5, kValue5);
316 EXPECT_EQ(read_value6, kValue6); 316 EXPECT_EQ(read_value6, kValue6);
317 EXPECT_EQ(read_value7, kValue7); 317 EXPECT_EQ(read_value7, kValue7);
318 } 318 }
319 319
320 } // namespace o3d 320 } // namespace o3d
OLDNEW
« no previous file with comments | « core/win/d3d9/effect_d3d9.cc ('k') | import/import.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698