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
     20 // get_weekday(iter_type s, iter_type end, ios_base& str,
     21 //             ios_base::iostate& err, tm* t) const;
     22 
     23 // TODO: investigation needed
     24 // XFAIL: linux-gnu
     25 
     26 #include <locale>
     27 #include <cassert>
     28 #include "test_iterators.h"
     29 
     30 #include "platform_support.h" // locale name macros
     31 
     32 typedef input_iterator<const wchar_t*> I;
     33 
     34 typedef std::time_get_byname<wchar_t, I> F;
     35 
     36 class my_facet
     37     : public F
     38 {
     39 public:
     40     explicit my_facet(const std::string& nm, std::size_t refs = 0)
     41         : F(nm, refs) {}
     42 };
     43 
     44 int main()
     45 {
     46     std::ios ios(0);
     47     std::ios_base::iostate err;
     48     std::tm t;
     49     {
     50         const my_facet f(LOCALE_en_US_UTF_8, 1);
     51         const wchar_t in[] = L"Monday";
     52         err = std::ios_base::goodbit;
     53         t = std::tm();
     54         I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
     55         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
     56         assert(t.tm_wday == 1);
     57         assert(err == std::ios_base::eofbit);
     58     }
     59     {
     60         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
     61         const wchar_t in[] = L"Lundi";
     62         err = std::ios_base::goodbit;
     63         t = std::tm();
     64         I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
     65         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
     66         assert(t.tm_wday == 1);
     67         assert(err == std::ios_base::eofbit);
     68     }
     69     {
     70         const my_facet f(LOCALE_ru_RU_UTF_8, 1);
     71         const wchar_t in[] = L"\x43F\x43E\x43D\x435\x434\x435\x43B\x44C\x43D\x438\x43A";
     72         err = std::ios_base::goodbit;
     73         t = std::tm();
     74         I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
     75         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
     76         assert(t.tm_wday == 1);
     77         assert(err == std::ios_base::eofbit);
     78     }
     79     {
     80         const my_facet f(LOCALE_zh_CN_UTF_8, 1);
     81         const wchar_t in[] = L"\x661F\x671F\x4E00";
     82         err = std::ios_base::goodbit;
     83         t = std::tm();
     84         I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
     85         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
     86         assert(t.tm_wday == 1);
     87         assert(err == std::ios_base::eofbit);
     88     }
     89 }
     90