aboutsummaryrefslogtreecommitdiff
path: root/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-01-16 17:20:41 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-01-16 17:20:41 +0000
commitdfd66a522f6e3ab9b03c0921ba40f012de0958b0 (patch)
treeb0d11b87de3fd53ccd72be004b0c8a22ff52a404 /test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
parent043da5ce84d67963aeeba7fa694033d953da16b6 (diff)
downloadsrc-dfd66a522f6e3ab9b03c0921ba40f012de0958b0.tar.gz
src-dfd66a522f6e3ab9b03c0921ba40f012de0958b0.zip
Notes
Diffstat (limited to 'test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp')
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
index 3bf2afa25521..82e6fb5895e7 100644
--- a/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
@@ -15,7 +15,7 @@
#include <string>
#include <cassert>
-#include "../../input_iterator.h"
+#include "test_iterators.h"
#include "min_allocator.h"
template <class S, class It>
@@ -27,6 +27,20 @@ test(S s, It first, It last, S expected)
assert(s == expected);
}
+template <class S, class It>
+void
+test_exceptions(S s, It first, It last)
+{
+ S aCopy = s;
+ try {
+ s.append(first, last);
+ assert(false);
+ }
+ catch (...) {}
+ assert(s.__invariants());
+ assert(s == aCopy);
+}
+
int main()
{
{
@@ -87,7 +101,7 @@ int main()
test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -147,4 +161,17 @@ int main()
S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}
#endif
+ { // test iterator operations that throw
+ typedef std::string S;
+ typedef ThrowingIterator<char> TIter;
+ typedef input_iterator<TIter> IIter;
+ const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ test_exceptions(S(), IIter(TIter(s, s+10, 4, TIter::TAIncrement)), IIter());
+ test_exceptions(S(), IIter(TIter(s, s+10, 5, TIter::TADereference)), IIter());
+ test_exceptions(S(), IIter(TIter(s, s+10, 6, TIter::TAComparison)), IIter());
+
+ test_exceptions(S(), TIter(s, s+10, 4, TIter::TAIncrement), TIter());
+ test_exceptions(S(), TIter(s, s+10, 5, TIter::TADereference), TIter());
+ test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
+ }
}