Skip to content

Commit 2fb8e8c

Browse files
committed
Tests: spanbuf constructor tests
1 parent 7bd735d commit 2fb8e8c

File tree

10 files changed

+615
-32
lines changed

10 files changed

+615
-32
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
#include "constexpr_char_traits.h"
3131
#include "test_macros.h"
3232

33-
template <typename CharT, typename Traits = std::char_traits<CharT>>
33+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3434
void test() {
35-
using SpStream = std::basic_ispanstream<CharT, Traits>;
35+
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
3636

3737
// Types
3838

39-
static_assert(std::is_base_of_v<std::basic_istream<CharT, Traits>, SpStream>);
39+
static_assert(std::is_base_of_v<std::basic_istream<CharT, TraitsT>, SpStream>);
4040
static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
41-
static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
42-
static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
43-
static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
44-
static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
41+
static_assert(std::is_same_v<typename SpStream::int_type, typename TraitsT::int_type>);
42+
static_assert(std::is_same_v<typename SpStream::pos_type, typename TraitsT::pos_type>);
43+
static_assert(std::is_same_v<typename SpStream::off_type, typename TraitsT::off_type>);
44+
static_assert(std::is_same_v<typename SpStream::traits_type, TraitsT>);
4545

4646
// Copy properties
4747

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
#ifndef TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H
10+
#define TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H
11+
12+
#include "make_string.h"
13+
14+
#define CS(S) MAKE_CSTRING(CharT, S)
15+
#define ST(S, a) std::basic_string<CharT, TraitsT, AllocT>(MAKE_CSTRING(CharT, S), MKSTR_LEN(CharT, S), a)
16+
#define SV(S) std::basic_string_view<CharT, TraitsT>(MAKE_CSTRING(CharT, S), MKSTR_LEN(CharT, S))
17+
18+
#endif // TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
#include "constexpr_char_traits.h"
3131
#include "test_macros.h"
3232

33-
template <typename CharT, typename Traits = std::char_traits<CharT>>
33+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3434
void test() {
35-
using SpStream = std::basic_ospanstream<CharT, Traits>;
35+
using SpStream = std::basic_ospanstream<CharT, TraitsT>;
3636

3737
// Types
3838

39-
static_assert(std::is_base_of_v<std::basic_ostream<CharT, Traits>, SpStream>);
39+
static_assert(std::is_base_of_v<std::basic_ostream<CharT, TraitsT>, SpStream>);
4040
static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
41-
static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
42-
static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
43-
static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
44-
static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
41+
static_assert(std::is_same_v<typename SpStream::int_type, typename TraitsT::int_type>);
42+
static_assert(std::is_same_v<typename SpStream::pos_type, typename TraitsT::pos_type>);
43+
static_assert(std::is_same_v<typename SpStream::off_type, typename TraitsT::off_type>);
44+
static_assert(std::is_same_v<typename SpStream::traits_type, TraitsT>);
4545

4646
// Copy properties
4747

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,36 @@
2121
#include <spanstream>
2222

2323
#include "constexpr_char_traits.h"
24+
#include "nasty_string.h"
2425
#include "test_macros.h"
2526

26-
template <typename CharT, typename Traits = std::char_traits<CharT>>
27-
void test() {
28-
using SpanBuf = std::basic_spanbuf<CharT, Traits>;
27+
void test_sfinae_with_nasty_char() {
28+
using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
29+
30+
static_assert(std::default_initializable<SpBuf>);
31+
}
32+
33+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
34+
void test_sfinae() {
35+
using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
2936

30-
static_assert(std::default_initializable<SpanBuf>);
37+
static_assert(std::default_initializable<SpBuf>);
38+
}
39+
40+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
41+
void test() {
42+
using SpanBuf = std::basic_spanbuf<CharT, TraitsT>;
3143

3244
SpanBuf spBuf;
45+
assert(spBuf.span().data() == nullptr);
3346
assert(spBuf.span().empty());
47+
assert(spBuf.span().size() == 0);
3448
}
3549

3650
int main(int, char**) {
51+
test_sfinae_with_nasty_char();
52+
test_sfinae<char>();
53+
test_sfinae<char, constexpr_char_traits<char>>();
3754
test<char>();
3855
test<char, constexpr_char_traits<char>>();
3956
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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_spanbuf
15+
// : public basic_streambuf<charT, traits> {
16+
17+
// // [spanbuf.cons], constructors
18+
//
19+
// explicit basic_spanbuf(ios_base::openmode which);
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+
#include "../../types.h"
32+
33+
void test_sfinae_with_nasty_char() {
34+
using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
35+
36+
static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
37+
static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
38+
}
39+
40+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
41+
void test_sfinae() {
42+
using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
43+
44+
// `Mode`
45+
static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
46+
static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
47+
48+
// Non-mode
49+
static_assert(!std::constructible_from<SpBuf, const NonMode>);
50+
static_assert(!test_convertible<SpBuf, const NonMode>());
51+
}
52+
53+
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
54+
void test() {
55+
using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
56+
57+
static_assert(std::default_initializable<SpBuf>);
58+
59+
// Mode: `in`
60+
{
61+
SpBuf spBuf(std::ios_base::in);
62+
assert(spBuf.span().data() == nullptr);
63+
assert(spBuf.span().empty());
64+
assert(spBuf.span().size() == 0);
65+
}
66+
// Mode: `out`
67+
{
68+
SpBuf spBuf(std::ios_base::out);
69+
assert(spBuf.span().data() == nullptr);
70+
assert(spBuf.span().empty());
71+
assert(spBuf.span().size() == 0);
72+
}
73+
// Mode: multiple
74+
{
75+
SpBuf spBuf(std::ios_base::out | std::ios_base::in | std::ios_base::binary);
76+
assert(spBuf.span().data() == nullptr);
77+
assert(spBuf.span().empty());
78+
assert(spBuf.span().size() == 0);
79+
}
80+
}
81+
82+
int main(int, char**) {
83+
test_sfinae_with_nasty_char();
84+
test_sfinae<char>();
85+
test_sfinae<char, constexpr_char_traits<char>>();
86+
test<char>();
87+
test<char, constexpr_char_traits<char>>();
88+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
89+
test_sfinae<wchar_t>();
90+
test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
91+
test<wchar_t>();
92+
test<wchar_t, constexpr_char_traits<wchar_t>>();
93+
#endif
94+
95+
return 0;
96+
}

0 commit comments

Comments
 (0)