OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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/byteorder.h" | 11 #include "webrtc/base/byteorder.h" |
12 | 12 |
13 #include "webrtc/base/basictypes.h" | 13 #include "webrtc/base/basictypes.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 memory set functions put values into memory in expected order. | 18 // Test memory set functions put values into memory in expected order. |
19 TEST(ByteOrderTest, TestSet) { | 19 TEST(ByteOrderTest, TestSet) { |
20 uint8 buf[8] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; | 20 uint8_t buf[8] = {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}; |
21 Set8(buf, 0, 0xfb); | 21 Set8(buf, 0, 0xfb); |
22 Set8(buf, 1, 0x12); | 22 Set8(buf, 1, 0x12); |
23 EXPECT_EQ(0xfb, buf[0]); | 23 EXPECT_EQ(0xfb, buf[0]); |
24 EXPECT_EQ(0x12, buf[1]); | 24 EXPECT_EQ(0x12, buf[1]); |
25 SetBE16(buf, 0x1234); | 25 SetBE16(buf, 0x1234); |
26 EXPECT_EQ(0x12, buf[0]); | 26 EXPECT_EQ(0x12, buf[0]); |
27 EXPECT_EQ(0x34, buf[1]); | 27 EXPECT_EQ(0x34, buf[1]); |
28 SetLE16(buf, 0x1234); | 28 SetLE16(buf, 0x1234); |
29 EXPECT_EQ(0x34, buf[0]); | 29 EXPECT_EQ(0x34, buf[0]); |
30 EXPECT_EQ(0x12, buf[1]); | 30 EXPECT_EQ(0x12, buf[1]); |
(...skipping 22 matching lines...) Expand all Loading... |
53 EXPECT_EQ(0xab, buf[2]); | 53 EXPECT_EQ(0xab, buf[2]); |
54 EXPECT_EQ(0x89, buf[3]); | 54 EXPECT_EQ(0x89, buf[3]); |
55 EXPECT_EQ(0x67, buf[4]); | 55 EXPECT_EQ(0x67, buf[4]); |
56 EXPECT_EQ(0x45, buf[5]); | 56 EXPECT_EQ(0x45, buf[5]); |
57 EXPECT_EQ(0x23, buf[6]); | 57 EXPECT_EQ(0x23, buf[6]); |
58 EXPECT_EQ(0x01, buf[7]); | 58 EXPECT_EQ(0x01, buf[7]); |
59 } | 59 } |
60 | 60 |
61 // Test memory get functions get values from memory in expected order. | 61 // Test memory get functions get values from memory in expected order. |
62 TEST(ByteOrderTest, TestGet) { | 62 TEST(ByteOrderTest, TestGet) { |
63 uint8 buf[8]; | 63 uint8_t buf[8]; |
64 buf[0] = 0x01u; | 64 buf[0] = 0x01u; |
65 buf[1] = 0x23u; | 65 buf[1] = 0x23u; |
66 buf[2] = 0x45u; | 66 buf[2] = 0x45u; |
67 buf[3] = 0x67u; | 67 buf[3] = 0x67u; |
68 buf[4] = 0x89u; | 68 buf[4] = 0x89u; |
69 buf[5] = 0xabu; | 69 buf[5] = 0xabu; |
70 buf[6] = 0xcdu; | 70 buf[6] = 0xcdu; |
71 buf[7] = 0xefu; | 71 buf[7] = 0xefu; |
72 EXPECT_EQ(0x01u, Get8(buf, 0)); | 72 EXPECT_EQ(0x01u, Get8(buf, 0)); |
73 EXPECT_EQ(0x23u, Get8(buf, 1)); | 73 EXPECT_EQ(0x23u, Get8(buf, 1)); |
74 EXPECT_EQ(0x0123u, GetBE16(buf)); | 74 EXPECT_EQ(0x0123u, GetBE16(buf)); |
75 EXPECT_EQ(0x2301u, GetLE16(buf)); | 75 EXPECT_EQ(0x2301u, GetLE16(buf)); |
76 EXPECT_EQ(0x01234567u, GetBE32(buf)); | 76 EXPECT_EQ(0x01234567u, GetBE32(buf)); |
77 EXPECT_EQ(0x67452301u, GetLE32(buf)); | 77 EXPECT_EQ(0x67452301u, GetLE32(buf)); |
78 EXPECT_EQ(UINT64_C(0x0123456789abcdef), GetBE64(buf)); | 78 EXPECT_EQ(UINT64_C(0x0123456789abcdef), GetBE64(buf)); |
79 EXPECT_EQ(UINT64_C(0xefcdab8967452301), GetLE64(buf)); | 79 EXPECT_EQ(UINT64_C(0xefcdab8967452301), GetLE64(buf)); |
80 } | 80 } |
81 | 81 |
82 } // namespace rtc | 82 } // namespace rtc |
83 | 83 |
OLD | NEW |