]> git.saurik.com Git - apt.git/commitdiff
add a testcase for FindPackages() to better validate that cdrom should work.
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 11 Dec 2011 01:55:20 +0000 (02:55 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 11 Dec 2011 01:55:20 +0000 (02:55 +0100)
Unfortunately it's hard to do an automated integration test with cd, so we
test this method in isolation which tries to find Indexes and dropping
of duplications with DropRepeats()

apt-pkg/cdrom.cc
test/libapt/cdromfindpackages_test.cc [new file with mode: 0644]
test/libapt/makefile
test/libapt/run-tests

index d9ecdf4f6dfe07a3b528dd0c571eaf40423badd3..4462d4e246abb0273031d88c1568739b6117e2e8 100644 (file)
@@ -277,6 +277,7 @@ bool pkgCdrom::DropBinaryArch(vector<string> &List)
 /* Here we go and stat every file that we found and strip dup inodes. */
 bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
 {
+   bool couldFindAllFiles = true;
    // Get a list of all the inodes
    ino_t *Inodes = new ino_t[List.size()];
    for (unsigned int I = 0; I != List.size(); ++I)
@@ -297,21 +298,22 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
       }
 
       if (found == false)
-         _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name);
+      {
+        _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name);
+        couldFindAllFiles = false;
+        Inodes[I] = 0;
+      }
    }
 
-   if (_error->PendingError() == true) {
-      delete[] Inodes;
-      return false;
-   }
-   
    // Look for dups
    for (unsigned int I = 0; I != List.size(); I++)
    {
+      if (Inodes[I] == 0)
+        continue;
       for (unsigned int J = I+1; J < List.size(); J++)
       {
         // No match
-        if (Inodes[J] != Inodes[I])
+        if (Inodes[J] == 0 || Inodes[J] != Inodes[I])
            continue;
         
         // We score the two paths.. and erase one
@@ -337,7 +339,7 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
         List.erase(List.begin()+I);
    }
    
-   return true;
+   return couldFindAllFiles;
 }
                                                                        /*}}}*/
 // ReduceSourceList - Takes the path list and reduces it               /*{{{*/
@@ -716,8 +718,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log)                                    /*{{{*/
    DropBinaryArch(List);
    DropRepeats(List,"Packages");
    DropRepeats(SourceList,"Sources");
+   // FIXME: We ignore stat() errors here as we usually have only one of those in use
+   // This has little potencial to drop 'valid' stat() errors as we know that one of these
+   // files need to exist, but it would be better if we would check it here
+   _error->PushToStack();
    DropRepeats(SigList,"Release.gpg");
    DropRepeats(SigList,"InRelease");
+   _error->RevertToStack();
    DropRepeats(TransList,"");
    if(log != NULL) {
       msg.str("");
diff --git a/test/libapt/cdromfindpackages_test.cc b/test/libapt/cdromfindpackages_test.cc
new file mode 100644 (file)
index 0000000..e9f5a51
--- /dev/null
@@ -0,0 +1,86 @@
+#include <apt-pkg/cdrom.h>
+#include <apt-pkg/error.h>
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include "assert.h"
+
+class Cdrom : public pkgCdrom {
+       public:
+       bool FindPackages(std::string const &CD,
+                         std::vector<std::string> &List,
+                         std::vector<std::string> &SList,
+                         std::vector<std::string> &SigList,
+                         std::vector<std::string> &TransList,
+                         std::string &InfoDir) {
+               bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
+               std::sort(List.begin(), List.end());
+               std::sort(SList.begin(), SList.end());
+               std::sort(SigList.begin(), SigList.end());
+               std::sort(TransList.begin(), TransList.end());
+               return result;
+       }
+
+       bool DropRepeats(std::vector<std::string> &List, char const *Name) {
+               return pkgCdrom::DropRepeats(List, Name);
+       }
+};
+
+int main(int argc, char const *argv[]) {
+       if (argc != 2) {
+               std::cout << "One parameter expected - given " << argc << std::endl;
+               return 100;
+       }
+
+       Cdrom cd;
+       std::vector<std::string> Packages, Sources, Signatur, Translation;
+       std::string InfoDir;
+       std::string path = argv[1];
+       equals(true, cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
+       equals(4, Packages.size());
+       equals(path + "/dists/sid/main/binary-i386/", Packages[0]);
+       equals(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
+       equals(path + "/dists/stable/main/binary-i386/", Packages[2]);
+       equals(path + "/dists/unstable/main/binary-i386/", Packages[3]);
+       equals(3, Sources.size());
+       equals(path + "/dists/sid/main/source/", Sources[0]);
+       equals(path + "/dists/stable/main/source/", Sources[1]);
+       equals(path + "/dists/unstable/main/source/", Sources[2]);
+       equals(3, Signatur.size());
+       equals(path + "/dists/sid/", Signatur[0]);
+       equals(path + "/dists/stable/", Signatur[1]);
+       equals(path + "/dists/unstable/", Signatur[2]);
+       equals(4, Translation.size());
+       equals(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
+       equals(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
+       equals(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
+       equals(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
+       equals(path + "/.disk/", InfoDir);
+
+       cd.DropRepeats(Packages, "Packages");
+       cd.DropRepeats(Sources, "Sources");
+       _error->PushToStack();
+       cd.DropRepeats(Signatur, "InRelease");
+       cd.DropRepeats(Signatur, "Release.gpg");
+       _error->RevertToStack();
+       _error->DumpErrors();
+       cd.DropRepeats(Translation, "");
+
+       equals(3, Packages.size());
+       equals(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
+       equals(path + "/dists/stable/main/binary-i386/", Packages[1]);
+       equals(path + "/dists/unstable/main/binary-i386/", Packages[2]);
+       equals(2, Sources.size());
+       equals(path + "/dists/stable/main/source/", Sources[0]);
+       equals(path + "/dists/unstable/main/source/", Sources[1]);
+       equals(2, Signatur.size());
+       equals(path + "/dists/stable/", Signatur[0]);
+       equals(path + "/dists/unstable/", Signatur[1]);
+       equals(2, Translation.size());
+       equals(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
+       equals(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
+
+       return 0;
+}
index d3dddaeedcef5f9cf8a0decdb2b93f11e66696ce..1952051e28008e23a2bb552ed781f0923b1c2efb 100644 (file)
@@ -74,3 +74,9 @@ PROGRAM = Configuration${BASENAME}
 SLIBS = -lapt-pkg
 SOURCE = configuration_test.cc
 include $(PROGRAM_H)
+
+# test cdroms core FindPackages
+PROGRAM = CdromFindPackages${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = cdromfindpackages_test.cc
+include $(PROGRAM_H)
index ada2dc38b0a84e8b6b97afe6a875e221ddca0b9c..bd47d4e0d8dd50a4825b757e11dfbd43fb4b21ec 100755 (executable)
@@ -75,6 +75,35 @@ do
                continue
        elif [ $name = "CompareVersion${EXT}" ]; then
                tmppath="${DIR}/versions.lst"
+       elif [ $name = "CdromFindPackages${EXT}" ]; then
+               tmppath=$(mktemp -d)
+               mkdir -p "${tmppath}/.disk" "${tmppath}/pool" \
+                       "${tmppath}/dists/stable/main/binary-i386" \
+                       "${tmppath}/dists/stable/main/source" \
+                       "${tmppath}/dists/stable/contrib/binary-amd64" \
+                       "${tmppath}/dists/stable/contrib/binary-all" \
+                       "${tmppath}/dists/unstable/main/binary-i386" \
+                       "${tmppath}/dists/unstable/main/i18n" \
+                       "${tmppath}/dists/unstable/main/source" \
+                       "${tmppath}/dists/broken/non-free/source"
+               touch "${tmppath}/dists/broken/.aptignr" \
+                       "${tmppath}/dists/stable/main/binary-i386/Packages" \
+                       "${tmppath}/dists/stable/main/binary-i386/Packages.gz" \
+                       "${tmppath}/dists/stable/main/source/Sources.gz" \
+                       "${tmppath}/dists/stable/contrib/binary-amd64/Packages" \
+                       "${tmppath}/dists/stable/contrib/binary-amd64/Packages.gz" \
+                       "${tmppath}/dists/stable/contrib/binary-all/Packages" \
+                       "${tmppath}/dists/unstable/main/binary-i386/Packages.gz" \
+                       "${tmppath}/dists/unstable/main/binary-i386/Packages.gz" \
+                       "${tmppath}/dists/unstable/main/i18n/Translation-en" \
+                       "${tmppath}/dists/unstable/main/i18n/Translation-de.gz" \
+                       "${tmppath}/dists/unstable/main/source/Sources.gz" \
+                       "${tmppath}/dists/broken/non-free/source/Sources.gz" \
+                       "${tmppath}/dists/stable/Release.gpg" \
+                       "${tmppath}/dists/stable/Release" \
+                       "${tmppath}/dists/unstable/InRelease" \
+                       "${tmppath}/dists/broken/Release.gpg"
+               ln -s "${tmppath}/dists/unstable" "${tmppath}/dists/sid"
        fi
 
        echo -n "Testing with ${NAME} "