Skip to content

Commit b078864

Browse files
committed
Tests: Added setbuf.pass
1 parent 6a4f012 commit b078864

File tree

3 files changed

+75
-11
lines changed

3 files changed

+75
-11
lines changed

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <spanstream>
2828

2929
#include "constexpr_char_traits.h"
30-
#include "test_convertible.h"
30+
#include "nasty_string.h"
3131
#include "test_macros.h"
3232

3333
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
@@ -51,6 +51,9 @@ void test() {
5151
}
5252

5353
int main(int, char**) {
54+
#ifndef TEST_HAS_NO_NASTY_STRING
55+
test<nasty_char, nasty_char_traits>();
56+
#endif
5457
test<char>();
5558
test<char, constexpr_char_traits<char>>();
5659
#ifndef TEST_HAS_NO_WIDE_CHARACTERS

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <spanstream>
2626

2727
#include "constexpr_char_traits.h"
28-
#include "test_convertible.h"
28+
#include "nasty_string.h"
2929
#include "test_macros.h"
3030

3131
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
@@ -47,6 +47,9 @@ void test() {
4747
}
4848

4949
int main(int, char**) {
50+
#ifndef TEST_HAS_NO_NASTY_STRING
51+
test<nasty_char, nasty_char_traits>();
52+
#endif
5053
test<char>();
5154
test<char, constexpr_char_traits<char>>();
5255
#ifndef TEST_HAS_NO_WIDE_CHARACTERS

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <spanstream>
2424

2525
#include "constexpr_char_traits.h"
26-
#include "test_convertible.h"
26+
#include "nasty_string.h"
2727
#include "test_macros.h"
2828

2929
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
@@ -33,20 +33,78 @@ void test() {
3333
CharT arr[4];
3434
std::span<CharT> sp{arr};
3535

36-
// TODO:
36+
// Mode: default (`in` | `out`)
37+
{
38+
SpBuf spBuf{sp};
39+
assert(spBuf.span().data() == arr);
40+
// Mode `out` counts read characters
41+
assert(spBuf.span().empty());
42+
assert(spBuf.span().size() == 0);
3743

38-
// Mode: default
44+
spBuf.pubsetbuf(nullptr, 0);
45+
assert(spBuf.span().data() == nullptr);
46+
// Mode `out` counts read characters
47+
assert(spBuf.span().empty());
48+
assert(spBuf.span().size() == 0);
49+
}
50+
// Mode: `ios_base::in`
3951
{
40-
SpBuf rhsSpBuf{sp};
41-
SpBuf spBuf(std::span<CharT>{});
42-
spBuf.swap(rhsSpBuf);
43-
// assert(spBuf.span().data() == arr);
44-
// assert(!spBuf.span().empty());
45-
// assert(spBuf.span().size() == 4);
52+
SpBuf spBuf{sp, std::ios_base::in};
53+
assert(spBuf.span().data() == arr);
54+
assert(!spBuf.span().empty());
55+
assert(spBuf.span().size() == 4);
56+
57+
spBuf.pubsetbuf(nullptr, 0);
58+
assert(spBuf.span().data() == nullptr);
59+
assert(spBuf.span().empty());
60+
assert(spBuf.span().size() == 0);
61+
}
62+
// Mode `ios_base::out`
63+
{
64+
SpBuf spBuf{sp, std::ios_base::out};
65+
assert(spBuf.span().data() == arr);
66+
// Mode `out` counts read characters
67+
assert(spBuf.span().empty());
68+
assert(spBuf.span().size() == 0);
69+
70+
spBuf.pubsetbuf(nullptr, 0);
71+
assert(spBuf.span().data() == nullptr);
72+
// Mode `out` counts read characters
73+
assert(spBuf.span().empty());
74+
assert(spBuf.span().size() == 0);
75+
}
76+
// Mode: multiple
77+
{
78+
SpBuf spBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
79+
assert(spBuf.span().data() == arr);
80+
// Mode `out` counts read characters
81+
assert(spBuf.span().empty());
82+
assert(spBuf.span().size() == 0);
83+
84+
spBuf.pubsetbuf(nullptr, 0);
85+
assert(spBuf.span().data() == nullptr);
86+
// Mode `out` counts read characters
87+
assert(spBuf.span().empty());
88+
assert(spBuf.span().size() == 0);
89+
}
90+
// Mode: `ios_base::ate`
91+
{
92+
SpBuf spBuf{sp, std::ios_base::out | std::ios_base::ate};
93+
assert(spBuf.span().data() == arr);
94+
assert(!spBuf.span().empty());
95+
assert(spBuf.span().size() == 4);
96+
97+
spBuf.pubsetbuf(nullptr, 0);
98+
assert(spBuf.span().data() == nullptr);
99+
assert(spBuf.span().empty());
100+
assert(spBuf.span().size() == 0);
46101
}
47102
}
48103

49104
int main(int, char**) {
105+
#ifndef TEST_HAS_NO_NASTY_STRING
106+
test<nasty_char, nasty_char_traits>();
107+
#endif
50108
test<char>();
51109
test<char, constexpr_char_traits<char>>();
52110
#ifndef TEST_HAS_NO_WIDE_CHARACTERS

0 commit comments

Comments
 (0)