| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <iostream> | ||
| 2 | #include <vector> | ||
| 3 | #include <functional> | ||
| 4 | #include <string> | ||
| 5 | #include <optional> | ||
| 6 | #include <set> | ||
| 7 | #include <map> | ||
| 8 | #include <list> | ||
| 9 | #include <deque> | ||
| 10 | #include <unordered_set> | ||
| 11 | #include <unordered_map> | ||
| 12 | |||
| 13 | #include "TestCommon.h" | ||
| 14 | |||
| 15 | using namespace CXXIter; | ||
| 16 | |||
| 17 | |||
| 18 | 8 | TEST(CXXIter, ContiguousMemoryCompile) { | |
| 19 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<uint32_t> src = {1, 3, 3, 7}; |
| 20 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | auto rawIter = CXXIter::from(src); |
| 21 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | auto skipIter = CXXIter::from(src).skip(1); |
| 22 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | auto filterIter = CXXIter::from(src).filter([](uint32_t val) { return (val > 3); }); |
| 23 | |||
| 24 | static_assert(CXXIterContiguousMemoryIterator<decltype(rawIter)>); | ||
| 25 | static_assert(CXXIterContiguousMemoryIterator<decltype(skipIter)>); | ||
| 26 | static_assert(!CXXIterContiguousMemoryIterator<decltype(filterIter)>); | ||
| 27 | 2 | } | |
| 28 | |||
| 29 | 8 | TEST(CXXIter, ContiguousSource) { | |
| 30 | { // SrcCRef | ||
| 31 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | const std::vector<uint32_t> src = {1, 3, 3, 7}; |
| 32 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | auto iter = CXXIter::from(src); |
| 33 | using ContiguousTrait = trait::ContiguousMemoryIterator<decltype(iter)>; | ||
| 34 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ContiguousTrait::ItemPtr itemPtr = ContiguousTrait::currentPtr(iter); |
| 35 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
2 | ASSERT_EQ(itemPtr, &src[0]); |
| 36 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | } |
| 37 | { // SrcRef | ||
| 38 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<uint32_t> src = {1, 3, 3, 7}; |
| 39 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | auto iter = CXXIter::from(src); |
| 40 | using ContiguousTrait = trait::ContiguousMemoryIterator<decltype(iter)>; | ||
| 41 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ContiguousTrait::ItemPtr itemPtr = ContiguousTrait::currentPtr(iter); |
| 42 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
2 | ASSERT_EQ(itemPtr, &src[0]); |
| 43 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | } |
| 44 | { // SrcMov | ||
| 45 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<uint32_t> src = {1, 3, 3, 7}; |
| 46 | // The src will be moved into the iterator, but the heap memory region for the | ||
| 47 | // actual vector elements will stay the same, so we take the pointer before | ||
| 48 | // constructing an iterator here. | ||
| 49 | 2 | uint32_t* firstElementPtr = &src[0]; | |
| 50 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | auto iter = CXXIter::from(std::move(src)); |
| 51 | using ContiguousTrait = trait::ContiguousMemoryIterator<decltype(iter)>; | ||
| 52 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ContiguousTrait::ItemPtr itemPtr = ContiguousTrait::currentPtr(iter); |
| 53 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
2 | ASSERT_EQ(itemPtr, firstElementPtr); |
| 54 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | } |
| 55 | } | ||
| 56 | |||
| 57 | 8 | TEST(CXXIter, ContiguousSkipN) { | |
| 58 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<uint32_t> src = {1, 3, 3, 7}; |
| 59 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | auto iter = CXXIter::from(src).skip(1); |
| 60 | using ContiguousTrait = trait::ContiguousMemoryIterator<decltype(iter)>; | ||
| 61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ContiguousTrait::ItemPtr itemPtr = ContiguousTrait::currentPtr(iter); |
| 62 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
2 | ASSERT_EQ(itemPtr, &src[1]); |
| 63 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | } |
| 64 |