Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / stdlib / atof_test.cpp
blobed3d4c26308cb23c9c4ccde0f58dd749ddf1873c
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 //===----------------------------------------------------------------------===//
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"
16 #include <limits.h>
17 #include <stddef.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));
27 libc_errno = 0;
28 EXPECT_THAT(LIBC_NAMESPACE::atof("123"),
29 Succeeds<double>(static_cast<double>(expected_fp)));
32 TEST(LlvmLibcAToFTest, FailedParsingTest) {
33 libc_errno = 0;
34 // atof does not flag errors.
35 EXPECT_THAT(LIBC_NAMESPACE::atof("???"), Succeeds<double>(0.0));