1 //===-- Unittests for atof ------------------------------------------------===// 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/FPUtil/FPBits.h" 10 #include "src/errno/libc_errno.h" 11 #include "src/stdlib/atof.h" 12 13 #include "test/UnitTest/ErrnoSetterMatcher.h" 14 #include "test/UnitTest/Test.h" 15 16 #include <stddef.h> 17 18 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; 19 20 // This is just a simple test to make sure that this function works at all. It's 21 // functionally identical to strtod so the bulk of the testing is there. TEST(LlvmLibcAToFTest,SimpleTest)22TEST(LlvmLibcAToFTest, SimpleTest) { 23 LIBC_NAMESPACE::fputil::FPBits<double> expected_fp = 24 LIBC_NAMESPACE::fputil::FPBits<double>(uint64_t(0x405ec00000000000)); 25 26 LIBC_NAMESPACE::libc_errno = 0; 27 EXPECT_THAT(LIBC_NAMESPACE::atof("123"), 28 Succeeds<double>(expected_fp.get_val())); 29 } 30 TEST(LlvmLibcAToFTest,FailedParsingTest)31TEST(LlvmLibcAToFTest, FailedParsingTest) { 32 LIBC_NAMESPACE::libc_errno = 0; 33 // atof does not flag errors. 34 EXPECT_THAT(LIBC_NAMESPACE::atof("???"), Succeeds<double>(0.0)); 35 } 36