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