1 //===----------------------------------------------------------------------===//
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 // <locale>
10
11 // class time_get<charT, InputIterator>
12
13 // iter_type
14 // get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err, tm *t,
15 // const char_type *fmt, const char_type *fmtend) const;
16
17 #include <locale>
18 #include <cassert>
19 #include <ios>
20 #include "test_macros.h"
21 #include "test_iterators.h"
22
23 typedef input_iterator<const char*> I;
24
25 typedef std::time_get<char, I> F;
26
27 class my_facet
28 : public F
29 {
30 public:
my_facet(std::size_t refs=0)31 explicit my_facet(std::size_t refs = 0)
32 : F(refs) {}
33 };
34
main(int,char **)35 int main(int, char**)
36 {
37 const my_facet f(1);
38 std::ios ios(0);
39 std::ios_base::iostate err;
40 std::tm t;
41 {
42 const char in[] = "2009 May 9, 10:27pm";
43 const char fmt[] = "%Y %b %d, %I:%M%p";
44 err = std::ios_base::goodbit;
45 t = std::tm();
46 I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1);
47 assert(i.base() == in+sizeof(in)-1);
48 assert(t.tm_year == 109);
49 assert(t.tm_mon == 4);
50 assert(t.tm_mday == 9);
51 assert(t.tm_hour == 22);
52 assert(t.tm_min == 27);
53 assert(err == std::ios_base::eofbit);
54 }
55 {
56 const char in[] = "10:27PM May 9, 2009";
57 const char fmt[] = "%I:%M%p %b %d, %Y";
58 err = std::ios_base::goodbit;
59 t = std::tm();
60 I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1);
61 assert(i.base() == in+sizeof(in)-1);
62 assert(t.tm_year == 109);
63 assert(t.tm_mon == 4);
64 assert(t.tm_mday == 9);
65 assert(t.tm_hour == 22);
66 assert(t.tm_min == 27);
67 assert(err == std::ios_base::eofbit);
68 }
69
70 return 0;
71 }
72