1*03a78d15Sespie // 2001-07-17 Benjamin Kosnik  <bkoz@redhat.com>
2*03a78d15Sespie 
3*03a78d15Sespie // Copyright (C) 2001 Free Software Foundation
4*03a78d15Sespie //
5*03a78d15Sespie // This file is part of the GNU ISO C++ Library.  This library is free
6*03a78d15Sespie // software; you can redistribute it and/or modify it under the
7*03a78d15Sespie // terms of the GNU General Public License as published by the
8*03a78d15Sespie // Free Software Foundation; either version 2, or (at your option)
9*03a78d15Sespie // any later version.
10*03a78d15Sespie 
11*03a78d15Sespie // This library is distributed in the hope that it will be useful,
12*03a78d15Sespie // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*03a78d15Sespie // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*03a78d15Sespie // GNU General Public License for more details.
15*03a78d15Sespie 
16*03a78d15Sespie // You should have received a copy of the GNU General Public License along
17*03a78d15Sespie // with this library; see the file COPYING.  If not, write to the Free
18*03a78d15Sespie // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19*03a78d15Sespie // USA.
20*03a78d15Sespie 
21*03a78d15Sespie // 22.2.7.2 Template class messages_byname
22*03a78d15Sespie 
23*03a78d15Sespie #include <locale>
24*03a78d15Sespie #include <testsuite_hooks.h>
25*03a78d15Sespie 
26*03a78d15Sespie // XXX This test is not working for non-glibc locale models.
27*03a78d15Sespie // { dg-do run { xfail *-*-* } }
28*03a78d15Sespie 
test01()29*03a78d15Sespie void test01()
30*03a78d15Sespie {
31*03a78d15Sespie   using namespace std;
32*03a78d15Sespie   typedef std::messages<char>::catalog catalog;
33*03a78d15Sespie   typedef std::messages<char>::string_type string_type;
34*03a78d15Sespie 
35*03a78d15Sespie   bool test = true;
36*03a78d15Sespie   string str;
37*03a78d15Sespie   // This is exported through RUNTESTFLAGS in testsuite/Makefile.am.
38*03a78d15Sespie   const char* dir = LOCALEDIR;
39*03a78d15Sespie   locale loc_c = locale::classic();
40*03a78d15Sespie 
41*03a78d15Sespie   locale loc_byname(locale::classic(), new messages_byname<char>("de_DE"));
42*03a78d15Sespie   str = loc_byname.name();
43*03a78d15Sespie 
44*03a78d15Sespie   locale loc_de("de_DE");
45*03a78d15Sespie   str = loc_de.name();
46*03a78d15Sespie 
47*03a78d15Sespie   VERIFY( loc_de != loc_byname );
48*03a78d15Sespie 
49*03a78d15Sespie   // cache the messages facets
50*03a78d15Sespie   const messages<char>& mssg_byname = use_facet<messages<char> >(loc_byname);
51*03a78d15Sespie   const messages<char>& mssg_de = use_facet<messages<char> >(loc_de);
52*03a78d15Sespie 
53*03a78d15Sespie   // catalog open(const string&, const locale&) const;
54*03a78d15Sespie   // string_type get(catalog, int, int, const string_type& ) const;
55*03a78d15Sespie   // void close(catalog) const;
56*03a78d15Sespie 
57*03a78d15Sespie   // Check German (de_DE) locale.
58*03a78d15Sespie   catalog cat_de = mssg_de.open("libstdc++", loc_c, dir);
59*03a78d15Sespie   string s01 = mssg_de.get(cat_de, 0, 0, "please");
60*03a78d15Sespie   string s02 = mssg_de.get(cat_de, 0, 0, "thank you");
61*03a78d15Sespie   VERIFY ( s01 == "bitte" );
62*03a78d15Sespie   VERIFY ( s02 == "danke" );
63*03a78d15Sespie   mssg_de.close(cat_de);
64*03a78d15Sespie 
65*03a78d15Sespie   // Check byname locale.
66*03a78d15Sespie   catalog cat_byname = mssg_byname.open("libstdc++", loc_c, dir);
67*03a78d15Sespie   string s03 = mssg_byname.get(cat_de, 0, 0, "please");
68*03a78d15Sespie   string s04 = mssg_byname.get(cat_de, 0, 0, "thank you");
69*03a78d15Sespie   VERIFY ( s03 == "bitte" );
70*03a78d15Sespie   VERIFY ( s04 == "danke" );
71*03a78d15Sespie   mssg_byname.close(cat_byname);
72*03a78d15Sespie 
73*03a78d15Sespie   VERIFY ( s01 == s03 );
74*03a78d15Sespie   VERIFY ( s02 == s04 );
75*03a78d15Sespie }
76*03a78d15Sespie 
main()77*03a78d15Sespie int main()
78*03a78d15Sespie {
79*03a78d15Sespie   test01();
80*03a78d15Sespie 
81*03a78d15Sespie   return 0;
82*03a78d15Sespie }
83