1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <codecvt>
10 
11 // template <class Elem, unsigned long Maxcode = 0x10ffff,
12 //           codecvt_mode Mode = (codecvt_mode)0>
13 // class codecvt_utf8
14 //     : public codecvt<Elem, char, mbstate_t>
15 // {
16 //     // unspecified
17 // };
18 
19 // int max_length() const throw();
20 
21 #include <codecvt>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 template <class CharT, size_t = sizeof(CharT)>
27 struct TestHelper;
28 
29 template <class CharT>
30 struct TestHelper<CharT, 2> {
31   static void test();
32 };
33 
34 template <class CharT>
35 struct TestHelper<CharT, 4> {
36   static void test();
37 };
38 
39 template <class CharT>
40 void TestHelper<CharT, 2>::test() {
41   {
42     typedef std::codecvt_utf8<CharT> C;
43     C c;
44     int r = c.max_length();
45     assert(r == 3);
46   }
47   {
48     typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
49     C c;
50     int r = c.max_length();
51     assert(r == 6);
52   }
53 }
54 
55 template <class CharT>
56 void TestHelper<CharT, 4>::test() {
57   {
58     typedef std::codecvt_utf8<CharT> C;
59     C c;
60     int r = c.max_length();
61     assert(r == 4);
62   }
63   {
64     typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
65     C c;
66     int r = c.max_length();
67     assert(r == 7);
68   }
69 }
70 
71 int main(int, char**) {
72 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
73   TestHelper<wchar_t>::test();
74 #endif
75   TestHelper<char16_t>::test();
76   TestHelper<char32_t>::test();
77   return 0;
78 }
79