get_weekday.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <locale>
11
12// class time_get_byname<charT, InputIterator>
13
14// iter_type
15// get_weekday(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
22typedef input_iterator<const char*> I;
23
24typedef std::time_get_byname<char, I> F;
25
26class my_facet
27    : public F
28{
29public:
30    explicit my_facet(const std::string& nm, std::size_t refs = 0)
31        : F(nm, refs) {}
32};
33
34int main()
35{
36    std::ios ios(0);
37    std::ios_base::iostate err;
38    std::tm t;
39    {
40        const my_facet f("en_US", 1);
41        const char in[] = "Monday";
42        err = std::ios_base::goodbit;
43        t = std::tm();
44        I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
45        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
46        assert(t.tm_wday == 1);
47        assert(err == std::ios_base::eofbit);
48    }
49    {
50        const my_facet f("fr_FR", 1);
51        const char in[] = "Lundi";
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("ru_RU", 1);
61        const char in[] = "\xD0\xBF\xD0\xBE\xD0\xBD\xD0\xB5"
62                          "\xD0\xB4\xD0\xB5\xD0\xBB\xD1\x8C"
63                          "\xD0\xBD\xD0\xB8\xD0\xBA";
64        err = std::ios_base::goodbit;
65        t = std::tm();
66        I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
67        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
68        assert(t.tm_wday == 1);
69        assert(err == std::ios_base::eofbit);
70    }
71    {
72        const my_facet f("zh_CN", 1);
73        const char in[] = "\xE6\x98\x9F\xE6\x9C\x9F\xE4\xB8\x80";
74        err = std::ios_base::goodbit;
75        t = std::tm();
76        I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
77        assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
78        assert(t.tm_wday == 1);
79        assert(err == std::ios_base::eofbit);
80    }
81}
82