blob: 631a500362da53896531fc6faa06d840a292d951 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
Dan Albertb4ed5ca2014-08-04 18:44:48 +000010// REQUIRES: locale.en_US.UTF-8
11// REQUIRES: locale.fr_FR.UTF-8
Dan Albert1d4a1ed2016-05-25 22:36:09 -070012// REQUIRES: locale.ru_RU.UTF-8
Dan Albertb4ed5ca2014-08-04 18:44:48 +000013// REQUIRES: locale.zh_CN.UTF-8
14
Dan Albert1d4a1ed2016-05-25 22:36:09 -070015// NOTE: debian and opensuse use bad locale data for ru_RU.UTF-8 abreviated
16// months. This locale data was fixed 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021// <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>
Marshall Clow83e2c4d2013-01-05 03:21:01 +000031#include "test_iterators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032
Marshall Clow83e2c4d2013-01-05 03:21:01 +000033#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000034
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035typedef input_iterator<const wchar_t*> I;
36
37typedef std::time_get_byname<wchar_t, I> F;
38
39class my_facet
40 : public F
41{
42public:
43 explicit my_facet(const std::string& nm, std::size_t refs = 0)
44 : F(nm, refs) {}
45};
46
47typedef std::time_put_byname<wchar_t, wchar_t*> F2;
48class my_facet2
49 : public F2
50{
51public:
52 explicit my_facet2(const std::string& nm, std::size_t refs = 0)
53 : F2(nm, refs) {}
54};
55
56int main()
57{
58 std::ios ios(0);
59 std::ios_base::iostate err;
60 std::tm t;
61 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000062 const my_facet f(LOCALE_en_US_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063 const wchar_t in[] = L"June";
64 err = std::ios_base::goodbit;
65 t = std::tm();
66 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
67 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
68 assert(t.tm_mon == 5);
69 assert(err == std::ios_base::eofbit);
70 }
71 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000072 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073 const wchar_t in[] = L"juin";
74 err = std::ios_base::goodbit;
75 t = std::tm();
76 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
77 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
78 assert(t.tm_mon == 5);
79 assert(err == std::ios_base::eofbit);
80 }
81 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070082 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
83 const wchar_t in[] = L"\x438\x44E\x43D\x44F";
84 err = std::ios_base::goodbit;
85 t = std::tm();
86 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
87 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
88 assert(t.tm_mon == 5);
89 assert(err == std::ios_base::eofbit);
90 }
91 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000092 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093 const wchar_t in[] = L"\x516D\x6708";
94 err = std::ios_base::goodbit;
95 t = std::tm();
96 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
97 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
98 assert(t.tm_mon == 5);
99 assert(err == std::ios_base::eofbit);
100 }
101}