1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Adaptation to Boost of the libcxx
// Copyright 2010 Vicente J. Botet Escriba
// Copyright (c) Microsoft Corporation 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/type_traits/is_same.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
#include <boost/chrono/thread_clock.hpp>
#include <boost/system/system_error.hpp>
#include <boost/detail/lightweight_test.hpp>
#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
#define NOTHING ""
#endif
template <typename Clock>
void check_clock_invariants()
{
BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::rep, typename Clock::duration::rep>::value), NOTHING, ());
BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::period, typename Clock::duration::period>::value), NOTHING, ());
BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::duration, typename Clock::time_point::duration>::value), NOTHING, ());
BOOST_CHRONO_STATIC_ASSERT(Clock::is_steady || !Clock::is_steady, NOTHING, ());
// to be replaced by has static member bool is_steady
}
template <typename Clock>
void check_clock_now()
{
typename Clock::time_point t1 = Clock::now();
(void)t1;
}
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
template <typename Clock>
void check_clock_now_ec()
{
boost::system::error_code ec;
typename Clock::time_point t1 = Clock::now(ec);
(void)t1;
BOOST_TEST(ec.value()==0);
}
template <typename Clock>
void check_clock_now_throws()
{
typename Clock::time_point t1 = Clock::now(boost::throws());
(void)t1;
}
#ifndef BOOST_NO_EXCEPTIONS
template <typename Clock>
void check_clock_now_err(int err)
{
Clock::set_errno(err);
try {
typename Clock::time_point t1 = Clock::now();
} catch (boost::system::system_error& ex) {
BOOST_TEST(ex.code().value()==err);
// BOOST_TEST(ex.code().category() == ::boost::system::system_category());
// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock"));
}
Clock::set_errno(0);
}
#endif
template <typename Clock>
void check_clock_now_ec_err(int err)
{
Clock::set_errno(err);
boost::system::error_code ec;
typename Clock::time_point t1 = Clock::now(ec);
BOOST_TEST(ec.value()==err);
// BOOST_TEST(ec.category() == ::boost::system::system_category());
Clock::set_errno(0);
}
#ifndef BOOST_NO_EXCEPTIONS
template <typename Clock>
void check_clock_now_throws_err(int err)
{
Clock::set_errno(err);
try {
typename Clock::time_point t1 = Clock::now(boost::throws());
BOOST_TEST(0&&"exception not thown");
} catch (boost::system::system_error& ex) {
BOOST_TEST(ex.code().value()==err);
// BOOST_TEST(ex.code().category() == ::boost::system::system_category());
// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock"));
}
Clock::set_errno(0);
}
#endif
#endif
int main()
{
check_clock_invariants<boost::chrono::high_resolution_clock>();
check_clock_now<boost::chrono::high_resolution_clock>();
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
check_clock_invariants<boost::chrono::steady_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::steady_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::steady_clock>();
#endif
check_clock_invariants<boost::chrono::system_clock>();
BOOST_CHRONO_STATIC_ASSERT(!boost::chrono::system_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::system_clock>();
{
typedef boost::chrono::system_clock C;
C::time_point t1 = C::from_time_t(C::to_time_t(C::now()));
(void)t1;
}
{
typedef boost::chrono::system_clock C;
std::time_t t1 = C::to_time_t(C::now());
(void)t1;
}
{
BOOST_TEST((boost::chrono::system_clock::duration::min)() <
boost::chrono::system_clock::duration::zero());
}
#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
check_clock_invariants<boost::chrono::thread_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::thread_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::thread_clock>();
#endif
#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
check_clock_invariants<boost::chrono::process_real_cpu_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_real_cpu_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::process_real_cpu_clock>();
#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
check_clock_invariants<boost::chrono::process_user_cpu_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_user_cpu_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::process_user_cpu_clock>();
check_clock_invariants<boost::chrono::process_system_cpu_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_system_cpu_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::process_system_cpu_clock>();
check_clock_invariants<boost::chrono::process_cpu_clock>();
BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_cpu_clock::is_steady, NOTHING, ());
check_clock_now<boost::chrono::process_cpu_clock>();
#endif
#endif
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
check_clock_now_ec<boost::chrono::high_resolution_clock>();
check_clock_now_throws<boost::chrono::high_resolution_clock>();
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
check_clock_now_ec<boost::chrono::steady_clock>();
check_clock_now_throws<boost::chrono::steady_clock>();
#endif
check_clock_now_ec<boost::chrono::system_clock>();
check_clock_now_throws<boost::chrono::system_clock>();
#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
check_clock_now_ec<boost::chrono::thread_clock>();
check_clock_now_throws<boost::chrono::thread_clock>();
#endif
#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
check_clock_now_ec<boost::chrono::process_real_cpu_clock>();
check_clock_now_throws<boost::chrono::process_real_cpu_clock>();
#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
check_clock_now_ec<boost::chrono::process_user_cpu_clock>();
check_clock_now_throws<boost::chrono::process_user_cpu_clock>();
check_clock_now_ec<boost::chrono::process_system_cpu_clock>();
check_clock_now_throws<boost::chrono::process_system_cpu_clock>();
check_clock_now_ec<boost::chrono::process_cpu_clock>();
check_clock_now_throws<boost::chrono::process_cpu_clock>();
#endif
#endif
#endif
return boost::report_errors();
}
|