blob: 009dc490e40ea170dfae567a167329392484ad9c [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
12// REQUIRES: locale.ru_RU.UTF-8
13// REQUIRES: locale.zh_CN.UTF-8
14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000015// <locale>
16
17// class time_get_byname<charT, InputIterator>
18
19// iter_type
20// get_monthname(iter_type s, iter_type end, ios_base& str,
21// ios_base::iostate& err, tm* t) const;
22
23#include <locale>
24#include <cassert>
Marshall Clow83e2c4d2013-01-05 03:21:01 +000025#include "test_iterators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026
Marshall Clow83e2c4d2013-01-05 03:21:01 +000027#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000028
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029typedef input_iterator<const wchar_t*> I;
30
31typedef std::time_get_byname<wchar_t, I> F;
32
33class my_facet
34 : public F
35{
36public:
37 explicit my_facet(const std::string& nm, std::size_t refs = 0)
38 : F(nm, refs) {}
39};
40
41typedef std::time_put_byname<wchar_t, wchar_t*> F2;
42class my_facet2
43 : public F2
44{
45public:
46 explicit my_facet2(const std::string& nm, std::size_t refs = 0)
47 : F2(nm, refs) {}
48};
49
50int main()
51{
52 std::ios ios(0);
53 std::ios_base::iostate err;
54 std::tm t;
55 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000056 const my_facet f(LOCALE_en_US_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057 const wchar_t in[] = L"June";
58 err = std::ios_base::goodbit;
59 t = std::tm();
60 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
61 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
62 assert(t.tm_mon == 5);
63 assert(err == std::ios_base::eofbit);
64 }
65 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000066 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 const wchar_t in[] = L"juin";
68 err = std::ios_base::goodbit;
69 t = std::tm();
70 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
71 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
72 assert(t.tm_mon == 5);
73 assert(err == std::ios_base::eofbit);
74 }
75 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000076 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077 const wchar_t in[] = L"\x438\x44E\x43D\x44F";
78 err = std::ios_base::goodbit;
79 t = std::tm();
80 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
81 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
82 assert(t.tm_mon == 5);
83 assert(err == std::ios_base::eofbit);
84 }
85 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000086 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087 const wchar_t in[] = L"\x516D\x6708";
88 err = std::ios_base::goodbit;
89 t = std::tm();
90 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
91 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
92 assert(t.tm_mon == 5);
93 assert(err == std::ios_base::eofbit);
94 }
95}