repositories from the server side.
- Fix priority not being set on reading service indexes
ADD_TESTS( ProductFileReader )
ADD_TESTS( RepoFileReader )
+ADD_TESTS( RepoindexFileReader )
--- /dev/null
+#include <sstream>
+#include <string>
+#include <zypp/Pathname.h>
+#include <zypp/parser/RepoindexFileReader.h>
+#include <zypp/base/NonCopyable.h>
+
+#include "TestSetup.h"
+
+using std::stringstream;
+using std::string;
+using namespace zypp;
+
+static string service = "<repoindex>"
+ "<repo alias=\"company-foo\" name=\"Company's Foo\""
+ " path=\"products/foo\" distro_target=\"sle-11-i386\" priority=\"20\"/>"
+ "<repo alias=\"company-bar\" name=\"Company's Bar\""
+ " path=\"products/bar\" distro_target=\"sle-11-i386\" enabled=\"true\"/>"
+ "<repo alias=\"company-foo-upd\" name=\"Company's Foo Updates\""
+ " path=\"products/foo/updates\" distro_target=\"sle-11-i386\" priority=\"1\"/>"
+ "</repoindex>";
+
+struct RepoCollector : private base::NonCopyable
+{
+ bool collect( const RepoInfo &repo )
+ {
+ repos.push_back(repo);
+ return true;
+ }
+
+ RepoInfoList repos;
+};
+
+// Must be the first test!
+BOOST_AUTO_TEST_CASE(read_index_file)
+{
+ {
+ stringstream input(service);
+ RepoCollector collector;
+ parser::RepoindexFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
+ BOOST_REQUIRE_EQUAL(3, collector.repos.size());
+
+ RepoInfo repo;
+ repo = collector.repos.front();
+
+ BOOST_CHECK_EQUAL("Company's Foo", repo.name());
+ BOOST_CHECK_EQUAL("company-foo", repo.alias());
+ BOOST_CHECK_EQUAL("sle-11-i386", repo.targetDistribution());
+ BOOST_CHECK_EQUAL(20, repo.priority());
+ BOOST_CHECK_EQUAL("/repo/products/foo", repo.path());
+
+ collector.repos.pop_front( );
+ repo = collector.repos.front();
+
+ BOOST_CHECK_EQUAL("company-bar", repo.alias());
+ BOOST_CHECK_EQUAL("sle-11-i386", repo.targetDistribution());
+ // "Priority should be 99 when not explictly defined"
+ BOOST_CHECK_EQUAL(99, repo.priority());
+ // "Repository is explicitly enabled"
+ BOOST_CHECK(repo.enabled());
+
+
+ }
+}
#include "zypp/base/String.h"
#include "zypp/base/Logger.h"
#include "zypp/base/Gettext.h"
+#include "zypp/base/InputStream.h"
+
#include "zypp/Pathname.h"
#include "zypp/parser/xml/Reader.h"
*
* \see RepoindexFileReader::RepoindexFileReader(Pathname,ProcessResource)
*/
- Impl(const Pathname &repoindex_file, const ProcessResource & callback);
+ Impl(const InputStream &is, const ProcessResource & callback);
/**
* Callback provided to the XML parser.
};
///////////////////////////////////////////////////////////////////////
- RepoindexFileReader::Impl::Impl(
- const Pathname &repoindex_file, const ProcessResource & callback)
+ RepoindexFileReader::Impl::Impl(const InputStream &is,
+ const ProcessResource & callback)
: _callback(callback)
{
- Reader reader( repoindex_file );
- MIL << "Reading " << repoindex_file << endl;
+ Reader reader( is );
+ MIL << "Reading " << is.path() << endl;
reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) );
}
RepoInfo info;
+ // enabled or disabled is controlled by the
+ // reposToEnable/Disable list, unless the
+ // enabled attribute is set
+ info.setEnabled(false);
+
// url and/or path
string url_s;
s = reader_r->getAttribute("url");
if (s.get())
info.setTargetDistribution(s.asString());
+ // optional priority
+ s = reader_r->getAttribute("priority");
+ if (s.get()) {
+ info.setPriority(str::strtonum<unsigned>(s.asString()));
+ }
+
+ // optional enabled
+ s = reader_r->getAttribute("enabled");
+ if (s.get()) {
+ info.setEnabled(str::strToTrue(s.asString()));
+ }
+
DBG << info << endl;
-
+
// Set some defaults that are not contained in the repo information
info.setAutorefresh( true );
- // enabled or disabled is controlled by the
- // reposToEnable/Disable list
- info.setEnabled(false);
-
+
// ignore the rest
_callback(info);
return true;
RepoindexFileReader::RepoindexFileReader(
const Pathname & repoindex_file, const ProcessResource & callback)
:
- _pimpl(new Impl(repoindex_file, callback))
+ _pimpl(new Impl(InputStream(repoindex_file), callback))
+ {}
+
+ RepoindexFileReader::RepoindexFileReader(
+ const InputStream &is, const ProcessResource & callback )
+ : _pimpl(new Impl(is, callback))
{}
RepoindexFileReader::~RepoindexFileReader()
#include "zypp/base/PtrTypes.h"
#include "zypp/base/NonCopyable.h"
#include "zypp/base/Function.h"
+#include "zypp/base/InputStream.h"
+#include "zypp/Pathname.h"
namespace zypp
{
*
*
* \code
- * RepoindexFileReader reader(repoindex_file,
+ * RepoindexFileReader reader(repoindex_file,
* bind( &SomeClass::callbackfunc, &SomeClassInstance, _1) );
* \endcode
*/
/**
* CTOR. Creates also \ref xml::Reader and starts reading.
- *
+ *
* \param repoindexFile is the repoindex.xml file you want to read
* \param callback is a function.
*
* \see RepoindexFileReader::ProcessResource
*/
- RepoindexFileReader(
- const Pathname & repoindexFile, const ProcessResource & callback);
+ RepoindexFileReader( const zypp::Pathname & repoindexFile,
+ const ProcessResource & callback);
+
+ /**
+ * \short Constructor. Creates the reader and start reading.
+ *
+ * \param is a valid input stream
+ * \param callback Callback that will be called for each repository.
+ *
+ * \see RepoindexFileReader::ProcessResource
+ */
+ RepoindexFileReader( const InputStream &is,
+ const ProcessResource & callback );
/**
* DTOR