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

vocabulary.test.h

Go to the documentation of this file.
00001 /*
00002  * Tag vocabulary access
00003  *
00004  * Copyright (C) 2003--2007  Enrico Zini <enrico@debian.org>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #include <wibble/test.h>
00022 #include <ept/debtags/vocabulary.h>
00023 #include <ept/debtags/maint/path.h>
00024 #include <tagcoll/utils/set.h>
00025 #include <tagcoll/input/stdio.h>
00026 
00027 #include "ept/test.h"
00028 
00029 using namespace std;
00030 using namespace tagcoll::utils;
00031 using namespace ept::debtags;
00032 
00033 struct TestVocabulary : DebtagsTestEnvironment
00034 {
00035     Vocabulary  m_tags;
00036     Vocabulary& tags() { return m_tags; }
00037 
00038         Test _1()
00039 {
00040     tags(); // this will throw if the open above didn't work
00041 }
00042 
00043         Test _2()
00044 {
00045     assert( tags().hasFacet( "works-with" ) );
00046     assert( !tags().hasFacet( "blah" ) );
00047 }
00048 
00049         Test _3()
00050 {
00051     assert( tags().hasTag( "works-with::people" ) );
00052     assert( !tags().hasTag( "works-with::midgets" ) );
00053 }
00054 
00055         Test _4()
00056 {
00057     const voc::TagData *people = tags().tagData( "works-with::people" ),
00058                        *midgets = tags().tagData( "works-with::midgets" ),
00059                        *blahg = tags().tagData( "works-with::blahg" ),
00060                        *text = tags().tagData( "works-with::text" ),
00061                        *people2 = tags().tagData( "works-with::people" );
00062     assert( people != midgets );
00063     assert( people != text );
00064     assert( people != blahg );
00065     assert( midgets == blahg );
00066     assert( midgets == midgets );
00067     assert( people == people2 );
00068     assert( people == people );
00069 }
00070 
00071         Test _5()
00072 {
00073     std::string a = "works-with::people",
00074                 b = "works-with::midgets";
00075     std::set<std::string> s = tags().tags(),
00076                           f = tags().tags( "works-with" ),
00077                           n = tags().tags( "nonsense" );
00078     assert( set_contains(s, a) );
00079     assert( set_contains(f, a) );
00080     assert( set_contains(s, f) );
00081     assert( !set_contains(s, b) );
00082     assert( !set_contains(f, b) );
00083     assert( n.empty() );
00084 }
00085 
00086         Test _6()
00087 {
00088     const voc::FacetData* f = tags().facetData( "works-with" );
00089     assert(f);
00090     assert_eq(f->name, "works-with");
00091 
00092     const voc::TagData* t = tags().tagData( "works-with::people" );
00093     assert(t);
00094     assert_eq(t->name, "works-with::people");
00095 }
00096 
00097         Test _7()
00098 {
00099     const voc::FacetData* f = tags().facetData( "works-with" );
00100     std::set<std::string> x = tags().tags( "works-with" );
00101     assert( x == f->tags() );
00102 }
00103 
00104         Test _8()
00105 {
00106     const voc::FacetData* f = tags().facetData( "does-not-work-with" );
00107     assert(!f);
00108 }
00109 
00110         Test _9()
00111 {
00112     const voc::FacetData* f = tags().facetData( "legacy" );
00113     assert(f);
00114     assert_eq(f->shortDescription(), "");
00115     assert_eq(f->longDescription(), "");
00116     //assert_eq(f.shortDescription( "weehee" ), "weehee");
00117 }
00118 
00119         Test _10()
00120 {
00121     // assert that one-character tag names are parsed correctly
00122     assert( tags().hasTag( "implemented-in::c" ) );
00123 }
00124 
00125         Test _11()
00126 {
00127     // assert that all facets are somehow working
00128     std::set<std::string> facets = tags().facets();
00129 
00130     for (std::set<std::string>::const_iterator i = facets.begin();
00131             i != facets.end(); i++)
00132     {
00133         const voc::FacetData* f = tags().facetData(*i);
00134         assert(f);
00135     }
00136 }
00137 
00138         Test _12()
00139 {
00140     // assert that all tags are somehow working
00141     std::set<std::string> tags = this->tags().tags();
00142     for (std::set<std::string>::const_iterator i = tags.begin();
00143             i != tags.end(); i++)
00144     {
00145         const voc::TagData* t = this->tags().tagData(*i);
00146         assert(t);
00147     }
00148 }
00149 
00150 // Check for correctness of the first and last tag in the vocabulary
00151         Test _13()
00152 {
00153     Vocabulary& tags = this->tags();
00154 
00155     const voc::TagData* first = tags.tagData("accessibility::TODO");
00156     assert(first);
00157     assert_eq(first->name, string("accessibility::TODO"));
00158     assert_eq(first->shortDescription(), string("Need an extra tag"));
00159 
00160     const voc::TagData* last = tags.tagData("x11::xserver");
00161     assert(last);
00162     assert_eq(last->name, string("x11::xserver"));
00163     assert_eq(last->shortDescription(), string("X Server"));
00164 }
00165 
00166         Test _14()
00167 {
00168     // assert that it's possible to go from facet to ID and back
00169     // we don't use IDs anymore
00170 }
00171 
00172         Test _15()
00173 {
00174     // assert that it's possible to go from tag to ID and back
00175     // we don't use IDs anymore
00176 }
00177 
00178         Test _16()
00179 {
00180     // assert that facet IDs are distinct
00181     // we don't use IDs anymore
00182 }
00183 
00184         Test _17()
00185 {
00186     // assert that tag IDs are distinct
00187     // we don't use IDs anymore
00188 }
00189 
00190         Test _18()
00191 {
00192     // assert that all the tags are indexed
00193     // we don't use the index anymore
00194 }
00195 
00196         Test _19()
00197 {
00198     // test the tagcmp function
00199     // we don't have tagcmp anymore
00200 }
00201 
00202         Test _20()
00203 {
00204     // check that we're seeing all the tags for a facet
00205     std::set<std::string> t = tags().tags("accessibility");
00206     assert_eq(t.size(), 10u);
00207 
00208     t = tags().tags("works-with-format");
00209     assert_eq(t.size(), 33u);
00210 }
00211 
00212 // If there is no data, Vocabulary should work as an empty vocabulary
00213         Test _21()
00214 {
00215     Path::OverrideDebtagsSourceDir odsd("./empty");
00216     Path::OverrideDebtagsIndexDir odid("./empty");
00217     Path::OverrideDebtagsUserSourceDir odusd("./empty");
00218     Path::OverrideDebtagsUserIndexDir oduid("./empty");
00219     Vocabulary empty;
00220 
00221     assert(!empty.hasData());
00222 
00223     set<std::string> facets = empty.facets();
00224     assert_eq(facets.size(), 0u);
00225 
00226     set<std::string> tags = empty.tags();
00227     assert_eq(tags.size(), 0u);
00228 }
00229 
00230 };
00231 
00232 // vim:set ts=4 sw=4:

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