There's no need to be so picky about the particular register.
[llvm/stm8.git] / unittests / ADT / PackedVectorTest.cpp
blob55b5d8d049ddd544dbcaea4bd3fa69270472a7bf
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 //===----------------------------------------------------------------------===//
10 // BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
11 // as well since it depends on a BitVector.
12 #ifndef __ppc__
14 #include "llvm/ADT/PackedVector.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 namespace {
21 TEST(PackedVectorTest, Operation) {
22 PackedVector<unsigned, 2> Vec;
23 EXPECT_EQ(0U, Vec.size());
24 EXPECT_TRUE(Vec.empty());
26 Vec.resize(5);
27 EXPECT_EQ(5U, Vec.size());
28 EXPECT_FALSE(Vec.empty());
30 Vec.resize(11);
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());
38 Vec.clear();
39 EXPECT_EQ(0U, Vec.size());
40 EXPECT_TRUE(Vec.empty());
42 Vec.push_back(2);
43 Vec.push_back(0);
44 Vec.push_back(1);
45 Vec.push_back(3);
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);
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]);
62 EXPECT_EQ(2U, Vec2[0]);
63 EXPECT_EQ(0U, Vec2[1]);
64 EXPECT_EQ(1U, Vec2[2]);
65 EXPECT_EQ(3U, Vec2[3]);
67 Vec = Vec2;
68 EXPECT_TRUE(Vec == Vec2);
69 EXPECT_FALSE(Vec != Vec2);
71 Vec[1] = 1;
72 Vec2[1] = 2;
73 Vec |= Vec2;
74 EXPECT_EQ(3U, Vec[1]);
77 #ifdef EXPECT_DEBUG_DEATH
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");
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");
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");
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");
111 #endif
115 #endif