1// { dg-require-namedlocale "de_DE.utf8" }
2// { dg-options " -std=gnu++11 " }
3
4// 2014-04-14 Rüdiger Sonderfeld  <ruediger@c-plusplus.de>
5
6// Copyright (C) 2014-2015 Free Software Foundation, Inc.
7//
8// This file is part of the GNU ISO C++ Library.  This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 3, or (at your option)
12// any later version.
13
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING3.  If not see
21// <http://www.gnu.org/licenses/>.
22
23// 22.4.5.1.1 (C++11) time_get members [locale.time.get.members]
24
25#include <locale>
26#include <sstream>
27#include <testsuite_hooks.h>
28
29#ifndef _GLIBCXX_ASSERT
30#  include <iostream>
31#  define PRINT(x) cout << #x << ": " << x << endl
32#  define TESTHEAD(x) cout << x << endl
33#else
34#  define PRINT(x) do {} while(false)
35#  define TESTHEAD(x) do {} while(false)
36#endif
37
38void test02()
39{
40  using namespace std;
41  bool test __attribute__((unused)) = true;
42
43  locale loc_c = locale::classic();
44  locale loc_de = locale("de_DE.utf8");
45  VERIFY( loc_de != loc_c );
46
47  istringstream iss;
48  iss.imbue(loc_de);
49  const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc());
50  typedef istreambuf_iterator<char> iter;
51  const iter end;
52
53  ios_base::iostate err;
54  tm time;
55
56  TESTHEAD("German locale test");
57  iss.str("Montag, den 14. April 2014");
58  string format = "%A, den %d. %B %Y";
59  auto ret = tget.get(iter(iss), end, iss, err, &time,
60                      format.data(), format.data()+format.size());
61  PRINT(err);
62  VERIFY(err == ios_base::eofbit);
63  PRINT(time.tm_year);
64  VERIFY(time.tm_year == 114);
65  PRINT(time.tm_mon);
66  VERIFY(time.tm_mon == 3);
67  PRINT(time.tm_wday);
68  VERIFY(time.tm_wday == 1);
69  PRINT(time.tm_mday);
70  VERIFY(time.tm_mday == 14);
71  VERIFY(end == end);
72
73  TESTHEAD("German locale: Check case-insensitivity");
74  tm time2;
75  iss.str("Montag, den 14. April 2014");
76  format = "%A, DEN %d. %B %Y"; // check case-insensitivity
77  ret = tget.get(iter(iss), end, iss, err, &time2,
78                 format.data(), format.data()+format.size());
79  PRINT(err);
80  VERIFY(err == ios_base::eofbit);
81  PRINT(time2.tm_year);
82  VERIFY(time2.tm_year == 114);
83  PRINT(time2.tm_mon);
84  VERIFY(time2.tm_mon == 3);
85  PRINT(time2.tm_wday);
86  VERIFY(time2.tm_wday == 1);
87  PRINT(time2.tm_mday);
88  VERIFY(time2.tm_mday == 14);
89  VERIFY(end == end);
90
91  TESTHEAD("German locale: Check single");
92  iss.str("Mittwoch");
93  ret = tget.get(iter(iss), end, iss, err, &time, 'A');
94  PRINT(err);
95  VERIFY(err == ios_base::eofbit);
96  PRINT(time.tm_wday);
97  VERIFY(time.tm_wday == 3);
98  VERIFY(end == end);
99}
100
101int main()
102{
103  test02();
104}
105