187c01607SMichael Jones //===-- Unittests for atof ------------------------------------------------===// 287c01607SMichael Jones // 387c01607SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 487c01607SMichael Jones // See https://llvm.org/LICENSE.txt for license information. 587c01607SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 687c01607SMichael Jones // 787c01607SMichael Jones //===----------------------------------------------------------------------===// 887c01607SMichael Jones 987c01607SMichael Jones #include "src/__support/FPUtil/FPBits.h" 1004a9c625SMichael Jones #include "src/errno/libc_errno.h" 1187c01607SMichael Jones #include "src/stdlib/atof.h" 1287c01607SMichael Jones 134f1fe19dSSiva Chandra Reddy #include "test/UnitTest/ErrnoSetterMatcher.h" 14af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h" 1587c01607SMichael Jones 1687c01607SMichael Jones #include <stddef.h> 1787c01607SMichael Jones 18b6bc9d72SGuillaume Chatelet using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; 194f1fe19dSSiva Chandra Reddy 2087c01607SMichael Jones // This is just a simple test to make sure that this function works at all. It's 2187c01607SMichael Jones // functionally identical to strtod so the bulk of the testing is there. TEST(LlvmLibcAToFTest,SimpleTest)2287c01607SMichael JonesTEST(LlvmLibcAToFTest, SimpleTest) { 23b6bc9d72SGuillaume Chatelet LIBC_NAMESPACE::fputil::FPBits<double> expected_fp = 24b6bc9d72SGuillaume Chatelet LIBC_NAMESPACE::fputil::FPBits<double>(uint64_t(0x405ec00000000000)); 2587c01607SMichael Jones 26*3eb1e6d8Smichaelrj-google LIBC_NAMESPACE::libc_errno = 0; 27b6bc9d72SGuillaume Chatelet EXPECT_THAT(LIBC_NAMESPACE::atof("123"), 282856db0dSGuillaume Chatelet Succeeds<double>(expected_fp.get_val())); 2987c01607SMichael Jones } 3087c01607SMichael Jones TEST(LlvmLibcAToFTest,FailedParsingTest)3187c01607SMichael JonesTEST(LlvmLibcAToFTest, FailedParsingTest) { 32*3eb1e6d8Smichaelrj-google LIBC_NAMESPACE::libc_errno = 0; 334f1fe19dSSiva Chandra Reddy // atof does not flag errors. 34b6bc9d72SGuillaume Chatelet EXPECT_THAT(LIBC_NAMESPACE::atof("???"), Succeeds<double>(0.0)); 3587c01607SMichael Jones } 36