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

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

Issue 194061: This fixes some warnings in the Linux release build. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: Created 11 years, 3 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/cross/math_utilities.cc ('k') | no next file » | 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 232 }
233 233
234 // Basic sanity check for endian writing/reading 234 // Basic sanity check for endian writing/reading
235 TEST_F(MemoryStreamTest, EndianSanityFloat32) { 235 TEST_F(MemoryStreamTest, EndianSanityFloat32) {
236 // Sanity check int32 236 // Sanity check int32
237 MemoryBuffer<float> buffer32(2); 237 MemoryBuffer<float> buffer32(2);
238 float *p = buffer32; 238 float *p = buffer32;
239 uint8 *p8 = reinterpret_cast<uint8*>(p); 239 uint8 *p8 = reinterpret_cast<uint8*>(p);
240 MemoryWriteStream write_stream(p8, sizeof(int32) * 2); 240 MemoryWriteStream write_stream(p8, sizeof(int32) * 2);
241 241
242 float value = 3.14159f; 242 union {
243 write_stream.WriteLittleEndianFloat32(value); 243 int32 ivalue;
244 write_stream.WriteBigEndianFloat32(value); 244 float fvalue;
245 } value;
246 value.fvalue = 3.14159f;
247 write_stream.WriteLittleEndianFloat32(value.fvalue);
248 write_stream.WriteBigEndianFloat32(value.fvalue);
245 249
246 // Verify that the bytes are in the correct order 250 // Verify that the bytes are in the correct order
247 int32 ivalue = *reinterpret_cast<int32*>(&value); // interpret float as int32 251 uint8 byte1 = value.ivalue & 0xff;
248 uint8 byte1 = ivalue & 0xff; 252 uint8 byte2 = (value.ivalue >> 8) & 0xff;
249 uint8 byte2 = (ivalue >> 8) & 0xff; 253 uint8 byte3 = (value.ivalue >> 16) & 0xff;
250 uint8 byte3 = (ivalue >> 16) & 0xff; 254 uint8 byte4 = (value.ivalue >> 24) & 0xff;
251 uint8 byte4 = (ivalue >> 24) & 0xff;
252 255
253 // validate little-endian 256 // validate little-endian
254 EXPECT_EQ(byte1, p8[0]); 257 EXPECT_EQ(byte1, p8[0]);
255 EXPECT_EQ(byte2, p8[1]); 258 EXPECT_EQ(byte2, p8[1]);
256 EXPECT_EQ(byte3, p8[2]); 259 EXPECT_EQ(byte3, p8[2]);
257 EXPECT_EQ(byte4, p8[3]); 260 EXPECT_EQ(byte4, p8[3]);
258 261
259 // validate big-endian 262 // validate big-endian
260 EXPECT_EQ(byte4, p8[4]); 263 EXPECT_EQ(byte4, p8[4]);
261 EXPECT_EQ(byte3, p8[5]); 264 EXPECT_EQ(byte3, p8[5]);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EXPECT_EQ(read_value1, kValue1); 320 EXPECT_EQ(read_value1, kValue1);
318 EXPECT_EQ(read_value2, kValue2); 321 EXPECT_EQ(read_value2, kValue2);
319 EXPECT_EQ(read_value3, kValue3); 322 EXPECT_EQ(read_value3, kValue3);
320 EXPECT_EQ(read_value4, kValue4); 323 EXPECT_EQ(read_value4, kValue4);
321 EXPECT_EQ(read_value5, kValue5); 324 EXPECT_EQ(read_value5, kValue5);
322 EXPECT_EQ(read_value6, kValue6); 325 EXPECT_EQ(read_value6, kValue6);
323 EXPECT_EQ(read_value7, kValue7); 326 EXPECT_EQ(read_value7, kValue7);
324 } 327 }
325 328
326 } // namespace o3d 329 } // namespace o3d
OLDNEW
« no previous file with comments | « core/cross/math_utilities.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698