Skip to content

Commit 251a064

Browse files
committed
Tests: updated spanstream and ospanstream
1 parent 39d3ab9 commit 251a064

File tree

10 files changed

+753
-142
lines changed

10 files changed

+753
-142
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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_ospanstream
15+
// : public basic_ostream<charT, traits> {
16+
17+
// // [spanstream.cons], constructors
18+
19+
// basic_spanstream& operator=(basic_ospanstream&& rhs);
20+
21+
#include <cassert>
22+
#include <span>
23+
#include <spanstream>
24+
25+
#include "constexpr_char_traits.h"
26+
#include "nasty_string.h"
27+
#include "test_macros.h"
28+
29+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
30+
void test() {
31+
using SpStream = std::basic_ospanstream<CharT, TraitsT>;
32+
33+
CharT arr[4];
34+
std::span<CharT> sp{arr};
35+
36+
// Mode: default (`in` | `out`)
37+
{
38+
SpStream rhsSpSt{sp};
39+
SpStream spSt = std::move(rhsSpSt);
40+
assert(spSt.span().data() == arr);
41+
assert(spSt.span().empty());
42+
assert(spSt.span().size() == 0);
43+
}
44+
// Mode: `in`
45+
{
46+
SpStream rhsSpSt{sp, std::ios_base::in};
47+
SpStream spSt = std::move(rhsSpSt);
48+
assert(spSt.span().data() == arr);
49+
assert(spSt.span().empty());
50+
assert(spSt.span().size() == 0);
51+
}
52+
// Mode `out`
53+
{
54+
SpStream rhsSpSt{sp, std::ios_base::out};
55+
SpStream spSt = std::move(rhsSpSt);
56+
assert(spSt.span().data() == arr);
57+
assert(spSt.span().empty());
58+
assert(spSt.span().size() == 0);
59+
}
60+
// Mode: multiple
61+
{
62+
SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
63+
SpStream spSt = std::move(rhsSpSt);
64+
assert(spSt.span().data() == arr);
65+
assert(spSt.span().empty());
66+
assert(spSt.span().size() == 0);
67+
}
68+
// Mode `ate`
69+
{
70+
SpStream rhsSpSt{sp, std::ios_base::out | std::ios_base::ate};
71+
SpStream spSt = std::move(rhsSpSt);
72+
assert(spSt.span().data() == arr);
73+
assert(!spSt.span().empty());
74+
assert(spSt.span().size() == 4);
75+
}
76+
}
77+
78+
int main(int, char**) {
79+
#ifndef TEST_HAS_NO_NASTY_STRING
80+
test<nasty_char, nasty_char_traits>();
81+
#endif
82+
test<char>();
83+
test<char, constexpr_char_traits<char>>();
84+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
85+
test<wchar_t>();
86+
test<wchar_t, constexpr_char_traits<wchar_t>>();
87+
#endif
88+
89+
return 0;
90+
}

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp renamed to libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/ctor.move.pass.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212

1313
// template<class charT, class traits = char_traits<charT>>
1414
// class basic_ospanstream
15-
// : public basic_streambuf<charT, traits> {
15+
// : public basic_ostream<charT, traits> {
16+
17+
// // [spanstream.cons], constructors
1618

17-
// // [spanbuf.cons], constructors
18-
//
1919
// basic_ospanstream(basic_ospanstream&& rhs);
2020

2121
#include <cassert>
22-
#include <concepts>
2322
#include <span>
2423
#include <spanstream>
2524

2625
#include "constexpr_char_traits.h"
27-
#include "test_convertible.h"
26+
#include "nasty_string.h"
2827
#include "test_macros.h"
2928

3029
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
@@ -34,41 +33,52 @@ void test() {
3433
CharT arr[4];
3534
std::span<CharT> sp{arr};
3635

37-
// Mode: default
36+
// Mode: default (`in` | `out`)
3837
{
3938
SpStream rhsSpSt{sp};
40-
SpStream spSt(std::move(rhsSpSt));
39+
SpStream spSt{std::move(rhsSpSt)};
4140
assert(spSt.span().data() == arr);
4241
assert(spSt.span().empty());
4342
assert(spSt.span().size() == 0);
4443
}
4544
// Mode: `in`
4645
{
4746
SpStream rhsSpSt{sp, std::ios_base::in};
48-
SpStream spSt(std::move(rhsSpSt));
47+
SpStream spSt{std::move(rhsSpSt)};
4948
assert(spSt.span().data() == arr);
5049
assert(spSt.span().empty());
5150
assert(spSt.span().size() == 0);
5251
}
5352
// Mode `out`
5453
{
5554
SpStream rhsSpSt{sp, std::ios_base::out};
56-
SpStream spSt(std::move(rhsSpSt));
55+
SpStream spSt{std::move(rhsSpSt)};
5756
assert(spSt.span().data() == arr);
5857
assert(spSt.span().empty());
5958
assert(spSt.span().size() == 0);
6059
}
6160
// Mode: multiple
6261
{
6362
SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
64-
SpStream spSt(std::move(rhsSpSt));
63+
SpStream spSt{std::move(rhsSpSt)};
6564
assert(spSt.span().data() == arr);
6665
assert(spSt.span().empty());
6766
assert(spSt.span().size() == 0);
6867
}
68+
// Mode `ate`
69+
{
70+
SpStream rhsSpSt{sp, std::ios_base::out | std::ios_base::ate};
71+
SpStream spSt{std::move(rhsSpSt)};
72+
assert(spSt.span().data() == arr);
73+
assert(!spSt.span().empty());
74+
assert(spSt.span().size() == 4);
75+
}
6976
}
7077

7178
int main(int, char**) {
79+
#ifndef TEST_HAS_NO_NASTY_STRING
80+
test<nasty_char, nasty_char_traits>();
81+
#endif
7282
test<char>();
7383
test<char, constexpr_char_traits<char>>();
7484
#ifndef TEST_HAS_NO_WIDE_CHARACTERS

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp renamed to libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/ctor.span.mode.pass.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212

1313
// template<class charT, class traits = char_traits<charT>>
1414
// class basic_ospanstream
15-
// : public basic_streambuf<charT, traits> {
15+
// : public basic_ostream<charT, traits> {
1616

17-
// // [spanbuf.cons], constructors
18-
//
17+
// // [spanstream.cons], constructors
1918
// explicit basic_ospanstream(std::span<charT> s,
20-
// ios_base::openmode which = ios_base::in);
19+
// ios_base::openmode which = ios_base::out | ios_base::in);
2120

2221
#include <cassert>
23-
#include <concepts>
2422
#include <span>
2523
#include <spanstream>
2624
#include <utility>
@@ -30,12 +28,11 @@
3028
#include "test_convertible.h"
3129
#include "test_macros.h"
3230

33-
#include "../../helper_macros.h"
3431
#include "../../helper_types.h"
3532

3633
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3734
void test_sfinae() {
38-
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
35+
using SpStream = std::basic_ospanstream<CharT, TraitsT>;
3936

4037
// Mode
4138
static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
@@ -53,58 +50,71 @@ void test() {
5350
CharT arr[4];
5451
std::span<CharT> sp{arr};
5552

56-
// Mode: default
53+
// Mode: default (`in` | `out`)
5754
{
58-
SpStream spSt(sp);
55+
SpStream spSt{sp};
5956
assert(spSt.span().data() == arr);
6057
assert(spSt.span().empty());
6158
assert(spSt.span().size() == 0);
6259
}
6360
{
64-
SpStream spSt(std::as_const(sp));
61+
SpStream spSt{std::as_const(sp)};
6562
assert(spSt.span().data() == arr);
6663
assert(spSt.span().empty());
6764
assert(spSt.span().size() == 0);
6865
}
6966
// Mode: `in`
7067
{
71-
SpStream spSt(sp, std::ios_base::in);
68+
SpStream spSt{sp, std::ios_base::in};
7269
assert(spSt.span().data() == arr);
7370
assert(spSt.span().empty());
7471
assert(spSt.span().size() == 0);
7572
}
7673
{
77-
SpStream spSt(std::as_const(sp), std::ios_base::in);
74+
SpStream spSt{std::as_const(sp), std::ios_base::in};
7875
assert(spSt.span().data() == arr);
7976
assert(spSt.span().empty());
8077
assert(spSt.span().size() == 0);
8178
}
8279
// Mode `out`
8380
{
84-
SpStream spSt(sp, std::ios_base::out);
81+
SpStream spSt{sp, std::ios_base::out};
8582
assert(spSt.span().data() == arr);
8683
assert(spSt.span().empty());
8784
assert(spSt.span().size() == 0);
8885
}
8986
{
90-
SpStream spSt(std::as_const(sp), std::ios_base::out);
87+
SpStream spSt{std::as_const(sp), std::ios_base::out};
9188
assert(spSt.span().data() == arr);
9289
assert(spSt.span().empty());
9390
assert(spSt.span().size() == 0);
9491
}
9592
// Mode: multiple
9693
{
97-
SpStream spSt(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
94+
SpStream spSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
9895
assert(spSt.span().data() == arr);
9996
assert(spSt.span().empty());
10097
assert(spSt.span().size() == 0);
10198
}
10299
{
103-
SpStream spSt(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
100+
SpStream spSt{std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary};
104101
assert(spSt.span().data() == arr);
105102
assert(spSt.span().empty());
106103
assert(spSt.span().size() == 0);
107104
}
105+
// Mode `ate`
106+
{
107+
SpStream spSt{sp, std::ios_base::out | std::ios_base::ate};
108+
assert(spSt.span().data() == arr);
109+
assert(!spSt.span().empty());
110+
assert(spSt.span().size() == 4);
111+
}
112+
{
113+
SpStream spSt{std::as_const(sp), std::ios_base::out | std::ios_base::ate};
114+
assert(spSt.span().data() == arr);
115+
assert(!spSt.span().empty());
116+
assert(spSt.span().size() == 4);
117+
}
108118
}
109119

110120
int main(int, char**) {
@@ -113,6 +123,9 @@ int main(int, char**) {
113123
#endif
114124
test_sfinae<char>();
115125
test_sfinae<char, constexpr_char_traits<char>>();
126+
#ifndef TEST_HAS_NO_NASTY_STRING
127+
test<nasty_char, nasty_char_traits>();
128+
#endif
116129
test<char>();
117130
test<char, constexpr_char_traits<char>>();
118131
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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_ospanstream
15+
// : public basic_ostream<charT, traits> {
16+
17+
// // [ospanstream.members], members
18+
// basic_spanbuf<charT, traits>* rdbuf() const noexcept;
19+
20+
#include <cassert>
21+
#include <span>
22+
#include <spanstream>
23+
24+
#include "constexpr_char_traits.h"
25+
#include "nasty_string.h"
26+
#include "test_macros.h"
27+
28+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
29+
void test() {
30+
using SpStream = std::basic_ospanstream<CharT, TraitsT>;
31+
32+
CharT arr[4];
33+
34+
std::span<CharT> sp{arr};
35+
assert(sp.data() == arr);
36+
assert(!sp.empty());
37+
assert(sp.size() == 4);
38+
39+
// Mode: default (`in` | `out`)
40+
{
41+
SpStream spSt{sp};
42+
assert(spSt.rdbuf()->span().data() == arr);
43+
// Mode `out` counts read characters
44+
assert(spSt.rdbuf()->span().empty());
45+
assert(spSt.rdbuf()->span().size() == 0);
46+
}
47+
// Mode: `in`
48+
{
49+
SpStream spSt{sp, std::ios_base::in};
50+
assert(spSt.rdbuf()->span().data() == arr);
51+
assert(spSt.rdbuf()->span().empty());
52+
assert(spSt.rdbuf()->span().size() == 0);
53+
}
54+
// Mode: `out`
55+
{
56+
SpStream spSt{sp, std::ios_base::out};
57+
assert(spSt.rdbuf()->span().data() == arr);
58+
// Mode `out` counts read characters
59+
assert(spSt.rdbuf()->span().empty());
60+
assert(spSt.rdbuf()->span().size() == 0);
61+
}
62+
// Mode: multiple
63+
{
64+
SpStream spSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
65+
assert(spSt.rdbuf()->span().data() == arr);
66+
// Mode `out` counts read characters
67+
assert(spSt.rdbuf()->span().empty());
68+
assert(spSt.rdbuf()->span().size() == 0);
69+
}
70+
// Mode: `ate`
71+
{
72+
SpStream spSt{sp, std::ios_base::out | std::ios_base::ate};
73+
assert(spSt.rdbuf()->span().data() == arr);
74+
assert(!spSt.rdbuf()->span().empty());
75+
assert(spSt.rdbuf()->span().size() == 4);
76+
}
77+
}
78+
79+
int main(int, char**) {
80+
#ifndef TEST_HAS_NO_NASTY_STRING
81+
test<nasty_char, nasty_char_traits>();
82+
#endif
83+
test<char>();
84+
test<char, constexpr_char_traits<char>>();
85+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
86+
test<wchar_t>();
87+
test<wchar_t, constexpr_char_traits<wchar_t>>();
88+
#endif
89+
90+
return 0;
91+
}

0 commit comments

Comments
 (0)