// sanity_check_universe.h -*-c++-*- // // Copyright (C) 2007-2009 Daniel Burrows // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. #include #include #include "problemresolver.h" #include "solution.h" /** \file sanity_check_universe.h */ /** Check that forward/reverse linkages in a package universe * are correct, and spit errors to stdout if not. * * Tests that: * - For each package, each version of that package links * back to the package. * - For each package, the package's "current version" occurs * in its version list. * - For each version, the version is the source of all its * forward dependencies. * - For each version of each package, and each reverse * dependency of that version, some version of that package * occurs in the solvers list. * - For each version of each package, each dependency and * reverse dependency of the version occur in the global * dependency list. (TODO: unimplemented) * - Each dependency in the universe occurs in its * source version's dependency list. * - For each dependency in the universe, solved_by() returns * \b true for all its solvers and all other versions of its * source, and \b false for all other package versions. * - Each dependency in the universe, for each of its solvers, * appears either in that solver's reverse dependency list * or in the reverse dependency list of EACH version of * that same package that is not a solver of the dependency. * - Each broken dependency is broken in an empty solution. */ template void sanity_check_universe(const PackageUniverse &universe) { typedef typename PackageUniverse::package package; typedef typename PackageUniverse::version version; typedef typename PackageUniverse::dep dep; typedef typename PackageUniverse::package_iterator package_iterator; typedef typename PackageUniverse::dep_iterator dep_iterator; typedef typename PackageUniverse::broken_dep_iterator broken_dep_iterator; std::set seenRevDeps, seenDeps; std::set seenPkgs; std::set seenVers; for(package_iterator pIt = universe.packages_begin(); !pIt.end(); ++pIt) { seenPkgs.insert(*pIt); for(typename package::version_iterator vIt = (*pIt).versions_begin(); !vIt.end(); ++vIt) { seenVers.insert(*vIt); } } for(package_iterator pIt = universe.packages_begin(); !pIt.end(); ++pIt) { for(typename package::version_iterator vIt = (*pIt).versions_begin(); !vIt.end(); ++vIt) { for(typename version::dep_iterator dIt = (*vIt).deps_begin(); !dIt.end(); ++dIt) { if((*dIt).get_source() != *vIt) { std::cout << "Error: " << *dIt << " is a forward dep of a different version " << *vIt << std::endl; } for(typename dep::solver_iterator sIt = (*dIt).solvers_begin(); !sIt.end(); ++sIt) { if(seenVers.find(*sIt) == seenVers.end()) std::cout << "Error: " << *sIt << " exists as a solver of " << *dIt << " but is not a member of the global version list." << std::endl; } seenDeps.insert(*dIt); if((*dIt).get_source() != (*vIt)) { std::cout << "Error: " << (*dIt) << " belongs to the forward dependency list of " << (*vIt) <::const_iterator it = seenDeps.begin(); it != seenDeps.end(); ++it) { std::cout << "Error: " << (*it) << " is contained in a package dep list but not the global dep list." << std::endl; } for(typename std::set::const_iterator it = seenRevDeps.begin(); it != seenRevDeps.end(); ++it) { std::cout << "Error: " << (*it) << " is contained in a package reverse dep list but not the global dep list." << std::endl; } resolver_initial_state initial_state(imm::map(), universe.get_package_count()); for(broken_dep_iterator bdIt = universe.broken_begin(); !bdIt.end(); ++bdIt) { if(!(*bdIt).broken_under(initial_state)) { std::cout << "Error: " << (*bdIt) <<" is in the broken dep list but isn't broken in the empty solution." << std::endl; } } }