LTP GCOV extension - code coverage report
Current view: directory - ept/debtags/maint - serializer.test.h
Test: lcov.info
Date: 2008-08-14 Instrumented lines: 48
Code covered: 100.0 % Executed lines: 48

       1                 : // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
       2                 : /**
       3                 :  * @file
       4                 :  * @author Enrico Zini (enrico) <enrico@enricozini.org>
       5                 :  */
       6                 : 
       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                 : 
      27                 : #include <ept/debtags/maint/serializer.h>
      28                 : #include <ept/debtags/maint/pkgid.h>
      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                 : 
      44                 : struct TestSerializer : DebtagsTestEnvironment
      45               2 : {
      46                 :         Debtags debtags;
      47                 :         Vocabulary& voc;
      48                 :         PkgId& pkgid;
      49                 : 
      50               2 :         TestSerializer()
      51               2 :                 : 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               1 :         Test _1()
      58                 : {
      59                 :         // Source data <string, string>
      60               1 :         coll::Simple<string, string> source;
      61               1 :         source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("use::editing")));
      62               2 :         source.insert(wibble::singleton(string("debtags")), wibble::singleton(string("role::program")));
      63                 : 
      64                 :         // <string, string> -> <int, int>
      65               1 :         coll::Simple<int, int> dest;
      66               1 :         source.output(stringToInt(pkgid, voc, inserter(dest)));
      67                 : 
      68               1 :         assert_eq(dest.itemCount(), 1u);
      69               2 :         assert_eq(dest.tagCount(), 2u);
      70                 : 
      71                 :         // <int, int> -> <Package, Tag>
      72               1 :         coll::Simple<string, Tag> dest1;
      73               1 :         dest.output(intToPkg(pkgid, voc, inserter(dest1)));
      74                 : 
      75               1 :         assert_eq(dest1.itemCount(), 1u);
      76               2 :         assert_eq(dest1.tagCount(), 2u);
      77                 : 
      78               2 :         std::set<Tag> tags = dest1.getTagsOfItem("debtags");
      79               2 :         assert_eq(tags.size(), 2u);
      80                 : 
      81               2 :         Tag useEditing = voc.tagByName("use::editing");
      82               2 :         Tag roleProgram = voc.tagByName("role::program");
      83                 : 
      84               2 :         assert(tags.find(useEditing) != tags.end());
      85               2 :         assert(tags.find(roleProgram) != tags.end());
      86                 : 
      87                 :         // <Package, Tag> -> <string, string>
      88               1 :         coll::Simple<string, string> dest2;
      89               1 :         dest1.output(pkgToString(inserter(dest2)));
      90                 : 
      91               1 :         assert_eq(dest2.itemCount(), 1u);
      92               2 :         assert_eq(dest2.tagCount(), 2u);
      93                 : 
      94               2 :         std::set<std::string> tags1 = dest2.getTagsOfItem("debtags");
      95               2 :         assert_eq(tags1.size(), 2u);
      96                 : 
      97               2 :         assert(tags1.find("use::editing") != tags1.end());
      98               2 :         assert(tags1.find("role::program") != tags1.end());
      99               1 : }
     100                 : 
     101                 : /* Test going from patch with strings to patch with ints and vice versa */
     102               1 :         Test _2()
     103                 : {
     104               1 :         PatchList<string, string> change;
     105                 :         change.addPatch(Patch<string, string>("debtags",
     106                 :                                 wibble::singleton(string("use::gameplaying")),
     107               1 :                                 wibble::singleton(string("use::editing"))));
     108                 : 
     109                 :         // Deserialise to ints
     110               1 :         PatchList<int, int> intChange;
     111               1 :         change.output(patchStringToInt(pkgid, voc, tagcoll::inserter(intChange)));
     112               1 :         assert_eq(intChange.size(), 1u);
     113               2 :         assert_eq(intChange.begin()->second.added.size(), 1u);
     114               2 :         assert_eq(intChange.begin()->second.removed.size(), 1u);
     115                 :         
     116                 :         // Serialise back to strings
     117               1 :         PatchList<string, string> change1;
     118               1 :         intChange.output(patchIntToString(pkgid, voc, tagcoll::inserter(change1)));
     119               1 :         assert_eq(change1.size(), 1u);
     120               2 :         assert_eq(change1.begin()->first, string("debtags"));
     121               2 :         assert_eq(change1.begin()->second.item, string("debtags"));
     122               2 :         assert_eq(change1.begin()->second.added.size(), 1u);
     123               2 :         assert_eq(*change1.begin()->second.added.begin(), string("use::gameplaying"));
     124               2 :         assert_eq(change1.begin()->second.removed.size(), 1u);
     125               2 :         assert_eq(*change1.begin()->second.removed.begin(), string("use::editing"));
     126               1 : }
     127                 : 
     128                 : };
     129                 : 
     130                 : #include <tagcoll/coll/simple.tcc>
     131                 : #include <tagcoll/patch.tcc>
     132                 : 
     133                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6