| 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/stdlib/atof.h" |
| 11 | |
| 12 | #include "test/UnitTest/ErrnoCheckingTest.h" |
| 13 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
| 14 | #include "test/UnitTest/Test.h" |
| 15 | |
| 16 | #include <stddef.h> |
| 17 | |
| 18 | using LlvmLibcAToFTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
| 19 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; |
| 20 | |
| 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_F(LlvmLibcAToFTest, SimpleTest) { |
| 24 | LIBC_NAMESPACE::fputil::FPBits<double> expected_fp = |
| 25 | LIBC_NAMESPACE::fputil::FPBits<double>(uint64_t(0x405ec00000000000)); |
| 26 | |
| 27 | EXPECT_THAT(LIBC_NAMESPACE::atof("123" ), |
| 28 | Succeeds<double>(expected_fp.get_val())); |
| 29 | } |
| 30 | |
| 31 | TEST_F(LlvmLibcAToFTest, FailedParsingTest) { |
| 32 | // atof does not flag errors. |
| 33 | EXPECT_THAT(LIBC_NAMESPACE::atof("???" ), Succeeds<double>(0.0)); |
| 34 | } |
| 35 | |