1/* 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#include "webrtc/base/basictypes.h" 12 13#include "webrtc/base/gunit.h" 14 15namespace rtc { 16 17TEST(BasicTypesTest, Endian) { 18 uint16 v16 = 0x1234u; 19 uint8 first_byte = *reinterpret_cast<uint8*>(&v16); 20#if defined(ARCH_CPU_LITTLE_ENDIAN) 21 EXPECT_EQ(0x34u, first_byte); 22#elif defined(ARCH_CPU_BIG_ENDIAN) 23 EXPECT_EQ(0x12u, first_byte); 24#endif 25} 26 27TEST(BasicTypesTest, SizeOfTypes) { 28 int8 i8 = -1; 29 uint8 u8 = 1u; 30 int16 i16 = -1; 31 uint16 u16 = 1u; 32 int32 i32 = -1; 33 uint32 u32 = 1u; 34 int64 i64 = -1; 35 uint64 u64 = 1u; 36 EXPECT_EQ(1u, sizeof(i8)); 37 EXPECT_EQ(1u, sizeof(u8)); 38 EXPECT_EQ(2u, sizeof(i16)); 39 EXPECT_EQ(2u, sizeof(u16)); 40 EXPECT_EQ(4u, sizeof(i32)); 41 EXPECT_EQ(4u, sizeof(u32)); 42 EXPECT_EQ(8u, sizeof(i64)); 43 EXPECT_EQ(8u, sizeof(u64)); 44 EXPECT_GT(0, i8); 45 EXPECT_LT(0u, u8); 46 EXPECT_GT(0, i16); 47 EXPECT_LT(0u, u16); 48 EXPECT_GT(0, i32); 49 EXPECT_LT(0u, u32); 50 EXPECT_GT(0, i64); 51 EXPECT_LT(0u, u64); 52} 53 54TEST(BasicTypesTest, SizeOfConstants) { 55 EXPECT_EQ(8u, sizeof(INT64_C(0))); 56 EXPECT_EQ(8u, sizeof(UINT64_C(0))); 57 EXPECT_EQ(8u, sizeof(INT64_C(0x1234567887654321))); 58 EXPECT_EQ(8u, sizeof(UINT64_C(0x8765432112345678))); 59} 60 61// Test CPU_ macros 62#if !defined(CPU_ARM) && defined(__arm__) 63#error expected CPU_ARM to be defined. 64#endif 65#if !defined(CPU_X86) && (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)) 66#error expected CPU_X86 to be defined. 67#endif 68#if !defined(ARCH_CPU_LITTLE_ENDIAN) && \ 69 (defined(WEBRTC_WIN) || defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(CPU_X86)) 70#error expected ARCH_CPU_LITTLE_ENDIAN to be defined. 71#endif 72 73// TODO(fbarchard): Test all macros in basictypes.h 74 75} // namespace rtc 76