LCOV - lcov.info - ept/popcon/popcon.test.h

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

           1                 : // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
           2                 : /*
           3                 :  * popcon test
           4                 :  *
           5                 :  * Copyright (C) 2007  Enrico Zini <enrico@debian.org>
           6                 :  *
           7                 :  * This program is free software; you can redistribute it and/or modify
           8                 :  * it under the terms of the GNU General Public License as published by
           9                 :  * the Free Software Foundation; either version 2 of the License, or
          10                 :  * (at your option) any later version.
          11                 :  *
          12                 :  * This program is distributed in the hope that it will be useful,
          13                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
          14                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
          15                 :  * GNU General Public License for more details.
          16                 :  *
          17                 :  * You should have received a copy of the GNU General Public License
          18                 :  * along with this program; if not, write to the Free Software
          19                 :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
          20                 :  */
          21                 :
          22                 : #include <ept/popcon/popcon.h>
          23                 : #include <ept/popcon/maint/path.h>
          24                 : #include <ept/apt/apt.h>
          25                 : #include <set>
          26                 :
          27                 : #include <ept/test.h>
          28                 :
          29                 : using namespace std;
          30                 : using namespace ept;
          31                 : using namespace ept::popcon;
          32                 : using namespace ept::apt;
          33                 :
          34                 : struct TestPopcon
          35               5 : {
          36                 :         popcon::Path::OverridePopconSourceDir odsd;
          37                 :         popcon::Path::OverridePopconIndexDir odid;
          38                 :         popcon::Path::OverridePopconUserSourceDir odusd;
          39                 :         popcon::Path::OverridePopconUserIndexDir oduid;
          40                 :
          41                 :         Apt apt;
          42                 :         Popcon popcon;
          43                 :
          44               5 :         TestPopcon()
          45                 :                 : odsd( TEST_ENV_DIR "popcon" ),
          46                 :                   odid( TEST_ENV_DIR "popcon" ),
          47                 :                   odusd( TEST_ENV_DIR "popcon" ),
          48               5 :                   oduid( TEST_ENV_DIR "popcon" )
          49               5 :         {}
          50                 :
          51               1 :         Test basicAccess()
          52                 :         {
          53               1 :                 assert_eq(popcon.submissions(), 52024);
          54               2 :                 assert(popcon.size() > 0);
          55               2 :                 assert(popcon.score(0) > 0);
          56               2 :                 assert(!popcon.name(0).empty());
          57               1 :         }
          58                 :
          59                 :     // Check that every valid index is accessible
          60               1 :         Test accessibility()
          61                 :         {
          62          139822 :                 for (size_t i = 0; i < popcon.size(); ++i)
          63                 :                 {
          64                 :                         //cerr << popcon.name(i) << " " << popcon.score(i) << endl;
          65           69910 :                         assert(popcon.score(i) > 0);
          66                 :                 }
          67               1 :         }
          68                 :
          69                 :         // Check that we can get a score for every package
          70               1 :         Test haveScores()
          71                 :         {
          72               1 :                 int has = 0;
          73            1789 :                 for (Apt::iterator i = apt.begin(); i != apt.end(); ++i)
          74                 :                 {
          75            1788 :                         float score = popcon.score(*i);
          76            1788 :                         if (score > 0)
          77            1758 :                                 ++has;
          78               1 :                 }
          79                 :                 // At least 1000 packages should have a score
          80               2 :                 assert(has > 1000);
          81               1 :         }
          82                 :
          83                 :     // Check that scores are meaningful
          84               1 :         Test validScores()
          85                 :         {
          86               1 :                 assert(popcon["apt"] > popcon["libapt-pkg-dev"]);
          87               1 :         }
          88                 :
          89                 :     // If there is no data, Popcon should work as if all scores were 0
          90               1 :         Test fallbackValues()
          91                 :         {
          92               1 :                 popcon::Path::OverridePopconSourceDir odsd("./empty");
          93               2 :                 popcon::Path::OverridePopconIndexDir odid("./empty");
          94               2 :                 popcon::Path::OverridePopconUserSourceDir odusd("./empty");
          95               2 :                 popcon::Path::OverridePopconUserIndexDir oduid("./empty");
          96               1 :                 Popcon empty;
          97                 :
          98               1 :                 assert_eq(empty.timestamp(), 0);
          99               2 :                 assert(!empty.hasData());
         100                 :
         101               2 :                 assert_eq(empty.submissions(), 0);
         102               2 :                 assert(empty.size() == 0);
         103               2 :                 assert(empty.score("apt") == 0.0);
         104               1 :         }
         105                 :
         106                 : };
         107                 :
         108                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6