summaryrefslogtreecommitdiff
path: root/test/interactive-helper
diff options
context:
space:
mode:
Diffstat (limited to 'test/interactive-helper')
-rw-r--r--test/interactive-helper/extract-control.cc43
-rw-r--r--test/interactive-helper/makefile43
-rw-r--r--test/interactive-helper/mthdcat.cc20
-rw-r--r--test/interactive-helper/networkless-install-fixes/README5
-rw-r--r--test/interactive-helper/networkless-install-fixes/sources.test.list25
-rwxr-xr-xtest/interactive-helper/networkless-install-fixes/test.sh25
-rw-r--r--test/interactive-helper/rpmver.cc117
-rw-r--r--test/interactive-helper/test_udevcdrom.cc21
-rw-r--r--test/interactive-helper/testdeb.cc39
-rw-r--r--test/interactive-helper/testextract.cc103
10 files changed, 441 insertions, 0 deletions
diff --git a/test/interactive-helper/extract-control.cc b/test/interactive-helper/extract-control.cc
new file mode 100644
index 000000000..a1b3600aa
--- /dev/null
+++ b/test/interactive-helper/extract-control.cc
@@ -0,0 +1,43 @@
+#include <apt-pkg/debfile.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+
+#include <iostream>
+#include <unistd.h>
+
+using namespace std;
+
+bool ExtractMember(const char *File,const char *Member)
+{
+ FileFd Fd(File,FileFd::ReadOnly);
+ debDebFile Deb(Fd);
+ if(_error->PendingError() == true)
+ return false;
+
+ debDebFile::MemControlExtract Extract(Member);
+ if (Extract.Read(Deb) == false)
+ return false;
+
+ if (Extract.Control == 0)
+ return true;
+
+ write(STDOUT_FILENO,Extract.Control,Extract.Length);
+ return true;
+}
+
+int main(int argc, const char *argv[])
+{
+ if (argc < 2)
+ {
+ cerr << "Need two arguments, a .deb and the control member" << endl;
+ return 100;
+ }
+
+ if (ExtractMember(argv[1],argv[2]) == false)
+ {
+ _error->DumpErrors();
+ return 100;
+ }
+
+ return 0;
+}
diff --git a/test/interactive-helper/makefile b/test/interactive-helper/makefile
new file mode 100644
index 000000000..b96139fda
--- /dev/null
+++ b/test/interactive-helper/makefile
@@ -0,0 +1,43 @@
+# -*- make -*-
+BASE=../..
+SUBDIR=test/interactive-helper
+
+# Bring in the default rules
+include ../../buildlib/defaults.mak
+
+# Program for testing methods
+PROGRAM=mthdcat
+SLIBS =
+SOURCE = mthdcat.cc
+include $(PROGRAM_H)
+
+# Version compare tester
+PROGRAM=testextract
+SLIBS = -lapt-pkg -lapt-inst
+LIB_MAKES = apt-pkg/makefile apt-inst/makefile
+SOURCE = testextract.cc
+include $(PROGRAM_H)
+
+# Program for testing the tar/deb extractor
+PROGRAM=testdeb
+SLIBS = -lapt-pkg -lapt-inst
+SOURCE = testdeb.cc
+include $(PROGRAM_H)
+
+# Program for testing tar extraction
+PROGRAM=extract-control
+SLIBS = -lapt-pkg -lapt-inst
+SOURCE = extract-control.cc
+include $(PROGRAM_H)
+
+# Program for testing udevcdrom
+PROGRAM=test_udevcdrom
+SLIBS = -lapt-pkg
+SOURCE = test_udevcdrom.cc
+include $(PROGRAM_H)
+
+# Program for checking rpm versions
+#PROGRAM=rpmver
+#SLIBS = -lapt-pkg -lrpm
+#SOURCE = rpmver.cc
+#include $(PROGRAM_H)
diff --git a/test/interactive-helper/mthdcat.cc b/test/interactive-helper/mthdcat.cc
new file mode 100644
index 000000000..25d09a3f5
--- /dev/null
+++ b/test/interactive-helper/mthdcat.cc
@@ -0,0 +1,20 @@
+/* Usage, mthdcat < cmds | methods/mthd
+ All this does is cat a file into the method without closing the FD when
+ the file ends */
+
+#include <unistd.h>
+
+int main()
+{
+ char Buffer[4096];
+
+ while (1)
+ {
+ int Res = read(STDIN_FILENO,Buffer,sizeof(Buffer));
+ if (Res <= 0)
+ while (1) sleep(100);
+ if (write(STDOUT_FILENO,Buffer,Res) != Res)
+ break;
+ }
+ return 0;
+}
diff --git a/test/interactive-helper/networkless-install-fixes/README b/test/interactive-helper/networkless-install-fixes/README
new file mode 100644
index 000000000..e7ee2b03d
--- /dev/null
+++ b/test/interactive-helper/networkless-install-fixes/README
@@ -0,0 +1,5 @@
+
+Those tests aim at making the networkless install timeout
+quicker, see
+https://wiki.ubuntu.com/NetworklessInstallationFixes
+for details
diff --git a/test/interactive-helper/networkless-install-fixes/sources.test.list b/test/interactive-helper/networkless-install-fixes/sources.test.list
new file mode 100644
index 000000000..380e1804d
--- /dev/null
+++ b/test/interactive-helper/networkless-install-fixes/sources.test.list
@@ -0,0 +1,25 @@
+
+# archive.ubuntu.com
+deb http://archive.ubuntu.com/ubuntu/ hardy main restricted
+deb-src http://archive.ubuntu.com/ubuntu/ hardy main restricted
+
+deb http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted
+deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted
+
+deb http://archive.ubuntu.com/ubuntu/ hardy universe
+deb-src http://archive.ubuntu.com/ubuntu/ hardy universe
+
+deb http://archive.ubuntu.com/ubuntu/ hardy-updates universe
+deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates universe
+
+# security.ubuntu.com
+deb http://security.ubuntu.com/ubuntu/ hardy-security main restricted
+deb-src http://security.ubuntu.com/ubuntu/ hardy-security main restricted
+
+deb http://security.ubuntu.com/ubuntu/ hardy-security universe
+deb-src http://security.ubuntu.com/ubuntu/ hardy-security universe
+
+
+# archive.canonical.com
+deb http://archive.canonical.com/ubuntu/ hardy-partner universe
+deb-src http://archive.canonical.com/ubuntu/ hardy-partner universe
diff --git a/test/interactive-helper/networkless-install-fixes/test.sh b/test/interactive-helper/networkless-install-fixes/test.sh
new file mode 100755
index 000000000..809d467ba
--- /dev/null
+++ b/test/interactive-helper/networkless-install-fixes/test.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+OPTS="-o Dir::Etc::sourcelist=./sources.test.list -o Acquire::http::timeout=20"
+
+# setup
+unset http_proxy
+iptables --flush
+
+echo "No network at all"
+ifdown eth0
+time apt-get update $OPTS 2>&1 |grep system
+ifup eth0
+echo ""
+
+echo "no working DNS (port 53 DROP)"
+iptables -A OUTPUT -p udp --dport 53 -j DROP
+time apt-get update $OPTS 2>&1 |grep system
+iptables --flush
+echo ""
+
+echo "DNS but no access to archive.ubuntu.com (port 80 DROP)"
+iptables -A OUTPUT -p tcp --dport 80 -j DROP
+time apt-get update $OPTS 2>&1 |grep system
+iptables --flush
+echo ""
diff --git a/test/interactive-helper/rpmver.cc b/test/interactive-helper/rpmver.cc
new file mode 100644
index 000000000..9fc807de8
--- /dev/null
+++ b/test/interactive-helper/rpmver.cc
@@ -0,0 +1,117 @@
+#include <apt-pkg/debversion.h>
+#include <rpm/rpmio.h>
+#include <rpm/misc.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define xisdigit(x) isdigit(x)
+#define xisalpha(x) isalpha(x)
+#define xisalnum(x) (isdigit(x) || isalpha(x))
+
+using namespace std;
+
+int rpmvercmp(const char * a, const char * b)
+{
+ char oldch1, oldch2;
+ char * str1, * str2;
+ char * one, * two;
+ int rc;
+ int isnum;
+
+ /* easy comparison to see if versions are identical */
+ if (!strcmp(a, b)) return 0;
+
+ str1 = (char *)alloca(strlen(a) + 1);
+ str2 = (char *)alloca(strlen(b) + 1);
+
+ strcpy(str1, a);
+ strcpy(str2, b);
+
+ one = str1;
+ two = str2;
+
+ /* loop through each version segment of str1 and str2 and compare them */
+ while (*one && *two) {
+ while (*one && !xisalnum(*one)) one++;
+ while (*two && !xisalnum(*two)) two++;
+
+ str1 = one;
+ str2 = two;
+
+ /* grab first completely alpha or completely numeric segment */
+ /* leave one and two pointing to the start of the alpha or numeric */
+ /* segment and walk str1 and str2 to end of segment */
+ if (xisdigit(*str1)) {
+ while (*str1 && xisdigit(*str1)) str1++;
+ while (*str2 && xisdigit(*str2)) str2++;
+ isnum = 1;
+ } else {
+ while (*str1 && xisalpha(*str1)) str1++;
+ while (*str2 && xisalpha(*str2)) str2++;
+ isnum = 0;
+ }
+
+ /* save character at the end of the alpha or numeric segment */
+ /* so that they can be restored after the comparison */
+ oldch1 = *str1;
+ *str1 = '\0';
+ oldch2 = *str2;
+ *str2 = '\0';
+
+ /* take care of the case where the two version segments are */
+ /* different types: one numeric, the other alpha (i.e. empty) */
+ if (one == str1) return -1; /* arbitrary */
+ if (two == str2) return 1;
+
+ if (isnum) {
+ /* this used to be done by converting the digit segments */
+ /* to ints using atoi() - it's changed because long */
+ /* digit segments can overflow an int - this should fix that. */
+
+ /* throw away any leading zeros - it's a number, right? */
+ while (*one == '0') one++;
+ while (*two == '0') two++;
+
+ /* whichever number has more digits wins */
+ if (strlen(one) > strlen(two)) return 1;
+ if (strlen(two) > strlen(one)) return -1;
+ }
+
+ /* strcmp will return which one is greater - even if the two */
+ /* segments are alpha or if they are numeric. don't return */
+ /* if they are equal because there might be more segments to */
+ /* compare */
+ rc = strcmp(one, two);
+ if (rc) return rc;
+
+ /* restore character that was replaced by null above */
+ *str1 = oldch1;
+ one = str1;
+ *str2 = oldch2;
+ two = str2;
+ }
+
+ /* this catches the case where all numeric and alpha segments have */
+ /* compared identically but the segment sepparating characters were */
+ /* different */
+ if ((!*one) && (!*two)) return 0;
+
+ /* whichever version still has characters left over wins */
+ if (!*one) return -1; else return 1;
+}
+
+int main(int argc,const char *argv[])
+{
+ printf("%i\n",strcmp(argv[1],argv[2]));
+
+ printf("'%s' <> '%s': ",argv[1],argv[2]);
+ printf("rpm: %i deb: %i\n",rpmvercmp(argv[1],argv[2]),
+ debVS.CmpFragment(argv[1],argv[1]+strlen(argv[1]),
+ argv[2],argv[2]+strlen(argv[2])));
+
+ printf("'%s' <> '%s': ",argv[2],argv[1]);
+ printf("rpm: %i deb: %i\n",rpmvercmp(argv[2],argv[1]),
+ debVS.CmpFragment(argv[2],argv[2]+strlen(argv[2]),
+ argv[1],argv[1]+strlen(argv[1])));
+ return 0;
+}
diff --git a/test/interactive-helper/test_udevcdrom.cc b/test/interactive-helper/test_udevcdrom.cc
new file mode 100644
index 000000000..88f5f0153
--- /dev/null
+++ b/test/interactive-helper/test_udevcdrom.cc
@@ -0,0 +1,21 @@
+#include <apt-pkg/cdrom.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <vector>
+#include <iostream>
+
+int main()
+{
+ pkgUdevCdromDevices c;
+ assert(c.Dlopen());
+
+ std::vector<CdromDevice> l;
+ l = c.Scan();
+ assert(l.empty() == false);
+ for (size_t i = 0; i < l.size(); ++i)
+ std::cerr << l[i].DeviceName << " "
+ << l[i].Mounted << " "
+ << l[i].MountPath << std::endl;
+
+}
diff --git a/test/interactive-helper/testdeb.cc b/test/interactive-helper/testdeb.cc
new file mode 100644
index 000000000..d28f20114
--- /dev/null
+++ b/test/interactive-helper/testdeb.cc
@@ -0,0 +1,39 @@
+#include <apt-pkg/dirstream.h>
+#include <apt-pkg/debfile.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/extracttar.h>
+
+class NullStream : public pkgDirStream
+{
+ public:
+ virtual bool DoItem(Item &Itm,int &Fd) {return true;};
+};
+
+bool Test(const char *File)
+{
+ FileFd Fd(File,FileFd::ReadOnly);
+ debDebFile Deb(Fd);
+
+ if (_error->PendingError() == true)
+ return false;
+
+ // Get the archive member and positition the file
+ const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
+ if (Member == 0)
+ return false;
+
+ // Extract it.
+ ExtractTar Tar(Deb.GetFile(),Member->Size, "gzip");
+ NullStream Dir;
+ if (Tar.Go(Dir) == false)
+ return false;
+
+ return true;
+}
+
+int main(int argc, const char *argv[])
+{
+ Test(argv[1]);
+ _error->DumpErrors();
+ return 0;
+}
diff --git a/test/interactive-helper/testextract.cc b/test/interactive-helper/testextract.cc
new file mode 100644
index 000000000..f7ddb72f0
--- /dev/null
+++ b/test/interactive-helper/testextract.cc
@@ -0,0 +1,103 @@
+#include <apt-pkg/dpkgdb.h>
+#include <apt-pkg/debfile.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/extract.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/pkgsystem.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace std;
+
+bool Go(int argc,char *argv[])
+{
+ // Init the database
+ debDpkgDB Db;
+ {
+ OpTextProgress Prog;
+
+ if (Db.ReadyPkgCache(Prog) == false)
+ return false;
+ Prog.Done();
+
+ if (Db.ReadyFileList(Prog) == false)
+ return false;
+ }
+
+ for (int I = 1; I < argc; I++)
+ {
+ const char *Fake = 0;
+ for (unsigned J = 0; argv[I][J] != 0; J++)
+ {
+ if (argv[I][J] != ',')
+ continue;
+ Fake = argv[I] + J + 1;
+ argv[I][J] = 0;
+ }
+
+ FileFd F(argv[I],FileFd::ReadOnly);
+ debDebFile Deb(F);
+
+ if (_error->PendingError() == true)
+ return false;
+
+ if (Deb.ExtractControl(Db) == false)
+ return false;
+ cout << argv[I] << endl;
+
+ pkgCache::VerIterator Ver = Deb.MergeControl(Db);
+ if (Ver.end() == true)
+ return false;
+
+ cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
+
+ pkgExtract Extract(Db.GetFLCache(),Ver);
+
+ if (Fake != 0)
+ {
+ pkgExtract::Item Itm;
+ memset(&Itm,0,sizeof(Itm));
+ FILE *F = fopen(Fake,"r");
+ while (feof(F) == 0)
+ {
+ char Line[300];
+ fgets(Line,sizeof(Line),F);
+ Itm.Name = _strstrip(Line);
+ Itm.Type = pkgDirStream::Item::File;
+ if (Line[strlen(Line)-1] == '/')
+ Itm.Type = pkgDirStream::Item::Directory;
+
+ int Fd;
+ if (Extract.DoItem(Itm,Fd) == false) {
+ fclose(F);
+ return false;
+ }
+ }
+ fclose(F);
+ }
+ else
+ if (Deb.ExtractArchive(Extract) == false)
+ return false;
+ }
+ return true;
+}
+
+int main(int argc,char *argv[])
+{
+ pkgInitConfig(*_config);
+ pkgInitSystem(*_config,_system);
+ _config->Set("Dir::State::status","/tmp/testing/status");
+
+ Go(argc,argv);
+
+ if (_error->PendingError() == true)
+ {
+ _error->DumpErrors();
+ return 0;
+ }
+}