]> git.saurik.com Git - apt.git/blame_incremental - test/libapt/cdromfindpackages_test.cc
fix same-mirror redirection for Release{,.gpg} pair
[apt.git] / test / libapt / cdromfindpackages_test.cc
... / ...
CommitLineData
1#include <config.h>
2
3#include <apt-pkg/cdrom.h>
4#include <apt-pkg/error.h>
5#include <apt-pkg/fileutl.h>
6
7#include <algorithm>
8#include <string>
9#include <vector>
10#include <stddef.h>
11#include <iostream>
12
13#include <gtest/gtest.h>
14
15#include "file-helpers.h"
16
17class Cdrom : public pkgCdrom {
18 public:
19 bool FindPackages(std::string const &CD,
20 std::vector<std::string> &List,
21 std::vector<std::string> &SList,
22 std::vector<std::string> &SigList,
23 std::vector<std::string> &TransList,
24 std::string &InfoDir) {
25 std::string const startdir = SafeGetCWD();
26 EXPECT_FALSE(startdir.empty());
27 EXPECT_TRUE(InfoDir.empty());
28 bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
29 EXPECT_FALSE(InfoDir.empty());
30 std::sort(List.begin(), List.end());
31 std::sort(SList.begin(), SList.end());
32 std::sort(SigList.begin(), SigList.end());
33 std::sort(TransList.begin(), TransList.end());
34 EXPECT_EQ(0, chdir(startdir.c_str()));
35 return result;
36 }
37
38 using pkgCdrom::DropRepeats;
39};
40
41TEST(CDROMTest,FindPackages)
42{
43 std::string path;
44 createTemporaryDirectory("findpackage", path);
45
46 createDirectory(path, ".disk");
47 createDirectory(path, "pool");
48 createDirectory(path, "dists/stable/main/binary-i386");
49 createDirectory(path, "dists/stable/main/source");
50 createDirectory(path, "dists/stable/contrib/binary-amd64");
51 createDirectory(path, "dists/stable/non-free/binary-all");
52 createDirectory(path, "dists/unstable/main/binary-i386");
53 createDirectory(path, "dists/unstable/main/i18n");
54 createDirectory(path, "dists/unstable/main/source");
55 createDirectory(path, "dists/broken/non-free/source");
56 createFile(path, "dists/broken/.aptignr");
57 createFile(path, "dists/stable/main/binary-i386/Packages");
58 createFile(path, "dists/stable/main/binary-i386/Packages.bz2");
59 createFile(path, "dists/stable/main/source/Sources.xz");
60 createFile(path, "dists/stable/contrib/binary-amd64/Packages");
61 createFile(path, "dists/stable/contrib/binary-amd64/Packages.gz");
62 createFile(path, "dists/stable/non-free/binary-all/Packages");
63 createFile(path, "dists/unstable/main/binary-i386/Packages.xz");
64 createFile(path, "dists/unstable/main/binary-i386/Packages.lzma");
65 createFile(path, "dists/unstable/main/i18n/Translation-en");
66 createFile(path, "dists/unstable/main/i18n/Translation-de.bz2");
67 createFile(path, "dists/unstable/main/source/Sources.xz");
68 createFile(path, "dists/broken/non-free/source/Sources.gz");
69 createFile(path, "dists/stable/Release.gpg");
70 createFile(path, "dists/stable/Release");
71 createFile(path, "dists/unstable/InRelease");
72 createFile(path, "dists/broken/Release.gpg");
73 createLink(path, "dists/unstable", "dists/sid");
74
75 Cdrom cd;
76 std::vector<std::string> Packages, Sources, Signatur, Translation;
77 std::string InfoDir;
78 EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
79 EXPECT_EQ(5, Packages.size());
80 EXPECT_EQ(path + "/dists/sid/main/binary-i386/", Packages[0]);
81 EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
82 EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[2]);
83 EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[3]);
84 EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[4]);
85 EXPECT_EQ(3, Sources.size());
86 EXPECT_EQ(path + "/dists/sid/main/source/", Sources[0]);
87 EXPECT_EQ(path + "/dists/stable/main/source/", Sources[1]);
88 EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[2]);
89 EXPECT_EQ(3, Signatur.size());
90 EXPECT_EQ(path + "/dists/sid/", Signatur[0]);
91 EXPECT_EQ(path + "/dists/stable/", Signatur[1]);
92 EXPECT_EQ(path + "/dists/unstable/", Signatur[2]);
93 EXPECT_EQ(4, Translation.size());
94 EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
95 EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
96 EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
97 EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
98 EXPECT_EQ(path + "/.disk/", InfoDir);
99
100 cd.DropRepeats(Packages, "Packages");
101 cd.DropRepeats(Sources, "Sources");
102 _error->PushToStack();
103 cd.DropRepeats(Signatur, "InRelease");
104 cd.DropRepeats(Signatur, "Release.gpg");
105 _error->RevertToStack();
106 _error->DumpErrors();
107 cd.DropRepeats(Translation, "");
108
109 EXPECT_EQ(4, Packages.size());
110 EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
111 EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]);
112 EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[2]);
113 EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]);
114 EXPECT_EQ(2, Sources.size());
115 EXPECT_EQ(path + "/dists/stable/main/source/", Sources[0]);
116 EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[1]);
117 EXPECT_EQ(2, Signatur.size());
118 EXPECT_EQ(path + "/dists/stable/", Signatur[0]);
119 EXPECT_EQ(path + "/dists/unstable/", Signatur[1]);
120 EXPECT_EQ(2, Translation.size());
121 EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
122 EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
123
124 removeDirectory(path);
125}