GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/zserio/UniquePtrTest.cpp Lines: 10 10 100.0 %
Date: 2023-12-13 14:51:09 Branches: 27 99 27.3 %

Line Branch Exec Source
1
#include "zserio/UniquePtr.h"
2
#include "zserio/CppRuntimeException.h"
3
4
#include "TrackingAllocator.h"
5
6
#include "gtest/gtest.h"
7
8
namespace zserio
9
{
10
11
namespace
12
{
13
14
struct ThrowingStruct
15
{
16
1
    ThrowingStruct()
17
    {
18
1
        throw CppRuntimeException("oops");
19
    }
20
};
21
22
} // namespace
23
24


802
TEST(UniquePtrTest, allocateUnique)
25
{
26
2
    TrackingAllocator<int> alloc;
27
28

2
    unique_ptr<int, TrackingAllocator<int>> unique = allocate_unique<int>(alloc, 12345);
29



1
    ASSERT_TRUE(bool(unique));
30



1
    ASSERT_EQ(12345, *unique);
31



1
    ASSERT_EQ(1, alloc.numAllocs());
32
33










2
    ASSERT_THROW(allocate_unique<ThrowingStruct>(alloc), CppRuntimeException);
34
}
35
36

2394
} // namespace zserio