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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ASSERT_EQ(counter1, ownCounter1->get()); | 198 ASSERT_EQ(counter1, ownCounter1->get()); |
199 ASSERT_EQ(0u, vector.size()); | 199 ASSERT_EQ(0u, vector.size()); |
200 ASSERT_EQ(1, destructNumber); | 200 ASSERT_EQ(1, destructNumber); |
201 | 201 |
202 ownCounter1.reset(); | 202 ownCounter1.reset(); |
203 EXPECT_EQ(2, destructNumber); | 203 EXPECT_EQ(2, destructNumber); |
204 | 204 |
205 size_t count = 1025; | 205 size_t count = 1025; |
206 destructNumber = 0; | 206 destructNumber = 0; |
207 for (size_t i = 0; i < count; i++) | 207 for (size_t i = 0; i < count; i++) |
208 vector.prepend(WTF::wrapUnique(new DestructCounter(i, &destructNumber))); | 208 vector.push_front(WTF::wrapUnique(new DestructCounter(i, &destructNumber))); |
209 | 209 |
210 // Vector relocation must not destruct std::unique_ptr element. | 210 // Vector relocation must not destruct std::unique_ptr element. |
211 EXPECT_EQ(0, destructNumber); | 211 EXPECT_EQ(0, destructNumber); |
212 EXPECT_EQ(count, vector.size()); | 212 EXPECT_EQ(count, vector.size()); |
213 | 213 |
214 OwnPtrVector copyVector; | 214 OwnPtrVector copyVector; |
215 vector.swap(copyVector); | 215 vector.swap(copyVector); |
216 EXPECT_EQ(0, destructNumber); | 216 EXPECT_EQ(0, destructNumber); |
217 EXPECT_EQ(count, copyVector.size()); | 217 EXPECT_EQ(count, copyVector.size()); |
218 EXPECT_EQ(0u, vector.size()); | 218 EXPECT_EQ(0u, vector.size()); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 testValuesMovedAndSwappedWithInlineCapacity<10>(); | 564 testValuesMovedAndSwappedWithInlineCapacity<10>(); |
565 } | 565 } |
566 | 566 |
567 TEST(VectorTest, UniquePtr) { | 567 TEST(VectorTest, UniquePtr) { |
568 using Pointer = std::unique_ptr<int>; | 568 using Pointer = std::unique_ptr<int>; |
569 Vector<Pointer> vector; | 569 Vector<Pointer> vector; |
570 vector.push_back(Pointer(new int(1))); | 570 vector.push_back(Pointer(new int(1))); |
571 vector.reserveCapacity(2); | 571 vector.reserveCapacity(2); |
572 vector.uncheckedAppend(Pointer(new int(2))); | 572 vector.uncheckedAppend(Pointer(new int(2))); |
573 vector.insert(2, Pointer(new int(3))); | 573 vector.insert(2, Pointer(new int(3))); |
574 vector.prepend(Pointer(new int(0))); | 574 vector.push_front(Pointer(new int(0))); |
575 | 575 |
576 ASSERT_EQ(4u, vector.size()); | 576 ASSERT_EQ(4u, vector.size()); |
577 EXPECT_EQ(0, *vector[0]); | 577 EXPECT_EQ(0, *vector[0]); |
578 EXPECT_EQ(1, *vector[1]); | 578 EXPECT_EQ(1, *vector[1]); |
579 EXPECT_EQ(2, *vector[2]); | 579 EXPECT_EQ(2, *vector[2]); |
580 EXPECT_EQ(3, *vector[3]); | 580 EXPECT_EQ(3, *vector[3]); |
581 | 581 |
582 vector.shrink(3); | 582 vector.shrink(3); |
583 EXPECT_EQ(3u, vector.size()); | 583 EXPECT_EQ(3u, vector.size()); |
584 vector.grow(4); | 584 vector.grow(4); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, | 716 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, |
717 "UChar should be copied with memcpy."); | 717 "UChar should be copied with memcpy."); |
718 | 718 |
719 class UnknownType; | 719 class UnknownType; |
720 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, | 720 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, |
721 "Pointers should be copied with memcpy."); | 721 "Pointers should be copied with memcpy."); |
722 | 722 |
723 } // anonymous namespace | 723 } // anonymous namespace |
724 | 724 |
725 } // namespace WTF | 725 } // namespace WTF |
OLD | NEW |