|
32 | 32 | //
|
33 | 33 | // This file tests the universal value printer.
|
34 | 34 |
|
35 |
| -#include <ctype.h> |
36 |
| -#include <string.h> |
37 | 35 | #include <algorithm>
|
| 36 | +#include <cctype> |
38 | 37 | #include <cstdint>
|
| 38 | +#include <cstring> |
39 | 39 | #include <deque>
|
40 | 40 | #include <forward_list>
|
41 | 41 | #include <limits>
|
42 | 42 | #include <list>
|
43 | 43 | #include <map>
|
| 44 | +#include <memory> |
44 | 45 | #include <set>
|
45 | 46 | #include <sstream>
|
46 | 47 | #include <string>
|
@@ -1702,6 +1703,56 @@ TEST(UniversalPrintTest, IncompleteType) {
|
1702 | 1703 | PrintToString(reinterpret_cast<Incomplete&>(some_object)));
|
1703 | 1704 | }
|
1704 | 1705 |
|
| 1706 | +TEST(UniversalPrintTest, SmartPointers) { |
| 1707 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>())); |
| 1708 | + std::unique_ptr<int> p(new int(17)); |
| 1709 | + EXPECT_EQ("(ptr = " + PrintPointer(p.get()) + ", value = 17)", |
| 1710 | + PrintToString(p)); |
| 1711 | + std::unique_ptr<int[]> p2(new int[2]); |
| 1712 | + EXPECT_EQ("(" + PrintPointer(p2.get()) + ")", PrintToString(p2)); |
| 1713 | + |
| 1714 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>())); |
| 1715 | + std::shared_ptr<int> p3(new int(1979)); |
| 1716 | + EXPECT_EQ("(ptr = " + PrintPointer(p3.get()) + ", value = 1979)", |
| 1717 | + PrintToString(p3)); |
| 1718 | +#if __cpp_lib_shared_ptr_arrays >= 201611L |
| 1719 | + std::shared_ptr<int[]> p4(new int[2]); |
| 1720 | + EXPECT_EQ("(" + PrintPointer(p4.get()) + ")", PrintToString(p4)); |
| 1721 | +#endif |
| 1722 | + |
| 1723 | + // modifiers |
| 1724 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>())); |
| 1725 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int>())); |
| 1726 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int>())); |
| 1727 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile const int>())); |
| 1728 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int[]>())); |
| 1729 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int[]>())); |
| 1730 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int[]>())); |
| 1731 | + EXPECT_EQ("(nullptr)", |
| 1732 | + PrintToString(std::unique_ptr<volatile const int[]>())); |
| 1733 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>())); |
| 1734 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int>())); |
| 1735 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int>())); |
| 1736 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile const int>())); |
| 1737 | +#if __cpp_lib_shared_ptr_arrays >= 201611L |
| 1738 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int[]>())); |
| 1739 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int[]>())); |
| 1740 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int[]>())); |
| 1741 | + EXPECT_EQ("(nullptr)", |
| 1742 | + PrintToString(std::shared_ptr<volatile const int[]>())); |
| 1743 | +#endif |
| 1744 | + |
| 1745 | + // void |
| 1746 | + EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<void, void (*)(void*)>( |
| 1747 | + nullptr, nullptr))); |
| 1748 | + EXPECT_EQ("(" + PrintPointer(p.get()) + ")", |
| 1749 | + PrintToString( |
| 1750 | + std::unique_ptr<void, void (*)(void*)>(p.get(), [](void*) {}))); |
| 1751 | + EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<void>())); |
| 1752 | + EXPECT_EQ("(" + PrintPointer(p.get()) + ")", |
| 1753 | + PrintToString(std::shared_ptr<void>(p.get(), [](void*) {}))); |
| 1754 | +} |
| 1755 | + |
1705 | 1756 | TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
|
1706 | 1757 | Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
|
1707 | 1758 | EXPECT_EQ(0u, result.size());
|
|
0 commit comments