#
# Makefile.am for libzypp/testsuite
#
-SUBDIRS = zypp target solver source
+SUBDIRS = zypp target solver source parser
--- /dev/null
+#
+# Makefile.am for testsuite/parser
+#
+SUBDIRS = tests
+AUTOMAKE_OPTIONS = dejagnu
+PACKAGE = parser
+
+LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la
+
+noinst_PROGRAMS = YUMtest
+
+YUMtest_SOURCES = YUMtest.cc
+
+EXTRA_DIST = lib/*.exp config/*.exp $(PACKAGE).test/*.exp
+
+clean-local:
+ rm -rf *.log
+ rm -rf *.exp
--- /dev/null
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+File: YUMtest.cc
+
+Author: Michael Radziej <mir@suse.de>
+Maintainer: Michael Radziej <mir@suse.de>
+
+Purpose: main() to test the YUM parsers
+/-*/
+
+#include "zypp/parser/yum/YUMParser.h"
+#include "zypp/base/Logger.h"
+
+using namespace zypp;
+using namespace zypp::parser;
+using namespace zypp::parser::yum;
+using namespace std;
+
+namespace {
+ void usage() {
+ cerr << "YUMtest usage: "<< endl
+ << "YUMtest TYPE" << endl
+ << "TYPE: repomd|primary|group|pattern|filelist|other|patch|patches|product" << endl;
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ usage();
+ return 2;
+ }
+
+// set_log_filename("-");
+
+ try {
+ if (!strcmp(argv[1],"repomd")) {
+ YUMRepomdParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"primary")) {
+ YUMPrimaryParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"group")) {
+ YUMGroupParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"pattern")) {
+ YUMPatternParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"filelist")) {
+ YUMFileListParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"other")) {
+ YUMOtherParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"patch")) {
+ YUMPatchParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"patches")) {
+ YUMPatchesParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else if (!strcmp(argv[1],"product")) {
+ YUMProductParser iter(cin,"");
+ for (;
+ !iter.atEnd();
+ ++iter) {
+ cout << **iter;
+ }
+ if (iter.errorStatus())
+ throw *iter.errorStatus();
+ }
+ else {
+ usage();
+ return 2;
+ }
+ }
+ catch (XMLParserError& err) {
+ cerr << "** ouch **" << endl
+ << "syntax error encountered in XML input:" << endl
+ << err.msg() << " " << err.position() << endl;
+ return 1;
+ }
+
+ return 0;
+}
--- /dev/null
+# default.exp -- empty
+
--- /dev/null
+load_lib "parser_init.exp"
+proc parser_exit {} {}
+proc parser_version {} {}
+
--- /dev/null
+perror "No setup for current configuration"
+exit 1
--- /dev/null
+# parser_init.exp
+
+#
+# run binary $path/$prog
+# and expect $expected_result as a result
+# (expected_result == 0 ==> program should pass)
+# (expected_result == 1 ==> program should fail)
+#
+
+proc runYumTest { prog {path ""} {expected_result 0} } {
+
+ if { $path == "" } { set path "tests" }
+
+ set result 0
+ set oops [catch { set result [exec "$path/runtxxxxest.sh" "$path/$prog" ">" "/dev/null" "2>/dev/null"] } catched]
+
+ # check if the program crashed
+
+ if {$oops != 0 && $result != 0} {
+ puts ""
+ fail "$prog crashed ($oops) with: $catched"
+ return -1
+ }
+
+ # check return code from $prog
+
+ if {$result != ""} {
+ if {$expected_result != "0"} {
+ xfail $prog # expected failure
+ return 0
+ }
+ puts ""
+ warning "Running of $prog results in '$result'"
+ return -1
+ }
+
+ pass $prog
+
+ return 0
+}
+
+# expect prog to pass
+
+proc shouldPass { prog {path ""} } {
+ return [runBinary $prog $path "0"]
+}
+
+# expect prog to fail
+
+proc shouldFail { prog {path ""} } {
+ return [runBinary $prog $path "1"]
+}
+
--- /dev/null
+#
+# parser_yum.exp
+# 'main' file for all YUM parser tests
+#
+# Runs all tests with the extention "xml" for all their data.
+#
+# Each testprogram <programname>.multi has an own subdirectory
+# data.<programmname> in which several subdirectories with test-
+# cases are defined for this program.
+# Each of these testcase has 2 files:
+#
+# *-test.xml
+# *-test.solution
+#
+# The program "<programname>.multi" will be called with the argument
+# "...-test.xml" and its output redirected to "...-test.mistake".
+# The "...-test.mistake" is then diffed to the "...solution" file
+# generating a "...diff" file.
+#
+# The testcase is successful if the program returns 0 AND
+# the "...diff" file is empty
+#
+# Additionally, if a subdirectory contains the file "xfail",
+# it is supposed to contain the filename of testcases which
+# are expected to fail
+#
+#
+if { [catch { set filenames [glob $srcdir/tests/*.xml] } ] } {
+ puts "No .xml files found"
+} else {
+ # foreach file, call multi-run (from testsuite/lib)
+
+ foreach file $filenames { runYumTest $file }
+}
--- /dev/null
+#!/bin/bash
+# goes through each testcase in this directory
+# see README
+testcase=$1;
+mode="${testcase#*-}"
+mode="${mode%%-*}"
+
+./YUMtest "$mode" < "$testcase"
+echo "Exit Code: $?"
--- /dev/null
+#
+# Makefile.am for testsuite/parser/tests
+#
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<repomd xmlns="http://linux.duke.edu/metadata/repo">
+ <data type="other">
+ <location href="repodata/other.xml"/>
+ <checksum type="sha">e7ba668ab0d49486f0a3e7a0b168406a88a46ed9</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">394bb178eb19423f1c9f255acfd50719809cabba</open-checksum>
+ </data>
+ <data type="filelists">
+ <location href="repodata/filelists.xml"/>
+ <checksum type="sha">603594e2dd7d875a876babaf1b39f3aede460ef1</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">047041a0149308416aa1b62eb5e11a191ca6c2e9</open-checksum>
+ </data>
+ <data type="primary">
+ <location href="repodata/primary.xml"/>
+ <checksum type="sha">20f45621426fcd74364d6fabe6929d1164797801</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">e8f9b1f8b3aa049ba3e3e813ee33e37302e9b16a</open-checksum>
+ </data>
+ <data type="product">
+ <location href="repodata/product.xml"/>
+ <checksum type="sha">20f45621426fcd74364d6fabe6929d1164797801</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">e8f9b1f8b3aa049ba3e3e813ee33e37302e9b16a</open-checksum>
+ </data>
+ <data type="group">
+ <location href="repodata/group.xml"/>
+ <checksum type="sha">20f45621426fcd74364d6fabe6929d1164797801</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">e8f9b1f8b3aa049ba3e3e813ee33e37302e9b16a</open-checksum>
+ </data>
+ <data type="patches">
+ <location href="repodata/patches.xml"/>
+ <checksum type="sha">20f45621426fcd74364d6fabe6929d1164797801</checksum>
+ <timestamp>1119534896</timestamp>
+ <open-checksum type="sha">e8f9b1f8b3aa049ba3e3e813ee33e37302e9b16a</open-checksum>
+ </data>
+</repomd>