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 // NOTE: debian and opensuse use old locale data for ru_RU.UTF-8 abbreviated
16 // months. This locale data was changed in glibc 2.14.
17 // Debian uses glibc 2.13 as of 20/11/2014
18 // OpenSuse uses glibc 2.19 with old locale data as of 20/11/2014
19 // XFAIL: debian, opensuse
20 
21 // <locale>
22 
23 // class time_get_byname<charT, InputIterator>
24 
25 // iter_type
26 // get_monthname(iter_type s, iter_type end, ios_base& str,
27 //               ios_base::iostate& err, tm* t) const;
28 
29 #include <locale>
30 #include <cassert>
31 #include "test_iterators.h"
32 
33 #include "platform_support.h" // locale name macros
34 
35 typedef input_iterator<const char*> I;
36 
37 typedef std::time_get_byname<char, I> F;
38 
39 class my_facet
40     : public F
41 {
42 public:
my_facet(const std::string & nm,std::size_t refs=0)43     explicit my_facet(const std::string& nm, std::size_t refs = 0)
44         : F(nm, refs) {}
45 };
46 
main()47 int main()
48 {
49     std::ios ios(0);
50     std::ios_base::iostate err;
51     std::tm t;
52     {
53         const my_facet f(LOCALE_en_US_UTF_8, 1);
54         const char in[] = "June";
55         err = std::ios_base::goodbit;
56         t = std::tm();
57         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
58         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
59         assert(t.tm_mon == 5);
60         assert(err == std::ios_base::eofbit);
61     }
62     {
63         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
64         const char in[] = "juin";
65         err = std::ios_base::goodbit;
66         t = std::tm();
67         I i = f.get_monthname(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(err == std::ios_base::eofbit);
71     }
72     {
73         const my_facet f(LOCALE_ru_RU_UTF_8, 1);
74         const char in[] = "\xD0\xB8\xD1\x8E\xD0\xBD\xD1\x8F";
75         err = std::ios_base::goodbit;
76         t = std::tm();
77         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
78         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
79         assert(t.tm_mon == 5);
80         assert(err == std::ios_base::eofbit);
81     }
82     {
83         const my_facet f(LOCALE_zh_CN_UTF_8, 1);
84         const char in[] = "\xE5\x85\xAD\xE6\x9C\x88";
85         err = std::ios_base::goodbit;
86         t = std::tm();
87         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
88         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
89         assert(t.tm_mon == 5);
90         assert(err == std::ios_base::eofbit);
91     }
92 }
93