From dd93960662cf5d335818afa5304d153839317f0c Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 5 Mar 2014 14:34:08 +0100 Subject: [PATCH] Complete the test suite --- tstl/test_suite/strings.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tstl/test_suite/strings.cpp b/tstl/test_suite/strings.cpp index 347cd313..afc65fb1 100644 --- a/tstl/test_suite/strings.cpp +++ b/tstl/test_suite/strings.cpp @@ -210,6 +210,31 @@ void test_large(){ check(strcmp(s.c_str(), large_buffer) == 0, "Invalid content"); } +void test_reserve(){ + std::string s1("asdf"); + + check(!s1.empty(), "String mustn't be empty"); + check_equals(s1.size(), 4, "Invalid size"); + check_equals(s1.capacity(), 16, "Invalid capacity"); + check(strcmp(s1.c_str(), "asdf") == 0, "Invalid content"); + + s1.reserve(1000); + + check(!s1.empty(), "String mustn't be empty"); + check_equals(s1.size(), 4, "Invalid size"); + check(s1.capacity() >= 1000, "Invalid capacity"); + check(strcmp(s1.c_str(), "asdf") == 0, "Invalid content"); + + std::string s2("123456789012345678"); + + s2.reserve(1000); + + check(!s2.empty(), "String mustn't be empty"); + check_equals(s2.size(), 18, "Invalid size"); + check(s2.capacity() >= 1000, "Invalid capacity"); + check(strcmp(s2.c_str(), "123456789012345678") == 0, "Invalid content"); +} + } //end of anonymous namespace void string_tests(){ @@ -220,4 +245,5 @@ void string_tests(){ test_concat(); test_move(); test_large(); + test_reserve(); }