| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 std::generate(testData.begin(), testData.end(), &std::rand); | 170 std::generate(testData.begin(), testData.end(), &std::rand); |
| 171 | 171 |
| 172 PurgeableVector purgeableVector(makePurgeableOption()); | 172 PurgeableVector purgeableVector(makePurgeableOption()); |
| 173 purgeableVector.reserveCapacity(kTestSize); | 173 purgeableVector.reserveCapacity(kTestSize); |
| 174 const char* const data = purgeableVector.data(); | 174 const char* const data = purgeableVector.data(); |
| 175 | 175 |
| 176 purgeableVector.append(testData.data(), testData.size()); | 176 purgeableVector.append(testData.data(), testData.size()); |
| 177 EXPECT_EQ(data, purgeableVector.data()); | 177 EXPECT_EQ(data, purgeableVector.data()); |
| 178 EXPECT_EQ(0, memcmp(purgeableVector.data(), testData.data(), testData.size()
)); | 178 EXPECT_EQ(0, memcmp(purgeableVector.data(), testData.data(), testData.size()
)); |
| 179 | 179 |
| 180 // Appending one extra byte should cause a reallocation since the first | 180 // This test is not reliable if the PurgeableVector uses a plain WTF::Vector |
| 181 // allocation happened while the purgeable vector was empty. This behavior | 181 // for storage, as it does if discardable memory is not supported; the vecto
rs |
| 182 // helps us guarantee that there is no memory waste on very small vectors | 182 // capacity will always be expanded to fill the PartitionAlloc bucket. |
| 183 // (which SharedBuffer requires). | 183 if (isDiscardableMemorySupported()) { |
| 184 purgeableVector.append(testData.data(), 1); | 184 // Appending one extra byte should cause a reallocation since the first |
| 185 EXPECT_NE(data, purgeableVector.data()); | 185 // allocation happened while the purgeable vector was empty. This behavi
or |
| 186 // helps us guarantee that there is no memory waste on very small vector
s |
| 187 // (which SharedBuffer requires). |
| 188 purgeableVector.append(testData.data(), 1); |
| 189 EXPECT_NE(data, purgeableVector.data()); |
| 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 TEST_P(PurgeableVectorTestWithPlatformSupport, appendReservesCapacityIfNeeded) | 193 TEST_P(PurgeableVectorTestWithPlatformSupport, appendReservesCapacityIfNeeded) |
| 189 { | 194 { |
| 190 Vector<char> testData(kTestSize); | 195 Vector<char> testData(kTestSize); |
| 191 std::generate(testData.begin(), testData.end(), &std::rand); | 196 std::generate(testData.begin(), testData.end(), &std::rand); |
| 192 | 197 |
| 193 PurgeableVector purgeableVector(makePurgeableOption()); | 198 PurgeableVector purgeableVector(makePurgeableOption()); |
| 194 // No reserveCapacity(). | 199 // No reserveCapacity(). |
| 195 ASSERT_FALSE(purgeableVector.data()); | 200 ASSERT_FALSE(purgeableVector.data()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 ASSERT_EQ(0, memcmp(purgeableVector.data(), testData.data(), testData.si
ze())); | 328 ASSERT_EQ(0, memcmp(purgeableVector.data(), testData.data(), testData.si
ze())); |
| 324 } | 329 } |
| 325 | 330 |
| 326 // Instantiates all the unit tests using the SharedBufferTestWithPlatformSupport
fixture both with | 331 // Instantiates all the unit tests using the SharedBufferTestWithPlatformSupport
fixture both with |
| 327 // and without discardable memory support. | 332 // and without discardable memory support. |
| 328 INSTANTIATE_TEST_CASE_P(testsWithPlatformSetUp, PurgeableVectorTestWithPlatformS
upport, | 333 INSTANTIATE_TEST_CASE_P(testsWithPlatformSetUp, PurgeableVectorTestWithPlatformS
upport, |
| 329 ::testing::Values(DontSupportDiscardableMemory, SupportDiscardableMemory)); | 334 ::testing::Values(DontSupportDiscardableMemory, SupportDiscardableMemory)); |
| 330 | 335 |
| 331 } // namespace | 336 } // namespace |
| 332 | 337 |
| OLD | NEW |