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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libc/test/src/time/difftime_test.cpp