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

Commit 5f02ba8

Browse files
committed
string_view: port modifiers libcxx tests
- enable tests for remove_suffix/prefix and swap methods
1 parent 479fbfa commit 5f02ba8

File tree

4 files changed

+72
-105
lines changed

4 files changed

+72
-105
lines changed

tests/external/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,15 @@ if (TEST_STRING)
764764
build_test(string_libcxx_string_view_end libcxx/string.view/string.view.iterators/end.pass.cpp)
765765
add_test_generic(NAME string_libcxx_string_view_end TRACERS none pmemcheck memcheck)
766766

767+
build_test(string_libcxx_string_view_swap libcxx/string.view/string.view.modifiers/swap.pass.cpp)
768+
add_test_generic(NAME string_libcxx_string_view_swap TRACERS none pmemcheck memcheck)
769+
770+
build_test(string_libcxx_string_view_remove_prefix libcxx/string.view/string.view.modifiers/remove_prefix.pass.cpp)
771+
add_test_generic(NAME string_libcxx_string_view_remove_prefix TRACERS none pmemcheck memcheck)
772+
773+
build_test(string_libcxx_string_view_remove_suffix libcxx/string.view/string.view.modifiers/remove_suffix.pass.cpp)
774+
add_test_generic(NAME string_libcxx_string_view_remove_suffix TRACERS none pmemcheck memcheck)
775+
767776
if(MSVC_VERSION GREATER_EQUAL 1920)
768777
build_test(string_libcxx_string_view_opeq_string_view libcxx/string.view/string.view.comparison/opeq.string_view.string_view.pass.cpp)
769778
add_test_generic(NAME string_libcxx_string_view_opeq_string_view TRACERS none pmemcheck memcheck)

tests/external/libcxx/string.view/string.view.modifiers/remove_prefix.pass.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,45 @@
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
// void remove_prefix(size_type _n)
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-
typedef std::basic_string_view<CharT> SV;
26+
typedef pmem::obj::basic_string_view<CharT> SV;
2327
{
2428
SV sv1(s);
25-
assert(sv1.size() == len);
26-
assert(sv1.data() == s);
29+
UT_ASSERT(sv1.size() == len);
30+
UT_ASSERT(sv1.data() == s);
2731

2832
if (len > 0) {
2933
sv1.remove_prefix(1);
30-
assert(sv1.size() == (len - 1));
31-
assert(sv1.data() == (s + 1));
34+
UT_ASSERT(sv1.size() == (len - 1));
35+
UT_ASSERT(sv1.data() == (s + 1));
3236
sv1.remove_prefix(len - 1);
3337
}
3438

35-
assert(sv1.size() == 0);
39+
UT_ASSERT(sv1.size() == 0);
3640
sv1.remove_prefix(0);
37-
assert(sv1.size() == 0);
41+
UT_ASSERT(sv1.size() == 0);
3842
}
3943
}
4044

41-
#if TEST_STD_VER > 11
42-
constexpr size_t
43-
test_ce(size_t n, size_t k)
44-
{
45-
typedef std::basic_string_view<char> SV;
46-
SV sv1{"ABCDEFGHIJKL", n};
47-
sv1.remove_prefix(k);
48-
return sv1.size();
49-
}
50-
#endif
51-
52-
int
53-
main(int, char **)
45+
static void
46+
run()
5447
{
5548
test("ABCDE", 5);
5649
test("a", 1);
@@ -60,24 +53,17 @@ main(int, char **)
6053
test(L"a", 1);
6154
test(L"", 0);
6255

63-
#if TEST_STD_VER >= 11
6456
test(u"ABCDE", 5);
6557
test(u"a", 1);
6658
test(u"", 0);
6759

6860
test(U"ABCDE", 5);
6961
test(U"a", 1);
7062
test(U"", 0);
71-
#endif
72-
73-
#if TEST_STD_VER > 11
74-
{
75-
static_assert(test_ce(5, 0) == 5, "");
76-
static_assert(test_ce(5, 1) == 4, "");
77-
static_assert(test_ce(5, 5) == 0, "");
78-
static_assert(test_ce(9, 3) == 6, "");
79-
}
80-
#endif
63+
}
8164

82-
return 0;
65+
int
66+
main(int argc, char *argv[])
67+
{
68+
return run_test([&] { run(); });
8369
}

tests/external/libcxx/string.view/string.view.modifiers/remove_suffix.pass.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,45 @@
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
// void remove_suffix(size_type _n)
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-
typedef std::basic_string_view<CharT> SV;
26+
typedef pmem::obj::basic_string_view<CharT> SV;
2327
{
2428
SV sv1(s);
25-
assert(sv1.size() == len);
26-
assert(sv1.data() == s);
29+
UT_ASSERT(sv1.size() == len);
30+
UT_ASSERT(sv1.data() == s);
2731

2832
if (len > 0) {
2933
sv1.remove_suffix(1);
30-
assert(sv1.size() == (len - 1));
31-
assert(sv1.data() == s);
34+
UT_ASSERT(sv1.size() == (len - 1));
35+
UT_ASSERT(sv1.data() == s);
3236
sv1.remove_suffix(len - 1);
3337
}
3438

35-
assert(sv1.size() == 0);
39+
UT_ASSERT(sv1.size() == 0);
3640
sv1.remove_suffix(0);
37-
assert(sv1.size() == 0);
41+
UT_ASSERT(sv1.size() == 0);
3842
}
3943
}
4044

41-
#if TEST_STD_VER > 11
42-
constexpr size_t
43-
test_ce(size_t n, size_t k)
44-
{
45-
typedef std::basic_string_view<char> SV;
46-
SV sv1{"ABCDEFGHIJKL", n};
47-
sv1.remove_suffix(k);
48-
return sv1.size();
49-
}
50-
#endif
51-
52-
int
53-
main(int, char **)
45+
static void
46+
run()
5447
{
5548
test("ABCDE", 5);
5649
test("a", 1);
@@ -60,24 +53,17 @@ main(int, char **)
6053
test(L"a", 1);
6154
test(L"", 0);
6255

63-
#if TEST_STD_VER >= 11
6456
test(u"ABCDE", 5);
6557
test(u"a", 1);
6658
test(u"", 0);
6759

6860
test(U"ABCDE", 5);
6961
test(U"a", 1);
7062
test(U"", 0);
71-
#endif
72-
73-
#if TEST_STD_VER > 11
74-
{
75-
static_assert(test_ce(5, 0) == 5, "");
76-
static_assert(test_ce(5, 1) == 4, "");
77-
static_assert(test_ce(5, 5) == 0, "");
78-
static_assert(test_ce(9, 3) == 6, "");
79-
}
80-
#endif
63+
}
8164

82-
return 0;
65+
int
66+
main(int argc, char *argv[])
67+
{
68+
return run_test([&] { run(); });
8369
}

tests/external/libcxx/string.view/string.view.modifiers/swap.pass.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,42 @@
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
// void swap(basic_string_view& _other) 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-
typedef std::basic_string_view<CharT> SV;
26+
typedef pmem::obj::basic_string_view<CharT> SV;
2327
{
2428
SV sv1(s);
2529
SV sv2;
2630

27-
assert(sv1.size() == len);
28-
assert(sv1.data() == s);
29-
assert(sv2.size() == 0);
31+
UT_ASSERT(sv1.size() == len);
32+
UT_ASSERT(sv1.data() == s);
33+
UT_ASSERT(sv2.size() == 0);
3034

3135
sv1.swap(sv2);
32-
assert(sv1.size() == 0);
33-
assert(sv2.size() == len);
34-
assert(sv2.data() == s);
36+
UT_ASSERT(sv1.size() == 0);
37+
UT_ASSERT(sv2.size() == len);
38+
UT_ASSERT(sv2.data() == s);
3539
}
3640
}
3741

38-
#if TEST_STD_VER > 11
39-
constexpr size_t
40-
test_ce(size_t n, size_t k)
41-
{
42-
typedef std::basic_string_view<char> SV;
43-
SV sv1{"ABCDEFGHIJKL", n};
44-
SV sv2{sv1.data(), k};
45-
sv1.swap(sv2);
46-
return sv1.size();
47-
}
48-
#endif
49-
50-
int
51-
main(int, char **)
42+
static void
43+
run()
5244
{
5345
test("ABCDE", 5);
5446
test("a", 1);
@@ -58,23 +50,17 @@ main(int, char **)
5850
test(L"a", 1);
5951
test(L"", 0);
6052

61-
#if TEST_STD_VER >= 11
6253
test(u"ABCDE", 5);
6354
test(u"a", 1);
6455
test(u"", 0);
6556

6657
test(U"ABCDE", 5);
6758
test(U"a", 1);
6859
test(U"", 0);
69-
#endif
70-
71-
#if TEST_STD_VER > 11
72-
{
73-
static_assert(test_ce(2, 3) == 3, "");
74-
static_assert(test_ce(5, 3) == 3, "");
75-
static_assert(test_ce(0, 1) == 1, "");
76-
}
77-
#endif
60+
}
7861

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

0 commit comments

Comments
 (0)