3 * Copyright 2012 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "talk/base/basictypes.h"
30 #include "talk/base/gunit.h"
34 TEST(BasicTypesTest, Endian) {
36 uint8 first_byte = *reinterpret_cast<uint8*>(&v16);
37 #if defined(ARCH_CPU_LITTLE_ENDIAN)
38 EXPECT_EQ(0x34u, first_byte);
39 #elif defined(ARCH_CPU_BIG_ENDIAN)
40 EXPECT_EQ(0x12u, first_byte);
44 TEST(BasicTypesTest, SizeOfTypes) {
53 EXPECT_EQ(1u, sizeof(i8));
54 EXPECT_EQ(1u, sizeof(u8));
55 EXPECT_EQ(2u, sizeof(i16));
56 EXPECT_EQ(2u, sizeof(u16));
57 EXPECT_EQ(4u, sizeof(i32));
58 EXPECT_EQ(4u, sizeof(u32));
59 EXPECT_EQ(8u, sizeof(i64));
60 EXPECT_EQ(8u, sizeof(u64));
71 TEST(BasicTypesTest, SizeOfConstants) {
72 EXPECT_EQ(8u, sizeof(INT64_C(0)));
73 EXPECT_EQ(8u, sizeof(UINT64_C(0)));
74 EXPECT_EQ(8u, sizeof(INT64_C(0x1234567887654321)));
75 EXPECT_EQ(8u, sizeof(UINT64_C(0x8765432112345678)));
79 #if !defined(CPU_ARM) && defined(__arm__)
80 #error expected CPU_ARM to be defined.
82 #if !defined(CPU_X86) && (defined(WIN32) || defined(OSX))
83 #error expected CPU_X86 to be defined.
85 #if !defined(ARCH_CPU_LITTLE_ENDIAN) && \
86 (defined(WIN32) || defined(OSX) || defined(CPU_X86))
87 #error expected ARCH_CPU_LITTLE_ENDIAN to be defined.
90 // TODO(fbarchard): Test all macros in basictypes.h
92 } // namespace talk_base