Skip to content

Commit c905111

Browse files
committed
Tests: ispanstream constructors - WIP
1 parent b743d31 commit c905111

File tree

4 files changed

+283
-5
lines changed

4 files changed

+283
-5
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <spanstream>
12+
13+
// template<class charT, class traits = char_traits<charT>>
14+
// class basic_ispanstream
15+
// : public basic_streambuf<charT, traits> {
16+
17+
// // [spanbuf.cons], constructors
18+
//
19+
// basic_ispanstream(basic_ispanstream&& rhs);
20+
21+
#include <cassert>
22+
#include <concepts>
23+
#include <span>
24+
#include <spanstream>
25+
26+
#include "constexpr_char_traits.h"
27+
#include "nasty_string.h"
28+
#include "test_convertible.h"
29+
#include "test_macros.h"
30+
31+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
32+
void test() {
33+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
34+
35+
CharT arr[4];
36+
std::span<CharT> sp{arr};
37+
38+
// Mode: default
39+
{
40+
SpStream rhsSpStream{sp};
41+
SpStream sps(std::move(rhsSpStream));
42+
assert(sps.span().data() == arr);
43+
assert(!sps.span().empty());
44+
assert(sps.span().size() == 4);
45+
}
46+
// Mode: `ios_base::in`
47+
{
48+
SpStream rhsSpStream{sp, std::ios_base::in};
49+
SpStream sps(std::move(rhsSpStream));
50+
assert(sps.span().data() == arr);
51+
assert(!sps.span().empty());
52+
assert(sps.span().size() == 4);
53+
}
54+
// Mode `ios_base::out`
55+
{
56+
SpStream rhsSpStream{sp, std::ios_base::out};
57+
SpStream sps(std::move(rhsSpStream));
58+
assert(sps.span().data() == arr);
59+
assert(sps.span().empty());
60+
assert(sps.span().size() == 0);
61+
}
62+
// Mode: multiple
63+
{
64+
SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
65+
SpStream sps(std::move(rhsSpStream));
66+
assert(sps.span().data() == arr);
67+
assert(sps.span().empty());
68+
assert(sps.span().size() == 0);
69+
}
70+
}
71+
72+
int main(int, char**) {
73+
test<char>();
74+
test<char, constexpr_char_traits<char>>();
75+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
76+
test<wchar_t>();
77+
test<wchar_t, constexpr_char_traits<wchar_t>>();
78+
#endif
79+
80+
return 0;
81+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <spanstream>
12+
13+
// template<class charT, class traits = char_traits<charT>>
14+
// class basic_ispanstream
15+
// : public basic_streambuf<charT, traits> {
16+
17+
// // [spanbuf.cons], constructors
18+
//
19+
// template<class ROS> explicit basic_ispanstream(ROS&& s);
20+
21+
#include <cassert>
22+
#include <spanstream>
23+
24+
#include "constexpr_char_traits.h"
25+
#include "nasty_string.h"
26+
#include "test_macros.h"
27+
28+
void test_sfinae_with_nasty_char() {
29+
using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
30+
31+
// TODO:
32+
}
33+
34+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
35+
void test_sfinae() {
36+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
37+
38+
// TODO:
39+
}
40+
41+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
42+
void test() {
43+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
44+
45+
// TODO:
46+
}
47+
48+
int main(int, char**) {
49+
test_sfinae_with_nasty_char();
50+
test_sfinae<char>();
51+
test_sfinae<char, constexpr_char_traits<char>>();
52+
test<char>();
53+
test<char, constexpr_char_traits<char>>();
54+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
55+
test<wchar_t>();
56+
test<wchar_t, constexpr_char_traits<wchar_t>>();
57+
#endif
58+
59+
return 0;
60+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <spanstream>
12+
13+
// template<class charT, class traits = char_traits<charT>>
14+
// class basic_ispanstream
15+
// : public basic_streambuf<charT, traits> {
16+
17+
// // [spanbuf.cons], constructors
18+
//
19+
// explicit basic_ispanstream(std::span<charT> s,
20+
// ios_base::openmode which = ios_base::in);
21+
22+
#include <cassert>
23+
#include <concepts>
24+
#include <span>
25+
#include <spanstream>
26+
#include <utility>
27+
28+
#include "constexpr_char_traits.h"
29+
#include "nasty_string.h"
30+
#include "test_convertible.h"
31+
#include "test_macros.h"
32+
33+
#include "../../macros.h"
34+
#include "../../types.h"
35+
36+
void test_sfinae_with_nasty_char() {
37+
using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
38+
39+
// Mode
40+
static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
41+
static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
42+
43+
// Non-mode
44+
static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
45+
static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
46+
}
47+
48+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
49+
void test_sfinae() {
50+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
51+
52+
// Mode
53+
static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
54+
static_assert(!test_convertible<SpStream, const std::span<CharT>, std::ios_base::openmode>());
55+
56+
// Non-mode
57+
static_assert(!std::constructible_from<SpStream, const std::span<CharT>, const NonMode>);
58+
static_assert(!test_convertible<SpStream, const std::span<CharT>, const NonMode>());
59+
}
60+
61+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
62+
void test() {
63+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
64+
65+
CharT arr[4];
66+
std::span<CharT> sp{arr};
67+
68+
// Mode: default
69+
{
70+
SpStream sps(sp);
71+
assert(sps.span().data() == arr);
72+
assert(!sps.span().empty());
73+
assert(sps.span().size() == 4);
74+
}
75+
{
76+
SpStream sps(std::as_const(sp));
77+
assert(sps.span().data() == arr);
78+
assert(!sps.span().empty());
79+
assert(sps.span().size() == 4);
80+
}
81+
// Mode: `ios_base::in`
82+
{
83+
SpStream sps(sp, std::ios_base::in);
84+
assert(sps.span().data() == arr);
85+
assert(!sps.span().empty());
86+
assert(sps.span().size() == 4);
87+
}
88+
{
89+
SpStream sps(std::as_const(sp), std::ios_base::in);
90+
assert(sps.span().data() == arr);
91+
assert(!sps.span().empty());
92+
assert(sps.span().size() == 4);
93+
}
94+
// Mode `ios_base::out`
95+
{
96+
SpStream sps(sp, std::ios_base::out);
97+
assert(sps.span().data() == arr);
98+
assert(sps.span().empty());
99+
assert(sps.span().size() == 0);
100+
}
101+
{
102+
SpStream sps(std::as_const(sp), std::ios_base::out);
103+
assert(sps.span().data() == arr);
104+
assert(sps.span().empty());
105+
assert(sps.span().size() == 0);
106+
}
107+
// Mode: multiple
108+
{
109+
SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
110+
assert(sps.span().data() == arr);
111+
assert(sps.span().empty());
112+
assert(sps.span().size() == 0);
113+
}
114+
{
115+
SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
116+
assert(sps.span().data() == arr);
117+
assert(sps.span().empty());
118+
assert(sps.span().size() == 0);
119+
}
120+
}
121+
122+
int main(int, char**) {
123+
test_sfinae_with_nasty_char();
124+
test_sfinae<char>();
125+
test_sfinae<char, constexpr_char_traits<char>>();
126+
test<char>();
127+
test<char, constexpr_char_traits<char>>();
128+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
129+
test_sfinae<wchar_t>();
130+
test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
131+
test<wchar_t>();
132+
test<wchar_t, constexpr_char_traits<wchar_t>>();
133+
#endif
134+
135+
return 0;
136+
}

libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
#include <type_traits>
2929

3030
#include "constexpr_char_traits.h"
31+
#include "nasty_string.h"
3132
#include "test_macros.h"
3233

3334
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3435
void test() {
3536
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
3637

38+
// Constructors
39+
40+
static_assert(!std::is_default_constructible_v<SpStream>);
41+
3742
// Types
3843

3944
static_assert(std::is_base_of_v<std::basic_istream<CharT, TraitsT>, SpStream>);
@@ -50,18 +55,14 @@ void test() {
5055

5156
// Move properties
5257

53-
static_assert(!std::is_copy_constructible_v<SpStream>);
54-
static_assert(!std::is_copy_assignable_v<SpStream>);
55-
56-
// Move properties
57-
5858
static_assert(std::is_move_constructible_v<SpStream>);
5959
static_assert(std::is_move_assignable_v<SpStream>);
6060
}
6161

6262
void test() {
6363
test<char>();
6464
test<char, constexpr_char_traits<char>>();
65+
test<nasty_char, nasty_char_traits>();
6566
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
6667
test<wchar_t>();
6768
test<wchar_t, constexpr_char_traits<wchar_t>>();

0 commit comments

Comments
 (0)