Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 4e17da1

Browse files
committed
string_view: port LIBCXX access tests to use pmem::obj::string_view
- change implementation to use pmem::obj::string_view
1 parent acf4134 commit 4e17da1

6 files changed

Lines changed: 138 additions & 108 deletions

File tree

tests/external/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,21 @@ if (TEST_STRING)
740740
# XXX: port libcxx test basic_string/string.cons/initializer_list_assignment.pass
741741
add_test_expect_failure(string_libcxx_string_view libcxx/basic_string/string.cons/string_view.fail.cpp)
742742

743+
build_test(string_libcxx_string_view_at libcxx/string.view/string.view.access/at.pass.cpp)
744+
add_test_generic(NAME string_libcxx_string_view_at TRACERS none pmemcheck memcheck)
745+
746+
build_test(string_libcxx_string_view_back libcxx/string.view/string.view.access/back.pass.cpp)
747+
add_test_generic(NAME string_libcxx_string_view_back TRACERS none pmemcheck memcheck)
748+
749+
build_test(string_libcxx_string_view_data libcxx/string.view/string.view.access/data.pass.cpp)
750+
add_test_generic(NAME string_libcxx_string_view_data TRACERS none pmemcheck memcheck)
751+
752+
build_test(string_libcxx_string_view_front libcxx/string.view/string.view.access/front.pass.cpp)
753+
add_test_generic(NAME string_libcxx_string_view_front TRACERS none pmemcheck memcheck)
754+
755+
build_test(string_libcxx_string_view_index libcxx/string.view/string.view.access/index.pass.cpp)
756+
add_test_generic(NAME string_libcxx_string_view_index TRACERS none pmemcheck memcheck)
757+
743758
if(MSVC_VERSION GREATER_EQUAL 1920)
744759
build_test(string_libcxx_string_view_opeq_string_view libcxx/string.view/string.view.comparison/opeq.string_view.string_view.pass.cpp)
745760
add_test_generic(NAME string_libcxx_string_view_opeq_string_view TRACERS none pmemcheck memcheck)

tests/external/libcxx/string.view/string.view.access/at.pass.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Copyright 2020, Intel Corporation
10+
//
11+
// Modified to test pmem::obj containers
12+
//
813

914
// NOTE: Older versions of clang have a bug where they fail to evaluate
1015
// string_view::at as a constant expression.
@@ -14,58 +19,47 @@
1419

1520
// constexpr const _CharT& at(size_type _pos) const;
1621

17-
#include <cassert>
18-
#include <stdexcept>
19-
#include <string_view>
22+
#include "unittest.hpp"
2023

21-
#include "test_macros.h"
24+
#include <libpmemobj++/string_view.hpp>
2225

2326
template <typename CharT>
2427
void
2528
test(const CharT *s, size_t len)
2629
{
27-
std::basic_string_view<CharT> sv(s, len);
28-
assert(sv.length() == len);
30+
pmem::obj::basic_string_view<CharT> sv(s, len);
31+
UT_ASSERT(sv.length() == len);
2932
for (size_t i = 0; i < len; ++i) {
30-
assert(sv.at(i) == s[i]);
31-
assert(&sv.at(i) == s + i);
33+
UT_ASSERT(sv.at(i) == s[i]);
34+
UT_ASSERT(&sv.at(i) == s + i);
3235
}
3336

34-
#ifndef TEST_HAS_NO_EXCEPTIONS
3537
try {
3638
(void)sv.at(len);
3739
} catch (const std::out_of_range &) {
3840
return;
3941
}
40-
assert(false);
41-
#endif
42+
UT_ASSERT(false);
4243
}
4344

44-
int
45-
main(int, char **)
45+
static void
46+
run()
4647
{
4748
test("ABCDE", 5);
4849
test("a", 1);
4950

5051
test(L"ABCDE", 5);
5152
test(L"a", 1);
5253

53-
#if TEST_STD_VER >= 11
5454
test(u"ABCDE", 5);
5555
test(u"a", 1);
5656

5757
test(U"ABCDE", 5);
5858
test(U"a", 1);
59-
#endif
60-
61-
#if TEST_STD_VER >= 11
62-
{
63-
constexpr std::basic_string_view<char> sv("ABC", 2);
64-
static_assert(sv.length() == 2, "");
65-
static_assert(sv.at(0) == 'A', "");
66-
static_assert(sv.at(1) == 'B', "");
67-
}
68-
#endif
59+
}
6960

70-
return 0;
61+
int
62+
main(int argc, char *argv[])
63+
{
64+
return run_test([&] { run(); });
7165
}

tests/external/libcxx/string.view/string.view.access/back.pass.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,60 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Copyright 2020, Intel Corporation
10+
//
11+
// Modified to test pmem::obj containers
12+
//
813

914
// <string_view>
1015

1116
// constexpr const _CharT& front();
1217

13-
#include <cassert>
14-
#include <string_view>
18+
#include "unittest.hpp"
1519

16-
#include "test_macros.h"
20+
#include <libpmemobj++/string_view.hpp>
1721

1822
template <typename CharT>
1923
bool
2024
test(const CharT *s, size_t len)
2125
{
22-
typedef std::basic_string_view<CharT> SV;
26+
typedef pmem::obj::basic_string_view<CharT> SV;
2327
SV sv(s, len);
24-
ASSERT_SAME_TYPE(decltype(sv.back()), typename SV::const_reference);
25-
LIBCPP_ASSERT_NOEXCEPT(sv.back());
26-
assert(sv.length() == len);
27-
assert(sv.back() == s[len - 1]);
28+
29+
static_assert(std::is_same<decltype(sv.back()),
30+
typename SV::const_reference>::value,
31+
"must be const_reference");
32+
static_assert(noexcept(sv.back()), "Operation must be noexcept");
33+
UT_ASSERT(sv.length() == len);
34+
UT_ASSERT(sv.back() == s[len - 1]);
2835
return &sv.back() == s + len - 1;
2936
}
3037

31-
int
32-
main(int, char **)
38+
static void
39+
run()
3340
{
34-
assert(test("ABCDE", 5));
35-
assert(test("a", 1));
41+
UT_ASSERT(test("ABCDE", 5));
42+
UT_ASSERT(test("a", 1));
3643

37-
assert(test(L"ABCDE", 5));
38-
assert(test(L"a", 1));
44+
UT_ASSERT(test(L"ABCDE", 5));
45+
UT_ASSERT(test(L"a", 1));
3946

40-
#if TEST_STD_VER >= 11
41-
assert(test(u"ABCDE", 5));
42-
assert(test(u"a", 1));
47+
UT_ASSERT(test(u"ABCDE", 5));
48+
UT_ASSERT(test(u"a", 1));
4349

44-
assert(test(U"ABCDE", 5));
45-
assert(test(U"a", 1));
46-
#endif
50+
UT_ASSERT(test(U"ABCDE", 5));
51+
UT_ASSERT(test(U"a", 1));
4752

48-
#if TEST_STD_VER >= 11
4953
{
50-
constexpr std::basic_string_view<char> sv("ABC", 2);
54+
constexpr pmem::obj::basic_string_view<char> sv("ABC", 2);
5155
static_assert(sv.length() == 2, "");
5256
static_assert(sv.back() == 'B', "");
5357
}
54-
#endif
58+
}
5559

56-
return 0;
60+
int
61+
main(int argc, char *argv[])
62+
{
63+
return run_test([&] { run(); });
5764
}

tests/external/libcxx/string.view/string.view.access/data.pass.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,54 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Copyright 2020, Intel Corporation
10+
//
11+
// Modified to test pmem::obj containers
12+
//
813

914
// <string_view>
1015

1116
// constexpr const _CharT* data() const noexcept;
1217

13-
#include <cassert>
14-
#include <string_view>
18+
#include "unittest.hpp"
1519

16-
#include "test_macros.h"
20+
#include <libpmemobj++/string_view.hpp>
1721

1822
template <typename CharT>
1923
void
2024
test(const CharT *s, size_t len)
2125
{
22-
std::basic_string_view<CharT> sv(s, len);
23-
assert(sv.length() == len);
24-
assert(sv.data() == s);
25-
#if TEST_STD_VER > 14
26-
// make sure we pick up std::data, too!
27-
assert(sv.data() == std::data(sv));
28-
#endif
26+
pmem::obj::basic_string_view<CharT> sv(s, len);
27+
UT_ASSERT(sv.length() == len);
28+
UT_ASSERT(sv.data() == s);
2929
}
3030

31-
int
32-
main(int, char **)
31+
static void
32+
run()
3333
{
3434
test("ABCDE", 5);
3535
test("a", 1);
3636

3737
test(L"ABCDE", 5);
3838
test(L"a", 1);
3939

40-
#if TEST_STD_VER >= 11
4140
test(u"ABCDE", 5);
4241
test(u"a", 1);
4342

4443
test(U"ABCDE", 5);
4544
test(U"a", 1);
46-
#endif
4745

48-
#if TEST_STD_VER > 11
4946
{
5047
constexpr const char *s = "ABC";
51-
constexpr std::basic_string_view<char> sv(s, 2);
48+
constexpr pmem::obj::basic_string_view<char> sv(s, 2);
5249
static_assert(sv.length() == 2, "");
5350
static_assert(sv.data() == s, "");
5451
}
55-
#endif
52+
}
5653

57-
return 0;
54+
int
55+
main(int argc, char *argv[])
56+
{
57+
return run_test([&] { run(); });
5858
}

tests/external/libcxx/string.view/string.view.access/front.pass.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,59 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Copyright 2020, Intel Corporation
10+
//
11+
// Modified to test pmem::obj containers
12+
//
813

914
// <string_view>
1015

1116
// constexpr const _CharT& back();
1217

13-
#include <cassert>
14-
#include <string_view>
18+
#include "unittest.hpp"
1519

16-
#include "test_macros.h"
20+
#include <libpmemobj++/string_view.hpp>
1721

1822
template <typename CharT>
1923
bool
2024
test(const CharT *s, size_t len)
2125
{
22-
typedef std::basic_string_view<CharT> SV;
26+
typedef pmem::obj::basic_string_view<CharT> SV;
2327
SV sv(s, len);
24-
ASSERT_SAME_TYPE(decltype(sv.front()), typename SV::const_reference);
25-
LIBCPP_ASSERT_NOEXCEPT(sv.front());
26-
assert(sv.length() == len);
27-
assert(sv.front() == s[0]);
28+
static_assert(std::is_same<decltype(sv.front()),
29+
typename SV::const_reference>::value,
30+
"must be const_reference");
31+
static_assert(noexcept(sv.front()), "Operation must be noexcept");
32+
UT_ASSERT(sv.length() == len);
33+
UT_ASSERT(sv.front() == s[0]);
2834
return &sv.front() == s;
2935
}
3036

31-
int
32-
main(int, char **)
37+
static void
38+
run()
3339
{
34-
assert(test("ABCDE", 5));
35-
assert(test("a", 1));
40+
UT_ASSERT(test("ABCDE", 5));
41+
UT_ASSERT(test("a", 1));
3642

37-
assert(test(L"ABCDE", 5));
38-
assert(test(L"a", 1));
43+
UT_ASSERT(test(L"ABCDE", 5));
44+
UT_ASSERT(test(L"a", 1));
3945

40-
#if TEST_STD_VER >= 11
41-
assert(test(u"ABCDE", 5));
42-
assert(test(u"a", 1));
46+
UT_ASSERT(test(u"ABCDE", 5));
47+
UT_ASSERT(test(u"a", 1));
4348

44-
assert(test(U"ABCDE", 5));
45-
assert(test(U"a", 1));
46-
#endif
49+
UT_ASSERT(test(U"ABCDE", 5));
50+
UT_ASSERT(test(U"a", 1));
4751

48-
#if TEST_STD_VER >= 11
4952
{
50-
constexpr std::basic_string_view<char> sv("ABC", 2);
53+
constexpr pmem::obj::basic_string_view<char> sv("ABC", 2);
5154
static_assert(sv.length() == 2, "");
5255
static_assert(sv.front() == 'A', "");
5356
}
54-
#endif
57+
}
5558

56-
return 0;
59+
int
60+
main(int argc, char *argv[])
61+
{
62+
return run_test([&] { run(); });
5763
}

0 commit comments

Comments
 (0)