Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <ept/debtags/debtags.h>
00029 #include <ept/core/apt.h>
00030
00031 #include <tagcoll/coll/simple.h>
00032 #include <tagcoll/stream/sink.h>
00033
00034 #include <wibble/operators.h>
00035
00036 #include <ept/test.h>
00037
00038 #include <stdio.h>
00039
00040 #ifndef EPT_DEBTAGS_TESTH
00041 #define EPT_DEBTAGS_TESTH
00042
00043 using namespace tagcoll;
00044 using namespace std;
00045 using namespace ept;
00046 using namespace ept::debtags;
00047 using namespace wibble::operators;
00048
00049 struct TestDebtags : DebtagsTestEnvironment
00050 {
00051 Debtags debtags;
00052
00053 TestDebtags() {}
00054
00055 Vocabulary& voc() { return debtags.vocabulary(); }
00056
00057 Test _1() {
00058 for (Debtags::const_iterator i = debtags.begin(); i != debtags.end(); ++i)
00059 {
00060 *i;
00061 i->first;
00062 i->second;
00063 }
00064 int items = 0, tags = 0;
00065 debtags.outputSystem(stream::countingSink(items, tags));
00066
00067 int pitems = 0, ptags = 0;
00068 debtags.outputPatched(stream::countingSink(pitems, ptags));
00069
00070 assert(items > 10);
00071 assert(tags > 10);
00072 assert(items <= pitems);
00073 assert(tags <= ptags);
00074 }
00075
00076 Test _2()
00077 {
00078 string p("debtags");
00079 std::set<Tag> tags = debtags.getTagsOfItem(p);
00080 assert( !tags.empty() );
00081
00082 #if 0
00083 for ( std::set< Tag >::iterator i = tags.begin(); i != tags.end(); ++ i ) {
00084 std::cerr << i->id() << ": " << i->fullname() << std::endl;
00085 }
00086 std::cerr << "---" << std::endl;
00087 Tag t = voc().tagByName( "interface::commandline" );
00088 std::cerr << t.id() << ": " << t.fullname() << std::endl;
00089 #endif
00090
00091 assert_eq( tags.size(), 8u );
00092 assert( voc().tagByName( "devel::buildtools" ) <= tags );
00093 assert( voc().tagByName( "implemented-in::c++" ) <= tags );
00094 assert( voc().tagByName( "interface::commandline" ) <= tags );
00095 assert( voc().tagByName( "role::program" ) <= tags );
00096 assert( voc().tagByName( "scope::application" ) <= tags );
00097 assert( voc().tagByName( "suite::debian" ) <= tags );
00098 assert( voc().tagByName( "use::searching" ) <= tags );
00099 assert( voc().tagByName( "works-with::software:package" ) <= tags );
00100 }
00101
00102 Test _3()
00103 {
00104 using namespace std;
00105
00106
00107 string p("debtags");
00108
00109
00110 std::set<Tag> tags = debtags.getTagsOfItem(p);
00111 assert(!tags.empty());
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 std::set<string> packages = debtags.getItemsHavingTags(tags);
00155
00156 assert(!packages.empty());
00157
00158
00159
00160
00161
00162
00163
00164 assert( p <= packages );
00165
00166
00167 Tag tag = *tags.begin();
00168 assert(tag);
00169
00170
00171 {
00172
00173
00174
00175 std::set<Tag> ts;
00176 ts.insert(tag);
00177 packages = debtags.getItemsHavingTags(ts);
00178 }
00179
00180 assert(!packages.empty());
00181
00182 assert( p <= packages );
00183
00184
00185 }
00186
00187 Test _4()
00188 {
00189 std::string patchfile = Path::debtagsUserSourceDir() + "patch";
00190 unlink(patchfile.c_str());
00191
00192 string p("debtags");
00193
00194
00195 std::set<Tag> tags = debtags.getTagsOfItem(p);
00196 assert(!tags.empty());
00197
00198
00199 Tag t = voc().tagByName("use::gameplaying");
00200 assert(! (t <= tags) );
00201
00202
00203 PatchList<string, Tag> change;
00204 change.addPatch(Patch<string, Tag>(p, wibble::singleton(t), wibble::Empty<Tag>()));
00205 debtags.applyChange(change);
00206
00207
00208 PatchList<string, Tag> tmp = debtags.changes();
00209 assert(tmp.size() > 0);
00210 assert_eq(tmp.size(), 1u);
00211
00212
00213 tags = debtags.getTagsOfItem(p);
00214 assert(!tags.empty());
00215
00216 t = voc().tagByName("use::gameplaying");
00217 assert( t <= tags );
00218
00219
00220 debtags.savePatch();
00221
00222
00223 FILE* in = fopen(patchfile.c_str(), "r");
00224 string writtenPatch;
00225 int c;
00226 while ((c = getc(in)) != EOF)
00227 writtenPatch += c;
00228 fclose(in);
00229
00230 assert_eq(writtenPatch, string("debtags: +use::gameplaying\n"));
00231
00232 unlink(patchfile.c_str());
00233
00234
00235 debtags.applyChange(change);
00236
00237
00238 tmp = debtags.changes();
00239 assert_eq(tmp.size(), 1u);
00240 assert_eq(tmp.begin()->first, p);
00241 assert_eq(tmp.begin()->second.item, p);
00242 }
00243
00244
00245 Test _5()
00246 {
00247 Path::OverrideDebtagsSourceDir odsd("./empty");
00248 Path::OverrideDebtagsIndexDir odid("./empty");
00249 Path::OverrideDebtagsUserSourceDir odusd("./empty");
00250 Path::OverrideDebtagsUserIndexDir oduid("./empty");
00251 Debtags empty;
00252
00253 assert(empty.begin() == empty.end());
00254 assert_eq(empty.timestamp(), 0);
00255 assert(!empty.hasData());
00256
00257 tagcoll::PatchList<std::string, Tag> patches = empty.changes();
00258 assert(patches.empty());
00259
00260 set<Tag> res = empty.getTagsOfItem("apt");
00261 assert(res.empty());
00262 res = empty.getTagsOfItems(wibble::singleton(string("apt")));
00263 assert(res.empty());
00264
00265 res = empty.getAllTags();
00266 assert(res.empty());
00267
00268 tagcoll::coll::Simple<string, Tag> coll;
00269 empty.outputSystem(tagcoll::coll::inserter(coll));
00270 assert_eq(coll.itemCount(), 0u);
00271
00272 coll.clear();
00273
00274 empty.outputPatched(tagcoll::coll::inserter(coll));
00275 assert_eq(coll.itemCount(), 0u);
00276 }
00277
00278 };
00279
00280 #include <ept/debtags/debtags.tcc>
00281 #include <tagcoll/coll/simple.tcc>
00282
00283 #endif
00284
00285