OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 EXPECT_FALSE(Vector<T>() == Vector<T>(1)); | 295 EXPECT_FALSE(Vector<T>() == Vector<T>(1)); |
296 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1)); | 296 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1)); |
297 } | 297 } |
298 | 298 |
299 TEST(VectorTest, Compare) | 299 TEST(VectorTest, Compare) |
300 { | 300 { |
301 compare<int>(); | 301 compare<int>(); |
302 compare<Comparable>(); | 302 compare<Comparable>(); |
303 compare<WTF::String>(); | 303 compare<WTF::String>(); |
304 } | 304 } |
| 305 |
| 306 class LivenessCounter { |
| 307 public: |
| 308 void ref() { s_live++; } |
| 309 void deref() { s_live--; } |
| 310 |
| 311 static unsigned s_live; |
| 312 }; |
| 313 |
| 314 unsigned LivenessCounter::s_live = 0; |
| 315 |
| 316 template<size_t inlineCapacity> |
| 317 void theBigSwapTest() |
| 318 { |
| 319 LivenessCounter::s_live = 0; |
| 320 LivenessCounter counter; |
| 321 EXPECT_EQ(0u, LivenessCounter::s_live); |
| 322 |
| 323 Vector<RefPtr<LivenessCounter>, inlineCapacity> vector; |
| 324 Vector<RefPtr<LivenessCounter>, inlineCapacity> vector2; |
| 325 vector.append(&counter); |
| 326 vector2.append(&counter); |
| 327 EXPECT_EQ(2u, LivenessCounter::s_live); |
| 328 |
| 329 for (unsigned i = 0; i < 13; i++) { |
| 330 for (unsigned j = 0; j < 13; j++) { |
| 331 vector.clear(); |
| 332 vector2.clear(); |
| 333 EXPECT_EQ(0u, LivenessCounter::s_live); |
| 334 |
| 335 for (unsigned k = 0; k < j; k++) |
| 336 vector.append(&counter); |
| 337 EXPECT_EQ(j, LivenessCounter::s_live); |
| 338 EXPECT_EQ(j, vector.size()); |
| 339 |
| 340 for (unsigned k = 0; k < i; k++) |
| 341 vector2.append(&counter); |
| 342 EXPECT_EQ(i + j, LivenessCounter::s_live); |
| 343 EXPECT_EQ(i, vector2.size()); |
| 344 |
| 345 vector.swap(vector2); |
| 346 EXPECT_EQ(i + j, LivenessCounter::s_live); |
| 347 EXPECT_EQ(i, vector.size()); |
| 348 EXPECT_EQ(j, vector2.size()); |
| 349 |
| 350 unsigned size = vector.size(); |
| 351 unsigned size2 = vector2.size(); |
| 352 |
| 353 for (unsigned k = 0; k < 5; k++) { |
| 354 vector.swap(vector2); |
| 355 std::swap(size, size2); |
| 356 EXPECT_EQ(i + j, LivenessCounter::s_live); |
| 357 EXPECT_EQ(size, vector.size()); |
| 358 EXPECT_EQ(size2, vector2.size()); |
| 359 |
| 360 vector2.append(&counter); |
| 361 vector2.remove(0); |
| 362 } |
| 363 } |
| 364 } |
| 365 |
| 366 } |
| 367 |
| 368 TEST(VectorTest, BigSwapTest) |
| 369 { |
| 370 theBigSwapTest<0>(); |
| 371 theBigSwapTest<2>(); |
| 372 theBigSwapTest<10>(); |
| 373 } |
| 374 |
| 375 template<size_t inlineCapacity> |
| 376 void swapValuesTest() |
| 377 { |
| 378 Vector<unsigned, inlineCapacity> vector; |
| 379 Vector<unsigned, inlineCapacity> vector2; |
| 380 |
| 381 for (unsigned size = 0; size < 13; size++) { |
| 382 for (unsigned size2 = 0; size2 < 13; size2++) { |
| 383 vector.clear(); |
| 384 vector2.clear(); |
| 385 for (unsigned i = 0; i < size; i++) |
| 386 vector.append(i); |
| 387 for (unsigned i = 0; i < size2; i++) |
| 388 vector2.append(i + 42); |
| 389 EXPECT_EQ(size, vector.size()); |
| 390 EXPECT_EQ(size2, vector2.size()); |
| 391 vector.swap(vector2); |
| 392 for (unsigned i = 0; i < size; i++) |
| 393 EXPECT_EQ(i, vector2[i]); |
| 394 for (unsigned i = 0; i < size2; i++) |
| 395 EXPECT_EQ(i + 42, vector[i]); |
| 396 } |
| 397 } |
| 398 } |
| 399 |
| 400 TEST(VectorTest, SwapValuesTest) |
| 401 { |
| 402 swapValuesTest<0>(); |
| 403 swapValuesTest<2>(); |
| 404 swapValuesTest<10>(); |
| 405 } |
| 406 |
305 } // namespace | 407 } // namespace |
OLD | NEW |