get_date_wide.pass.cpp revision c0d0cbad9ed434267a7af9531bdeeae52eb6d706
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// <locale> 11 12// class time_get_byname<charT, InputIterator> 13 14// iter_type 15// get_date(iter_type s, iter_type end, ios_base& str, 16// ios_base::iostate& err, tm* t) const; 17 18#include <locale> 19#include <cassert> 20#include "iterators.h" 21 22#include "../../../../platform_support.h" // locale name macros 23 24typedef input_iterator<const wchar_t*> I; 25 26typedef std::time_get_byname<wchar_t, I> F; 27 28class my_facet 29 : public F 30{ 31public: 32 explicit my_facet(const std::string& nm, std::size_t refs = 0) 33 : F(nm, refs) {} 34}; 35 36int main() 37{ 38 std::ios ios(0); 39 std::ios_base::iostate err; 40 std::tm t; 41 { 42 const my_facet f(LOCALE_en_US_UTF_8, 1); 43 const wchar_t in[] = L"06/10/2009"; 44 err = std::ios_base::goodbit; 45 t = std::tm(); 46 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 47 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 48 assert(t.tm_mon == 5); 49 assert(t.tm_mday == 10); 50 assert(t.tm_year == 109); 51 assert(err == std::ios_base::eofbit); 52 } 53 { 54 const my_facet f(LOCALE_fr_FR_UTF_8, 1); 55 const wchar_t in[] = L"10.06.2009"; 56 err = std::ios_base::goodbit; 57 t = std::tm(); 58 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 59 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 60 assert(t.tm_mon == 5); 61 assert(t.tm_mday == 10); 62 assert(t.tm_year == 109); 63 assert(err == std::ios_base::eofbit); 64 } 65 { 66 const my_facet f(LOCALE_ru_RU_UTF_8, 1); 67 const wchar_t in[] = L"10.06.2009"; 68 err = std::ios_base::goodbit; 69 t = std::tm(); 70 I i = f.get_date(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(t.tm_mday == 10); 74 assert(t.tm_year == 109); 75 assert(err == std::ios_base::eofbit); 76 } 77 { 78 const my_facet f(LOCALE_zh_CN_UTF_8, 1); 79 const wchar_t in[] = L"2009/06/10"; 80 err = std::ios_base::goodbit; 81 t = std::tm(); 82 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 83 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 84 assert(t.tm_mon == 5); 85 assert(t.tm_mday == 10); 86 assert(t.tm_year == 109); 87 assert(err == std::ios_base::eofbit); 88 } 89} 90