Debian Codegraph @

libstdc++-v3/testsuite/22_locale/messages/13631.cc

raw symbols SCIP
1 // { dg-require-namedlocale "fr_FR.ISO8859-15" }
2
3 // Copyright (C) 2014-2025 Free Software Foundation, Inc.
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
23 void test01()
24 {
25 // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
26 const char* dir = LOCALEDIR;
27
28 std::locale l(ISO_8859(15,fr_FR));
29
30 typedef std::messages<char> messages;
31
32 const messages &msgs_facet = std::use_facet<messages>(l);
33
34 messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
35 VERIFY( msgs >= 0 );
36
37 const char msgid[] = "please";
38 std::string translation1 = msgs_facet.get(msgs, 0, 0, msgid);
39
40 // Without a real translation this test doesn't mean anything:
41 VERIFY( translation1 != msgid );
42
43 // Opening another catalog was enough to show the problem, even a fake
44 // catalog.
45 messages::catalog fake_msgs = msgs_facet.open("fake", l);
46
47 std::string translation2 = msgs_facet.get(msgs, 0, 0, msgid);
48
49 // Close catalogs before doing the check to avoid leaks.
50 msgs_facet.close(fake_msgs);
51 msgs_facet.close(msgs);
52
53 VERIFY( translation1 == translation2 );
54 }
55
56 void test02()
57 {
58 #ifdef _GLIBCXX_USE_WCHAR_T
59 // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
60 const char* dir = LOCALEDIR;
61
62 std::locale l(ISO_8859(15,fr_FR));
63
64 typedef std::messages<wchar_t> messages;
65
66 const messages &msgs_facet = std::use_facet<messages>(l);
67
68 messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
69 VERIFY( msgs >= 0 );
70
71 const wchar_t msgid[] = L"please";
72 std::wstring translation1 = msgs_facet.get(msgs, 0, 0, msgid);
73
74 // Without a real translation this test doesn't mean anything:
75 VERIFY( !translation1.empty() );
76 VERIFY( translation1 != msgid );
77
78 // Opening another catalog was enough to show the problem, even a fake
79 // catalog.
80 messages::catalog fake_msgs = msgs_facet.open("fake", l);
81
82 std::wstring translation2 = msgs_facet.get(msgs, 0, 0, msgid);
83
84 // Close catalogs before doing the check to avoid leaks.
85 msgs_facet.close(fake_msgs);
86 msgs_facet.close(msgs);
87
88 VERIFY( translation1 == translation2 );
89 #endif
90 }
91
92 int main()
93 {
94 test01();
95 test02();
96 return 0;
97 }