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 <tagcoll/utils/set.h>
24 #include <tagcoll/input/stdio.h>
25 #include "ept/test.h"
26 
27 using namespace std;
28 using namespace tagcoll::utils;
29 using namespace ept::debtags;
30 
31 #define testfile TEST_ENV_DIR "debtags/vocabulary"
32 
33 
35 {
36  Test _1()
37 {
38  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
39  Vocabulary tags; // this will throw if it failed to load
40 }
41 
42  Test _2()
43 {
44  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
45  Vocabulary tags;
46  assert( tags.hasFacet( "works-with" ) );
47  assert( !tags.hasFacet( "blah" ) );
48 }
49 
50  Test _3()
51 {
52  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
53  Vocabulary tags;
54  assert( tags.hasTag( "works-with::people" ) );
55  assert( !tags.hasTag( "works-with::midgets" ) );
56 }
57 
58  Test _4()
59 {
60  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
61  Vocabulary tags;
62  const voc::TagData *people = tags.tagData( "works-with::people" ),
63  *midgets = tags.tagData( "works-with::midgets" ),
64  *blahg = tags.tagData( "works-with::blahg" ),
65  *text = tags.tagData( "works-with::text" ),
66  *people2 = tags.tagData( "works-with::people" );
67  assert( people != midgets );
68  assert( people != text );
69  assert( people != blahg );
70  assert( midgets == blahg );
71  assert( midgets == midgets );
72  assert( people == people2 );
73  assert( people == people );
74 }
75 
76  Test _5()
77 {
78  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
79  Vocabulary tags;
80  std::string a = "works-with::people",
81  b = "works-with::midgets";
82  std::set<std::string> s = tags.tags(),
83  f = tags.tags( "works-with" ),
84  n = tags.tags( "nonsense" );
85  assert( set_contains(s, a) );
86  assert( set_contains(f, a) );
87  assert( set_contains(s, f) );
88  assert( !set_contains(s, b) );
89  assert( !set_contains(f, b) );
90  assert( n.empty() );
91 }
92 
93  Test _6()
94 {
95  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
96  Vocabulary tags;
97 
98  const voc::FacetData* f = tags.facetData( "works-with" );
99  assert(f);
100  assert_eq(f->name, "works-with");
101 
102  const voc::TagData* t = tags.tagData( "works-with::people" );
103  assert(t);
104  assert_eq(t->name, "works-with::people");
105 }
106 
107  Test _7()
108 {
109  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
110  Vocabulary tags;
111 
112  const voc::FacetData* f = tags.facetData( "works-with" );
113  std::set<std::string> x = tags.tags( "works-with" );
114  assert( x == f->tags() );
115 }
116 
117  Test _8()
118 {
119  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
120  Vocabulary tags;
121 
122  const voc::FacetData* f = tags.facetData( "does-not-work-with" );
123  assert(!f);
124 }
125 
126  Test _9()
127 {
128  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
129  Vocabulary tags;
130 
131  const voc::FacetData* f = tags.facetData( "legacy" );
132  assert(f);
133  assert_eq(f->shortDescription(), "");
134  assert_eq(f->longDescription(), "");
135  //assert_eq(f.shortDescription( "weehee" ), "weehee");
136 }
137 
138  Test _10()
139 {
140  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
141  Vocabulary tags;
142 
143  // assert that one-character tag names are parsed correctly
144  assert( tags.hasTag( "implemented-in::c" ) );
145 }
146 
147  Test _11()
148 {
149  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
150  Vocabulary tags;
151 
152  // assert that all facets are somehow working
153  std::set<std::string> facets = tags.facets();
154 
155  for (std::set<std::string>::const_iterator i = facets.begin();
156  i != facets.end(); i++)
157  {
158  const voc::FacetData* f = tags.facetData(*i);
159  assert(f);
160  }
161 }
162 
163  Test _12()
164 {
165  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
166  Vocabulary voc;
167 
168  // assert that all tags are somehow working
169  std::set<std::string> tags = voc.tags();
170  for (std::set<std::string>::const_iterator i = tags.begin();
171  i != tags.end(); i++)
172  {
173  const voc::TagData* t = voc.tagData(*i);
174  assert(t);
175  }
176 }
177 
178 // Check for correctness of the first and last tag in the vocabulary
179  Test _13()
180 {
181  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
182  Vocabulary tags;
183 
184  const voc::TagData* first = tags.tagData("accessibility::TODO");
185  assert(first);
186  assert_eq(first->name, string("accessibility::TODO"));
187  assert_eq(first->shortDescription(), string("Need an extra tag"));
188 
189  const voc::TagData* last = tags.tagData("x11::xserver");
190  assert(last);
191  assert_eq(last->name, string("x11::xserver"));
192  assert_eq(last->shortDescription(), string("X Server"));
193 }
194 
195  Test _14()
196 {
197  EnvOverride eo("DEBTAGS_VOCABULARY", testfile);
198  Vocabulary tags;
199 
200  // check that we're seeing all the tags for a facet
201  std::set<std::string> t = tags.tags("accessibility");
202  assert_eq(t.size(), 10u);
203 
204  t = tags.tags("works-with-format");
205  assert_eq(t.size(), 33u);
206 }
207 
208 // If there is no data, Vocabulary should work as an empty vocabulary
209  Test _15()
210 {
211  EnvOverride eo("DEBTAGS_VOCABULARY", "./empty/novocabularyhere");
212  Vocabulary empty;
213 
214  assert(!empty.hasData());
215 
216  set<std::string> facets = empty.facets();
217  assert_eq(facets.size(), 0u);
218 
219  set<std::string> tags = empty.tags();
220  assert_eq(tags.size(), 0u);
221 }
222 
223 };
Test _6()
Definition: vocabulary.test.h:93
Definition: test.h:35
std::string name
Definition: vocabulary.h:53
Representation of a tag.
Definition: vocabulary.h:92
Test _4()
Definition: vocabulary.test.h:58
std::set< std::string > tags() const
Return the list of tags in this facet.
Definition: vocabulary.cc:85
std::set< std::string > tags() const
Return all the tags in the vocabulary.
Definition: vocabulary.cc:193
Test _14()
Definition: vocabulary.test.h:195
Test _3()
Definition: vocabulary.test.h:50
Definition: packagerecord.test.h:22
Test _12()
Definition: vocabulary.test.h:163
Definition: test.h:39
std::string shortDescription() const
Return the short description of the tag.
Definition: vocabulary.cc:51
Test _8()
Definition: vocabulary.test.h:117
Test _10()
Definition: vocabulary.test.h:138
Definition: debtags.cc:50
Definition: vocabulary.test.h:34
#define testfile
Definition: vocabulary.test.h:31
bool hasTag(const std::string &name) const
Check if the vocabulary contains the tag `fullname'.
Definition: vocabulary.cc:161
Test _13()
Definition: vocabulary.test.h:179
Test _7()
Definition: vocabulary.test.h:107
Test _11()
Definition: vocabulary.test.h:147
const voc::TagData * tagData(const std::string &fullname) const
Return the tag with the given full name.
Definition: vocabulary.cc:176
Definition: vocabulary.h:149
std::set< std::string > facets() const
Return all the facets in the vocabulary.
Definition: vocabulary.cc:184
Test _1()
Definition: vocabulary.test.h:36
Test _2()
Definition: vocabulary.test.h:42
bool hasFacet(const std::string &name) const
Check if the vocabulary contains the facet `name'.
Definition: vocabulary.cc:156
bool hasData() const
Return true if this data source has data, false if it's empty.
Definition: vocabulary.h:179
Test _5()
Definition: vocabulary.test.h:76
std::string longDescription() const
Return the long description of the tag.
Definition: vocabulary.cc:66
Test _15()
Definition: vocabulary.test.h:209
Test _9()
Definition: vocabulary.test.h:126
Representation of a facet.
Definition: vocabulary.h:122
const voc::FacetData * facetData(const std::string &name) const
Return the facet with the given name.
Definition: vocabulary.cc:168