| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 private: | 153 private: |
| 154 int m_i; | 154 int m_i; |
| 155 int* m_destructNumber; | 155 int* m_destructNumber; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 typedef WTF::Vector<std::unique_ptr<DestructCounter>> OwnPtrVector; | 158 typedef WTF::Vector<std::unique_ptr<DestructCounter>> OwnPtrVector; |
| 159 | 159 |
| 160 TEST(VectorTest, OwnPtr) { | 160 TEST(VectorTest, OwnPtr) { |
| 161 int destructNumber = 0; | 161 int destructNumber = 0; |
| 162 OwnPtrVector vector; | 162 OwnPtrVector vector; |
| 163 vector.append(wrapUnique(new DestructCounter(0, &destructNumber))); | 163 vector.append(WTF::wrapUnique(new DestructCounter(0, &destructNumber))); |
| 164 vector.append(wrapUnique(new DestructCounter(1, &destructNumber))); | 164 vector.append(WTF::wrapUnique(new DestructCounter(1, &destructNumber))); |
| 165 EXPECT_EQ(2u, vector.size()); | 165 EXPECT_EQ(2u, vector.size()); |
| 166 | 166 |
| 167 std::unique_ptr<DestructCounter>& counter0 = vector.front(); | 167 std::unique_ptr<DestructCounter>& counter0 = vector.front(); |
| 168 ASSERT_EQ(0, counter0->get()); | 168 ASSERT_EQ(0, counter0->get()); |
| 169 int counter1 = vector.back()->get(); | 169 int counter1 = vector.back()->get(); |
| 170 ASSERT_EQ(1, counter1); | 170 ASSERT_EQ(1, counter1); |
| 171 ASSERT_EQ(0, destructNumber); | 171 ASSERT_EQ(0, destructNumber); |
| 172 | 172 |
| 173 size_t index = 0; | 173 size_t index = 0; |
| 174 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end(); | 174 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end(); |
| (...skipping 23 matching lines...) Expand all 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(wrapUnique(new DestructCounter(i, &destructNumber))); | 208 vector.prepend(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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, | 699 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, |
| 700 "UChar should be copied with memcpy."); | 700 "UChar should be copied with memcpy."); |
| 701 | 701 |
| 702 class UnknownType; | 702 class UnknownType; |
| 703 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, | 703 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, |
| 704 "Pointers should be copied with memcpy."); | 704 "Pointers should be copied with memcpy."); |
| 705 | 705 |
| 706 } // anonymous namespace | 706 } // anonymous namespace |
| 707 | 707 |
| 708 } // namespace WTF | 708 } // namespace WTF |
| OLD | NEW |