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

serializer.test.h

Go to the documentation of this file.
00001 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
00007 /*
00008  * Tests for Debtags serialization filters
00009  *
00010  * Copyright (C) 2003-2007  Enrico Zini <enrico@debian.org>
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2.1 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00025  */
00026 
00027 #include <ept/debtags/maint/serializer.h>
00028 #include <ept/debtags/maint/pkgid.h>
00029 #include <ept/debtags/maint/path.h>
00030 #include <ept/debtags/vocabulary.h>
00031 #include <ept/debtags/debtags.h>
00032 
00033 #include <tagcoll/coll/simple.h>
00034 
00035 #include <wibble/singleton.h>
00036 
00037 #include <ept/test.h>
00038 
00039 using namespace std;
00040 using namespace tagcoll;
00041 using namespace ept;
00042 using namespace ept::debtags;
00043 
00044 struct TestSerializer : DebtagsTestEnvironment
00045 {
00046     Debtags debtags;
00047     Vocabulary& voc;
00048     PkgId& pkgid;
00049 
00050     TestSerializer()
00051         : voc(debtags.vocabulary()), pkgid(debtags.pkgid()) {}
00052 
00053 /* Test going from a stream of tag data <string, string> to a stream of tag
00054  * data <int, int> to a stream of tag data <Package, Tag> and finally back to a
00055  * stream of tag data <string, string>
00056  */
00057     Test _1()
00058 {
00059     // Source data <string, string>
00060     coll::Simple<string, string> source;
00061     source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("use::editing")));
00062     source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("role::program")));
00063 
00064     // <string, string> -> <int, int>
00065     coll::Simple<int, int> dest;
00066     source.output(stringToInt(pkgid, voc, inserter(dest)));
00067 
00068     assert_eq(dest.itemCount(), 1u);
00069     assert_eq(dest.tagCount(), 2u);
00070 
00071     // <int, int> -> <Package, Tag>
00072     coll::Simple<string, Tag> dest1;
00073     dest.output(intToPkg(pkgid, voc, inserter(dest1)));
00074 
00075     assert_eq(dest1.itemCount(), 1u);
00076     assert_eq(dest1.tagCount(), 2u);
00077 
00078     std::set<Tag> tags = dest1.getTagsOfItem("debtags");
00079     assert_eq(tags.size(), 2u);
00080 
00081     Tag useEditing = voc.tagByName("use::editing");
00082     Tag roleProgram = voc.tagByName("role::program");
00083 
00084     assert(tags.find(useEditing) != tags.end());
00085     assert(tags.find(roleProgram) != tags.end());
00086 
00087     // <Package, Tag> -> <string, string>
00088     coll::Simple<string, string> dest2;
00089     dest1.output(pkgToString(inserter(dest2)));
00090 
00091     assert_eq(dest2.itemCount(), 1u);
00092     assert_eq(dest2.tagCount(), 2u);
00093 
00094     std::set<std::string> tags1 = dest2.getTagsOfItem("debtags");
00095     assert_eq(tags1.size(), 2u);
00096 
00097     assert(tags1.find("use::editing") != tags1.end());
00098     assert(tags1.find("role::program") != tags1.end());
00099 }
00100 
00101 /* Test going from patch with strings to patch with ints and vice versa */
00102     Test _2()
00103 {
00104     PatchList<string, string> change;
00105     change.addPatch(Patch<string, string>("debtags",
00106                 wibble::singleton(string("use::gameplaying")),
00107                 wibble::singleton(string("use::editing"))));
00108 
00109     // Deserialise to ints
00110     PatchList<int, int> intChange;
00111     change.output(patchStringToInt(pkgid, voc, tagcoll::inserter(intChange)));
00112     assert_eq(intChange.size(), 1u);
00113     assert_eq(intChange.begin()->second.added.size(), 1u);
00114     assert_eq(intChange.begin()->second.removed.size(), 1u);
00115     
00116     // Serialise back to strings
00117     PatchList<string, string> change1;
00118     intChange.output(patchIntToString(pkgid, voc, tagcoll::inserter(change1)));
00119     assert_eq(change1.size(), 1u);
00120     assert_eq(change1.begin()->first, string("debtags"));
00121     assert_eq(change1.begin()->second.item, string("debtags"));
00122     assert_eq(change1.begin()->second.added.size(), 1u);
00123     assert_eq(*change1.begin()->second.added.begin(), string("use::gameplaying"));
00124     assert_eq(change1.begin()->second.removed.size(), 1u);
00125     assert_eq(*change1.begin()->second.removed.begin(), string("use::editing"));
00126 }
00127 
00128 };
00129 
00130 #include <tagcoll/coll/simple.tcc>
00131 #include <tagcoll/patch.tcc>
00132 
00133 // vim:set ts=4 sw=4:

Generated on Fri Aug 19 2016 15:05:45 for libept by  doxygen 1.7.1