]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/22_locale/messages/13631.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / messages / 13631.cc
CommitLineData
d31008d7
FD
1// { dg-require-namedlocale "fr_FR" }
2
5624e564 3// Copyright (C) 2014-2015 Free Software Foundation, Inc.
d31008d7
FD
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20#include <locale>
21#include <testsuite_hooks.h>
22
23void test01()
24{
25 bool test __attribute__((unused)) = true;
26
27 // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
28 const char* dir = LOCALEDIR;
29
30 std::locale l("fr_FR");
31
32 typedef std::messages<char> messages;
33
34 const messages &msgs_facet = std::use_facet<messages>(l);
35
36 messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
37 VERIFY( msgs >= 0 );
38
39 const char msgid[] = "please";
40 std::string translation1 = msgs_facet.get(msgs, 0, 0, msgid);
41
42 // Without a real translation this test doesn't mean anything:
43 VERIFY( translation1 != msgid );
44
45 // Opening another catalog was enough to show the problem, even a fake
46 // catalog.
47 messages::catalog fake_msgs = msgs_facet.open("fake", l);
48
49 std::string translation2 = msgs_facet.get(msgs, 0, 0, msgid);
50
51 // Close catalogs before doing the check to avoid leaks.
52 msgs_facet.close(fake_msgs);
53 msgs_facet.close(msgs);
54
55 VERIFY( translation1 == translation2 );
56}
57
58void test02()
59{
60 bool test __attribute__((unused)) = true;
61
62 // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
63 const char* dir = LOCALEDIR;
64
65 std::locale l("fr_FR");
66
67 typedef std::messages<wchar_t> messages;
68
69 const messages &msgs_facet = std::use_facet<messages>(l);
70
71 messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
72 VERIFY( msgs >= 0 );
73
74 const wchar_t msgid[] = L"please";
75 std::wstring translation1 = msgs_facet.get(msgs, 0, 0, msgid);
76
77 // Without a real translation this test doesn't mean anything:
78 VERIFY( !translation1.empty() );
79 VERIFY( translation1 != msgid );
80
81 // Opening another catalog was enough to show the problem, even a fake
82 // catalog.
83 messages::catalog fake_msgs = msgs_facet.open("fake", l);
84
85 std::wstring translation2 = msgs_facet.get(msgs, 0, 0, msgid);
86
87 // Close catalogs before doing the check to avoid leaks.
88 msgs_facet.close(fake_msgs);
89 msgs_facet.close(msgs);
90
91 VERIFY( translation1 == translation2 );
92}
93
94int main()
95{
96 test01();
97 test02();
98 return 0;
99}
This page took 0.062947 seconds and 5 git commands to generate.