aboutsummaryrefslogtreecommitdiff
path: root/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp')
-rw-r--r--test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp b/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp
new file mode 100644
index 000000000000..a3fa585e44ff
--- /dev/null
+++ b/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// __resize_default_init(size_type)
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+void write_c_str(char *buf, int size) {
+ for (int i=0; i < size; ++i) {
+ buf[i] = 'a';
+ }
+ buf[size] = '\0';
+}
+
+void test_buffer_usage()
+{
+ {
+ unsigned buff_size = 125;
+ unsigned used_size = buff_size - 16;
+ std::string s;
+ s.__resize_default_init(buff_size);
+ write_c_str(&s[0], used_size);
+ assert(s.size() == buff_size);
+ assert(strlen(s.data()) == used_size);
+ s.__resize_default_init(used_size);
+ assert(s.size() == used_size);
+ assert(s.data()[used_size] == '\0');
+ for (unsigned i=0; i < used_size; ++i) {
+ assert(s[i] == 'a');
+ }
+ }
+}
+
+void test_basic() {
+ {
+ std::string s;
+ s.__resize_default_init(3);
+ assert(s.size() == 3);
+ assert(s.data()[3] == '\0');
+ for (int i=0; i < 3; ++i)
+ s[i] = 'a' + i;
+ s.__resize_default_init(1);
+ assert(s[0] == 'a');
+ assert(s.data()[1] == '\0');
+ assert(s.size() == 1);
+ }
+}
+
+int main() {
+ test_basic();
+ test_buffer_usage();
+}