diff options
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.ops')
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> |