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// GLIBC Expects "10/06/2009" for fr_FR as opposed to "10.06.2009"
16// GLIBC also failes on the zh_CN test.
17// XFAIL: linux
18
19// <locale>
20
21// class time_get_byname<charT, InputIterator>
22
23// iter_type
24// get_date(iter_type s, iter_type end, ios_base& str,
25//          ios_base::iostate& err, tm* t) const;
26
27#include <locale>
28#include <cassert>
29#include "test_iterators.h"
30
31#include "platform_support.h" // locale name macros
32
33typedef input_iterator<const wchar_t*> I;
34
35typedef std::time_get_byname<wchar_t, I> F;
36
37class my_facet
38    : public F
39{
40public:
41    explicit my_facet(const std::string& nm, std::size_t refs = 0)
42        : F(nm, refs) {}
43};
44
45int main()
46{
47    std::ios ios(0);
48    std::ios_base::iostate err;
49    std::tm t;
50    {
51        const my_facet f(LOCALE_en_US_UTF_8, 1);
52        const wchar_t in[] = L"06/10/2009";
53        err = std::ios_base::goodbit;
54        t = std::tm();
55        I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
56        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
57        assert(t.tm_mon == 5);
58        assert(t.tm_mday == 10);
59        assert(t.tm_year == 109);
60        assert(err == std::ios_base::eofbit);
61    }
62    {
63        const my_facet f(LOCALE_fr_FR_UTF_8, 1);
64        const wchar_t in[] = L"10.06.2009";
65        err = std::ios_base::goodbit;
66        t = std::tm();
67        I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
68        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
69        assert(t.tm_mon == 5);
70        assert(t.tm_mday == 10);
71        assert(t.tm_year == 109);
72        assert(err == std::ios_base::eofbit);
73    }
74    {
75        const my_facet f(LOCALE_ru_RU_UTF_8, 1);
76        const wchar_t in[] = L"10.06.2009";
77        err = std::ios_base::goodbit;
78        t = std::tm();
79        I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
80        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
81        assert(t.tm_mon == 5);
82        assert(t.tm_mday == 10);
83        assert(t.tm_year == 109);
84        assert(err == std::ios_base::eofbit);
85    }
86    {
87        const my_facet f(LOCALE_zh_CN_UTF_8, 1);
88        const wchar_t in[] = L"2009/06/10";
89        err = std::ios_base::goodbit;
90        t = std::tm();
91        I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
92        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
93        assert(t.tm_mon == 5);
94        assert(t.tm_mday == 10);
95        assert(t.tm_year == 109);
96        assert(err == std::ios_base::eofbit);
97    }
98}
99