OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/zone/zone-chunk-list.h" | 5 #include "src/zone/zone-chunk-list.h" |
6 | 6 |
7 #include "src/list-inl.h" | 7 #include "src/list-inl.h" |
8 #include "src/zone/accounting-allocator.h" | 8 #include "src/zone/accounting-allocator.h" |
9 #include "src/zone/zone.h" | 9 #include "src/zone/zone.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 const size_t index = kItemCount / 2 + 42; | 134 const size_t index = kItemCount / 2 + 42; |
135 | 135 |
136 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index)); | 136 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index)); |
137 | 137 |
138 *zone_chunk_list.Find(index) = 42; | 138 *zone_chunk_list.Find(index) = 42; |
139 | 139 |
140 EXPECT_EQ(*zone_chunk_list.Find(index), 42); | 140 EXPECT_EQ(*zone_chunk_list.Find(index), 42); |
141 } | 141 } |
142 | 142 |
| 143 TEST(ZoneChunkList, CopyToTest) { |
| 144 AccountingAllocator allocator; |
| 145 Zone zone(&allocator, ZONE_NAME); |
| 146 |
| 147 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); |
| 148 |
| 149 for (size_t i = 0; i < kItemCount; ++i) { |
| 150 zone_chunk_list.push_back(static_cast<uintptr_t>(i)); |
| 151 } |
| 152 |
| 153 uintptr_t* array = zone.NewArray<uintptr_t>(kItemCount); |
| 154 |
| 155 zone_chunk_list.CopyTo(array); |
| 156 |
| 157 for (size_t i = 0; i < kItemCount; ++i) { |
| 158 EXPECT_EQ(array[i], static_cast<uintptr_t>(i)); |
| 159 } |
| 160 } |
| 161 |
| 162 TEST(ZoneChunkList, SmallCopyToTest) { |
| 163 AccountingAllocator allocator; |
| 164 Zone zone(&allocator, ZONE_NAME); |
| 165 |
| 166 ZoneChunkList<uint8_t> zone_chunk_list(&zone); |
| 167 |
| 168 for (size_t i = 0; i < kItemCount; ++i) { |
| 169 zone_chunk_list.push_back(static_cast<uint8_t>(i & 0xFF)); |
| 170 } |
| 171 |
| 172 uint8_t* array = zone.NewArray<uint8_t>(kItemCount); |
| 173 |
| 174 zone_chunk_list.CopyTo(array); |
| 175 |
| 176 for (size_t i = 0; i < kItemCount; ++i) { |
| 177 EXPECT_EQ(array[i], static_cast<uint8_t>(i & 0xFF)); |
| 178 } |
| 179 } |
| 180 |
| 181 struct Fubar { |
| 182 size_t a_; |
| 183 size_t b_; |
| 184 }; |
| 185 |
| 186 TEST(ZoneChunkList, BigCopyToTest) { |
| 187 AccountingAllocator allocator; |
| 188 Zone zone(&allocator, ZONE_NAME); |
| 189 |
| 190 ZoneChunkList<Fubar> zone_chunk_list(&zone); |
| 191 |
| 192 for (size_t i = 0; i < kItemCount; ++i) { |
| 193 zone_chunk_list.push_back({i, i + 5}); |
| 194 } |
| 195 |
| 196 Fubar* array = zone.NewArray<Fubar>(kItemCount); |
| 197 |
| 198 zone_chunk_list.CopyTo(array); |
| 199 |
| 200 for (size_t i = 0; i < kItemCount; ++i) { |
| 201 EXPECT_EQ(array[i].a_, i); |
| 202 EXPECT_EQ(array[i].b_, i + 5); |
| 203 } |
| 204 } |
| 205 |
143 } // namespace internal | 206 } // namespace internal |
144 } // namespace v8 | 207 } // namespace v8 |
OLD | NEW |