From 369c919f2be8d2c93b990a97436b41ba4ae1ff29 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Aug 2011 12:06:37 +0200 Subject: move the interactive helper to a subdirectory of test --- test/extract-control.cc | 42 ----------- test/interactive-helper/extract-control.cc | 42 +++++++++++ test/interactive-helper/makefile | 43 +++++++++++ test/interactive-helper/mthdcat.cc | 20 +++++ test/interactive-helper/rpmver.cc | 117 +++++++++++++++++++++++++++++ test/interactive-helper/test_udevcdrom.cc | 19 +++++ test/interactive-helper/testdeb.cc | 39 ++++++++++ test/interactive-helper/testextract.cc | 101 +++++++++++++++++++++++++ test/makefile | 56 -------------- test/mthdcat.cc | 20 ----- test/rpmver.cc | 117 ----------------------------- test/test_udevcdrom.cc | 19 ----- test/testdeb.cc | 39 ---------- test/testextract.cc | 101 ------------------------- 14 files changed, 381 insertions(+), 394 deletions(-) delete mode 100644 test/extract-control.cc create mode 100644 test/interactive-helper/extract-control.cc create mode 100644 test/interactive-helper/makefile create mode 100644 test/interactive-helper/mthdcat.cc create mode 100644 test/interactive-helper/rpmver.cc create mode 100644 test/interactive-helper/test_udevcdrom.cc create mode 100644 test/interactive-helper/testdeb.cc create mode 100644 test/interactive-helper/testextract.cc delete mode 100644 test/makefile delete mode 100644 test/mthdcat.cc delete mode 100644 test/rpmver.cc delete mode 100644 test/test_udevcdrom.cc delete mode 100644 test/testdeb.cc delete mode 100644 test/testextract.cc diff --git a/test/extract-control.cc b/test/extract-control.cc deleted file mode 100644 index 29dcbf371..000000000 --- a/test/extract-control.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include -#include - -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/extract-control.cc b/test/interactive-helper/extract-control.cc new file mode 100644 index 000000000..29dcbf371 --- /dev/null +++ b/test/interactive-helper/extract-control.cc @@ -0,0 +1,42 @@ +#include +#include + +#include +#include + +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 + +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/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 +#include +#include +#include +#include + +#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..577e2d013 --- /dev/null +++ b/test/interactive-helper/test_udevcdrom.cc @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + int i; + pkgUdevCdromDevices c; + assert(c.Dlopen()); + + vector l; + l = c.Scan(); + assert(l.empty() == false); + for (i=0;i +#include +#include +#include + +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..b790df618 --- /dev/null +++ b/test/interactive-helper/testextract.cc @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +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; + } +} diff --git a/test/makefile b/test/makefile deleted file mode 100644 index 9fcd6a826..000000000 --- a/test/makefile +++ /dev/null @@ -1,56 +0,0 @@ -# -*- make -*- -BASE=.. -SUBDIR=test - -# Bring in the default rules -include ../buildlib/defaults.mak - -# Program for testing methods -PROGRAM=mthdcat -SLIBS = -SOURCE = mthdcat.cc -include $(PROGRAM_H) - -# Scratch program to test incomplete code fragments in -PROGRAM=scratch-test -SLIBS = -lapt-inst -lapt-pkg -LIB_MAKES = apt-pkg/makefile apt-inst/makefile -SOURCE = scratch.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 hashes -PROGRAM=hash -SLIBS = -lapt-pkg -SOURCE = hash.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/mthdcat.cc b/test/mthdcat.cc deleted file mode 100644 index 25d09a3f5..000000000 --- a/test/mthdcat.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* Usage, mthdcat < cmds | methods/mthd - All this does is cat a file into the method without closing the FD when - the file ends */ - -#include - -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/rpmver.cc b/test/rpmver.cc deleted file mode 100644 index 9fc807de8..000000000 --- a/test/rpmver.cc +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include -#include -#include -#include - -#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/test_udevcdrom.cc b/test/test_udevcdrom.cc deleted file mode 100644 index 577e2d013..000000000 --- a/test/test_udevcdrom.cc +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -int main() -{ - int i; - pkgUdevCdromDevices c; - assert(c.Dlopen()); - - vector l; - l = c.Scan(); - assert(l.empty() == false); - for (i=0;i -#include -#include -#include - -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/testextract.cc b/test/testextract.cc deleted file mode 100644 index b790df618..000000000 --- a/test/testextract.cc +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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; - } -} -- cgit v1.2.3