blob: a442ae577b47f0b66f7c4cc75c42cbcf5ee81769 [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 old locale data for ru_RU.UTF-8 abreviated
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
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 char*> I;
36
37typedef std::time_get_byname<char, 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
47int main()
48{
49 std::ios ios(0);
50 std::ios_base::iostate err;
51 std::tm t;
52 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000053 const my_facet f(LOCALE_en_US_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 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 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000063 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064 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 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070073 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 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000083 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084 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}