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