libept
vocabulary.test.h
Go to the documentation of this file.
1 /*
2  * Tag vocabulary access
3  *
4  * Copyright (C) 2003--2007 Enrico Zini <enrico@debian.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #include <wibble/test.h>
22 #include <ept/debtags/vocabulary.h>
23 #include <ept/debtags/maint/path.h>
24 #include <tagcoll/utils/set.h>
25 #include <tagcoll/input/stdio.h>
26 
27 #include "ept/test.h"
28 
29 using namespace std;
30 using namespace tagcoll::utils;
31 using namespace ept::debtags;
32 
34 {
36  Vocabulary& tags() { return m_tags; }
37 
38  Test _1()
39 {
40  tags(); // this will throw if the open above didn't work
41 }
42 
43  Test _2()
44 {
45  assert( tags().hasFacet( "works-with" ) );
46  assert( !tags().hasFacet( "blah" ) );
47 }
48 
49  Test _3()
50 {
51  assert( tags().hasTag( "works-with::people" ) );
52  assert( !tags().hasTag( "works-with::midgets" ) );
53 }
54 
55  Test _4()
56 {
57  const voc::TagData *people = tags().tagData( "works-with::people" ),
58  *midgets = tags().tagData( "works-with::midgets" ),
59  *blahg = tags().tagData( "works-with::blahg" ),
60  *text = tags().tagData( "works-with::text" ),
61  *people2 = tags().tagData( "works-with::people" );
62  assert( people != midgets );
63  assert( people != text );
64  assert( people != blahg );
65  assert( midgets == blahg );
66  assert( midgets == midgets );
67  assert( people == people2 );
68  assert( people == people );
69 }
70 
71  Test _5()
72 {
73  std::string a = "works-with::people",
74  b = "works-with::midgets";
75  std::set<std::string> s = tags().tags(),
76  f = tags().tags( "works-with" ),
77  n = tags().tags( "nonsense" );
78  assert( set_contains(s, a) );
79  assert( set_contains(f, a) );
80  assert( set_contains(s, f) );
81  assert( !set_contains(s, b) );
82  assert( !set_contains(f, b) );
83  assert( n.empty() );
84 }
85 
86  Test _6()
87 {
88  const voc::FacetData* f = tags().facetData( "works-with" );
89  assert(f);
90  assert_eq(f->name, "works-with");
91 
92  const voc::TagData* t = tags().tagData( "works-with::people" );
93  assert(t);
94  assert_eq(t->name, "works-with::people");
95 }
96 
97  Test _7()
98 {
99  const voc::FacetData* f = tags().facetData( "works-with" );
100  std::set<std::string> x = tags().tags( "works-with" );
101  assert( x == f->tags() );
102 }
103 
104  Test _8()
105 {
106  const voc::FacetData* f = tags().facetData( "does-not-work-with" );
107  assert(!f);
108 }
109 
110  Test _9()
111 {
112  const voc::FacetData* f = tags().facetData( "legacy" );
113  assert(f);
114  assert_eq(f->shortDescription(), "");
115  assert_eq(f->longDescription(), "");
116  //assert_eq(f.shortDescription( "weehee" ), "weehee");
117 }
118 
119  Test _10()
120 {
121  // assert that one-character tag names are parsed correctly
122  assert( tags().hasTag( "implemented-in::c" ) );
123 }
124 
125  Test _11()
126 {
127  // assert that all facets are somehow working
128  std::set<std::string> facets = tags().facets();
129 
130  for (std::set<std::string>::const_iterator i = facets.begin();
131  i != facets.end(); i++)
132  {
133  const voc::FacetData* f = tags().facetData(*i);
134  assert(f);
135  }
136 }
137 
138  Test _12()
139 {
140  // assert that all tags are somehow working
141  std::set<std::string> tags = this->tags().tags();
142  for (std::set<std::string>::const_iterator i = tags.begin();
143  i != tags.end(); i++)
144  {
145  const voc::TagData* t = this->tags().tagData(*i);
146  assert(t);
147  }
148 }
149 
150 // Check for correctness of the first and last tag in the vocabulary
151  Test _13()
152 {
153  Vocabulary& tags = this->tags();
154 
155  const voc::TagData* first = tags.tagData("accessibility::TODO");
156  assert(first);
157  assert_eq(first->name, string("accessibility::TODO"));
158  assert_eq(first->shortDescription(), string("Need an extra tag"));
159 
160  const voc::TagData* last = tags.tagData("x11::xserver");
161  assert(last);
162  assert_eq(last->name, string("x11::xserver"));
163  assert_eq(last->shortDescription(), string("X Server"));
164 }
165 
166  Test _14()
167 {
168  // assert that it's possible to go from facet to ID and back
169  // we don't use IDs anymore
170 }
171 
172  Test _15()
173 {
174  // assert that it's possible to go from tag to ID and back
175  // we don't use IDs anymore
176 }
177 
178  Test _16()
179 {
180  // assert that facet IDs are distinct
181  // we don't use IDs anymore
182 }
183 
184  Test _17()
185 {
186  // assert that tag IDs are distinct
187  // we don't use IDs anymore
188 }
189 
190  Test _18()
191 {
192  // assert that all the tags are indexed
193  // we don't use the index anymore
194 }
195 
196  Test _19()
197 {
198  // test the tagcmp function
199  // we don't have tagcmp anymore
200 }
201 
202  Test _20()
203 {
204  // check that we're seeing all the tags for a facet
205  std::set<std::string> t = tags().tags("accessibility");
206  assert_eq(t.size(), 10u);
207 
208  t = tags().tags("works-with-format");
209  assert_eq(t.size(), 33u);
210 }
211 
212 // If there is no data, Vocabulary should work as an empty vocabulary
213  Test _21()
214 {
215  Path::OverrideDebtagsSourceDir odsd("./empty");
216  Path::OverrideDebtagsIndexDir odid("./empty");
217  Path::OverrideDebtagsUserSourceDir odusd("./empty");
218  Path::OverrideDebtagsUserIndexDir oduid("./empty");
219  Vocabulary empty;
220 
221  assert(!empty.hasData());
222 
223  set<std::string> facets = empty.facets();
224  assert_eq(facets.size(), 0u);
225 
226  set<std::string> tags = empty.tags();
227  assert_eq(tags.size(), 0u);
228 }
229 
230 };
231 
232 // vim:set ts=4 sw=4: