diff --git a/include/libyuv/basic_types.h b/include/libyuv/basic_types.h index 9e9f2abc3..3cf7693ba 100644 --- a/include/libyuv/basic_types.h +++ b/include/libyuv/basic_types.h @@ -30,7 +30,7 @@ typedef __int64 int64; #endif #define INT64_F "I64" #else // COMPILER_MSVC -#ifdef __LP64__ +#if defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__) typedef unsigned long uint64; // NOLINT typedef long int64; // NOLINT #ifndef INT64_C @@ -40,7 +40,7 @@ typedef long int64; // NOLINT #define UINT64_C(x) x ## UL #endif #define INT64_F "l" -#else // __LP64__ +#else // defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__) typedef unsigned long long uint64; // NOLINT typedef long long int64; // NOLINT #ifndef INT64_C diff --git a/libyuv_test.gyp b/libyuv_test.gyp index 9b9d8c9ee..6b3660e5b 100644 --- a/libyuv_test.gyp +++ b/libyuv_test.gyp @@ -26,6 +26,7 @@ 'unit_test/unit_test.h', # sources + 'unit_test/basictypes_test.cc', 'unit_test/compare_test.cc', 'unit_test/convert_test.cc', 'unit_test/cpu_test.cc', diff --git a/unit_test/basictypes_test.cc b/unit_test/basictypes_test.cc new file mode 100644 index 000000000..b1f898117 --- /dev/null +++ b/unit_test/basictypes_test.cc @@ -0,0 +1,47 @@ +/* + * Copyright 2012 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "../unit_test/unit_test.h" +#include "libyuv/basic_types.h" + +namespace libyuv { + +TEST_F(libyuvTest, Endian) { + uint16 v16 = 0x1234u; + uint8 first_byte = *reinterpret_cast(&v16); +#if defined(ARCH_CPU_LITTLE_ENDIAN) + EXPECT_EQ(0x34u, first_byte); +#elif defined(ARCH_CPU_BIG_ENDIAN) + EXPECT_EQ(0x12u, first_byte); +#endif +} + +TEST_F(libyuvTest, SizeOfTypes) { + EXPECT_EQ(1u, sizeof(int8)); // NOLINT Using sizeof(type) + EXPECT_EQ(1u, sizeof(uint8)); // NOLINT + EXPECT_EQ(2u, sizeof(int16)); // NOLINT + EXPECT_EQ(2u, sizeof(uint16)); // NOLINT + EXPECT_EQ(4u, sizeof(int32)); // NOLINT + EXPECT_EQ(4u, sizeof(uint32)); // NOLINT + EXPECT_EQ(8u, sizeof(int64)); // NOLINT + EXPECT_EQ(8u, sizeof(uint64)); // NOLINT +} + +TEST_F(libyuvTest, SizeOfConstants) { + EXPECT_EQ(8u, sizeof(INT64_C(0))); + EXPECT_EQ(8u, sizeof(UINT64_C(0))); + EXPECT_EQ(8u, sizeof(INT64_C(0x1234567887654321))); + EXPECT_EQ(8u, sizeof(UINT64_C(0x8765432112345678))); +} + +} // namespace libyuv