summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/strings/basic.string/string.modifiers/string_replace
diff options
context:
space:
mode:
authorRoger Ferrer Ibanez <roger.ferreribanez@arm.com>2016-11-01 15:46:16 +0000
committerRoger Ferrer Ibanez <roger.ferreribanez@arm.com>2016-11-01 15:46:16 +0000
commit8a915ed644b910ae9d7d2aef7ad491791fbd4944 (patch)
tree94c9f6f9eb9628a577e8d227b3b2646c3e03a2d1 /libcxx/test/std/strings/basic.string/string.modifiers/string_replace
parent6dd8fab443451e1bbab87186057a80e3088d6d84 (diff)
downloadbcm5719-llvm-8a915ed644b910ae9d7d2aef7ad491791fbd4944.tar.gz
bcm5719-llvm-8a915ed644b910ae9d7d2aef7ad491791fbd4944.zip
Protect exceptional paths under libcpp-no-exceptions
These tests are of the form try { action-that-may-throw assert(!exceptional-condition) assert(some-other-facts) } catch (relevant-exception) { assert(exceptional-condition) } Under libcpp-no-exceptions there is still value in verifying some-other-facts while avoiding the exceptional case. So for these tests just conditionally check some-other-facts if exceptional-condition is false. When exception are supported make sure that a true exceptional-condition throws an exception Differential Revision: https://reviews.llvm.org/D26136 llvm-svn: 285697
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.modifiers/string_replace')
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp43
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp43
6 files changed, 120 insertions, 54 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
index 1ebaa3b36f0..542da0d08cb 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <class T>
@@ -31,23 +30,32 @@ test(S s, typename S::size_type pos1, typename S::size_type n1,
S expected)
{
static_assert((!std::is_same<S, SV>::value), "");
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos1 <= old_size && pos2 <= sv.size())
{
s.replace(pos1, n1, sv, pos2, n2);
LIBCPP_ASSERT(s.__invariants());
- assert(pos1 <= old_size && pos2 <= sv.size());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(n2, sv.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > old_size || pos2 > sv.size());
- assert(s == s0);
+ try
+ {
+ s.replace(pos1, n1, sv, pos2, n2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size || pos2 > sv.size());
+ assert(s == s0);
+ }
}
+#endif
}
template <class S, class SV>
@@ -57,23 +65,32 @@ test_npos(S s, typename S::size_type pos1, typename S::size_type n1,
S expected)
{
static_assert((!std::is_same<S, SV>::value), "");
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos1 <= old_size && pos2 <= sv.size())
{
s.replace(pos1, n1, sv, pos2);
LIBCPP_ASSERT(s.__invariants());
- assert(pos1 <= old_size && pos2 <= sv.size());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(S::npos, sv.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > old_size || pos2 > sv.size());
- assert(s == s0);
+ try
+ {
+ s.replace(pos1, n1, sv, pos2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size || pos2 > sv.size());
+ assert(s == s0);
+ }
}
+#endif
}
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
index 3beb074c0fd..d09c9c2efd6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -26,23 +25,32 @@ void
test(S s, typename S::size_type pos, typename S::size_type n1,
const typename S::value_type* str, S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos <= old_size)
{
s.replace(pos, n1, str);
LIBCPP_ASSERT(s.__invariants());
- assert(pos <= old_size);
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos);
typename S::size_type rlen = S::traits_type::length(str);
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos > old_size);
- assert(s == s0);
+ try
+ {
+ s.replace(pos, n1, str);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos > old_size);
+ assert(s == s0);
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
index d961e9e8f76..5c751285cb0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -27,23 +26,32 @@ test(S s, typename S::size_type pos, typename S::size_type n1,
const typename S::value_type* str, typename S::size_type n2,
S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos <= old_size)
{
s.replace(pos, n1, str, n2);
LIBCPP_ASSERT(s.__invariants());
- assert(pos <= old_size);
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos);
typename S::size_type rlen = n2;
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos > old_size);
- assert(s == s0);
+ try
+ {
+ s.replace(pos, n1, str, n2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos > old_size);
+ assert(s == s0);
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
index d4696fba8a8..75745dab61f 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -27,23 +26,32 @@ test(S s, typename S::size_type pos, typename S::size_type n1,
typename S::size_type n2, typename S::value_type c,
S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos <= old_size)
{
s.replace(pos, n1, n2, c);
LIBCPP_ASSERT(s.__invariants());
- assert(pos <= old_size);
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos);
typename S::size_type rlen = n2;
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos > old_size);
- assert(s == s0);
+ try
+ {
+ s.replace(pos, n1, n2, c);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos > old_size);
+ assert(s == s0);
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
index 1be45d8a662..612e1e200c9 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -25,23 +24,32 @@ template <class S>
void
test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos1 <= old_size)
{
s.replace(pos1, n1, str);
LIBCPP_ASSERT(s.__invariants());
- assert(pos1 <= old_size);
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = str.size();
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > old_size);
- assert(s == s0);
+ try
+ {
+ s.replace(pos1, n1, str);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size);
+ assert(s == s0);
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
index 3f4bf450d85..b49b6f987b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -29,23 +28,32 @@ test(S s, typename S::size_type pos1, typename S::size_type n1,
S str, typename S::size_type pos2, typename S::size_type n2,
S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos1 <= old_size && pos2 <= str.size())
{
s.replace(pos1, n1, str, pos2, n2);
LIBCPP_ASSERT(s.__invariants());
- assert(pos1 <= old_size && pos2 <= str.size());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(n2, str.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > old_size || pos2 > str.size());
- assert(s == s0);
+ try
+ {
+ s.replace(pos1, n1, str, pos2, n2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size || pos2 > str.size());
+ assert(s == s0);
+ }
}
+#endif
}
template <class S>
@@ -54,23 +62,32 @@ test_npos(S s, typename S::size_type pos1, typename S::size_type n1,
S str, typename S::size_type pos2,
S expected)
{
- typename S::size_type old_size = s.size();
+ const typename S::size_type old_size = s.size();
S s0 = s;
- try
+ if (pos1 <= old_size && pos2 <= str.size())
{
s.replace(pos1, n1, str, pos2);
LIBCPP_ASSERT(s.__invariants());
- assert(pos1 <= old_size && pos2 <= str.size());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(S::npos, str.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > old_size || pos2 > str.size());
- assert(s == s0);
+ try
+ {
+ s.replace(pos1, n1, str, pos2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size || pos2 > str.size());
+ assert(s == s0);
+ }
}
+#endif
}
OpenPOWER on IntegriCloud