Skip to content

Commit 53a323b

Browse files
committed
Updated: basic_ostream tests
1 parent 63a14a3 commit 53a323b

File tree

10 files changed

+221
-141
lines changed

10 files changed

+221
-141
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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_spanstream
15+
// : public basic_iostream<charT, traits> {
16+
17+
// Test stream operations inherited from `basic_istream` and `basic_ostream`
18+
19+
#include <cassert>
20+
#include <span>
21+
#include <spanstream>
22+
#include <string>
23+
#include <string_view>
24+
25+
#include "constexpr_char_traits.h"
26+
#include "test_macros.h"
27+
28+
#include "../helper_functions.h"
29+
#include "../helper_macros.h"
30+
#include "../helper_types.h"
31+
32+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
33+
void test() {
34+
using SpStream = std::basic_ospanstream<CharT, TraitsT>;
35+
36+
constexpr std::basic_string_view<CharT, TraitsT> sv{SV("zmt 94 hkt 82 pir 43vr")};
37+
constexpr auto arrSize{30UZ};
38+
assert(sv.size() < arrSize);
39+
40+
// Create a std::span test value
41+
CharT arr[arrSize]{};
42+
initialize_array_from_string_view(arr, sv);
43+
44+
std::span<CharT> sp{arr};
45+
46+
// `std::span` + Mode: default (`out`)
47+
{
48+
SpStream spSt(sp);
49+
50+
assert(spSt);
51+
assert(!spSt.bad());
52+
assert(!spSt.fail());
53+
assert(spSt.good());
54+
assert(spSt.span().size() == 0);
55+
56+
spSt.clear();
57+
58+
assert(spSt);
59+
assert(!spSt.bad());
60+
assert(!spSt.fail());
61+
assert(spSt.good());
62+
}
63+
}
64+
65+
int main(int, char**) {
66+
test<char>();
67+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
68+
test<wchar_t>();
69+
#endif
70+
71+
return 0;
72+
}

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/assign.move.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ void test() {
4141
{
4242
SpStream rhsSpSt{sp};
4343
assert(rhsSpSt.span().data() == arr);
44+
// Mode `out` counts read characters
4445
assert(rhsSpSt.span().empty());
4546
assert(rhsSpSt.span().size() == 0);
4647

4748
SpStream spSt = std::move(rhsSpSt);
4849
assert(spSt.span().data() == arr);
50+
// Mode `out` counts read characters
4951
assert(spSt.span().empty());
5052
assert(spSt.span().size() == 0);
5153

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ void test() {
4141
{
4242
SpStream rhsSpSt{sp};
4343
assert(rhsSpSt.span().data() == arr);
44+
// Mode `out` counts read characters
4445
assert(rhsSpSt.span().empty());
4546
assert(rhsSpSt.span().size() == 0);
4647

4748
SpStream spSt{std::move(rhsSpSt)};
4849
assert(spSt.span().data() == arr);
50+
// Mode `out` counts read characters
4951
assert(spSt.span().empty());
5052
assert(spSt.span().size() == 0);
5153

@@ -58,11 +60,13 @@ void test() {
5860
{
5961
SpStream rhsSpSt{sp, std::ios_base::out};
6062
assert(rhsSpSt.span().data() == arr);
63+
// Mode `out` counts read characters
6164
assert(rhsSpSt.span().empty());
6265
assert(rhsSpSt.span().size() == 0);
6366

6467
SpStream spSt{std::move(rhsSpSt)};
6568
assert(spSt.span().data() == arr);
69+
// Mode `out` counts read characters
6670
assert(spSt.span().empty());
6771
assert(spSt.span().size() == 0);
6872

@@ -73,7 +77,7 @@ void test() {
7377
}
7478
// Mode `ate`
7579
{
76-
SpStream rhsSpSt{sp, std::ios_base::out | std::ios_base::ate};
80+
SpStream rhsSpSt{sp, std::ios_base::ate};
7781
assert(rhsSpSt.span().data() == arr);
7882
assert(!rhsSpSt.span().empty());
7983
assert(rhsSpSt.span().size() == 4);

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

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,67 +55,58 @@ void test() {
5555
assert(!sp.empty());
5656
assert(sp.size() == 4);
5757

58-
// Mode: default (`in` | `out`)
58+
// Mode: default (`out`)
5959
{
6060
SpStream spSt{sp};
6161
assert(spSt.span().data() == arr);
62+
// Mode `out` counts read characters
6263
assert(spSt.span().empty());
6364
assert(spSt.span().size() == 0);
6465
}
6566
{
6667
SpStream spSt{std::as_const(sp)};
6768
assert(spSt.span().data() == arr);
68-
assert(spSt.span().empty());
69-
assert(spSt.span().size() == 0);
70-
}
71-
// Mode: `in`
72-
{
73-
SpStream spSt{sp, std::ios_base::in};
74-
assert(spSt.span().data() == arr);
75-
assert(spSt.span().empty());
76-
assert(spSt.span().size() == 0);
77-
}
78-
{
79-
SpStream spSt{std::as_const(sp), std::ios_base::in};
80-
assert(spSt.span().data() == arr);
69+
// Mode `out` counts read characters
8170
assert(spSt.span().empty());
8271
assert(spSt.span().size() == 0);
8372
}
8473
// Mode `out`
8574
{
8675
SpStream spSt{sp, std::ios_base::out};
8776
assert(spSt.span().data() == arr);
77+
// Mode `out` counts read characters
8878
assert(spSt.span().empty());
8979
assert(spSt.span().size() == 0);
9080
}
9181
{
9282
SpStream spSt{std::as_const(sp), std::ios_base::out};
9383
assert(spSt.span().data() == arr);
84+
// Mode `out` counts read characters
9485
assert(spSt.span().empty());
9586
assert(spSt.span().size() == 0);
9687
}
97-
// Mode: multiple
88+
// Mode `ate`
9889
{
99-
SpStream spSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
90+
SpStream spSt{sp, std::ios_base::ate};
10091
assert(spSt.span().data() == arr);
101-
assert(spSt.span().empty());
102-
assert(spSt.span().size() == 0);
92+
assert(!spSt.span().empty());
93+
assert(spSt.span().size() == 4);
10394
}
10495
{
105-
SpStream spSt{std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary};
96+
SpStream spSt{std::as_const(sp), std::ios_base::ate};
10697
assert(spSt.span().data() == arr);
107-
assert(spSt.span().empty());
108-
assert(spSt.span().size() == 0);
98+
assert(!spSt.span().empty());
99+
assert(spSt.span().size() == 4);
109100
}
110-
// Mode `ate`
101+
// Mode: multiple
111102
{
112-
SpStream spSt{sp, std::ios_base::out | std::ios_base::ate};
103+
SpStream spSt{sp, std::ios_base::ate | std::ios_base::binary};
113104
assert(spSt.span().data() == arr);
114105
assert(!spSt.span().empty());
115106
assert(spSt.span().size() == 4);
116107
}
117108
{
118-
SpStream spSt{std::as_const(sp), std::ios_base::out | std::ios_base::ate};
109+
SpStream spSt{std::as_const(sp), std::ios_base::ate | std::ios_base::binary};
119110
assert(spSt.span().data() == arr);
120111
assert(!spSt.span().empty());
121112
assert(spSt.span().size() == 4);
@@ -126,19 +117,42 @@ int main(int, char**) {
126117
#ifndef TEST_HAS_NO_NASTY_STRING
127118
test_sfinae<nasty_char, nasty_char_traits>();
128119
#endif
120+
129121
test_sfinae<char>();
130122
test_sfinae<char, constexpr_char_traits<char>>();
123+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
124+
test_sfinae<wchar_t>();
125+
test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
126+
#endif
127+
128+
#ifndef TEST_HAS_NO_CHAR8_T
129+
test_sfinae<char8_t>();
130+
test_sfinae<char8_t, constexpr_char_traits<char8_t>>();
131+
#endif
132+
test_sfinae<char16_t>();
133+
test_sfinae<char16_t, constexpr_char_traits<char16_t>>();
134+
test_sfinae<char32_t>();
135+
test_sfinae<char32_t, constexpr_char_traits<char32_t>>();
136+
131137
#ifndef TEST_HAS_NO_NASTY_STRING
132138
test<nasty_char, nasty_char_traits>();
133139
#endif
140+
134141
test<char>();
135142
test<char, constexpr_char_traits<char>>();
136143
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
137-
test_sfinae<wchar_t>();
138-
test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
139144
test<wchar_t>();
140145
test<wchar_t, constexpr_char_traits<wchar_t>>();
141146
#endif
142147

148+
#ifndef TEST_HAS_NO_CHAR8_T
149+
test<char8_t>();
150+
test<char8_t, constexpr_char_traits<char8_t>>();
151+
#endif
152+
test<char16_t>();
153+
test<char16_t, constexpr_char_traits<char16_t>>();
154+
test<char32_t>();
155+
test<char32_t, constexpr_char_traits<char32_t>>();
156+
143157
return 0;
144158
}

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.members/rdbuf.pass.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,14 @@ void test() {
3636
assert(!sp.empty());
3737
assert(sp.size() == 4);
3838

39-
// Mode: default (`in` | `out`)
39+
// Mode: default (`out`)
4040
{
4141
SpStream spSt{sp};
4242
assert(spSt.rdbuf()->span().data() == arr);
4343
// Mode `out` counts read characters
4444
assert(spSt.rdbuf()->span().empty());
4545
assert(spSt.rdbuf()->span().size() == 0);
4646
}
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-
}
5447
// Mode: `out`
5548
{
5649
SpStream spSt{sp, std::ios_base::out};
@@ -59,33 +52,43 @@ void test() {
5952
assert(spSt.rdbuf()->span().empty());
6053
assert(spSt.rdbuf()->span().size() == 0);
6154
}
62-
// Mode: multiple
55+
// Mode: `ate`
6356
{
64-
SpStream spSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
57+
SpStream spSt{sp, std::ios_base::ate};
6558
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);
59+
assert(!spSt.rdbuf()->span().empty());
60+
assert(spSt.rdbuf()->span().size() == 4);
6961
}
70-
// Mode: `ate`
62+
// Mode: multiple
7163
{
72-
SpStream spSt{sp, std::ios_base::out | std::ios_base::ate};
64+
SpStream spSt{sp, std::ios_base::ate | std::ios_base::binary};
7365
assert(spSt.rdbuf()->span().data() == arr);
7466
assert(!spSt.rdbuf()->span().empty());
7567
assert(spSt.rdbuf()->span().size() == 4);
7668
}
69+
7770
}
7871

7972
int main(int, char**) {
8073
#ifndef TEST_HAS_NO_NASTY_STRING
8174
test<nasty_char, nasty_char_traits>();
8275
#endif
76+
8377
test<char>();
8478
test<char, constexpr_char_traits<char>>();
8579
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
8680
test<wchar_t>();
8781
test<wchar_t, constexpr_char_traits<wchar_t>>();
8882
#endif
8983

84+
#ifndef TEST_HAS_NO_CHAR8_T
85+
test<char8_t>();
86+
test<char8_t, constexpr_char_traits<char8_t>>();
87+
#endif
88+
test<char16_t>();
89+
test<char16_t, constexpr_char_traits<char16_t>>();
90+
test<char32_t>();
91+
test<char32_t, constexpr_char_traits<char32_t>>();
92+
9093
return 0;
9194
}

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.members/span.pass.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,14 @@ void test() {
3737
assert(!sp.empty());
3838
assert(sp.size() == 4);
3939

40-
// Mode: default (`in` | `out`)
40+
// Mode: default (`out`)
4141
{
4242
SpStream spSt{sp};
4343
assert(spSt.span().data() == arr);
4444
// Mode `out` counts read characters
4545
assert(spSt.span().empty());
4646
assert(spSt.span().size() == 0);
4747
}
48-
// Mode: `in`
49-
{
50-
SpStream spSt{sp, std::ios_base::in};
51-
assert(spSt.span().data() == arr);
52-
assert(spSt.span().empty());
53-
assert(spSt.span().size() == 0);
54-
}
5548
// Mode: `out`
5649
{
5750
SpStream spSt{sp, std::ios_base::out};
@@ -60,17 +53,16 @@ void test() {
6053
assert(spSt.span().empty());
6154
assert(spSt.span().size() == 0);
6255
}
63-
// Mode: multiple
56+
// Mode: `ate`
6457
{
65-
SpStream spSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
58+
SpStream spSt{sp, std::ios_base::ate};
6659
assert(spSt.span().data() == arr);
67-
// Mode `out` counts read characters
68-
assert(spSt.span().empty());
69-
assert(spSt.span().size() == 0);
60+
assert(!spSt.span().empty());
61+
assert(spSt.span().size() == 4);
7062
}
71-
// Mode: `ate`
63+
// Mode: multiple
7264
{
73-
SpStream spSt{sp, std::ios_base::out | std::ios_base::ate};
65+
SpStream spSt{sp, std::ios_base::ate | std::ios_base::binary};
7466
assert(spSt.span().data() == arr);
7567
assert(!spSt.span().empty());
7668
assert(spSt.span().size() == 4);
@@ -81,12 +73,22 @@ int main(int, char**) {
8173
#ifndef TEST_HAS_NO_NASTY_STRING
8274
test<nasty_char, nasty_char_traits>();
8375
#endif
76+
8477
test<char>();
8578
test<char, constexpr_char_traits<char>>();
8679
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
8780
test<wchar_t>();
8881
test<wchar_t, constexpr_char_traits<wchar_t>>();
8982
#endif
9083

84+
#ifndef TEST_HAS_NO_CHAR8_T
85+
test<char8_t>();
86+
test<char8_t, constexpr_char_traits<char8_t>>();
87+
#endif
88+
test<char16_t>();
89+
test<char16_t, constexpr_char_traits<char16_t>>();
90+
test<char32_t>();
91+
test<char32_t, constexpr_char_traits<char32_t>>();
92+
9193
return 0;
9294
}

0 commit comments

Comments
 (0)