/usr/include/ept/apt/apt.test.h is in libept-dev 1.0.12.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (C) 2007 Enrico Zini <enrico@enricozini.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ept/test.h>
#include <ept/apt/apt.h>
#include <set>
#include <algorithm>
using namespace std;
using namespace ept;
using namespace ept::apt;
struct TestApt : AptTestEnvironment {
Apt apt;
// Check that iterations iterates among some packages
Test iterators()
{
Apt::iterator i = apt.begin();
assert(i != apt.end());
size_t count = 0;
for (; i != apt.end(); ++i)
++count;
assert(count > 100);
}
// Check that iteration gives some well-known packages
Test aptExists()
{
set<string> packages;
std::copy(apt.begin(), apt.end(), inserter(packages, packages.begin()));
assert(packages.find("libsp1") != packages.end());
// TODO this exposes a bug somewhere... sp definitely is among
// the packages
// assert(packages.find("sp") != packages.end());
assert(packages.find("") == packages.end());
}
// Check that timestamp gives some meaningful timestamp
Test timestamp()
{
time_t ts = apt.timestamp();
assert(ts > 1000000);
}
// Check the package validator
Test validity()
{
assert(apt.isValid("apt"));
assert(!apt.isValid("this-package-does-not-really-exists"));
}
// Check the version instantiators
Test versions()
{
std::string pkg("apt");
Version ver = apt.candidateVersion(pkg);
assert(ver.isValid());
ver = apt.installedVersion(pkg);
assert(ver.isValid());
ver = apt.anyVersion(pkg);
assert(ver.isValid());
std::string pkg1("this-package-does-not-really-exists");
ver = apt.candidateVersion(pkg1);
assert(!ver.isValid());
ver = apt.installedVersion(pkg1);
assert(!ver.isValid());
ver = apt.anyVersion(pkg1);
assert(!ver.isValid());
}
// Check the version validator
Test versionValidity()
{
Version ver = apt.candidateVersion("apt");
assert(apt.validate(ver) == ver);
ver = Version("this-package-does-not-really-exists", "0.1");
assert(!apt.validate(ver).isValid());
ver = Version("apt", "0.31415");
assert(!apt.validate(ver).isValid());
}
// Check the raw record accessor
Test rawRecord()
{
string pkg("sp");
Version ver = apt.candidateVersion(pkg);
assert(ver.isValid());
assert(apt.validate(ver) == ver);
string record = apt.rawRecord(ver);
assert(record.find("Package: sp") != string::npos);
assert(record.find("Section: text") != string::npos);
record = apt.rawRecord(Version("sp", "0.31415"));
assert_eq(record, string());
assert_eq(apt.rawRecord(pkg), apt.rawRecord(apt.anyVersion(pkg)));
}
// Check the package state accessor
Test state()
{
PackageState s = apt.state("kdenetwork");
assert(s.isValid());
assert(s.isInstalled());
s = apt.state("this-package-does-not-really-exists");
assert(!s.isValid());
}
// Check the record iterator (accessing with *)
Test recordIteration()
{
size_t count = 0;
for (Apt::record_iterator i = apt.recordBegin();
i != apt.recordEnd(); ++i)
{
assert((*i).size() > 8);
assert_eq((*i).substr(0, 8), "Package:");
++count;
}
assert(count > 200);
}
// Check the record iterator (accessing with ->)
Test recordIteration2()
{
size_t count = 0;
for (Apt::record_iterator i = apt.recordBegin();
i != apt.recordEnd(); ++i)
{
assert(i->size() > 8);
assert_eq(i->substr(0, 8), "Package:");
++count;
}
assert(count > 200);
}
// Check that the iterators can be used with the algorithms
Test stlIteration()
{
vector<string> out;
std::copy(apt.begin(), apt.end(), back_inserter(out));
}
// Check that the iterators can be used with the algorithms
Test stlRecordIteration()
{
vector<string> out;
std::copy(apt.recordBegin(), apt.recordEnd(), back_inserter(out));
}
// Check that checkUpdates will keep a working Apt object
Test checkUpdates()
{
assert(apt.isValid("apt"));
apt.checkCacheUpdates();
assert(apt.isValid("apt"));
apt.invalidateTimestamp();
apt.checkCacheUpdates();
assert(apt.isValid("apt"));
}
};
// vim:set ts=4 sw=4:
|