summaryrefslogtreecommitdiff
path: root/test/libapt/cdromfindpackages_test.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
committerMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
commit15ccc2a685b0b884b393e356f9960e86f97f532d (patch)
tree920a1fcf6fa2c92a05d0d1d2ccb22eb32b88522e /test/libapt/cdromfindpackages_test.cc
parenta40c6649b99814c7d30964accdd5ecc4f1ce369a (diff)
parent506ab3c78fb67f5e452a1748f4870af767de5ebb (diff)
Merge branch 'debian/sid' into ubuntu/master
Conflicts: debian/changelog
Diffstat (limited to 'test/libapt/cdromfindpackages_test.cc')
-rw-r--r--test/libapt/cdromfindpackages_test.cc169
1 files changed, 100 insertions, 69 deletions
diff --git a/test/libapt/cdromfindpackages_test.cc b/test/libapt/cdromfindpackages_test.cc
index 583de1423..719dd8f63 100644
--- a/test/libapt/cdromfindpackages_test.cc
+++ b/test/libapt/cdromfindpackages_test.cc
@@ -2,6 +2,7 @@
#include <apt-pkg/cdrom.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <algorithm>
#include <string>
@@ -9,82 +10,112 @@
#include <stddef.h>
#include <iostream>
-#include "assert.h"
+#include <gtest/gtest.h>
+
+#include "file-helpers.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;
- }
+ 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) {
+ std::string const startdir = SafeGetCWD();
+ EXPECT_FALSE(startdir.empty());
+ 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());
+ EXPECT_EQ(0, chdir(startdir.c_str()));
+ return result;
+ }
- bool DropRepeats(std::vector<std::string> &List, char const *Name) {
- return pkgCdrom::DropRepeats(List, Name);
- }
+ using pkgCdrom::DropRepeats;
};
-int main(int argc, char const *argv[]) {
- if (argc != 2) {
- std::cout << "One parameter expected - given " << argc << std::endl;
- return 100;
- }
+TEST(CDROMTest,FindPackages)
+{
+ std::string path;
+ createTemporaryDirectory("findpackage", path);
+
+ createDirectory(path, ".disk");
+ createDirectory(path, "pool");
+ createDirectory(path, "dists/stable/main/binary-i386");
+ createDirectory(path, "dists/stable/main/source");
+ createDirectory(path, "dists/stable/contrib/binary-amd64");
+ createDirectory(path, "dists/stable/contrib/binary-all");
+ createDirectory(path, "dists/unstable/main/binary-i386");
+ createDirectory(path, "dists/unstable/main/i18n");
+ createDirectory(path, "dists/unstable/main/source");
+ createDirectory(path, "dists/broken/non-free/source");
+ createFile(path, "dists/broken/.aptignr");
+ createFile(path, "dists/stable/main/binary-i386/Packages");
+ createFile(path, "dists/stable/main/binary-i386/Packages.bz2");
+ createFile(path, "dists/stable/main/source/Sources.xz");
+ createFile(path, "dists/stable/contrib/binary-amd64/Packages");
+ createFile(path, "dists/stable/contrib/binary-amd64/Packages.gz");
+ createFile(path, "dists/stable/contrib/binary-all/Packages");
+ createFile(path, "dists/unstable/main/binary-i386/Packages.xz");
+ createFile(path, "dists/unstable/main/binary-i386/Packages.lzma");
+ createFile(path, "dists/unstable/main/i18n/Translation-en");
+ createFile(path, "dists/unstable/main/i18n/Translation-de.bz2");
+ createFile(path, "dists/unstable/main/source/Sources.xz");
+ createFile(path, "dists/broken/non-free/source/Sources.gz");
+ createFile(path, "dists/stable/Release.gpg");
+ createFile(path, "dists/stable/Release");
+ createFile(path, "dists/unstable/InRelease");
+ createFile(path, "dists/broken/Release.gpg");
+ createLink(path, "dists/unstable", "dists/sid");
- 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);
+ Cdrom cd;
+ std::vector<std::string> Packages, Sources, Signatur, Translation;
+ std::string InfoDir;
+ EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
+ EXPECT_EQ(4, Packages.size());
+ EXPECT_EQ(path + "/dists/sid/main/binary-i386/", Packages[0]);
+ EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
+ EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[2]);
+ EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]);
+ EXPECT_EQ(3, Sources.size());
+ EXPECT_EQ(path + "/dists/sid/main/source/", Sources[0]);
+ EXPECT_EQ(path + "/dists/stable/main/source/", Sources[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[2]);
+ EXPECT_EQ(3, Signatur.size());
+ EXPECT_EQ(path + "/dists/sid/", Signatur[0]);
+ EXPECT_EQ(path + "/dists/stable/", Signatur[1]);
+ EXPECT_EQ(path + "/dists/unstable/", Signatur[2]);
+ EXPECT_EQ(4, Translation.size());
+ EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
+ EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
+ EXPECT_EQ(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, "");
+ 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]);
+ EXPECT_EQ(3, Packages.size());
+ EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
+ EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[2]);
+ EXPECT_EQ(2, Sources.size());
+ EXPECT_EQ(path + "/dists/stable/main/source/", Sources[0]);
+ EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[1]);
+ EXPECT_EQ(2, Signatur.size());
+ EXPECT_EQ(path + "/dists/stable/", Signatur[0]);
+ EXPECT_EQ(path + "/dists/unstable/", Signatur[1]);
+ EXPECT_EQ(2, Translation.size());
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
- return 0;
+ removeDirectory(path);
}