Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / localization / locale.categories / category.time / locale.time.get.byname / 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 // REQUIRES: locale.fr_FR.UTF-8
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14
15 // <locale>
16
17 // class time_get_byname<charT, InputIterator>
18
19 // iter_type
20 // get_time(iter_type s, iter_type end, ios_base& str,
21 //          ios_base::iostate& err, tm* t) const;
22
23 #include <locale>
24 #include <cassert>
25 #include "test_iterators.h"
26
27 #include "platform_support.h" // locale name macros
28
29 typedef input_iterator<const char*> I;
30
31 typedef std::time_get_byname<char, I> F;
32
33 class my_facet
34     : public F
35 {
36 public:
37     explicit my_facet(const std::string& nm, std::size_t refs = 0)
38         : F(nm, refs) {}
39 };
40
41 int main()
42 {
43     std::ios ios(0);
44     std::ios_base::iostate err;
45     std::tm t;
46     {
47         const my_facet f(LOCALE_en_US_UTF_8, 1);
48         const char in[] = "13:14:15";
49         err = std::ios_base::goodbit;
50         t = std::tm();
51         I i = f.get_time(I(in), I(in+sizeof(in)-1), ios, err, &t);
52         assert(i.base() == in+sizeof(in)-1);
53         assert(t.tm_hour == 13);
54         assert(t.tm_min == 14);
55         assert(t.tm_sec == 15);
56         assert(err == std::ios_base::eofbit);
57     }
58     {
59         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
60         const char in[] = "13:14:15";
61         err = std::ios_base::goodbit;
62         t = std::tm();
63         I i = f.get_time(I(in), I(in+sizeof(in)-1), ios, err, &t);
64         assert(i.base() == in+sizeof(in)-1);
65         assert(t.tm_hour == 13);
66         assert(t.tm_min == 14);
67         assert(t.tm_sec == 15);
68         assert(err == std::ios_base::eofbit);
69     }
70     {
71         const my_facet f(LOCALE_ru_RU_UTF_8, 1);
72         const char in[] = "13:14:15";
73         err = std::ios_base::goodbit;
74         t = std::tm();
75         I i = f.get_time(I(in), I(in+sizeof(in)-1), ios, err, &t);
76         assert(i.base() == in+sizeof(in)-1);
77         assert(t.tm_hour == 13);
78         assert(t.tm_min == 14);
79         assert(t.tm_sec == 15);
80         assert(err == std::ios_base::eofbit);
81     }
82     {
83         const my_facet f(LOCALE_zh_CN_UTF_8, 1);
84         const char in[] = "13:14:15";
85         err = std::ios_base::goodbit;
86         t = std::tm();
87         I i = f.get_time(I(in), I(in+sizeof(in)-1), ios, err, &t);
88         assert(i.base() == in+sizeof(in)-1);
89         assert(t.tm_hour == 13);
90         assert(t.tm_min == 14);
91         assert(t.tm_sec == 15);
92         assert(err == std::ios_base::eofbit);
93     }
94 }