1 | //===-- Unittests for difftime --------------------------------------------===// |
---|---|
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/time/difftime.h" |
11 | #include "src/time/time_utils.h" |
12 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
13 | #include "test/UnitTest/Test.h" |
14 | |
15 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; |
16 | using LIBC_NAMESPACE::time_utils::TimeConstants; |
17 | |
18 | TEST(LlvmLibcDifftime, SmokeTest) { |
19 | time_t t1_seconds = TimeConstants::SECONDS_PER_HOUR; |
20 | time_t t2_seconds = 0; |
21 | |
22 | LIBC_NAMESPACE::fputil::FPBits<long double> expected_fp = |
23 | LIBC_NAMESPACE::fputil::FPBits<long double>(); |
24 | expected_fp = LIBC_NAMESPACE::fputil::FPBits<long double>( |
25 | static_cast<long double>(t1_seconds)); |
26 | |
27 | double result = LIBC_NAMESPACE::difftime(end: t1_seconds, beginning: t2_seconds); |
28 | |
29 | LIBC_NAMESPACE::fputil::FPBits<long double> actual_fp = |
30 | LIBC_NAMESPACE::fputil::FPBits<long double>(); |
31 | actual_fp = LIBC_NAMESPACE::fputil::FPBits<long double>( |
32 | static_cast<long double>(result)); |
33 | |
34 | EXPECT_EQ(actual_fp.uintval(), expected_fp.uintval()); |
35 | EXPECT_EQ(actual_fp.is_neg(), expected_fp.is_neg()); |
36 | EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent()); |
37 | EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa()); |
38 | } |
39 |