1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* test_sid_list.cc: Part of GNU CSSC.
*
*
* Copyright (C) 2010, 2011, 2014, 2019 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Unit tests for sid_list.h.
*
*/
#include "sid_list.h"
#include "sl-merge.h"
#include <gtest/gtest.h>
TEST(SidListTest, NullConstructor)
{
sid_list x;
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.empty());
}
TEST(SidListTest, OtherConstructors)
{
sid_list a;
ASSERT_TRUE(a.valid());
ASSERT_TRUE(a.empty());
sid_list b(a);
ASSERT_TRUE(b.empty());
ASSERT_TRUE(b.valid());
sid_list c = a;
ASSERT_TRUE(c.empty());
ASSERT_TRUE(c.valid());
}
TEST(SidListTest, Invalidate)
{
sid_list x;
ASSERT_TRUE(x.valid());
x.invalidate();
ASSERT_FALSE(x.valid());
}
TEST(SidListTest, OpenRange)
{
/* SourceForge bug number #438857:
* ranges like "1.1.1.2," cause an assertion
* failure while SCCS just ignores the empty list item.
*/
const sid_list x("1.1.1.2,");
ASSERT_TRUE(x.valid());
const sid s("1.1.1.2");
ASSERT_TRUE(x.member(s));
}
TEST(SidListTest, SingleItem)
{
const sid_list x("1.7");
ASSERT_TRUE(x.valid());
ASSERT_FALSE(x.empty());
}
TEST(SidListTest, CommaSeparatedItems)
{
const sid_list x("1.1.1.2,2.2.2.3");
ASSERT_TRUE(x.valid());
const sid s("1.1.1.2");
const sid t("2.2.2.3");
ASSERT_TRUE(x.member(s));
ASSERT_TRUE(x.member(t));
}
TEST(SidListTest, OneRangeTrunk)
{
const sid_list x("1.1-1.8");
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.member(sid("1.2")));
ASSERT_TRUE(x.member(sid("1.3")));
ASSERT_TRUE(x.member(sid("1.8")));
ASSERT_FALSE(x.member(sid("1.9")));
ASSERT_FALSE(x.member(sid("1.2.1.1")));
}
TEST(SidListTest, OneRangeBranch)
{
const sid_list x("1.2.1.1-1.2.1.4");
ASSERT_TRUE(x.valid());
ASSERT_FALSE(x.member(sid("1.2")));
ASSERT_TRUE(x.member(sid("1.2.1.1")));
ASSERT_TRUE(x.member(sid("1.2.1.2")));
ASSERT_TRUE(x.member(sid("1.2.1.3")));
ASSERT_TRUE(x.member(sid("1.2.1.4")));
ASSERT_FALSE(x.member(sid("1.2.1.5")));
ASSERT_FALSE(x.member(sid("1.2")));
}
TEST(SidListTest, BackwardRange)
{
const sid_list x("1.2.1.4-1.2.1.1");
ASSERT_FALSE(x.valid());
}
TEST(SidListTest, Overlap)
{
const sid_list x("1.2.1.1-1.2.1.9,1.2.1.7-1.2.1.14");
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.member(sid("1.2.1.1")));
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.9")));
ASSERT_TRUE(x.member(sid("1.2.1.10")));
ASSERT_TRUE(x.member(sid("1.2.1.14")));
ASSERT_FALSE(x.member(sid("1.2.1.15")));
}
TEST(SidListTest, OverlapOtherOrder)
{
const sid_list x("1.2.1.7-1.2.1.14,1.2.1.1-1.2.1.9");
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.member(sid("1.2.1.1")));
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.9")));
ASSERT_TRUE(x.member(sid("1.2.1.10")));
ASSERT_TRUE(x.member(sid("1.2.1.14")));
ASSERT_FALSE(x.member(sid("1.2.1.15")));
}
TEST(SidListTest, Island)
{
const sid_list x("1.2.1.7-1.2.1.14,1.2.1.9");
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.9")));
ASSERT_TRUE(x.member(sid("1.2.1.14")));
ASSERT_FALSE(x.member(sid("1.2.1.15")));
}
TEST(SidListTest, Outlier)
{
const sid_list x("1.2.1.7-1.2.1.14,1.2.1.19");
ASSERT_TRUE(x.valid());
ASSERT_FALSE(x.empty());
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.9")));
ASSERT_TRUE(x.member(sid("1.2.1.14")));
ASSERT_FALSE(x.member(sid("1.2.1.15")));
ASSERT_TRUE(x.member(sid("1.2.1.19")));
}
TEST(SidListTest, Assignment)
{
const sid_list y("1.2.1.7-1.2.1.14,1.2.1.19");
const sid_list x(y);
ASSERT_TRUE(x.valid());
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.9")));
ASSERT_TRUE(x.member(sid("1.2.1.14")));
ASSERT_FALSE(x.member(sid("1.2.1.15")));
ASSERT_TRUE(x.member(sid("1.2.1.19")));
}
TEST(SidListTest, Merge)
{
sid_list x("1.2.1.7-1.2.1.14");
const sid_list y("1.2.1.10-1.2.1.20");
const sid_list z("1.8-1.20");
x.merge(y);
x.merge(z);
// Verify that the pre-merge conditions still hold.
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(y.member(sid("1.2.1.10")));
ASSERT_TRUE(z.member(sid("1.10")));
// Now verify that the y and z were merged into x.
ASSERT_TRUE(x.member(sid("1.2.1.7")));
ASSERT_TRUE(x.member(sid("1.2.1.10")));
ASSERT_TRUE(x.member(sid("1.10")));
// Verify that we don't just answer all questions with yes.
ASSERT_FALSE(x.member(sid("1.2.1.51")));
}
TEST(SidListTest, Remove)
{
sid_list x("1.2.1.7-1.2.1.14");
ASSERT_TRUE(x.member(sid("1.2.1.10")));
x.remove("1.2.1.10");
ASSERT_FALSE(x.member(sid("1.2.1.10")));
}
|