OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 size_t length = 10000; | 147 size_t length = 10000; |
148 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); | 148 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); |
149 ASSERT_EQ(length, sharedBuffer->size()); | 149 ASSERT_EQ(length, sharedBuffer->size()); |
150 | 150 |
151 // The internal flat buffer should have been resized to |length| therefore g
etSomeData() should | 151 // The internal flat buffer should have been resized to |length| therefore g
etSomeData() should |
152 // directly return the full size. | 152 // directly return the full size. |
153 const char* data; | 153 const char* data; |
154 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); | 154 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); |
155 } | 155 } |
156 | 156 |
157 TEST(SharedBufferTest, createPurgeable) | |
158 { | |
159 Vector<char> testData(30000); | |
160 std::generate(testData.begin(), testData.end(), &std::rand); | |
161 | |
162 size_t length = testData.size(); | |
163 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::createPurgeable(testData.d
ata(), length); | |
164 ASSERT_EQ(length, sharedBuffer->size()); | |
165 // Merge the segments into a single vector. | |
166 const char* data = sharedBuffer->data(); | |
167 ASSERT_EQ(0, memcmp(data, testData.data(), length)); | |
168 | |
169 // Do another append + merge the segments again. | |
170 size_t previousTestDataSize = testData.size(); | |
171 testData.resize(2 * previousTestDataSize); | |
172 std::generate(testData.begin() + previousTestDataSize, testData.end(), &std:
:rand); | |
173 sharedBuffer->append(testData.data() + previousTestDataSize, previousTestDat
aSize); | |
174 ASSERT_EQ(0, memcmp(data, testData.data(), length)); | |
175 } | |
176 | |
177 } // namespace blink | 157 } // namespace blink |
OLD | NEW |