]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctype/narrow/char/19955.cc
1 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 // 22.2.1.3.2 ctype<char> members
23 #include <testsuite_hooks.h>
26 : public std::ctype
<char>
30 do_narrow(const char* lo
, const char* hi
,
33 for (int i
= 0; lo
!= hi
; ++lo
, ++to
, ++i
)
40 : public std::ctype
<char>
44 do_narrow(const char* lo
, const char* hi
,
45 char dflt
, char* to
) const
47 for (int i
= 0; lo
!= hi
; ++lo
, ++to
, ++i
)
60 bool test
__attribute__((unused
)) = true;
62 const char src
[] = "abcd";
64 locale
mylocale1(locale::classic(), new Ctype1
);
65 const ctype
<char>& mc1
= use_facet
<ctype
<char> >(mylocale1
);
67 char dst1
[sizeof(src
)];
68 memset(dst1
, 0, sizeof(src
));
69 char dst2
[sizeof(src
)];
70 memset(dst2
, 0, sizeof(src
));
72 mc1
.narrow(src
, src
+ sizeof(src
), '*', dst1
);
73 mc1
.narrow(src
, src
+ sizeof(src
), '*', dst2
);
75 VERIFY( !memcmp(dst1
, "aceg\004", 5) );
76 VERIFY( !memcmp(dst1
, dst2
, 5) );
78 locale
mylocale2(locale::classic(), new Ctype2
);
79 const ctype
<char>& mc2
= use_facet
<ctype
<char> >(mylocale2
);
81 char dst3
[sizeof(src
)];
82 memset(dst3
, 0, sizeof(src
));
83 char dst4
[sizeof(src
)];
84 memset(dst4
, 0, sizeof(src
));
86 mc2
.narrow(src
, src
+ sizeof(src
), '*', dst3
);
87 mc2
.narrow(src
, src
+ sizeof(src
), '*', dst4
);
89 VERIFY( !memcmp(dst3
, "abcd*", 5) );
90 VERIFY( !memcmp(dst3
, dst4
, 5) );