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 // <locale>
10 
11 // wbuffer_convert<Codecvt, Elem, Tr>
12 
13 // wbuffer_convert(streambuf *bytebuf = 0, Codecvt *pcvt = new Codecvt,
14 //                 state_type state = state_type());
15 
16 #include <locale>
17 #include <codecvt>
18 #include <sstream>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "count_new.h"
23 
main(int,char **)24 int main(int, char**)
25 {
26     globalMemCounter.reset();
27     typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
28 #if TEST_STD_VER > 11
29     static_assert(!std::is_convertible<std::streambuf*, B>::value, "");
30     static_assert( std::is_constructible<B, std::streambuf*>::value, "");
31 #endif
32     {
33         B b;
34         assert(b.rdbuf() == nullptr);
35         assert(globalMemCounter.checkOutstandingNewNotEq(0));
36     }
37     assert(globalMemCounter.checkOutstandingNewEq(0));
38     {
39         std::stringstream s;
40         B b(s.rdbuf());
41         assert(b.rdbuf() == s.rdbuf());
42         assert(globalMemCounter.checkOutstandingNewNotEq(0));
43     }
44     assert(globalMemCounter.checkOutstandingNewEq(0));
45     {
46         std::stringstream s;
47         B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>);
48         assert(b.rdbuf() == s.rdbuf());
49         assert(globalMemCounter.checkOutstandingNewNotEq(0));
50     }
51     assert(globalMemCounter.checkOutstandingNewEq(0));
52     {
53         std::stringstream s;
54         B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>, std::mbstate_t());
55         assert(b.rdbuf() == s.rdbuf());
56         assert(globalMemCounter.checkOutstandingNewNotEq(0));
57     }
58     assert(globalMemCounter.checkOutstandingNewEq(0));
59 
60   return 0;
61 }
62