| 34 | } |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(linked_list_iteration) |
| 37 | { |
| 38 | CoinsCachePair sentinel; |
| 39 | sentinel.second.SelfRef(sentinel); |
| 40 | auto nodes{CreatePairs(sentinel)}; |
| 41 | |
| 42 | // Check iterating through pairs is identical to iterating through a list |
| 43 | auto node{sentinel.second.Next()}; |
| 44 | for (const auto& expected : nodes) { |
| 45 | BOOST_CHECK_EQUAL(&expected, node); |
| 46 | node = node->second.Next(); |
| 47 | } |
| 48 | BOOST_CHECK_EQUAL(node, &sentinel); |
| 49 | |
| 50 | // Check iterating through pairs is identical to iterating through a list |
| 51 | // Clear the state during iteration |
| 52 | node = sentinel.second.Next(); |
| 53 | for (const auto& expected : nodes) { |
| 54 | BOOST_CHECK_EQUAL(&expected, node); |
| 55 | auto next = node->second.Next(); |
| 56 | node->second.SetClean(); |
| 57 | node = next; |
| 58 | } |
| 59 | BOOST_CHECK_EQUAL(node, &sentinel); |
| 60 | // Check that sentinel's next and prev are itself |
| 61 | BOOST_CHECK_EQUAL(sentinel.second.Next(), &sentinel); |
| 62 | BOOST_CHECK_EQUAL(sentinel.second.Prev(), &sentinel); |
| 63 | |
| 64 | // Delete the nodes from the list to make sure there are no dangling pointers |
| 65 | for (auto it{nodes.begin()}; it != nodes.end(); it = nodes.erase(it)) { |
| 66 | BOOST_CHECK(!it->second.IsDirty() && !it->second.IsFresh()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_CASE(linked_list_iterate_erase) |
| 71 | { |