GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/zserio/AllocatorHolderTest.cpp Lines: 46 46 100.0 %
Date: 2023-12-13 14:51:09 Branches: 76 194 39.2 %

Line Branch Exec Source
1
#include <memory>
2
3
#include "gtest/gtest.h"
4
5
#include "zserio/AllocatorHolder.h"
6
7
namespace zserio
8
{
9
10
namespace
11
{
12
13
template <typename ALLOC>
14
4
class AllocatorHolderTester : public AllocatorHolder<ALLOC>
15
{
16
public:
17
    using allocator_type = typename AllocatorHolder<ALLOC>::allocator_type;
18
19
4
    explicit AllocatorHolderTester(allocator_type allocator) : AllocatorHolder<allocator_type>(allocator)
20
    {
21
4
    }
22
23
1
    void set_allocator(const allocator_type& allocator)
24
    {
25
1
        AllocatorHolder<ALLOC>::set_allocator(allocator);
26
1
    }
27
28
1
    void set_allocator(allocator_type&& allocator)
29
    {
30
1
        AllocatorHolder<ALLOC>::set_allocator(allocator);
31
1
    }
32
33
1
    allocator_type& get_allocator_ref()
34
    {
35
1
        return AllocatorHolder<ALLOC>::get_allocator_ref();
36
    }
37
38
1
    const allocator_type& get_allocator_ref() const
39
    {
40
1
        return AllocatorHolder<ALLOC>::get_allocator_ref();
41
    }
42
};
43
44
} // namespace
45
46


802
TEST(AllocatorHolderTest, emptyConstructor)
47
{
48
2
    const AllocatorHolder<std::allocator<uint8_t>> holder;
49
2
    std::allocator<uint8_t> allocator;
50




1
    ASSERT_EQ(allocator, holder.get_allocator());
51
}
52
53


802
TEST(AllocatorHolderTest, allocatorConstructor)
54
{
55
2
    std::allocator<uint8_t> allocator;
56
2
    const AllocatorHolder<std::allocator<uint8_t>> holder(allocator);
57




1
    ASSERT_EQ(allocator, holder.get_allocator());
58
}
59
60


802
TEST(AllocatorHolderTest, allocatorConstructorMove)
61
{
62
2
    std::allocator<uint8_t> allocator;
63
2
    const AllocatorHolder<std::allocator<uint8_t>> holder(std::move(allocator));
64




1
    ASSERT_EQ(std::allocator<uint8_t>(), holder.get_allocator());
65
}
66
67


802
TEST(AllocatorHolderTest, setAllocator)
68
{
69
2
    std::allocator<uint8_t> allocator1;
70
2
    AllocatorHolderTester<std::allocator<uint8_t>> holder(allocator1);
71
2
    std::allocator<uint8_t> allocator2;
72
1
    holder.set_allocator(allocator2);
73




1
    ASSERT_EQ(allocator2, holder.get_allocator());
74
}
75
76


802
TEST(AllocatorHolderTest, setAllocatorMove)
77
{
78
2
    std::allocator<uint8_t> allocator1;
79
2
    AllocatorHolderTester<std::allocator<uint8_t>> holder(allocator1);
80
2
    std::allocator<uint8_t> allocator2;
81
1
    holder.set_allocator(std::move(allocator2));
82




1
    ASSERT_EQ(std::allocator<uint8_t>(), holder.get_allocator());
83
}
84
85


802
TEST(AllocatorHolderTest, getAllocatorRef)
86
{
87
2
    std::allocator<uint8_t> allocator;
88
2
    AllocatorHolderTester<std::allocator<uint8_t>> holder(allocator);
89




1
    ASSERT_EQ(allocator, holder.get_allocator_ref());
90
}
91
92


802
TEST(AllocatorHolderTest, getAllocatorRefConst)
93
{
94
2
    std::allocator<uint8_t> allocator;
95
2
    const AllocatorHolderTester<std::allocator<uint8_t>> holder(allocator);
96




1
    ASSERT_EQ(allocator, holder.get_allocator_ref());
97
}
98
99

2394
} // namespace zserio