libept  0.5.25
serializer.test.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
7 /*
8  * Tests for Debtags serialization filters
9  *
10  * Copyright (C) 2003-2007 Enrico Zini <enrico@debian.org>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  */
26 
29 #include <ept/debtags/maint/path.h>
30 #include <ept/debtags/vocabulary.h>
31 #include <ept/debtags/debtags.h>
32 
33 #include <tagcoll/coll/simple.h>
34 
35 #include <wibble/singleton.h>
36 
37 #include <ept/test.h>
38 
39 using namespace std;
40 using namespace tagcoll;
41 using namespace ept;
42 using namespace ept::debtags;
43 
45 {
49 
51  : voc(debtags.vocabulary()), pkgid(debtags.pkgid()) {}
52 
53 /* Test going from a stream of tag data <string, string> to a stream of tag
54  * data <int, int> to a stream of tag data <Package, Tag> and finally back to a
55  * stream of tag data <string, string>
56  */
57  Test _1()
58 {
59  // Source data <string, string>
60  coll::Simple<string, string> source;
61  source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("use::editing")));
62  source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("role::program")));
63 
64  // <string, string> -> <int, int>
65  coll::Simple<int, int> dest;
66  source.output(stringToInt(pkgid, voc, inserter(dest)));
67 
68  assert_eq(dest.itemCount(), 1u);
69  assert_eq(dest.tagCount(), 2u);
70 
71  // <int, int> -> <Package, Tag>
72  coll::Simple<string, Tag> dest1;
73  dest.output(intToPkg(pkgid, voc, inserter(dest1)));
74 
75  assert_eq(dest1.itemCount(), 1u);
76  assert_eq(dest1.tagCount(), 2u);
77 
78  std::set<Tag> tags = dest1.getTagsOfItem("debtags");
79  assert_eq(tags.size(), 2u);
80 
81  Tag useEditing = voc.tagByName("use::editing");
82  Tag roleProgram = voc.tagByName("role::program");
83 
84  assert(tags.find(useEditing) != tags.end());
85  assert(tags.find(roleProgram) != tags.end());
86 
87  // <Package, Tag> -> <string, string>
88  coll::Simple<string, string> dest2;
89  dest1.output(pkgToString(inserter(dest2)));
90 
91  assert_eq(dest2.itemCount(), 1u);
92  assert_eq(dest2.tagCount(), 2u);
93 
94  std::set<std::string> tags1 = dest2.getTagsOfItem("debtags");
95  assert_eq(tags1.size(), 2u);
96 
97  assert(tags1.find("use::editing") != tags1.end());
98  assert(tags1.find("role::program") != tags1.end());
99 }
100 
101 /* Test going from patch with strings to patch with ints and vice versa */
102  Test _2()
103 {
105  change.addPatch(Patch<string, string>("debtags",
106  wibble::singleton(string("use::gameplaying")),
107  wibble::singleton(string("use::editing"))));
108 
109  // Deserialise to ints
110  PatchList<int, int> intChange;
111  change.output(patchStringToInt(pkgid, voc, tagcoll::inserter(intChange)));
112  assert_eq(intChange.size(), 1u);
113  assert_eq(intChange.begin()->second.added.size(), 1u);
114  assert_eq(intChange.begin()->second.removed.size(), 1u);
115 
116  // Serialise back to strings
118  intChange.output(patchIntToString(pkgid, voc, tagcoll::inserter(change1)));
119  assert_eq(change1.size(), 1u);
120  assert_eq(change1.begin()->first, string("debtags"));
121  assert_eq(change1.begin()->second.item, string("debtags"));
122  assert_eq(change1.begin()->second.added.size(), 1u);
123  assert_eq(*change1.begin()->second.added.begin(), string("use::gameplaying"));
124  assert_eq(change1.begin()->second.removed.size(), 1u);
125  assert_eq(*change1.begin()->second.removed.begin(), string("use::editing"));
126 }
127 
128 };
129 
130 #include <tagcoll/coll/simple.tcc>
131 #include <tagcoll/patch.tcc>
132 
133 // vim:set ts=4 sw=4:
Definition: test.h:24
Test _1()
Definition: serializer.test.h:57
Debtags debtags
Definition: serializer.test.h:46
TestSerializer()
Definition: serializer.test.h:50
PatchStringToInt< OUT > patchStringToInt(PkgId &pkgid, Vocabulary &voc, const OUT &out)
Definition: serializer.h:232
Vocabulary & voc
Definition: serializer.test.h:47
Definition: packagerecord.test.h:22
debtags paths
-*- C++ -*- (c) 2006, 2007 Petr Rockai me@mornfall.net
Definition: apt.cc:43
PatchIntToString< OUT > patchIntToString(PkgId &pkgid, Vocabulary &voc, const OUT &out)
Definition: serializer.h:276
Access the on-disk Debtags tag database.
Definition: debtags.h:75
Definition: debtags.h:44
Definition: debtags.cc:53
PkgToString< OUT > pkgToString(const OUT &out)
Definition: serializer.h:188
Representation of a tag.
Definition: tag.h:163
Test _2()
Definition: serializer.test.h:102
StringToInt< OUT > stringToInt(PkgId &pkgid, Vocabulary &voc, const OUT &out)
Definition: serializer.h:111
Maps Packages to IDs and vice-versa.
Definition: pkgid.h:40
Definition: vocabulary.h:37
Definition: debtags.h:43
IntToPkg< OUT > intToPkg(PkgId &pkgid, Vocabulary &voc, const OUT &out)
Definition: serializer.h:62
Tag tagByName(const std::string &fullname) const
Return the tag with the given full name.
Definition: vocabulary.h:203
Definition: serializer.test.h:44
PkgId & pkgid
Definition: serializer.test.h:48