aboutsummaryrefslogtreecommitdiff
path: root/gdb/unittests/basic_string_view/modifiers
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/modifiers
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/modifiers')
-rw-r--r--gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc11
-rw-r--r--gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc11
-rw-r--r--gdb/unittests/basic_string_view/modifiers/swap/char/1.cc11
3 files changed, 22 insertions, 11 deletions
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
index ba08a98..f73fdc7 100644
--- a/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
@@ -17,13 +17,12 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace modifiers_remove_prefix {
void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
@@ -33,6 +32,7 @@ test01()
VERIFY( str0 == string_view{"pus mons"} );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -50,12 +50,17 @@ test02()
return true;
}
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
return 0;
}
+
+} // namespace modifiers_remove_prefix
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
index 1b71ee9..0407f37 100644
--- a/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
@@ -17,13 +17,12 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace modifiers_remove_suffix {
void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
@@ -33,6 +32,7 @@ test01()
VERIFY( str0 == string_view{"olympus mo"} );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -50,12 +50,17 @@ test02()
return true;
}
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
return 0;
}
+
+} // namespace modifiers_remove_suffix
diff --git a/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
index 90d2669..3bc7f01 100644
--- a/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
@@ -18,18 +18,19 @@
// { dg-options "-std=gnu++17" }
// { dg-do compile { target c++17 } }
-#include <string_view>
+namespace modifiers_swap {
-constexpr bool
+void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view s1{"last"};
string_view s2{"first"};
s1.swap(s2);
- return s1 == "first" && s2 == "last";
+ VERIFY( s1 == "first" );
+ VERIFY( s2 == "last" );
}
-static_assert( test01() );
+} // namespace modifiers_swap