Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / localization / locale.categories / category.time / locale.time.put.byname / put1.pass.cpp
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
13 // <locale>
14
15 // template <class CharT, class OutputIterator = ostreambuf_iterator<CharT> >
16 // class time_put_byname
17 //     : public time_put<CharT, OutputIterator>
18 // {
19 // public:
20 //     explicit time_put_byname(const char* nm, size_t refs = 0);
21 //     explicit time_put_byname(const string& nm, size_t refs = 0);
22 //
23 // protected:
24 //     ~time_put_byname();
25 // };
26
27 #include <locale>
28 #include <cassert>
29 #include "test_iterators.h"
30
31 #include "platform_support.h" // locale name macros
32
33 typedef std::time_put_byname<char, output_iterator<char*> > F;
34
35 class my_facet
36     : public F
37 {
38 public:
39     explicit my_facet(const std::string& nm, std::size_t refs = 0)
40         : F(nm, refs) {}
41 };
42
43 int main()
44 {
45     char str[200];
46     output_iterator<char*> iter;
47     tm t;
48     t.tm_sec = 6;
49     t.tm_min = 3;
50     t.tm_hour = 13;
51     t.tm_mday = 2;
52     t.tm_mon = 4;
53     t.tm_year = 109;
54     t.tm_wday = 6;
55     t.tm_yday = -1;
56     t.tm_isdst = 1;
57     std::ios ios(0);
58     {
59         const my_facet f(LOCALE_en_US_UTF_8, 1);
60         std::string pat("Today is %A which is abbreviated %a.");
61         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
62                      pat.data(), pat.data() + pat.size());
63         std::string ex(str, iter.base());
64         assert(ex == "Today is Saturday which is abbreviated Sat.");
65     }
66     {
67         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
68         std::string pat("Today is %A which is abbreviated %a.");
69         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
70                      pat.data(), pat.data() + pat.size());
71         std::string ex(str, iter.base());
72         assert((ex == "Today is Samedi which is abbreviated Sam.")||
73                (ex == "Today is samedi which is abbreviated sam." ));
74     }
75 }