]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / input.output / iostream.format / ext.manip / get_time.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // REQUIRES: locale.en_US.UTF-8
11
12 // <iomanip>
13
14 // template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
15
16 #include <iomanip>
17 #include <istream>
18 #include <cassert>
19
20 #include "platform_support.h" // locale name macros
21
22 template <class CharT>
23 struct testbuf
24     : public std::basic_streambuf<CharT>
25 {
26     typedef std::basic_string<CharT> string_type;
27     typedef std::basic_streambuf<CharT> base;
28 private:
29     string_type str_;
30 public:
31
32     testbuf() {}
33     testbuf(const string_type& str)
34         : str_(str)
35     {
36         base::setg(const_cast<CharT*>(str_.data()),
37                    const_cast<CharT*>(str_.data()),
38                    const_cast<CharT*>(str_.data()) + str_.size());
39     }
40 };
41
42 int main()
43 {
44     {
45         testbuf<char> sb("  Sat Dec 31 23:55:59 2061");
46         std::istream is(&sb);
47         is.imbue(std::locale(LOCALE_en_US_UTF_8));
48         std::tm t = {};
49         is >> std::get_time(&t, "%a %b %d %H:%M:%S %Y");
50         assert(t.tm_sec == 59);
51         assert(t.tm_min == 55);
52         assert(t.tm_hour == 23);
53         assert(t.tm_mday == 31);
54         assert(t.tm_mon == 11);
55         assert(t.tm_year == 161);
56         assert(t.tm_wday == 6);
57         assert(is.eof());
58         assert(!is.fail());
59     }
60     {
61         testbuf<wchar_t> sb(L"  Sat Dec 31 23:55:59 2061");
62         std::wistream is(&sb);
63         is.imbue(std::locale(LOCALE_en_US_UTF_8));
64         std::tm t = {};
65         is >> std::get_time(&t, L"%a %b %d %H:%M:%S %Y");
66         assert(t.tm_sec == 59);
67         assert(t.tm_min == 55);
68         assert(t.tm_hour == 23);
69         assert(t.tm_mday == 31);
70         assert(t.tm_mon == 11);
71         assert(t.tm_year == 161);
72         assert(t.tm_wday == 6);
73         assert(is.eof());
74         assert(!is.fail());
75     }
76 }