| 1168 | }; |
| 1169 | |
| 1170 | TEST_F(WriteIntoTest, WriteInto) { |
| 1171 | // Validate that WriteInto reserves enough space and |
| 1172 | // sizes a string correctly. |
| 1173 | WritesCorrectly(1); |
| 1174 | WritesCorrectly(2); |
| 1175 | WritesCorrectly(5000); |
| 1176 | |
| 1177 | // Validate that WriteInto doesn't modify other strings |
| 1178 | // when using a Copy-on-Write implementation. |
| 1179 | const char kLive[] = "live"; |
| 1180 | const char kDead[] = "dead"; |
| 1181 | const std::string live = kLive; |
| 1182 | std::string dead = live; |
| 1183 | strncpy(WriteInto(&dead, 5), kDead, 4); |
| 1184 | EXPECT_EQ(kDead, dead); |
| 1185 | EXPECT_EQ(4u, dead.size()); |
| 1186 | EXPECT_EQ(kLive, live); |
| 1187 | EXPECT_EQ(4u, live.size()); |
| 1188 | } |
| 1189 | |
| 1190 | } // namespace butil |