00001 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*- 00002 /* 00003 * popcon test 00004 * 00005 * Copyright (C) 2007 Enrico Zini <enrico@debian.org> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include <ept/popcon/popcon.h> 00023 #include <ept/popcon/maint/path.h> 00024 #include <ept/apt/apt.h> 00025 #include <set> 00026 00027 #include <ept/test.h> 00028 00029 using namespace std; 00030 using namespace ept; 00031 using namespace ept::popcon; 00032 using namespace ept::apt; 00033 00034 struct TestPopcon 00035 { 00036 popcon::Path::OverridePopconSourceDir odsd; 00037 popcon::Path::OverridePopconIndexDir odid; 00038 popcon::Path::OverridePopconUserSourceDir odusd; 00039 popcon::Path::OverridePopconUserIndexDir oduid; 00040 00041 Apt apt; 00042 Popcon popcon; 00043 00044 TestPopcon() 00045 : odsd( TEST_ENV_DIR "popcon" ), 00046 odid( TEST_ENV_DIR "popcon" ), 00047 odusd( TEST_ENV_DIR "popcon" ), 00048 oduid( TEST_ENV_DIR "popcon" ) 00049 {} 00050 00051 Test basicAccess() 00052 { 00053 assert_eq(popcon.submissions(), 52024); 00054 assert(popcon.size() > 0); 00055 assert(popcon.score(0) > 0); 00056 assert(!popcon.name(0).empty()); 00057 } 00058 00059 // Check that every valid index is accessible 00060 Test accessibility() 00061 { 00062 for (size_t i = 0; i < popcon.size(); ++i) 00063 { 00064 //cerr << popcon.name(i) << " " << popcon.score(i) << endl; 00065 assert(popcon.score(i) > 0); 00066 } 00067 } 00068 00069 // Check that we can get a score for every package 00070 Test haveScores() 00071 { 00072 int has = 0; 00073 for (Apt::iterator i = apt.begin(); i != apt.end(); ++i) 00074 { 00075 float score = popcon.score(*i); 00076 if (score > 0) 00077 ++has; 00078 } 00079 // At least 1000 packages should have a score 00080 assert(has > 1000); 00081 } 00082 00083 // Check that scores are meaningful 00084 Test validScores() 00085 { 00086 assert(popcon["apt"] > popcon["libapt-pkg-dev"]); 00087 } 00088 00089 // If there is no data, Popcon should work as if all scores were 0 00090 Test fallbackValues() 00091 { 00092 popcon::Path::OverridePopconSourceDir odsd("./empty"); 00093 popcon::Path::OverridePopconIndexDir odid("./empty"); 00094 popcon::Path::OverridePopconUserSourceDir odusd("./empty"); 00095 popcon::Path::OverridePopconUserIndexDir oduid("./empty"); 00096 Popcon empty; 00097 00098 assert_eq(empty.timestamp(), 0); 00099 assert(!empty.hasData()); 00100 00101 assert_eq(empty.submissions(), 0); 00102 assert(empty.size() == 0); 00103 assert(empty.score("apt") == 0.0); 00104 } 00105 00106 }; 00107 00108 // vim:set ts=4 sw=4: