1 //===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
10 // as well since it depends on a BitVector.
13 #include "llvm/ADT/PackedVector.h"
14 #include "gtest/gtest.h"
20 TEST(PackedVectorTest
, Operation
) {
21 PackedVector
<unsigned, 2> Vec
;
22 EXPECT_EQ(0U, Vec
.size());
23 EXPECT_TRUE(Vec
.empty());
26 EXPECT_EQ(5U, Vec
.size());
27 EXPECT_FALSE(Vec
.empty());
30 EXPECT_EQ(11U, Vec
.size());
31 EXPECT_FALSE(Vec
.empty());
33 PackedVector
<unsigned, 2> Vec2(3);
34 EXPECT_EQ(3U, Vec2
.size());
35 EXPECT_FALSE(Vec2
.empty());
38 EXPECT_EQ(0U, Vec
.size());
39 EXPECT_TRUE(Vec
.empty());
46 EXPECT_EQ(2U, Vec
[0]);
47 EXPECT_EQ(0U, Vec
[1]);
48 EXPECT_EQ(1U, Vec
[2]);
49 EXPECT_EQ(3U, Vec
[3]);
51 EXPECT_FALSE(Vec
== Vec2
);
52 EXPECT_TRUE(Vec
!= Vec2
);
55 EXPECT_TRUE(Vec
== Vec2
);
56 EXPECT_FALSE(Vec
!= Vec2
);
61 EXPECT_EQ(3U, Vec
[1]);
64 #ifdef EXPECT_DEBUG_DEATH
66 TEST(PackedVectorTest
, UnsignedValues
) {
67 PackedVector
<unsigned, 2> Vec(1);
72 EXPECT_DEBUG_DEATH(Vec
[0] = 4, "value is too big");
73 EXPECT_DEBUG_DEATH(Vec
[0] = -1, "value is too big");
74 EXPECT_DEBUG_DEATH(Vec
[0] = 0x100, "value is too big");
76 PackedVector
<unsigned, 3> Vec2(1);
79 EXPECT_DEBUG_DEATH(Vec
[0] = 8, "value is too big");
82 TEST(PackedVectorTest
, SignedValues
) {
83 PackedVector
<signed, 2> Vec(1);
88 EXPECT_DEBUG_DEATH(Vec
[0] = -3, "value is too big");
89 EXPECT_DEBUG_DEATH(Vec
[0] = 2, "value is too big");
91 PackedVector
<signed, 3> Vec2(1);
94 EXPECT_DEBUG_DEATH(Vec
[0] = -5, "value is too big");
95 EXPECT_DEBUG_DEATH(Vec
[0] = 4, "value is too big");