1 //===-- Unittests for Limits ----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/__support/CPP/Limits.h" 10 #include "src/__support/CPP/UInt.h" 11 #include "utils/UnitTest/Test.h" 12 13 // This just checks against the C spec, almost all implementations will surpass 14 // this. 15 TEST(LlvmLibcLimitsTest, LimitsFollowSpec) { 16 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::max(), INT_MAX); 17 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::min(), INT_MIN); 18 19 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned int>::max(), UINT_MAX); 20 21 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::max(), LONG_MAX); 22 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::min(), LONG_MIN); 23 24 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long>::max(), ULONG_MAX); 25 26 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::max(), LLONG_MAX); 27 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::min(), LLONG_MIN); 28 29 ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long long>::max(), 30 ULLONG_MAX); 31 } 32 33 TEST(LlvmLibcLimitsTest, UInt128Limits) { 34 auto umax128 = 35 __llvm_libc::cpp::NumericLimits<__llvm_libc::cpp::UInt<128>>::max(); 36 auto umax64 = __llvm_libc::cpp::UInt<128>( 37 __llvm_libc::cpp::NumericLimits<uint64_t>::max()); 38 EXPECT_GT(umax128, umax64); 39 ASSERT_EQ(~__llvm_libc::cpp::UInt<128>(0), umax128); 40 #ifdef __SIZEOF_INT128__ 41 ASSERT_EQ(~__uint128_t(0), 42 __llvm_libc::cpp::NumericLimits<__uint128_t>::max()); 43 #endif 44 } 45