MakeUniqueTest.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit tests ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/ADT/STLExtras.h"
  10. #include "gtest/gtest.h"
  11. #include <tuple>
  12. using namespace llvm;
  13. namespace {
  14. TEST(MakeUniqueTest, SingleObject) {
  15. auto p0 = make_unique<int>();
  16. EXPECT_TRUE((bool)p0);
  17. EXPECT_EQ(0, *p0);
  18. auto p1 = make_unique<int>(5);
  19. EXPECT_TRUE((bool)p1);
  20. EXPECT_EQ(5, *p1);
  21. auto p2 = make_unique<std::tuple<int, int>>(0, 1);
  22. EXPECT_TRUE((bool)p2);
  23. EXPECT_EQ(std::make_tuple(0, 1), *p2);
  24. auto p3 = make_unique<std::tuple<int, int, int>>(0, 1, 2);
  25. EXPECT_TRUE((bool)p3);
  26. EXPECT_EQ(std::make_tuple(0, 1, 2), *p3);
  27. auto p4 = make_unique<std::tuple<int, int, int, int>>(0, 1, 2, 3);
  28. EXPECT_TRUE((bool)p4);
  29. EXPECT_EQ(std::make_tuple(0, 1, 2, 3), *p4);
  30. auto p5 = make_unique<std::tuple<int, int, int, int, int>>(0, 1, 2, 3, 4);
  31. EXPECT_TRUE((bool)p5);
  32. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4), *p5);
  33. auto p6 =
  34. make_unique<std::tuple<int, int, int, int, int, int>>(0, 1, 2, 3, 4, 5);
  35. EXPECT_TRUE((bool)p6);
  36. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5), *p6);
  37. auto p7 = make_unique<std::tuple<int, int, int, int, int, int, int>>(
  38. 0, 1, 2, 3, 4, 5, 6);
  39. EXPECT_TRUE((bool)p7);
  40. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6), *p7);
  41. auto p8 = make_unique<std::tuple<int, int, int, int, int, int, int, int>>(
  42. 0, 1, 2, 3, 4, 5, 6, 7);
  43. EXPECT_TRUE((bool)p8);
  44. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7), *p8);
  45. auto p9 =
  46. make_unique<std::tuple<int, int, int, int, int, int, int, int, int>>(
  47. 0, 1, 2, 3, 4, 5, 6, 7, 8);
  48. EXPECT_TRUE((bool)p9);
  49. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8), *p9);
  50. auto p10 =
  51. make_unique<std::tuple<int, int, int, int, int, int, int, int, int, int>>(
  52. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  53. EXPECT_TRUE((bool)p10);
  54. EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), *p10);
  55. }
  56. TEST(MakeUniqueTest, Array) {
  57. auto p1 = make_unique<int[]>(2);
  58. EXPECT_TRUE((bool)p1);
  59. EXPECT_EQ(0, p1[0]);
  60. EXPECT_EQ(0, p1[1]);
  61. }
  62. }