diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-01-16 17:20:41 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-01-16 17:20:41 +0000 |
| commit | dfd66a522f6e3ab9b03c0921ba40f012de0958b0 (patch) | |
| tree | b0d11b87de3fd53ccd72be004b0c8a22ff52a404 /test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp | |
| parent | 043da5ce84d67963aeeba7fa694033d953da16b6 (diff) | |
Notes
Diffstat (limited to 'test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp')
| -rw-r--r-- | test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp index 83b5dd14b3f6..690aebd4c2a6 100644 --- a/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp +++ b/test/std/strings/basic.string/string.modifiers/string_assign/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.assign(first, last); + assert(false); + } + catch (...) {} + assert(s.__invariants()); + assert(s == aCopy); +} + int main() { { @@ -147,4 +161,17 @@ int main() S("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()); + } } |
