| 205 | } |
| 206 | |
| 207 | TEST(FACE_Sequence, maintest) |
| 208 | { |
| 209 | S1 s1; |
| 210 | S2 s2; |
| 211 | EXPECT_TRUE(s1.maximum() == 0); |
| 212 | EXPECT_TRUE(s2.maximum() == 5); |
| 213 | int* const b1 = S1::allocbuf(3); |
| 214 | int* const b2 = S2::allocbuf(); |
| 215 | S1::freebuf(b1); |
| 216 | S2::freebuf(b2); |
| 217 | |
| 218 | testSeq(s1, 1); |
| 219 | testSeq(s2, 1); |
| 220 | |
| 221 | S3 s3; |
| 222 | testSeq(s3, MyStru()); |
| 223 | |
| 224 | int i = 42; |
| 225 | s2.replace(1, &i); |
| 226 | EXPECT_TRUE(s2[0] == i); |
| 227 | |
| 228 | S4 s4; |
| 229 | MyStru2 stru = {42, "42"}; |
| 230 | testSeq(s4, stru); |
| 231 | |
| 232 | S5 s5; |
| 233 | testSeq(s5, s4); |
| 234 | |
| 235 | SS ss; |
| 236 | testSeq(ss, FACE::string_dup("")); |
| 237 | |
| 238 | ss.length(2); |
| 239 | EXPECT_TRUE(ss[0][0] == '\0'); |
| 240 | EXPECT_TRUE(ss[1][0] == '\0'); |
| 241 | ss[0] = "foo"; |
| 242 | ss[1] = "bar"; |
| 243 | ss[0] = "baz"; // frees "foo" before copying "baz" |
| 244 | ss.length(1); |
| 245 | |
| 246 | const char* const storage[] = {"Hello", "world", "from", "sequence"}; |
| 247 | char* buffer[] = {const_cast<char*>(storage[0]), |
| 248 | const_cast<char*>(storage[1]), |
| 249 | const_cast<char*>(storage[2]), |
| 250 | const_cast<char*>(storage[3])}; |
| 251 | ss.replace(4, 2, buffer); |
| 252 | EXPECT_TRUE(ss.maximum() == 4); |
| 253 | EXPECT_TRUE(ss.length() == 2); |
| 254 | EXPECT_TRUE(!ss.release()); |
| 255 | EXPECT_TRUE(0 == std::strcmp(ss[0], "Hello")); |
| 256 | EXPECT_TRUE(0 == std::strcmp(ss[1], "world")); |
| 257 | ss.length(4); |
| 258 | EXPECT_TRUE(0 == std::strcmp(ss[2], "from")); |
| 259 | EXPECT_TRUE(0 == std::strcmp(ss[3], "sequence")); |
| 260 | |
| 261 | SB sb; |
| 262 | testSeq(sb, FACE::string_dup("")); |
| 263 | |
| 264 | SB sb2; |