• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

apt.test.h

Go to the documentation of this file.
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(ver.isValid());
00115         assert(apt.validate(ver) == ver);
00116 
00117         string record = apt.rawRecord(ver);
00118         assert(record.find("Package: sp") != string::npos);
00119         assert(record.find("Section: text") != string::npos);
00120 
00121         record = apt.rawRecord(Version("sp", "0.31415"));
00122         assert_eq(record, string());
00123 
00124         assert_eq(apt.rawRecord(pkg), apt.rawRecord(apt.anyVersion(pkg)));
00125     }
00126 
00127     // Check the package state accessor
00128     Test state()
00129     {
00130         PackageState s = apt.state("kdenetwork");
00131         assert(s.isValid());
00132         assert(s.isInstalled());
00133 
00134         s = apt.state("this-package-does-not-really-exists");
00135         assert(!s.isValid());
00136     }
00137 
00138     // Check the record iterator (accessing with *)
00139     Test recordIteration()
00140     {
00141         size_t count = 0;
00142         for (Apt::record_iterator i = apt.recordBegin();
00143              i != apt.recordEnd(); ++i)
00144             {
00145                 assert((*i).size() > 8);
00146                 assert_eq((*i).substr(0, 8), "Package:");
00147                 ++count;
00148             }
00149         assert(count > 200);
00150     }
00151 
00152     // Check the record iterator (accessing with ->)
00153     Test recordIteration2()
00154     {
00155         size_t count = 0;
00156         for (Apt::record_iterator i = apt.recordBegin();
00157              i != apt.recordEnd(); ++i)
00158             {
00159                 assert(i->size() > 8);
00160                 assert_eq(i->substr(0, 8), "Package:");
00161                 ++count;
00162             }
00163         assert(count > 200);
00164     }
00165 
00166     // Check that the iterators can be used with the algorithms
00167     Test stlIteration()
00168     {
00169         vector<string> out;
00170         std::copy(apt.begin(), apt.end(), back_inserter(out));
00171     }
00172 
00173     // Check that the iterators can be used with the algorithms
00174     Test stlRecordIteration()
00175     {
00176         vector<string> out;
00177         std::copy(apt.recordBegin(), apt.recordEnd(), back_inserter(out));
00178     }
00179 
00180     // Check that checkUpdates will keep a working Apt object
00181     Test checkUpdates()
00182     {
00183         assert(apt.isValid("apt"));
00184         apt.checkCacheUpdates();
00185         assert(apt.isValid("apt"));
00186         apt.invalidateTimestamp();      
00187         apt.checkCacheUpdates();
00188         assert(apt.isValid("apt"));
00189     }
00190 
00191 };
00192 
00193 // vim:set ts=4 sw=4:

Generated on Wed Oct 27 2010 12:43:31 for libept by  doxygen 1.7.1