aboutsummaryrefslogtreecommitdiff
path: root/gdb/unittests/basic_string_view/cons
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2018-04-09 13:31:06 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2018-04-09 14:20:47 -0400
commitc9638d2669ced9348eac869dadc7be24df85a9a8 (patch)
tree2020518c320679400ad58e2e03d5585c0ffe1dcd /gdb/unittests/basic_string_view/cons
parentfdc116781b03f5d30e93f5013159f39c4c0f3471 (diff)
downloadgdb-c9638d2669ced9348eac869dadc7be24df85a9a8.zip
gdb-c9638d2669ced9348eac869dadc7be24df85a9a8.tar.gz
gdb-c9638d2669ced9348eac869dadc7be24df85a9a8.tar.bz2
Adapt and integrate string_view tests
The previous patch copied the string_view tests from libstdc++. This patch adjusts them in a similar way that the libstdc++ optional tests are integrated in our unit test suite. Not all tests are used, some of them require language features not present in c++11. For example, we can't use a string_view constructor where the length is not explicit in a constexpr, because std::char_traits::length is not a constexpr itself (it is in c++17 though). Nevertheless, a good number of tests are integrated, which covers pretty well the string_view features. gdb/ChangeLog: * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add string_view-selftests.c. * unittests/basic_string_view/capacity/1.cc: Adapt to GDB testsuite. * unittests/basic_string_view/cons/char/1.cc: Likewise. * unittests/basic_string_view/cons/char/2.cc: Likewise. * unittests/basic_string_view/cons/char/3.cc: Likewise. * unittests/basic_string_view/element_access/char/1.cc: Likewise. * unittests/basic_string_view/element_access/char/empty.cc: Likewise. * unittests/basic_string_view/element_access/char/front_back.cc: Likewise. * unittests/basic_string_view/inserters/char/2.cc: Likewise. * unittests/basic_string_view/modifiers/remove_prefix/char/1.cc: Likewise. * unittests/basic_string_view/modifiers/remove_suffix/char/1.cc: Likewise. * unittests/basic_string_view/modifiers/swap/char/1.cc: Likewise. * unittests/basic_string_view/operations/compare/char/1.cc: Likewise. * unittests/basic_string_view/operations/compare/char/13650.cc: Likewise. * unittests/basic_string_view/operations/copy/char/1.cc: Likewise. * unittests/basic_string_view/operations/data/char/1.cc: Likewise. * unittests/basic_string_view/operations/find/char/1.cc: Likewise. * unittests/basic_string_view/operations/find/char/2.cc: Likewise. * unittests/basic_string_view/operations/find/char/3.cc: Likewise. * unittests/basic_string_view/operations/find/char/4.cc: Likewise. * unittests/basic_string_view/operations/rfind/char/1.cc: Likewise. * unittests/basic_string_view/operations/rfind/char/2.cc: Likewise. * unittests/basic_string_view/operations/rfind/char/3.cc: Likewise. * unittests/basic_string_view/operations/substr/char/1.cc: Likewise. * unittests/basic_string_view/operators/char/2.cc: Likewise. * unittests/string_view-selftests.c: New file.
Diffstat (limited to 'gdb/unittests/basic_string_view/cons')
-rw-r--r--gdb/unittests/basic_string_view/cons/char/1.cc21
-rw-r--r--gdb/unittests/basic_string_view/cons/char/2.cc11
-rw-r--r--gdb/unittests/basic_string_view/cons/char/3.cc8
3 files changed, 19 insertions, 21 deletions
diff --git a/gdb/unittests/basic_string_view/cons/char/1.cc b/gdb/unittests/basic_string_view/cons/char/1.cc
index f80ae92..cfe9cce 100644
--- a/gdb/unittests/basic_string_view/cons/char/1.cc
+++ b/gdb/unittests/basic_string_view/cons/char/1.cc
@@ -19,43 +19,40 @@
// basic_string_view constructors.
-#include <string_view>
-#include <string>
-#include <cstring>
-#include <testsuite_hooks.h>
+namespace cons_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
+ typedef gdb::string_view::size_type csize_type;
// basic_string_view()
- const std::string_view str00{};
+ const gdb::string_view str00{};
VERIFY( str00.length() == 0 );
VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const char str_lit01[] = "rodeo beach, marin";
- const std::string_view str01{str_lit01};
+ const gdb::string_view str01{str_lit01};
VERIFY( str01.length() == 18 );
VERIFY( str01.data() == str_lit01 );
- const std::string_view str02{"baker beach, san francisco"};
+ const gdb::string_view str02{"baker beach, san francisco"};
VERIFY( str02.length() == 26 );
// basic_string_view(const string_view&)
- std::string_view str04{str01};
+ gdb::string_view str04{str01};
VERIFY( str04.length() == str01.length() );
VERIFY( str04.data() == str01.data() );
// basic_string_view(const char* s)
csize_type len_lit01 = strlen(str_lit01);
- std::string_view str05{str_lit01, len_lit01};
+ gdb::string_view str05{str_lit01, len_lit01};
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
// basic_string_view(basic_string& s)
std::string istr07(10, 'z');
- std::string_view str07{istr07};
+ gdb::string_view str07{istr07};
VERIFY( str07.length() == 10 );
}
@@ -66,3 +63,5 @@ main()
return 0;
}
+
+} // namespace cons_1
diff --git a/gdb/unittests/basic_string_view/cons/char/2.cc b/gdb/unittests/basic_string_view/cons/char/2.cc
index 8dbca7a..a1b4536 100644
--- a/gdb/unittests/basic_string_view/cons/char/2.cc
+++ b/gdb/unittests/basic_string_view/cons/char/2.cc
@@ -19,10 +19,7 @@
// basic_string_view constructors.
-#include <new>
-#include <string_view>
-#include <stdexcept>
-#include <testsuite_hooks.h>
+namespace cons_2 {
void
test03()
@@ -32,9 +29,9 @@ test03()
// These are tests to see how basic_string_view handles data with NUL
// bytes. Obviously basic_string_view(char*) will halt at the first one, but
// nothing else should.
- std::string_view s1(with_nulls, 28);
+ gdb::string_view s1(with_nulls, 28);
VERIFY( s1.size() == 28 );
- std::string_view s2(s1);
+ gdb::string_view s2(s1);
VERIFY( s2.size() == 28 );
}
@@ -45,3 +42,5 @@ main()
return 0;
}
+
+} // namespace cons_2
diff --git a/gdb/unittests/basic_string_view/cons/char/3.cc b/gdb/unittests/basic_string_view/cons/char/3.cc
index c892cbc..358c118 100644
--- a/gdb/unittests/basic_string_view/cons/char/3.cc
+++ b/gdb/unittests/basic_string_view/cons/char/3.cc
@@ -19,15 +19,13 @@
// basic_string_view constructors.
-#include <string_view>
-#include <vector>
-#include <testsuite_hooks.h>
+namespace cons_3 {
void
test05()
{
char const * s = 0;
- std::string_view zero_length_built_with_NULL(s, 0);
+ gdb::string_view zero_length_built_with_NULL(s, 0);
}
int
@@ -37,3 +35,5 @@ main()
return 0;
}
+
+} // namespace cons_3