Coverage Report

Created: 2023-12-13 14:58

test/zserio/UniquePtrTest.cpp
Line
Count
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
    ThrowingStruct()
17
1
    {
18
1
        throw CppRuntimeException("oops");
19
1
    }
20
};
21
22
} // namespace
23
24
TEST(UniquePtrTest, allocateUnique)
25
1
{
26
1
    TrackingAllocator<int> alloc;
27
28
1
    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
1
    ASSERT_THROW(allocate_unique<ThrowingStruct>(alloc), CppRuntimeException);
34
1
}
35
36
} // namespace zserio