Home | History | Annotate | Download | only in ADT
      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   Vec = Vec2;
     56   EXPECT_TRUE(Vec == Vec2);
     57   EXPECT_FALSE(Vec != Vec2);
     58 
     59   Vec[1] = 1;
     60   Vec2[1] = 2;
     61   Vec |= Vec2;
     62   EXPECT_EQ(3U, Vec[1]);
     63 }
     64 
     65 #ifdef EXPECT_DEBUG_DEATH
     66 
     67 TEST(PackedVectorTest, UnsignedValues) {
     68   PackedVector<unsigned, 2> Vec(1);
     69   Vec[0] = 0;
     70   Vec[0] = 1;
     71   Vec[0] = 2;
     72   Vec[0] = 3;
     73   EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
     74   EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big");
     75   EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big");
     76 
     77   PackedVector<unsigned, 3> Vec2(1);
     78   Vec2[0] = 0;
     79   Vec2[0] = 7;
     80   EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big");
     81 }
     82 
     83 TEST(PackedVectorTest, SignedValues) {
     84   PackedVector<signed, 2> Vec(1);
     85   Vec[0] = -2;
     86   Vec[0] = -1;
     87   Vec[0] = 0;
     88   Vec[0] = 1;
     89   EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big");
     90   EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big");
     91 
     92   PackedVector<signed, 3> Vec2(1);
     93   Vec2[0] = -4;
     94   Vec2[0] = 3;
     95   EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big");
     96   EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
     97 }
     98 
     99 #endif
    100 
    101 }
    102 
    103 #endif
    104