get_time.pass.cpp revision db2e99f8528c17cdd1d6d53ac68a0c23a2b88049
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// <iomanip>
11
12// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
13
14#include <iomanip>
15#include <cassert>
16
17template <class CharT>
18struct testbuf
19    : public std::basic_streambuf<CharT>
20{
21    typedef std::basic_string<CharT> string_type;
22    typedef std::basic_streambuf<CharT> base;
23private:
24    string_type str_;
25public:
26
27    testbuf() {}
28    testbuf(const string_type& str)
29        : str_(str)
30    {
31        base::setg(const_cast<CharT*>(str_.data()),
32                   const_cast<CharT*>(str_.data()),
33                   const_cast<CharT*>(str_.data()) + str_.size());
34    }
35};
36
37int main()
38{
39    {
40        testbuf<char> sb("  Sat Dec 31 23:55:59 2061");
41        std::istream is(&sb);
42        is.imbue(std::locale("en_US.UTF-8"));
43        std::tm t = {0};
44        is >> std::get_time(&t, "%c");
45        assert(t.tm_sec == 59);
46        assert(t.tm_min == 55);
47        assert(t.tm_hour == 23);
48        assert(t.tm_mday == 31);
49        assert(t.tm_mon == 11);
50        assert(t.tm_year == 161);
51        assert(t.tm_wday == 6);
52        assert(is.eof());
53        assert(!is.fail());
54    }
55    {
56        testbuf<wchar_t> sb(L"  Sat Dec 31 23:55:59 2061");
57        std::wistream is(&sb);
58        is.imbue(std::locale("en_US.UTF-8"));
59        std::tm t = {0};
60        is >> std::get_time(&t, L"%c");
61        assert(t.tm_sec == 59);
62        assert(t.tm_min == 55);
63        assert(t.tm_hour == 23);
64        assert(t.tm_mday == 31);
65        assert(t.tm_mon == 11);
66        assert(t.tm_year == 161);
67        assert(t.tm_wday == 6);
68        assert(is.eof());
69        assert(!is.fail());
70    }
71}
72