]>
git.saurik.com Git - apt.git/blob - test/libapt/cdromfindpackages_test.cc
719dd8f63c8b0063c5099f7749206f689eee061e
3 #include <apt-pkg/cdrom.h>
4 #include <apt-pkg/error.h>
5 #include <apt-pkg/fileutl.h>
13 #include <gtest/gtest.h>
15 #include "file-helpers.h"
17 class Cdrom
: public pkgCdrom
{
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 bool const result
= pkgCdrom::FindPackages(CD
, List
, SList
, SigList
, TransList
, InfoDir
, NULL
, 0);
28 std::sort(List
.begin(), List
.end());
29 std::sort(SList
.begin(), SList
.end());
30 std::sort(SigList
.begin(), SigList
.end());
31 std::sort(TransList
.begin(), TransList
.end());
32 EXPECT_EQ(0, chdir(startdir
.c_str()));
36 using pkgCdrom::DropRepeats
;
39 TEST(CDROMTest
,FindPackages
)
42 createTemporaryDirectory("findpackage", path
);
44 createDirectory(path
, ".disk");
45 createDirectory(path
, "pool");
46 createDirectory(path
, "dists/stable/main/binary-i386");
47 createDirectory(path
, "dists/stable/main/source");
48 createDirectory(path
, "dists/stable/contrib/binary-amd64");
49 createDirectory(path
, "dists/stable/contrib/binary-all");
50 createDirectory(path
, "dists/unstable/main/binary-i386");
51 createDirectory(path
, "dists/unstable/main/i18n");
52 createDirectory(path
, "dists/unstable/main/source");
53 createDirectory(path
, "dists/broken/non-free/source");
54 createFile(path
, "dists/broken/.aptignr");
55 createFile(path
, "dists/stable/main/binary-i386/Packages");
56 createFile(path
, "dists/stable/main/binary-i386/Packages.bz2");
57 createFile(path
, "dists/stable/main/source/Sources.xz");
58 createFile(path
, "dists/stable/contrib/binary-amd64/Packages");
59 createFile(path
, "dists/stable/contrib/binary-amd64/Packages.gz");
60 createFile(path
, "dists/stable/contrib/binary-all/Packages");
61 createFile(path
, "dists/unstable/main/binary-i386/Packages.xz");
62 createFile(path
, "dists/unstable/main/binary-i386/Packages.lzma");
63 createFile(path
, "dists/unstable/main/i18n/Translation-en");
64 createFile(path
, "dists/unstable/main/i18n/Translation-de.bz2");
65 createFile(path
, "dists/unstable/main/source/Sources.xz");
66 createFile(path
, "dists/broken/non-free/source/Sources.gz");
67 createFile(path
, "dists/stable/Release.gpg");
68 createFile(path
, "dists/stable/Release");
69 createFile(path
, "dists/unstable/InRelease");
70 createFile(path
, "dists/broken/Release.gpg");
71 createLink(path
, "dists/unstable", "dists/sid");
74 std::vector
<std::string
> Packages
, Sources
, Signatur
, Translation
;
76 EXPECT_TRUE(cd
.FindPackages(path
, Packages
, Sources
, Signatur
, Translation
, InfoDir
));
77 EXPECT_EQ(4, Packages
.size());
78 EXPECT_EQ(path
+ "/dists/sid/main/binary-i386/", Packages
[0]);
79 EXPECT_EQ(path
+ "/dists/stable/contrib/binary-amd64/", Packages
[1]);
80 EXPECT_EQ(path
+ "/dists/stable/main/binary-i386/", Packages
[2]);
81 EXPECT_EQ(path
+ "/dists/unstable/main/binary-i386/", Packages
[3]);
82 EXPECT_EQ(3, Sources
.size());
83 EXPECT_EQ(path
+ "/dists/sid/main/source/", Sources
[0]);
84 EXPECT_EQ(path
+ "/dists/stable/main/source/", Sources
[1]);
85 EXPECT_EQ(path
+ "/dists/unstable/main/source/", Sources
[2]);
86 EXPECT_EQ(3, Signatur
.size());
87 EXPECT_EQ(path
+ "/dists/sid/", Signatur
[0]);
88 EXPECT_EQ(path
+ "/dists/stable/", Signatur
[1]);
89 EXPECT_EQ(path
+ "/dists/unstable/", Signatur
[2]);
90 EXPECT_EQ(4, Translation
.size());
91 EXPECT_EQ(path
+ "/dists/sid/main/i18n/Translation-de", Translation
[0]);
92 EXPECT_EQ(path
+ "/dists/sid/main/i18n/Translation-en", Translation
[1]);
93 EXPECT_EQ(path
+ "/dists/unstable/main/i18n/Translation-de", Translation
[2]);
94 EXPECT_EQ(path
+ "/dists/unstable/main/i18n/Translation-en", Translation
[3]);
95 EXPECT_EQ(path
+ "/.disk/", InfoDir
);
97 cd
.DropRepeats(Packages
, "Packages");
98 cd
.DropRepeats(Sources
, "Sources");
99 _error
->PushToStack();
100 cd
.DropRepeats(Signatur
, "InRelease");
101 cd
.DropRepeats(Signatur
, "Release.gpg");
102 _error
->RevertToStack();
103 _error
->DumpErrors();
104 cd
.DropRepeats(Translation
, "");
106 EXPECT_EQ(3, Packages
.size());
107 EXPECT_EQ(path
+ "/dists/stable/contrib/binary-amd64/", Packages
[0]);
108 EXPECT_EQ(path
+ "/dists/stable/main/binary-i386/", Packages
[1]);
109 EXPECT_EQ(path
+ "/dists/unstable/main/binary-i386/", Packages
[2]);
110 EXPECT_EQ(2, Sources
.size());
111 EXPECT_EQ(path
+ "/dists/stable/main/source/", Sources
[0]);
112 EXPECT_EQ(path
+ "/dists/unstable/main/source/", Sources
[1]);
113 EXPECT_EQ(2, Signatur
.size());
114 EXPECT_EQ(path
+ "/dists/stable/", Signatur
[0]);
115 EXPECT_EQ(path
+ "/dists/unstable/", Signatur
[1]);
116 EXPECT_EQ(2, Translation
.size());
117 EXPECT_EQ(path
+ "/dists/unstable/main/i18n/Translation-de", Translation
[0]);
118 EXPECT_EQ(path
+ "/dists/unstable/main/i18n/Translation-en", Translation
[1]);
120 removeDirectory(path
);