| 82 | } |
| 83 | |
| 84 | void reserve() { |
| 85 | #if 0 |
| 86 | TStringType s; |
| 87 | UNIT_ASSERT_EXCEPTION(s.reserve(s.max_size() + 1), std::length_error); |
| 88 | |
| 89 | // Non-shared behaviour - never shrink |
| 90 | |
| 91 | s.reserve(256); |
| 92 | #ifndef TSTRING_IS_STD_STRING |
| 93 | const auto* data = s.data(); |
| 94 | |
| 95 | UNIT_ASSERT(s.capacity() >= 256); |
| 96 | |
| 97 | s.reserve(128); |
| 98 | |
| 99 | UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); |
| 100 | #endif |
| 101 | |
| 102 | s.resize(64, 'x'); |
| 103 | s.reserve(10); |
| 104 | |
| 105 | #ifdef TSTRING_IS_STD_STRING |
| 106 | UNIT_ASSERT(s.capacity() >= 64); |
| 107 | #else |
| 108 | UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); |
| 109 | #endif |
| 110 | |
| 111 | #ifndef TSTRING_IS_STD_STRING |
| 112 | // Shared behaviour - always reallocate, just as much as requisted |
| 113 | |
| 114 | TStringType holder = s; |
| 115 | |
| 116 | UNIT_ASSERT(s.capacity() >= 256); |
| 117 | |
| 118 | s.reserve(128); |
| 119 | |
| 120 | UNIT_ASSERT(s.capacity() >= 128 && s.capacity() < 256 && s.data() != data); |
| 121 | UNIT_ASSERT(s.IsDetached()); |
| 122 | |
| 123 | s.resize(64, 'x'); |
| 124 | data = s.data(); |
| 125 | holder = s; |
| 126 | |
| 127 | s.reserve(10); |
| 128 | |
| 129 | UNIT_ASSERT(s.capacity() >= 64 && s.capacity() < 128 && s.data() != data); |
| 130 | UNIT_ASSERT(s.IsDetached()); |
| 131 | #endif |
| 132 | #endif |
| 133 | } |
| 134 | |
| 135 | void short_string() { |
| 136 | TStringType const ref_short_str1(Data_.str1()), ref_short_str2(Data_.str2()); |