Home | History | Annotate | Download | only in locale.time.get.byname
      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 // 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 
     15 // <locale>
     16 
     17 // class time_get_byname<charT, InputIterator>
     18 
     19 // iter_type get_year(iter_type s, iter_type end, ios_base& str,
     20 //                    ios_base::iostate& err, tm* t) const;
     21 
     22 #include <locale>
     23 #include <cassert>
     24 #include "test_iterators.h"
     25 
     26 #include "platform_support.h" // locale name macros
     27 
     28 typedef input_iterator<const wchar_t*> I;
     29 
     30 typedef std::time_get_byname<wchar_t, I> F;
     31 
     32 class my_facet
     33     : public F
     34 {
     35 public:
     36     explicit my_facet(const std::string& nm, std::size_t refs = 0)
     37         : F(nm, refs) {}
     38 };
     39 
     40 int main()
     41 {
     42     std::ios ios(0);
     43     std::ios_base::iostate err;
     44     std::tm t;
     45     {
     46         const my_facet f(LOCALE_en_US_UTF_8, 1);
     47         const wchar_t in[] = L"2009";
     48         err = std::ios_base::goodbit;
     49         t = std::tm();
     50         I i = f.get_year(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
     51         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
     52         assert(t.tm_year == 109);
     53         assert(err == std::ios_base::eofbit);
     54     }
     55     {
     56         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
     57         const wchar_t in[] = L"2009";
     58         err = std::ios_base::goodbit;
     59         t = std::tm();
     60         I i = f.get_year(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_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"2009";
     68         err = std::ios_base::goodbit;
     69         t = std::tm();
     70         I i = f.get_year(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_year == 109);
     73         assert(err == std::ios_base::eofbit);
     74     }
     75     {
     76         const my_facet f(LOCALE_zh_CN_UTF_8, 1);
     77         const wchar_t in[] = L"2009";
     78         err = std::ios_base::goodbit;
     79         t = std::tm();
     80         I i = f.get_year(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_year == 109);
     83         assert(err == std::ios_base::eofbit);
     84     }
     85 }
     86