From 0f5b687075181dbbb3ea2d177d0f66eb57df71c6 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 15 Jun 2011 19:19:09 +0000 Subject: [PATCH] Add unit tests for ADT/PackedVector git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133075 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ADT/PackedVectorTest.cpp | 111 +++++++++++++++++++++++++++++ unittests/CMakeLists.txt | 1 + 2 files changed, 112 insertions(+) create mode 100644 unittests/ADT/PackedVectorTest.cpp diff --git a/unittests/ADT/PackedVectorTest.cpp b/unittests/ADT/PackedVectorTest.cpp new file mode 100644 index 00000000000..19087abaf37 --- /dev/null +++ b/unittests/ADT/PackedVectorTest.cpp @@ -0,0 +1,111 @@ +//===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// BitVectorTest tests fail on PowerPC for unknown reasons, so disable this +// as well since it depends on a BitVector. +#ifndef __ppc__ + +#include "llvm/ADT/PackedVector.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(PackedVectorTest, Operation) { + PackedVector Vec; + EXPECT_EQ(0U, Vec.size()); + EXPECT_TRUE(Vec.empty()); + + Vec.resize(5); + EXPECT_EQ(5U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + + Vec.resize(11); + EXPECT_EQ(11U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + + PackedVector Vec2(3); + EXPECT_EQ(3U, Vec2.size()); + EXPECT_FALSE(Vec2.empty()); + + Vec.clear(); + EXPECT_EQ(0U, Vec.size()); + EXPECT_TRUE(Vec.empty()); + + Vec.push_back(2); + Vec.push_back(0); + Vec.push_back(1); + Vec.push_back(3); + + EXPECT_EQ(2U, Vec[0]); + EXPECT_EQ(0U, Vec[1]); + EXPECT_EQ(1U, Vec[2]); + EXPECT_EQ(3U, Vec[3]); + + EXPECT_FALSE(Vec == Vec2); + EXPECT_TRUE(Vec != Vec2); + + Vec2.swap(Vec); + EXPECT_EQ(3U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + EXPECT_EQ(0U, Vec[0]); + EXPECT_EQ(0U, Vec[1]); + EXPECT_EQ(0U, Vec[2]); + + EXPECT_EQ(2U, Vec2[0]); + EXPECT_EQ(0U, Vec2[1]); + EXPECT_EQ(1U, Vec2[2]); + EXPECT_EQ(3U, Vec2[3]); + + Vec = Vec2; + EXPECT_TRUE(Vec == Vec2); + EXPECT_FALSE(Vec != Vec2); + + Vec[1] = 1; + Vec2[1] = 2; + Vec |= Vec2; + EXPECT_EQ(3U, Vec[1]); +} + +TEST(PackedVectorTest, UnsignedValues) { + PackedVector Vec(1); + Vec[0] = 0; + Vec[0] = 1; + Vec[0] = 2; + Vec[0] = 3; + EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big"); + + PackedVector Vec2(1); + Vec2[0] = 0; + Vec2[0] = 7; + EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big"); +} + +TEST(PackedVectorTest, SignedValues) { + PackedVector Vec(1); + Vec[0] = -2; + Vec[0] = -1; + Vec[0] = 0; + Vec[0] = 1; + EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big"); + + PackedVector Vec2(1); + Vec2[0] = -4; + Vec2[0] = 3; + EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big"); +} + +} + +#endif diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index fcf6109a53a..0d17c40c009 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -64,6 +64,7 @@ add_llvm_unittest(ADT ADT/ImmutableSetTest.cpp ADT/IntEqClassesTest.cpp ADT/IntervalMapTest.cpp + ADT/PackedVectorTest.cpp ADT/SmallBitVectorTest.cpp ADT/SmallStringTest.cpp ADT/SmallVectorTest.cpp