]> git.saurik.com Git - apt.git/blame - test/libapt/cdromfindpackages_test.cc
Don't download "optional" files not in Release :/.
[apt.git] / test / libapt / cdromfindpackages_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
2c405a44
DK
3#include <apt-pkg/cdrom.h>
4#include <apt-pkg/error.h>
f00832cc 5#include <apt-pkg/fileutl.h>
2c405a44
DK
6
7#include <algorithm>
8#include <string>
9#include <vector>
453b82a3
DK
10#include <stddef.h>
11#include <iostream>
2c405a44 12
f00832cc
DK
13#include <gtest/gtest.h>
14
15#include "file-helpers.h"
2c405a44
DK
16
17class Cdrom : public pkgCdrom {
f00832cc
DK
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());
0300f007 27 EXPECT_TRUE(InfoDir.empty());
f00832cc 28 bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
0300f007 29 EXPECT_FALSE(InfoDir.empty());
f00832cc
DK
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 }
2c405a44 37
f00832cc 38 using pkgCdrom::DropRepeats;
2c405a44
DK
39};
40
f00832cc
DK
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");
1dd20368 51 createDirectory(path, "dists/stable/non-free/binary-all");
f00832cc
DK
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");
1dd20368 62 createFile(path, "dists/stable/non-free/binary-all/Packages");
f00832cc
DK
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");
2c405a44 74
f00832cc
DK
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));
1dd20368 79 EXPECT_EQ(5, Packages.size());
f00832cc
DK
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]);
1dd20368
DK
83 EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[3]);
84 EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[4]);
f00832cc
DK
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);
2c405a44 99
f00832cc
DK
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, "");
2c405a44 108
1dd20368 109 EXPECT_EQ(4, Packages.size());
f00832cc
DK
110 EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
111 EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]);
1dd20368
DK
112 EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[2]);
113 EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]);
f00832cc
DK
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]);
2c405a44 123
f00832cc 124 removeDirectory(path);
2c405a44 125}