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