[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / stdlib / atof_test.cpp
blob3ca27977ecd148dea8b3720369d404ee2b03b845
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/stdlib/atof.h"
12 #include "test/UnitTest/Test.h"
14 #include <errno.h>
15 #include <limits.h>
16 #include <stddef.h>
18 // This is just a simple test to make sure that this function works at all. It's
19 // functionally identical to strtod so the bulk of the testing is there.
20 TEST(LlvmLibcAToFTest, SimpleTest) {
21 __llvm_libc::fputil::FPBits<double> expected_fp =
22 __llvm_libc::fputil::FPBits<double>(uint64_t(0x405ec00000000000));
24 errno = 0;
25 double result = __llvm_libc::atof("123");
27 __llvm_libc::fputil::FPBits<double> actual_fp =
28 __llvm_libc::fputil::FPBits<double>(result);
30 EXPECT_EQ(actual_fp.bits, expected_fp.bits);
31 EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
32 EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
33 EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
34 EXPECT_EQ(errno, 0);
37 TEST(LlvmLibcAToFTest, FailedParsingTest) {
38 __llvm_libc::fputil::FPBits<double> expected_fp =
39 __llvm_libc::fputil::FPBits<double>(uint64_t(0));
41 errno = 0;
42 double result = __llvm_libc::atof("???");
44 __llvm_libc::fputil::FPBits<double> actual_fp =
45 __llvm_libc::fputil::FPBits<double>(result);
47 EXPECT_EQ(actual_fp.bits, expected_fp.bits);
48 EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
49 EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
50 EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
51 EXPECT_EQ(errno, 0);