1 //===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector 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 10 // BitVectorTest tests fail on PowerPC for unknown reasons, so disable this 11 // as well since it depends on a BitVector. 12 #ifndef __ppc__ 13 14 #include "llvm/ADT/PackedVector.h" 15 #include "gtest/gtest.h" 16 17 using namespace llvm; 18 19 namespace { 20 21 TEST(PackedVectorTest, Operation) { 22 PackedVector<unsigned, 2> Vec; 23 EXPECT_EQ(0U, Vec.size()); 24 EXPECT_TRUE(Vec.empty()); 25 26 Vec.resize(5); 27 EXPECT_EQ(5U, Vec.size()); 28 EXPECT_FALSE(Vec.empty()); 29 30 Vec.resize(11); 31 EXPECT_EQ(11U, Vec.size()); 32 EXPECT_FALSE(Vec.empty()); 33 34 PackedVector<unsigned, 2> Vec2(3); 35 EXPECT_EQ(3U, Vec2.size()); 36 EXPECT_FALSE(Vec2.empty()); 37 38 Vec.clear(); 39 EXPECT_EQ(0U, Vec.size()); 40 EXPECT_TRUE(Vec.empty()); 41 42 Vec.push_back(2); 43 Vec.push_back(0); 44 Vec.push_back(1); 45 Vec.push_back(3); 46 47 EXPECT_EQ(2U, Vec[0]); 48 EXPECT_EQ(0U, Vec[1]); 49 EXPECT_EQ(1U, Vec[2]); 50 EXPECT_EQ(3U, Vec[3]); 51 52 EXPECT_FALSE(Vec == Vec2); 53 EXPECT_TRUE(Vec != Vec2); 54 55 Vec2.swap(Vec); 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]); 61 62 EXPECT_EQ(2U, Vec2[0]); 63 EXPECT_EQ(0U, Vec2[1]); 64 EXPECT_EQ(1U, Vec2[2]); 65 EXPECT_EQ(3U, Vec2[3]); 66 67 Vec = Vec2; 68 EXPECT_TRUE(Vec == Vec2); 69 EXPECT_FALSE(Vec != Vec2); 70 71 Vec[1] = 1; 72 Vec2[1] = 2; 73 Vec |= Vec2; 74 EXPECT_EQ(3U, Vec[1]); 75 } 76 77 #ifdef EXPECT_DEBUG_DEATH 78 79 TEST(PackedVectorTest, UnsignedValues) { 80 PackedVector<unsigned, 2> Vec(1); 81 Vec[0] = 0; 82 Vec[0] = 1; 83 Vec[0] = 2; 84 Vec[0] = 3; 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"); 88 89 PackedVector<unsigned, 3> Vec2(1); 90 Vec2[0] = 0; 91 Vec2[0] = 7; 92 EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big"); 93 } 94 95 TEST(PackedVectorTest, SignedValues) { 96 PackedVector<signed, 2> Vec(1); 97 Vec[0] = -2; 98 Vec[0] = -1; 99 Vec[0] = 0; 100 Vec[0] = 1; 101 EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big"); 102 EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big"); 103 104 PackedVector<signed, 3> Vec2(1); 105 Vec2[0] = -4; 106 Vec2[0] = 3; 107 EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big"); 108 EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big"); 109 } 110 111 #endif 112 113 } 114 115 #endif 116