1 //===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit tests ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/STLExtras.h"
11 #include "gtest/gtest.h"
17 TEST(MakeUniqueTest, SingleObject) {
18 auto p0 = make_unique<int>();
19 EXPECT_TRUE((bool)p0);
22 auto p1 = make_unique<int>(5);
23 EXPECT_TRUE((bool)p1);
26 auto p2 = make_unique<std::tuple<int, int>>(0, 1);
27 EXPECT_TRUE((bool)p2);
28 EXPECT_EQ(std::make_tuple(0, 1), *p2);
30 auto p3 = make_unique<std::tuple<int, int, int>>(0, 1, 2);
31 EXPECT_TRUE((bool)p3);
32 EXPECT_EQ(std::make_tuple(0, 1, 2), *p3);
34 auto p4 = make_unique<std::tuple<int, int, int, int>>(0, 1, 2, 3);
35 EXPECT_TRUE((bool)p4);
36 EXPECT_EQ(std::make_tuple(0, 1, 2, 3), *p4);
38 auto p5 = make_unique<std::tuple<int, int, int, int, int>>(0, 1, 2, 3, 4);
39 EXPECT_TRUE((bool)p5);
40 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4), *p5);
43 make_unique<std::tuple<int, int, int, int, int, int>>(0, 1, 2, 3, 4, 5);
44 EXPECT_TRUE((bool)p6);
45 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5), *p6);
47 auto p7 = make_unique<std::tuple<int, int, int, int, int, int, int>>(
49 EXPECT_TRUE((bool)p7);
50 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6), *p7);
52 auto p8 = make_unique<std::tuple<int, int, int, int, int, int, int, int>>(
53 0, 1, 2, 3, 4, 5, 6, 7);
54 EXPECT_TRUE((bool)p8);
55 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7), *p8);
58 make_unique<std::tuple<int, int, int, int, int, int, int, int, int>>(
59 0, 1, 2, 3, 4, 5, 6, 7, 8);
60 EXPECT_TRUE((bool)p9);
61 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8), *p9);
64 make_unique<std::tuple<int, int, int, int, int, int, int, int, int, int>>(
65 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
66 EXPECT_TRUE((bool)p10);
67 EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), *p10);
70 TEST(MakeUniqueTest, Array) {
71 auto p1 = make_unique<int[]>(2);
72 EXPECT_TRUE((bool)p1);