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/basictypes.h" | 11 #include "webrtc/base/basictypes.h" |
12 | 12 |
13 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
14 | 14 |
15 namespace rtc { | 15 namespace rtc { |
16 | 16 |
17 static_assert(sizeof(int8) == 1, "Unexpected size"); | |
18 static_assert(sizeof(uint8) == 1, "Unexpected size"); | |
19 static_assert(sizeof(int16) == 2, "Unexpected size"); | |
20 static_assert(sizeof(uint16) == 2, "Unexpected size"); | |
21 static_assert(sizeof(int32) == 4, "Unexpected size"); | |
22 static_assert(sizeof(uint32) == 4, "Unexpected size"); | |
23 static_assert(sizeof(int64) == 8, "Unexpected size"); | |
24 static_assert(sizeof(uint64) == 8, "Unexpected size"); | |
25 | |
26 TEST(BasicTypesTest, Endian) { | 17 TEST(BasicTypesTest, Endian) { |
27 uint16 v16 = 0x1234u; | 18 uint16_t v16 = 0x1234u; |
28 uint8 first_byte = *reinterpret_cast<uint8*>(&v16); | 19 uint8_t first_byte = *reinterpret_cast<uint8_t*>(&v16); |
29 #if defined(RTC_ARCH_CPU_LITTLE_ENDIAN) | 20 #if defined(RTC_ARCH_CPU_LITTLE_ENDIAN) |
30 EXPECT_EQ(0x34u, first_byte); | 21 EXPECT_EQ(0x34u, first_byte); |
31 #elif defined(RTC_ARCH_CPU_BIG_ENDIAN) | 22 #elif defined(RTC_ARCH_CPU_BIG_ENDIAN) |
32 EXPECT_EQ(0x12u, first_byte); | 23 EXPECT_EQ(0x12u, first_byte); |
33 #endif | 24 #endif |
34 } | 25 } |
35 | 26 |
36 TEST(BasicTypesTest, SizeOfTypes) { | |
37 int8 i8 = -1; | |
38 uint8 u8 = 1u; | |
39 int16 i16 = -1; | |
40 uint16 u16 = 1u; | |
41 int32 i32 = -1; | |
42 uint32 u32 = 1u; | |
43 int64 i64 = -1; | |
44 uint64 u64 = 1u; | |
45 EXPECT_EQ(1u, sizeof(i8)); | |
46 EXPECT_EQ(1u, sizeof(u8)); | |
47 EXPECT_EQ(2u, sizeof(i16)); | |
48 EXPECT_EQ(2u, sizeof(u16)); | |
49 EXPECT_EQ(4u, sizeof(i32)); | |
50 EXPECT_EQ(4u, sizeof(u32)); | |
51 EXPECT_EQ(8u, sizeof(i64)); | |
52 EXPECT_EQ(8u, sizeof(u64)); | |
53 EXPECT_GT(0, i8); | |
54 EXPECT_LT(0u, u8); | |
55 EXPECT_GT(0, i16); | |
56 EXPECT_LT(0u, u16); | |
57 EXPECT_GT(0, i32); | |
58 EXPECT_LT(0u, u32); | |
59 EXPECT_GT(0, i64); | |
60 EXPECT_LT(0u, u64); | |
61 } | |
62 | |
63 TEST(BasicTypesTest, SizeOfConstants) { | 27 TEST(BasicTypesTest, SizeOfConstants) { |
64 EXPECT_EQ(8u, sizeof(INT64_C(0))); | 28 EXPECT_EQ(8u, sizeof(INT64_C(0))); |
65 EXPECT_EQ(8u, sizeof(UINT64_C(0))); | 29 EXPECT_EQ(8u, sizeof(UINT64_C(0))); |
66 EXPECT_EQ(8u, sizeof(INT64_C(0x1234567887654321))); | 30 EXPECT_EQ(8u, sizeof(INT64_C(0x1234567887654321))); |
67 EXPECT_EQ(8u, sizeof(UINT64_C(0x8765432112345678))); | 31 EXPECT_EQ(8u, sizeof(UINT64_C(0x8765432112345678))); |
68 } | 32 } |
69 | 33 |
70 // Test CPU_ macros | 34 // Test CPU_ macros |
71 #if !defined(CPU_ARM) && defined(__arm__) | 35 #if !defined(CPU_ARM) && defined(__arm__) |
72 #error expected CPU_ARM to be defined. | 36 #error expected CPU_ARM to be defined. |
73 #endif | 37 #endif |
74 #if !defined(CPU_X86) && (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined
(WEBRTC_IOS)) | 38 #if !defined(CPU_X86) && (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined
(WEBRTC_IOS)) |
75 #error expected CPU_X86 to be defined. | 39 #error expected CPU_X86 to be defined. |
76 #endif | 40 #endif |
77 #if !defined(RTC_ARCH_CPU_LITTLE_ENDIAN) && \ | 41 #if !defined(RTC_ARCH_CPU_LITTLE_ENDIAN) && \ |
78 (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined
(CPU_X86)) | 42 (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined
(CPU_X86)) |
79 #error expected RTC_ARCH_CPU_LITTLE_ENDIAN to be defined. | 43 #error expected RTC_ARCH_CPU_LITTLE_ENDIAN to be defined. |
80 #endif | 44 #endif |
81 | 45 |
82 // TODO(fbarchard): Test all macros in basictypes.h | 46 // TODO(fbarchard): Test all macros in basictypes.h |
83 | 47 |
84 } // namespace rtc | 48 } // namespace rtc |
OLD | NEW |