62 lines · cpp
1//===-- Unittests for nanf128 ---------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "hdr/signal_macros.h"10#include "src/__support/FPUtil/FPBits.h"11#include "src/__support/uint128.h"12#include "src/math/nanf128.h"13#include "test/UnitTest/FEnvSafeTest.h"14#include "test/UnitTest/FPMatcher.h"15#include "test/UnitTest/Test.h"16 17class LlvmLibcNanf128Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {18public:19 using FPBits128 = LIBC_NAMESPACE::fputil::FPBits<float128>;20 using StorageType = FPBits128::StorageType;21 22 const UInt128 QUIET_NAN = FPBits128::quiet_nan().uintval();23 const UInt128 ONE = UInt128(1);24 25 void run_test(const char *input_str, StorageType bits) {26 float128 result = LIBC_NAMESPACE::nanf128(input_str);27 auto actual_fp = FPBits128(result);28 auto expected_fp = FPBits128(bits);29 EXPECT_EQ(actual_fp.uintval(), expected_fp.uintval());30 }31};32 33TEST_F(LlvmLibcNanf128Test, NCharSeq) {34 run_test("", QUIET_NAN);35 run_test("1234", QUIET_NAN | 1234);36 run_test("0x1234", QUIET_NAN | 0x1234);37 run_test("2417851639229258349412352", QUIET_NAN | (ONE << 81));38 run_test("0x200000000000000000000", QUIET_NAN | (ONE << 81));39 run_test("10384593717069655257060992658440191",40 QUIET_NAN | FPBits128::SIG_MASK);41 run_test("0x1ffffffffffffffffffffffffffff", QUIET_NAN | FPBits128::SIG_MASK);42 run_test("10384593717069655257060992658440192", QUIET_NAN);43 run_test("0x20000000000000000000000000000", QUIET_NAN);44 run_test("1a", QUIET_NAN);45 run_test("10000000000000000000000000000000000000000000000000", QUIET_NAN);46}47 48TEST_F(LlvmLibcNanf128Test, RandomString) {49 run_test(" 1234", QUIET_NAN);50 run_test("-1234", QUIET_NAN);51 run_test("asd&f", QUIET_NAN);52 run_test("123 ", QUIET_NAN);53 run_test("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_",54 QUIET_NAN);55}56 57#if defined(LIBC_ADD_NULL_CHECKS)58TEST_F(LlvmLibcNanf128Test, InvalidInput) {59 EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); }, WITH_SIGNAL(-1));60}61#endif // LIBC_ADD_NULL_CHECKS62