libept
pkgid.test.h
Go to the documentation of this file.
00001 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
00002 /*
00003  * id->package mapping
00004  *
00005  * Copyright (C) 2006  Enrico Zini <enrico@debian.org>
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #include <ept/debtags/maint/pkgid.h>
00023 #include <ept/debtags/maint/path.h>
00024 #include <ept/debtags/debtags.h>
00025 #include <set>
00026 
00027 #include <ept/test.h>
00028 
00029 using namespace std;
00030 using namespace ept;
00031 using namespace ept::debtags;
00032 
00033 struct TestPkgid : DebtagsTestEnvironment
00034 {
00035     Debtags debtags;
00036     PkgId& pkgid;
00037 
00038     TestPkgid()
00039         : pkgid(debtags.pkgid())
00040     {
00041     }
00042 
00043 // Check that we can go from name to ID and back
00044     Test _1()
00045 {
00046     //int x = 0;
00047     for (Debtags::const_iterator i = debtags.begin();
00048             i != debtags.end(); ++i)
00049     {
00050         int id = pkgid.byName(i->first);
00051         std::string pkg = pkgid.byID(id);
00052         assert(i->first == pkg);
00053 
00054         /* std::cerr << x << ": " << i->id() << ": "
00055                   << i->name() << ", " << pkgidx().name( i->id() ) <<
00056                   std::endl; */
00057         //++ x;
00058     }
00059 }
00060 
00061 // Check that IDs are distinct
00062     Test _2()
00063 {
00064     using namespace std;
00065 
00066     size_t count = 0;
00067     set<int> ids;
00068     for (Debtags::const_iterator i = debtags.begin(); i != debtags.end(); ++i, ++count)
00069         ids.insert(pkgid.byName(i->first));
00070     assert_eq(ids.size(), count);
00071 }
00072 
00073 };
00074 
00075 // vim:set ts=4 sw=4: