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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 TEST(SharedBufferTest, copy) { | 123 TEST(SharedBufferTest, copy) { |
124 Vector<char> testData(10000); | 124 Vector<char> testData(10000); |
125 std::generate(testData.begin(), testData.end(), &std::rand); | 125 std::generate(testData.begin(), testData.end(), &std::rand); |
126 | 126 |
127 size_t length = testData.size(); | 127 size_t length = testData.size(); |
128 RefPtr<SharedBuffer> sharedBuffer = | 128 RefPtr<SharedBuffer> sharedBuffer = |
129 SharedBuffer::create(testData.data(), length); | 129 SharedBuffer::create(testData.data(), length); |
130 sharedBuffer->append(testData.data(), length); | 130 sharedBuffer->append(testData.data(), length); |
131 sharedBuffer->append(testData.data(), length); | 131 sharedBuffer->append(testData.data(), length); |
132 sharedBuffer->append(testData.data(), length); | 132 sharedBuffer->append(testData.data(), length); |
133 // sharedBuffer must contain data more than segmentSize (= 0x1000) to check co
py(). | 133 // sharedBuffer must contain data more than segmentSize (= 0x1000) to check |
| 134 // copy(). |
134 ASSERT_EQ(length * 4, sharedBuffer->size()); | 135 ASSERT_EQ(length * 4, sharedBuffer->size()); |
135 | 136 |
136 RefPtr<SharedBuffer> clone = sharedBuffer->copy(); | 137 RefPtr<SharedBuffer> clone = sharedBuffer->copy(); |
137 ASSERT_EQ(length * 4, clone->size()); | 138 ASSERT_EQ(length * 4, clone->size()); |
138 ASSERT_EQ(0, memcmp(clone->data(), sharedBuffer->data(), clone->size())); | 139 ASSERT_EQ(0, memcmp(clone->data(), sharedBuffer->data(), clone->size())); |
139 | 140 |
140 clone->append(testData.data(), length); | 141 clone->append(testData.data(), length); |
141 ASSERT_EQ(length * 5, clone->size()); | 142 ASSERT_EQ(length * 5, clone->size()); |
142 } | 143 } |
143 | 144 |
144 TEST(SharedBufferTest, constructorWithSizeOnly) { | 145 TEST(SharedBufferTest, constructorWithSizeOnly) { |
145 size_t length = 10000; | 146 size_t length = 10000; |
146 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); | 147 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); |
147 ASSERT_EQ(length, sharedBuffer->size()); | 148 ASSERT_EQ(length, sharedBuffer->size()); |
148 | 149 |
149 // The internal flat buffer should have been resized to |length| therefore get
SomeData() should | 150 // The internal flat buffer should have been resized to |length| therefore |
150 // directly return the full size. | 151 // getSomeData() should directly return the full size. |
151 const char* data; | 152 const char* data; |
152 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); | 153 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); |
153 } | 154 } |
154 | 155 |
155 } // namespace blink | 156 } // namespace blink |
OLD | NEW |