libept
debtags.test.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
7 /*
8  * Test for the Debtags data provider
9  *
10  * Copyright (C) 2003-2007 Enrico Zini <enrico@debian.org>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  */
26 
27 
28 #include <ept/debtags/debtags.h>
29 
30 #include <tagcoll/coll/simple.h>
31 #include <tagcoll/stream/sink.h>
32 #include <tagcoll/patch.h>
33 
34 #include <wibble/operators.h>
35 
36 #include <ept/test.h>
37 #include <cstdio>
38 
39 #ifndef EPT_DEBTAGS_TESTH
40 #define EPT_DEBTAGS_TESTH
41 
42 using namespace tagcoll;
43 using namespace std;
44 using namespace ept;
45 using namespace ept::debtags;
46 using namespace wibble::operators;
47 
48 #define testfile TEST_ENV_DIR "debtags/package-tags"
49 
51 {
53 
54  Test _1()
55  {
56  EnvOverride eo("DEBTAGS_TAGS", testfile);
57  Debtags debtags;
58  for (Debtags::const_iterator i = debtags.begin(); i != debtags.end(); ++i)
59  {
60  *i;
61  i->first;
62  i->second;
63  }
64  }
65 
66  Test _2()
67  {
68  EnvOverride eo("DEBTAGS_TAGS", testfile);
69  Debtags debtags;
70  string p("debtags");
71  std::set<std::string> tags = debtags.getTagsOfItem(p);
72  assert( !tags.empty() );
73 
74 #if 0
75  for ( std::set< Tag >::iterator i = tags.begin(); i != tags.end(); ++ i ) {
76  std::cerr << i->id() << ": " << i->fullname() << std::endl;
77  }
78  std::cerr << "---" << std::endl;
79  Tag t = voc().tagByName( "interface::commandline" );
80  std::cerr << t.id() << ": " << t.fullname() << std::endl;
81 #endif
82 
83  assert_eq( tags.size(), 8u );
84  assert( tags.find("devel::buildtools") != tags.end() );
85  assert( tags.find("implemented-in::c++") != tags.end() );
86  assert( tags.find("interface::commandline") != tags.end() );
87  assert( tags.find("role::program") != tags.end() );
88  assert( tags.find("scope::application") != tags.end() );
89  assert( tags.find("suite::debian") != tags.end() );
90  assert( tags.find("use::searching") != tags.end() );
91  assert( tags.find("works-with::software:package") != tags.end() );
92 }
93 
94  Test _3()
95  {
96  using namespace std;
97  EnvOverride eo("DEBTAGS_TAGS", testfile);
98  Debtags debtags;
99 
100  /* Get the 'debtags' package */
101  string p("debtags");
102 
103  /* Get its tags */
104  std::set<std::string> tags = debtags.getTagsOfItem(p);
105  assert(!tags.empty());
106 
107  /*
108  cerr << "Intersection size: " << endl;
109  using namespace wibble::operators;
110  std::set<Tag>::const_iterator dbgi = tags.begin();
111  cerr << "* " << dbgi->fullname() << ": " << dbgi->id() << endl;
112  std::set<int> dbgres = debtags.tagdb().getItemsHavingTag(dbgi->id());
113  std::set<Package> dbgpres = debtags.getItemsHavingTag(*dbgi);
114  cerr << " #pkgs " << dbgres.size() << " == " << dbgpres.size() << endl;
115  cerr << " #isec " << dbgres.size() << " == " << dbgpres.size() << endl;
116  cerr << " "; ppset(dbgpres); cerr << endl;
117  cerr << " "; piset(dbgres); cerr << endl;
118  for (++dbgi ; dbgi != tags.end(); ++dbgi)
119  {
120  cerr << "* " << dbgi->fullname() << ": " << dbgi->id() << endl;
121  std::set<Package> dbgpkgs = debtags.getItemsHavingTag(*dbgi);
122  std::set<int> dbgids = debtags.tagdb().getItemsHavingTag(dbgi->id());
123  cerr << " "; ppset(dbgpkgs); cerr << endl;
124  cerr << " "; piset(dbgids); cerr << endl;
125  cerr << " #pkgs " << dbgpkgs.size() << " == " << dbgids.size() << endl;
126  dbgres &= dbgids;
127  dbgpres &= dbgpkgs;
128  cerr << " #isec " << dbgres.size() << " == " << dbgpres.size() << endl;
129  }
130  cerr << " " << dbgres.size() << endl << "Results: " << endl;
131  for (std::set<int>::const_iterator i = dbgres.begin(); i != dbgres.end(); ++i)
132  cerr << " " << *i << endl;
133  */
134 
135 
136 // cerr << "Tags of debtags: ";
137 // for (std::set<Tag>::const_iterator i = tags.begin(); i != tags.end(); ++i)
138 // {
139 // cerr << " " + i->fullname() << endl;
140 // std::set<Package> packages = debtags.getItemsHavingTag(*i);
141 // for (std::set<Package>::const_iterator p = packages.begin();
142 // p != packages.end(); ++p)
143 // cerr << " PKG " << p->name() << endl;
144 // }
145 // cerr << endl;
146 
147  /* Get the items for the tagset of 'debtags' */
148  std::set<string> packages = debtags.getItemsHavingTags(tags);
149  //cerr << packages.size() << endl;
150  assert(!packages.empty());
151  /*
152  for ( std::set< Package >::iterator i = packages.begin(); i != packages.end(); ++ i )
153  std::cerr << i->name() << std::endl;
154  std::cerr << "---" << std::endl;
155  std::cerr << p.name() << std::endl;
156  */
157  /* They should at least contain 'debtags' */
158  assert( p <= packages );
159 
160  /* Get one of the tags of 'debtags' */
161  std::string tag = *tags.begin();
162 
163  /* Get its items */
164  {
165  /* Need this workaround until I figure out how to tell the new GCC
166  * that TagDB is a TDBReadonlyDiskIndex and should behave as such
167  */
168  std::set<std::string> ts;
169  ts.insert(tag);
170  packages = debtags.getItemsHavingTags(ts);
171  }
172  //packages = c.debtags().tagdb().getItems(tag);
173  assert(!packages.empty());
174  /* They should at least contain 'debtags' */
175  assert( p <= packages );
176 
177  //c.debtags().getTags(""); // XXX HACK AWW!
178 }
179 
180  // If there is no data, Debtags should work as an empty collection
181  Test _4()
182  {
183  EnvOverride eo("DEBTAGS_TAGS", "./empty/notags");
184  Debtags empty;
185 
186  assert(empty.begin() == empty.end());
187  assert_eq(empty.timestamp(), 0);
188  assert(!empty.hasData());
189 
190  set<std::string> res = empty.getTagsOfItem("apt");
191  assert(res.empty());
192  // TODO: currently does not compile because of a bug in tagcoll
193  //res = empty.getTagsOfItems(wibble::singleton(string("apt")));
194  //assert(res.empty());
195 
196  res = empty.getAllTags();
197  assert(res.empty());
198 }
199 
200 };
201 
202 #include <tagcoll/coll/simple.tcc>
203 
204 #endif
205 
206 // vim:set ts=4 sw=4:
Definition: test.h:35
Test _1()
Definition: debtags.test.h:54
Definition: packagerecord.test.h:22
Definition: apt.cc:42
Definition: test.h:39
Test _2()
Definition: debtags.test.h:66
Access the on-disk Debtags tag database.
Definition: debtags.h:54
Test _4()
Definition: debtags.test.h:181
Definition: debtags.cc:50
Test _3()
Definition: debtags.test.h:94
bool hasData() const
Return true if this data source has data, false if it's empty.
Definition: debtags.h:79
Definition: debdbparser.h:31
TestDebtags()
Definition: debtags.test.h:52
Definition: debtags.test.h:50
#define testfile
Definition: debtags.test.h:48
time_t timestamp() const
Get the timestamp of when the index was last updated.
Definition: debtags.h:76
set< string > & res
Definition: packagerecord.cc:73