test/zserio/UniquePtrTest.cpp
Line | Count | Source |
1 | | #include "gtest/gtest.h" |
2 | | #include "zserio/CppRuntimeException.h" |
3 | | #include "zserio/UniquePtr.h" |
4 | | |
5 | | #include "TrackingAllocator.h" |
6 | | |
7 | | namespace zserio |
8 | | { |
9 | | |
10 | | namespace |
11 | | { |
12 | | |
13 | | struct ThrowingStruct |
14 | | { |
15 | | ThrowingStruct() |
16 | 1 | { |
17 | 1 | throw CppRuntimeException("oops"); |
18 | 1 | } |
19 | | }; |
20 | | |
21 | | } // namespace |
22 | | |
23 | | TEST(UniquePtrTest, allocateUnique) |
24 | 1 | { |
25 | 1 | TrackingAllocator<int> alloc; |
26 | | |
27 | 1 | unique_ptr<int, TrackingAllocator<int>> unique = allocate_unique<int>(alloc, 12345); |
28 | 1 | ASSERT_TRUE(bool(unique)); |
29 | 1 | ASSERT_EQ(12345, *unique); |
30 | 1 | ASSERT_EQ(1, alloc.numAllocs()); |
31 | | |
32 | 1 | ASSERT_THROW(allocate_unique<ThrowingStruct>(alloc), CppRuntimeException); |
33 | 1 | } |
34 | | |
35 | | } // namespace zserio |