| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Verbose.hpp" | ||
| 2 | #include <experimental/propagate_const> | ||
| 3 | #include <gmock/gmock.h> | ||
| 4 | #include <iostream> | ||
| 5 | #include <memory> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | using namespace testing; | ||
| 9 | using namespace testing::internal; | ||
| 10 | |||
| 11 | template <typename T> | ||
| 12 | using SharedPtr = std::experimental::propagate_const<std::shared_ptr<T>>; | ||
| 13 | |||
| 14 | template <typename T> | ||
| 15 | using SharedVector = std::vector<SharedPtr<T>>; | ||
| 16 | |||
| 17 | template <typename T> | ||
| 18 | using UniquePtr = std::experimental::propagate_const<std::unique_ptr<T>>; | ||
| 19 | |||
| 20 | template <typename T> | ||
| 21 | using UniqueVector = std::vector<UniquePtr<T>>; | ||
| 22 | |||
| 23 | 8 | bool isConst(Verbose<>&) { return false; } | |
| 24 | |||
| 25 | 8 | bool isConst(const Verbose<>&) { return true; } | |
| 26 | |||
| 27 | 8 | TEST(ConstPointer, mutable_shared_ptr) { | |
| 28 | // const pointer to mutable object | ||
| 29 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | const auto p = std::make_shared<Verbose<>>("unqual"); |
| 30 |
1/10✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
|
2 | EXPECT_FALSE(isConst(*p)); |
| 31 | 4 | } | |
| 32 | |||
| 33 | 8 | TEST(ConstPointer, const_shared_ptr) { | |
| 34 | // const pointer to const object | ||
| 35 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | const auto p = SharedPtr<Verbose<>>{std::make_shared<Verbose<>>("qual")}; |
| 36 |
2/12✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
2 | EXPECT_TRUE(isConst(*p)); |
| 37 | 4 | } | |
| 38 | |||
| 39 | 8 | TEST(ConstPointer, const_shared_vector) { | |
| 40 | // const pointers to const objects | ||
| 41 | 2 | auto v = SharedVector<Verbose<>>{}; | |
| 42 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_shared<Verbose<>>("one")); |
| 43 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_shared<Verbose<>>("two")); |
| 44 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_shared<Verbose<>>("three")); |
| 45 | |||
| 46 |
4/14✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✓ Branch 47 taken 3 times.
✓ Branch 48 taken 1 times.
|
8 | for (auto& p : v) { EXPECT_FALSE(isConst(*p)); } |
| 47 | |||
| 48 |
4/14✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✓ Branch 47 taken 3 times.
✓ Branch 48 taken 1 times.
|
8 | for (const auto& p : v) { EXPECT_TRUE(isConst(*p)); } |
| 49 | 4 | } | |
| 50 | |||
| 51 | 8 | TEST(ConstPointer, mutable_unique_ptr) { | |
| 52 | // const pointer to mutable object | ||
| 53 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | const auto p = std::make_unique<Verbose<>>("unqual"); |
| 54 |
1/10✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
|
2 | EXPECT_FALSE(isConst(*p)); |
| 55 | 4 | } | |
| 56 | |||
| 57 | 8 | TEST(ConstPointer, const_unique_ptr) { | |
| 58 | // const pointer to const object | ||
| 59 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | const auto p = UniquePtr<Verbose<>>(std::make_unique<Verbose<>>("qual")); |
| 60 |
2/12✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
2 | EXPECT_TRUE(isConst(*p)); |
| 61 | 4 | } | |
| 62 | |||
| 63 | 8 | TEST(ConstPointer, const_unique_vector) { | |
| 64 | // const pointers to const objects | ||
| 65 | 2 | auto v = UniqueVector<Verbose<>>{}; | |
| 66 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_unique<Verbose<>>("one")); |
| 67 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_unique<Verbose<>>("two")); |
| 68 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | v.emplace_back(std::make_unique<Verbose<>>("three")); |
| 69 | |||
| 70 |
4/14✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✓ Branch 47 taken 3 times.
✓ Branch 48 taken 1 times.
|
8 | for (auto& p : v) { EXPECT_FALSE(isConst(*p)); } |
| 71 | |||
| 72 |
4/14✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✓ Branch 47 taken 3 times.
✓ Branch 48 taken 1 times.
|
8 | for (const auto& p : v) { EXPECT_TRUE(isConst(*p)); } |
| 73 | 4 | } | |
| 74 |