libept
0.5.25
|
00001 /* 00002 * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #include <ept/test.h> 00020 #include <ept/apt/apt.h> 00021 #include <set> 00022 #include <algorithm> 00023 00024 using namespace std; 00025 using namespace ept; 00026 using namespace ept::apt; 00027 00028 struct TestApt : AptTestEnvironment { 00029 Apt apt; 00030 00031 // Check that iterations iterates among some packages 00032 Test iterators() 00033 { 00034 Apt::iterator i = apt.begin(); 00035 assert(i != apt.end()); 00036 00037 size_t count = 0; 00038 for (; i != apt.end(); ++i) 00039 ++count; 00040 00041 assert(count > 100); 00042 } 00043 00044 // Check that iteration gives some well-known packages 00045 Test aptExists() 00046 { 00047 set<string> packages; 00048 00049 std::copy(apt.begin(), apt.end(), inserter(packages, packages.begin())); 00050 00051 assert(packages.find("libsp1") != packages.end()); 00052 // TODO this exposes a bug somewhere... sp definitely is among 00053 // the packages 00054 // assert(packages.find("sp") != packages.end()); 00055 assert(packages.find("") == packages.end()); 00056 } 00057 00058 // Check that timestamp gives some meaningful timestamp 00059 Test timestamp() 00060 { 00061 time_t ts = apt.timestamp(); 00062 assert(ts > 1000000); 00063 } 00064 00065 // Check the package validator 00066 Test validity() 00067 { 00068 assert(apt.isValid("apt")); 00069 assert(!apt.isValid("this-package-does-not-really-exists")); 00070 } 00071 00072 // Check the version instantiators 00073 Test versions() 00074 { 00075 std::string pkg("apt"); 00076 Version ver = apt.candidateVersion(pkg); 00077 assert(ver.isValid()); 00078 00079 ver = apt.installedVersion(pkg); 00080 assert(ver.isValid()); 00081 00082 ver = apt.anyVersion(pkg); 00083 assert(ver.isValid()); 00084 00085 std::string pkg1("this-package-does-not-really-exists"); 00086 ver = apt.candidateVersion(pkg1); 00087 assert(!ver.isValid()); 00088 00089 ver = apt.installedVersion(pkg1); 00090 assert(!ver.isValid()); 00091 00092 ver = apt.anyVersion(pkg1); 00093 assert(!ver.isValid()); 00094 } 00095 00096 // Check the version validator 00097 Test versionValidity() 00098 { 00099 Version ver = apt.candidateVersion("apt"); 00100 assert(apt.validate(ver) == ver); 00101 00102 ver = Version("this-package-does-not-really-exists", "0.1"); 00103 assert(!apt.validate(ver).isValid()); 00104 00105 ver = Version("apt", "0.31415"); 00106 assert(!apt.validate(ver).isValid()); 00107 } 00108 00109 // Check the raw record accessor 00110 Test rawRecord() 00111 { 00112 string pkg("sp"); 00113 Version ver = apt.candidateVersion(pkg); 00114 assert(apt.validate(ver) == ver); 00115 00116 string record = apt.rawRecord(ver); 00117 assert(record.find("Package: sp") != string::npos); 00118 assert(record.find("Section: text") != string::npos); 00119 00120 record = apt.rawRecord(Version("sp", "0.31415")); 00121 assert_eq(record, string()); 00122 00123 assert_eq(apt.rawRecord(pkg), apt.rawRecord(apt.anyVersion(pkg))); 00124 } 00125 00126 // Check the package state accessor 00127 Test state() 00128 { 00129 PackageState s = apt.state("kdenetwork"); 00130 assert(s.isValid()); 00131 assert(s.isInstalled()); 00132 00133 s = apt.state("this-package-does-not-really-exists"); 00134 assert(!s.isValid()); 00135 } 00136 00137 // Check the record iterator (accessing with *) 00138 Test recordIteration() 00139 { 00140 size_t count = 0; 00141 for (Apt::record_iterator i = apt.recordBegin(); 00142 i != apt.recordEnd(); ++i) 00143 { 00144 assert((*i).size() > 8); 00145 assert_eq((*i).substr(0, 8), "Package:"); 00146 ++count; 00147 } 00148 assert(count > 200); 00149 } 00150 00151 // Check the record iterator (accessing with ->) 00152 Test recordIteration2() 00153 { 00154 size_t count = 0; 00155 for (Apt::record_iterator i = apt.recordBegin(); 00156 i != apt.recordEnd(); ++i) 00157 { 00158 assert(i->size() > 8); 00159 assert_eq(i->substr(0, 8), "Package:"); 00160 ++count; 00161 } 00162 assert(count > 200); 00163 } 00164 00165 // Check that the iterators can be used with the algorithms 00166 Test stlIteration() 00167 { 00168 vector<string> out; 00169 std::copy(apt.begin(), apt.end(), back_inserter(out)); 00170 } 00171 00172 // Check that the iterators can be used with the algorithms 00173 Test stlRecordIteration() 00174 { 00175 vector<string> out; 00176 std::copy(apt.recordBegin(), apt.recordEnd(), back_inserter(out)); 00177 } 00178 00179 // Check that checkUpdates will keep a working Apt object 00180 Test checkUpdates() 00181 { 00182 assert(apt.isValid("apt")); 00183 apt.checkCacheUpdates(); 00184 assert(apt.isValid("apt")); 00185 apt.invalidateTimestamp(); 00186 apt.checkCacheUpdates(); 00187 assert(apt.isValid("apt")); 00188 } 00189 00190 }; 00191 00192 // vim:set ts=4 sw=4: