added first parser testsuite (however, unfortunately, it doesn't work)
authorJiri Srain <jsrain@suse.cz>
Wed, 18 Jan 2006 10:48:44 +0000 (10:48 +0000)
committerJiri Srain <jsrain@suse.cz>
Wed, 18 Jan 2006 10:48:44 +0000 (10:48 +0000)
testsuite/Makefile.am
testsuite/parser/Makefile.am [new file with mode: 0644]
testsuite/parser/YUMtest.cc [new file with mode: 0644]
testsuite/parser/config/default.exp [new file with mode: 0644]
testsuite/parser/config/unix.exp [new file with mode: 0644]
testsuite/parser/config/unknown.exp [new file with mode: 0644]
testsuite/parser/lib/parser_init.exp [new file with mode: 0644]
testsuite/parser/parser.test/parser-yum.exp [new file with mode: 0644]
testsuite/parser/runtest.sh [new file with mode: 0755]
testsuite/parser/tests/Makefile.am [new file with mode: 0644]
testsuite/parser/tests/yum-repomd-1.xml [new file with mode: 0644]

index 0c14bfa..6cbf460 100644 (file)
@@ -1,4 +1,4 @@
 #
 # Makefile.am for libzypp/testsuite
 #
-SUBDIRS = zypp target solver source
+SUBDIRS = zypp target solver source parser
diff --git a/testsuite/parser/Makefile.am b/testsuite/parser/Makefile.am
new file mode 100644 (file)
index 0000000..811e7e8
--- /dev/null
@@ -0,0 +1,18 @@
+#
+# 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
diff --git a/testsuite/parser/YUMtest.cc b/testsuite/parser/YUMtest.cc
new file mode 100644 (file)
index 0000000..1b6ce63
--- /dev/null
@@ -0,0 +1,151 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ 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;
+}
diff --git a/testsuite/parser/config/default.exp b/testsuite/parser/config/default.exp
new file mode 100644 (file)
index 0000000..fe1e08a
--- /dev/null
@@ -0,0 +1,2 @@
+# default.exp -- empty
+
diff --git a/testsuite/parser/config/unix.exp b/testsuite/parser/config/unix.exp
new file mode 100644 (file)
index 0000000..c113955
--- /dev/null
@@ -0,0 +1,4 @@
+load_lib "parser_init.exp"
+proc parser_exit {} {}
+proc parser_version {} {}
+
diff --git a/testsuite/parser/config/unknown.exp b/testsuite/parser/config/unknown.exp
new file mode 100644 (file)
index 0000000..fe48c2f
--- /dev/null
@@ -0,0 +1,2 @@
+perror "No setup for current configuration"
+exit 1
diff --git a/testsuite/parser/lib/parser_init.exp b/testsuite/parser/lib/parser_init.exp
new file mode 100644 (file)
index 0000000..8dd0090
--- /dev/null
@@ -0,0 +1,53 @@
+# 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"]
+}
+
diff --git a/testsuite/parser/parser.test/parser-yum.exp b/testsuite/parser/parser.test/parser-yum.exp
new file mode 100644 (file)
index 0000000..97df792
--- /dev/null
@@ -0,0 +1,34 @@
+#
+# 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 }
+}
diff --git a/testsuite/parser/runtest.sh b/testsuite/parser/runtest.sh
new file mode 100755 (executable)
index 0000000..22f2a49
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+# goes through each testcase in this directory
+# see README
+testcase=$1;
+mode="${testcase#*-}"
+mode="${mode%%-*}"
+
+./YUMtest "$mode" < "$testcase"
+echo "Exit Code: $?"
diff --git a/testsuite/parser/tests/Makefile.am b/testsuite/parser/tests/Makefile.am
new file mode 100644 (file)
index 0000000..92edd4b
--- /dev/null
@@ -0,0 +1,3 @@
+#
+# Makefile.am for testsuite/parser/tests
+#
diff --git a/testsuite/parser/tests/yum-repomd-1.xml b/testsuite/parser/tests/yum-repomd-1.xml
new file mode 100644 (file)
index 0000000..99fb851
--- /dev/null
@@ -0,0 +1,39 @@
+<?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>