diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
commit | 315d10f09ee888005b1da55e7bbb57d8a79b8447 (patch) | |
tree | 99a16e8c2272e507281e63fac5970e0548df04ea /test/std/utilities | |
parent | f36202620b428c45a1c8d91743727c9313424fb2 (diff) |
Vendor import of libc++ trunk r338536:vendor/libc++/libc++-trunk-r338536
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=337143
svn path=/vendor/libc++/libc++-trunk-r338536/; revision=337144; tag=vendor/libc++/libc++-trunk-r338536
Diffstat (limited to 'test/std/utilities')
5 files changed, 338 insertions, 0 deletions
diff --git a/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp b/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp new file mode 100644 index 000000000000..d21b638d0fc7 --- /dev/null +++ b/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// In +// +// from_chars_result from_chars(const char* first, const char* last, +// Integral& value, int base = 10) +// +// Integral cannot be bool. + +#include <charconv> + +int main() +{ + using std::from_chars; + char buf[] = "01001"; + bool lv; + + from_chars(buf, buf + sizeof(buf), lv); // expected-error {{call to deleted function}} + from_chars(buf, buf + sizeof(buf), lv, 16); // expected-error {{call to deleted function}} +} diff --git a/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp b/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp new file mode 100644 index 000000000000..3fc533a772fa --- /dev/null +++ b/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// from_chars_result from_chars(const char* first, const char* last, +// Integral& value, int base = 10) + +#include "charconv_test_helpers.h" + +template <typename T> +struct test_basics : roundtrip_test_base<T> +{ + using roundtrip_test_base<T>::test; + + void operator()() + { + test(0); + test(42); + test(32768); + test(0, 10); + test(42, 10); + test(32768, 10); + test(0xf, 16); + test(0xdeadbeaf, 16); + test(0755, 8); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test(1, b); + test(-1, b); + test(xl::lowest(), b); + test((xl::max)(), b); + test((xl::max)() / 2, b); + } + + using std::from_chars; + std::from_chars_result r; + T x; + + { + char s[] = "001x"; + + // the expected form of the subject sequence is a sequence of + // letters and digits representing an integer with the radix + // specified by base (C11 7.22.1.4/3) + r = from_chars(s, s + sizeof(s), x); + assert(r.ec == std::errc{}); + assert(r.ptr == s + 3); + assert(x == 1); + } + + { + char s[] = "0X7BAtSGHDkEIXZg "; + + // The letters from a (or A) through z (or Z) are ascribed the + // values 10 through 35; (C11 7.22.1.4/3) + r = from_chars(s, s + sizeof(s), x, 36); + assert(r.ec == std::errc::result_out_of_range); + // The member ptr of the return value points to the first character + // not matching the pattern + assert(r.ptr == s + sizeof(s) - 2); + assert(x == 1); + + // no "0x" or "0X" prefix shall appear if the value of base is 16 + r = from_chars(s, s + sizeof(s), x, 16); + assert(r.ec == std::errc{}); + assert(r.ptr == s + 1); + assert(x == 0); + + // only letters and digits whose ascribed values are less than that + // of base are permitted. (C11 7.22.1.4/3) + r = from_chars(s + 2, s + sizeof(s), x, 12); + // If the parsed value is not in the range representable by the type + // of value, + if (!fits_in<T>(1150)) + { + // value is unmodified and + assert(x == 0); + // the member ec of the return value is equal to + // errc::result_out_of_range + assert(r.ec == std::errc::result_out_of_range); + } + else + { + // Otherwise, value is set to the parsed value, + assert(x == 1150); + // and the member ec is value-initialized. + assert(r.ec == std::errc{}); + } + assert(r.ptr == s + 5); + } + } +}; + +template <typename T> +struct test_signed : roundtrip_test_base<T> +{ + using roundtrip_test_base<T>::test; + + void operator()() + { + test(-1); + test(-12); + test(-1, 10); + test(-12, 10); + test(-21734634, 10); + test(-2647, 2); + test(-0xcc1, 16); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test(0, b); + test(xl::lowest(), b); + test((xl::max)(), b); + } + + using std::from_chars; + std::from_chars_result r; + T x; + + { + // If the pattern allows for an optional sign, + // but the string has no digit characters following the sign, + char s[] = "- 9+12"; + r = from_chars(s, s + sizeof(s), x); + // no characters match the pattern. + assert(r.ptr == s); + assert(r.ec == std::errc::invalid_argument); + } + + { + char s[] = "9+12"; + r = from_chars(s, s + sizeof(s), x); + assert(r.ec == std::errc{}); + // The member ptr of the return value points to the first character + // not matching the pattern, + assert(r.ptr == s + 1); + assert(x == 9); + } + + { + char s[] = "12"; + r = from_chars(s, s + 2, x); + assert(r.ec == std::errc{}); + // or has the value last if all characters match. + assert(r.ptr == s + 2); + assert(x == 12); + } + + { + // '-' is the only sign that may appear + char s[] = "+30"; + // If no characters match the pattern, + r = from_chars(s, s + sizeof(s), x); + // value is unmodified, + assert(x == 12); + // the member ptr of the return value is first and + assert(r.ptr == s); + // the member ec is equal to errc::invalid_argument. + assert(r.ec == std::errc::invalid_argument); + } + } +}; + +int +main() +{ + run<test_basics>(integrals); + run<test_signed>(all_signed); +} diff --git a/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp b/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp new file mode 100644 index 000000000000..e3d702a3a9c3 --- /dev/null +++ b/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// In +// +// to_chars_result to_chars(char* first, char* last, Integral value, +// int base = 10) +// +// Integral cannot be bool. + +#include <charconv> + +int main() +{ + using std::to_chars; + char buf[10]; + bool lv = true; + + to_chars(buf, buf + sizeof(buf), false); // expected-error {{call to deleted function}} + to_chars(buf, buf + sizeof(buf), lv, 16); // expected-error {{call to deleted function}} +} diff --git a/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp b/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp new file mode 100644 index 000000000000..50ca5b1906ea --- /dev/null +++ b/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// to_chars_result to_chars(char* first, char* last, Integral value, +// int base = 10) + +#include "charconv_test_helpers.h" + +template <typename T> +struct test_basics : to_chars_test_base<T> +{ + using to_chars_test_base<T>::test; + using to_chars_test_base<T>::test_value; + + void operator()() + { + test(0, "0"); + test(42, "42"); + test(32768, "32768"); + test(0, "0", 10); + test(42, "42", 10); + test(32768, "32768", 10); + test(0xf, "f", 16); + test(0xdeadbeaf, "deadbeaf", 16); + test(0755, "755", 8); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test_value(1, b); + test_value(xl::lowest(), b); + test_value((xl::max)(), b); + test_value((xl::max)() / 2, b); + } + } +}; + +template <typename T> +struct test_signed : to_chars_test_base<T> +{ + using to_chars_test_base<T>::test; + using to_chars_test_base<T>::test_value; + + void operator()() + { + test(-1, "-1"); + test(-12, "-12"); + test(-1, "-1", 10); + test(-12, "-12", 10); + test(-21734634, "-21734634", 10); + test(-2647, "-101001010111", 2); + test(-0xcc1, "-cc1", 16); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test_value(0, b); + test_value(xl::lowest(), b); + test_value((xl::max)(), b); + } + } +}; + +int +main() +{ + run<test_basics>(integrals); + run<test_signed>(all_signed); +} diff --git a/test/std/utilities/time/date.time/ctime.pass.cpp b/test/std/utilities/time/date.time/ctime.pass.cpp index b9e19af32952..fe9f38daa3ff 100644 --- a/test/std/utilities/time/date.time/ctime.pass.cpp +++ b/test/std/utilities/time/date.time/ctime.pass.cpp @@ -10,6 +10,8 @@ #include <ctime> #include <type_traits> +#include "test_macros.h" + #ifndef NULL #error NULL not defined #endif @@ -18,6 +20,12 @@ #error CLOCKS_PER_SEC not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef TIME_UTC +#error TIME_UTC not defined +#endif +#endif + int main() { std::clock_t c = 0; @@ -30,10 +38,18 @@ int main() ((void)t); // Prevent unused warning ((void)tm); // Prevent unused warning ((void)str); // Prevent unused warning +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + std::timespec tmspec = {}; + ((void)tmspec); // Prevent unused warning +#endif + static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), ""); +#endif #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); |