brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 92b904e Raw
35 lines · cpp
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-exception6//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 18using LlvmLibcAToFTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;19using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;20 21// This is just a simple test to make sure that this function works at all. It's22// functionally identical to strtod so the bulk of the testing is there.23TEST_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 31TEST_F(LlvmLibcAToFTest, FailedParsingTest) {32  // atof does not flag errors.33  EXPECT_THAT(LIBC_NAMESPACE::atof("???"), Succeeds<double>(0.0));34}35