summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/strings/basic.string/string.ops/string_compare
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.ops/string_compare
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.ops/string_compare')
-rw-r--r--libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp43
-rw-r--r--libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp22
-rw-r--r--libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp43
5 files changed, 101 insertions, 51 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
index 2cdc348b6d3..bc2bf656db0 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <typename T>
@@ -22,6 +21,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -37,16 +38,22 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
SV sv, typename S::size_type pos2, typename S::size_type n2, int x)
{
static_assert((!std::is_same<S, SV>::value), "");
- try
- {
+ if (pos1 <= s.size() && pos2 <= sv.size())
assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= sv.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > sv.size());
+ try
+ {
+ s.compare(pos1, n1, sv, pos2, n2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > sv.size());
+ }
}
+#endif
}
template <class S, class SV>
@@ -55,16 +62,22 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
SV sv, typename S::size_type pos2, int x)
{
static_assert((!std::is_same<S, SV>::value), "");
- try
- {
+ if (pos1 <= s.size() && pos2 <= sv.size())
assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= sv.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > sv.size());
+ try
+ {
+ s.compare(pos1, n1, sv, pos2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > sv.size());
+ }
}
+#endif
}
template <class S, class SV>
diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
index 094c227030b..13f6c5a1cd7 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// int compare(size_type pos, size_type n1, const charT *s) const;
@@ -18,6 +17,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -32,15 +33,22 @@ void
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
const typename S::value_type* str, int x)
{
- try
- {
+ if (pos1 <= s.size())
assert(sign(s.compare(pos1, n1, str)) == sign(x));
- assert(pos1 <= s.size());
- }
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size());
+ try
+ {
+ s.compare(pos1, n1, str);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > s.size());
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
index 22aae785c19..fc811c84671 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// int compare(size_type pos, size_type n1, const charT *s, size_type n2) const;
@@ -18,6 +17,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -32,15 +33,22 @@ void
test(const S& s, typename S::size_type pos, typename S::size_type n1,
const typename S::value_type* str, typename S::size_type n2, int x)
{
- try
- {
+ if (pos <= s.size())
assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
- assert(pos <= s.size());
- }
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos > s.size());
+ try
+ {
+ s.compare(pos, n1, str, n2);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos > s.size());
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
index 90b4230f64d..b3d7da29fb1 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// int compare(size_type pos1, size_type n1, const basic_string& str) const;
@@ -18,6 +17,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -32,15 +33,22 @@ void
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
const S& str, int x)
{
- try
- {
+ if (pos1 <= s.size())
assert(sign(s.compare(pos1, n1, str)) == sign(x));
- assert(pos1 <= s.size());
- }
- catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size());
+ try
+ {
+ s.compare(pos1, n1, str);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > s.size());
+ }
}
+#endif
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
index 10f9d849c2b..42bba9d5eb2 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// int compare(size_type pos1, size_type n1, const basic_string& str,
@@ -20,6 +19,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -34,16 +35,22 @@ void
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
const S& str, typename S::size_type pos2, typename S::size_type n2, int x)
{
- try
- {
+ if (pos1 <= s.size() && pos2 <= str.size())
assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= str.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > str.size());
+ try
+ {
+ s.compare(pos1, n1, str, pos2, n2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > str.size());
+ }
}
+#endif
}
template <class S>
@@ -51,16 +58,22 @@ void
test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
const S& str, typename S::size_type pos2, int x)
{
- try
- {
+ if (pos1 <= s.size() && pos2 <= str.size())
assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= str.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > str.size());
+ try
+ {
+ s.compare(pos1, n1, str, pos2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > str.size());
+ }
}
+#endif
}
template <class S>
OpenPOWER on IntegriCloud