1 //===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector 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 // BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
11 // as well since it depends on a BitVector.
14 #include "llvm/ADT/PackedVector.h"
15 #include "gtest/gtest.h"
21 TEST(PackedVectorTest
, Operation
) {
22 PackedVector
<unsigned, 2> Vec
;
23 EXPECT_EQ(0U, Vec
.size());
24 EXPECT_TRUE(Vec
.empty());
27 EXPECT_EQ(5U, Vec
.size());
28 EXPECT_FALSE(Vec
.empty());
31 EXPECT_EQ(11U, Vec
.size());
32 EXPECT_FALSE(Vec
.empty());
34 PackedVector
<unsigned, 2> Vec2(3);
35 EXPECT_EQ(3U, Vec2
.size());
36 EXPECT_FALSE(Vec2
.empty());
39 EXPECT_EQ(0U, Vec
.size());
40 EXPECT_TRUE(Vec
.empty());
47 EXPECT_EQ(2U, Vec
[0]);
48 EXPECT_EQ(0U, Vec
[1]);
49 EXPECT_EQ(1U, Vec
[2]);
50 EXPECT_EQ(3U, Vec
[3]);
52 EXPECT_FALSE(Vec
== Vec2
);
53 EXPECT_TRUE(Vec
!= Vec2
);
56 EXPECT_EQ(3U, Vec
.size());
57 EXPECT_FALSE(Vec
.empty());
58 EXPECT_EQ(0U, Vec
[0]);
59 EXPECT_EQ(0U, Vec
[1]);
60 EXPECT_EQ(0U, Vec
[2]);
62 EXPECT_EQ(2U, Vec2
[0]);
63 EXPECT_EQ(0U, Vec2
[1]);
64 EXPECT_EQ(1U, Vec2
[2]);
65 EXPECT_EQ(3U, Vec2
[3]);
68 EXPECT_TRUE(Vec
== Vec2
);
69 EXPECT_FALSE(Vec
!= Vec2
);
74 EXPECT_EQ(3U, Vec
[1]);
77 #ifdef EXPECT_DEBUG_DEATH
79 TEST(PackedVectorTest
, UnsignedValues
) {
80 PackedVector
<unsigned, 2> Vec(1);
85 EXPECT_DEBUG_DEATH(Vec
[0] = 4, "value is too big");
86 EXPECT_DEBUG_DEATH(Vec
[0] = -1, "value is too big");
87 EXPECT_DEBUG_DEATH(Vec
[0] = 0x100, "value is too big");
89 PackedVector
<unsigned, 3> Vec2(1);
92 EXPECT_DEBUG_DEATH(Vec
[0] = 8, "value is too big");
95 TEST(PackedVectorTest
, SignedValues
) {
96 PackedVector
<signed, 2> Vec(1);
101 EXPECT_DEBUG_DEATH(Vec
[0] = -3, "value is too big");
102 EXPECT_DEBUG_DEATH(Vec
[0] = 2, "value is too big");
104 PackedVector
<signed, 3> Vec2(1);
107 EXPECT_DEBUG_DEATH(Vec
[0] = -5, "value is too big");
108 EXPECT_DEBUG_DEATH(Vec
[0] = 4, "value is too big");