[NFC][Py Reformat] Reformat python files in libcxx/libcxxabi
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf8_max_length.pass.cpp
blob32fdde30153ec80470455552c24a3032846b6f6b
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 //===----------------------------------------------------------------------===//
9 // <codecvt>
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // template <class Elem, unsigned long Maxcode = 0x10ffff,
14 // codecvt_mode Mode = (codecvt_mode)0>
15 // class codecvt_utf8
16 // : public codecvt<Elem, char, mbstate_t>
17 // {
18 // // unspecified
19 // };
21 // int max_length() const throw();
23 #include <codecvt>
24 #include <cassert>
26 #include "test_macros.h"
28 template <class CharT, std::size_t = sizeof(CharT)>
29 struct TestHelper;
31 template <class CharT>
32 struct TestHelper<CharT, 2> {
33 static void test();
36 template <class CharT>
37 struct TestHelper<CharT, 4> {
38 static void test();
41 template <class CharT>
42 void TestHelper<CharT, 2>::test() {
44 typedef std::codecvt_utf8<CharT> C;
45 C c;
46 int r = c.max_length();
47 assert(r == 3);
50 typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
51 C c;
52 int r = c.max_length();
53 assert(r == 6);
57 template <class CharT>
58 void TestHelper<CharT, 4>::test() {
60 typedef std::codecvt_utf8<CharT> C;
61 C c;
62 int r = c.max_length();
63 assert(r == 4);
66 typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
67 C c;
68 int r = c.max_length();
69 assert(r == 7);
73 int main(int, char**) {
74 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
75 TestHelper<wchar_t>::test();
76 #endif
77 TestHelper<char16_t>::test();
78 TestHelper<char32_t>::test();
79 return 0;