| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(wrapUnique(new DestructCounter(0, &destructNumber))); |
| 164 vector.append(wrapUnique(new DestructCounter(1, &destructNumber))); | 164 vector.append(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.first(); | 167 std::unique_ptr<DestructCounter>& counter0 = vector.first(); |
| 168 ASSERT_EQ(0, counter0->get()); | 168 ASSERT_EQ(0, counter0->get()); |
| 169 int counter1 = vector.last()->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(); |
| 175 ++iter) { | 175 ++iter) { |
| 176 std::unique_ptr<DestructCounter>* refCounter = iter; | 176 std::unique_ptr<DestructCounter>* refCounter = iter; |
| 177 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get())); | 177 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get())); |
| 178 EXPECT_EQ(index, static_cast<size_t>((*refCounter)->get())); | 178 EXPECT_EQ(index, static_cast<size_t>((*refCounter)->get())); |
| 179 index++; | 179 index++; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int m_i; | 242 int m_i; |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 TEST(VectorTest, MoveOnlyType) { | 245 TEST(VectorTest, MoveOnlyType) { |
| 246 WTF::Vector<MoveOnly> vector; | 246 WTF::Vector<MoveOnly> vector; |
| 247 vector.append(MoveOnly(1)); | 247 vector.append(MoveOnly(1)); |
| 248 vector.append(MoveOnly(2)); | 248 vector.append(MoveOnly(2)); |
| 249 EXPECT_EQ(2u, vector.size()); | 249 EXPECT_EQ(2u, vector.size()); |
| 250 | 250 |
| 251 ASSERT_EQ(1, vector.first().value()); | 251 ASSERT_EQ(1, vector.first().value()); |
| 252 ASSERT_EQ(2, vector.last().value()); | 252 ASSERT_EQ(2, vector.back().value()); |
| 253 | 253 |
| 254 vector.remove(0); | 254 vector.remove(0); |
| 255 EXPECT_EQ(2, vector[0].value()); | 255 EXPECT_EQ(2, vector[0].value()); |
| 256 EXPECT_EQ(1u, vector.size()); | 256 EXPECT_EQ(1u, vector.size()); |
| 257 | 257 |
| 258 MoveOnly moveOnly(std::move(vector[0])); | 258 MoveOnly moveOnly(std::move(vector[0])); |
| 259 vector.remove(0); | 259 vector.remove(0); |
| 260 ASSERT_EQ(2, moveOnly.value()); | 260 ASSERT_EQ(2, moveOnly.value()); |
| 261 ASSERT_EQ(0u, vector.size()); | 261 ASSERT_EQ(0u, vector.size()); |
| 262 | 262 |
| (...skipping 436 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 |