diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:56:32 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:56:32 +0000 |
commit | b2e465d6d32d2dc884f58b94acb7e35f671a87fe (patch) | |
tree | 5928383b9bde7b0ba9812e6526ad746466e558f7 /test | |
parent | 00b47c98ca4a4349686a082eba6d77decbb03a4d (diff) | |
download | apt-b2e465d6d32d2dc884f58b94acb7e35f671a87fe.tar.gz |
Join with aliencode
Author: jgg
Date: 2001-02-20 07:03:16 GMT
Join with aliencode
Diffstat (limited to 'test')
-rw-r--r-- | test/conf.cc | 35 | ||||
-rw-r--r-- | test/extract-control.cc | 40 | ||||
-rw-r--r-- | test/makefile | 26 | ||||
-rw-r--r-- | test/scratch.cc | 1 | ||||
-rw-r--r-- | test/testdeb.cc | 39 | ||||
-rw-r--r-- | test/testextract.cc | 96 | ||||
-rw-r--r-- | test/versiontest.cc | 5 |
7 files changed, 240 insertions, 2 deletions
diff --git a/test/conf.cc b/test/conf.cc new file mode 100644 index 00000000..c4416142 --- /dev/null +++ b/test/conf.cc @@ -0,0 +1,35 @@ +#include <apt-pkg/configuration.h> +#include <apt-pkg/error.h> + +int main(int argc,const char *argv[]) +{ + Configuration Cnf; + + ReadConfigFile(Cnf,argv[1],true); + + // Process 'simple-key' type sections + const Configuration::Item *Top = Cnf.Tree("simple-key"); + for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next) + { + Configuration Block(Top); + + string VendorID = Top->Tag; + string FingerPrint = Block.Find("Fingerprint"); + string Name = Block.Find("Name"); // Description? + + if (FingerPrint.empty() == true || Name.empty() == true) + _error->Error("Block %s is invalid",VendorID.c_str()); + + cout << VendorID << ' ' << FingerPrint << ' ' << Name << endl; + } + + // Print any errors or warnings found during parsing + if (_error->empty() == false) + { + bool Errors = _error->PendingError(); + _error->DumpErrors(); + return Errors == true?100:0; + } + + return 0; +} diff --git a/test/extract-control.cc b/test/extract-control.cc new file mode 100644 index 00000000..12508889 --- /dev/null +++ b/test/extract-control.cc @@ -0,0 +1,40 @@ +#include <apt-pkg/debfile.h> +#include <apt-pkg/error.h> + +#include <iostream> +#include <unistd.h> + +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/makefile b/test/makefile index e2f4c048..e3b2ac52 100644 --- a/test/makefile +++ b/test/makefile @@ -30,3 +30,29 @@ SLIBS = -lapt-pkg LIB_MAKES = apt-pkg/makefile SOURCE = versiontest.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 config file parser +PROGRAM=conftest +SLIBS = -lapt-pkg +SOURCE = conf.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) + diff --git a/test/scratch.cc b/test/scratch.cc index c8888a16..b5260815 100644 --- a/test/scratch.cc +++ b/test/scratch.cc @@ -1,3 +1,4 @@ +#define APT_COMPATIBILITY 1 #include <apt-pkg/dpkgdb.h> #include <apt-pkg/debfile.h> #include <apt-pkg/error.h> diff --git a/test/testdeb.cc b/test/testdeb.cc new file mode 100644 index 00000000..5986621b --- /dev/null +++ b/test/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); + 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/testextract.cc b/test/testextract.cc new file mode 100644 index 00000000..41a19706 --- /dev/null +++ b/test/testextract.cc @@ -0,0 +1,96 @@ +#define APT_COMPATIBILITY 1 +#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 <stdio.h> +#include <stdlib.h> + +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) + return false; + } + } + else + if (Deb.ExtractArchive(Extract) == false) + return false; + } + return true; +} + +int main(int argc,char *argv[]) +{ + pkgInitialize(*_config); + _config->Set("Dir::State::status","/tmp/testing/status"); + + Go(argc,argv); + + if (_error->PendingError() == true) + { + _error->DumpErrors(); + return 0; + } +} diff --git a/test/versiontest.cc b/test/versiontest.cc index d3bfe18f..20da49b7 100644 --- a/test/versiontest.cc +++ b/test/versiontest.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: versiontest.cc,v 1.1 1998/11/26 23:29:20 jgg Exp $ +// $Id: versiontest.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $ /* ###################################################################### Version Test - Simple program to run through a file and comare versions. @@ -14,13 +14,14 @@ ##################################################################### */ /*}}}*/ +#define APT_COMPATIBILITY 1 #include <system.h> #include <apt-pkg/error.h> #include <apt-pkg/version.h> #include <iostream.h> #include <fstream.h> -static int verrevcmp(const char *val, const char *ref) + static int verrevcmp(const char *val, const char *ref) { int vc, rc; long vl, rl; |