]>
Commit | Line | Data |
---|---|---|
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 | |
17 | class 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()); | |
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())); | |
33 | return result; | |
34 | } | |
2c405a44 | 35 | |
f00832cc | 36 | using pkgCdrom::DropRepeats; |
2c405a44 DK |
37 | }; |
38 | ||
f00832cc DK |
39 | TEST(CDROMTest,FindPackages) |
40 | { | |
41 | std::string path; | |
42 | createTemporaryDirectory("findpackage", path); | |
43 | ||
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"); | |
1dd20368 | 49 | createDirectory(path, "dists/stable/non-free/binary-all"); |
f00832cc DK |
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"); | |
1dd20368 | 60 | createFile(path, "dists/stable/non-free/binary-all/Packages"); |
f00832cc DK |
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"); | |
2c405a44 | 72 | |
f00832cc DK |
73 | Cdrom cd; |
74 | std::vector<std::string> Packages, Sources, Signatur, Translation; | |
75 | std::string InfoDir; | |
76 | EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir)); | |
1dd20368 | 77 | EXPECT_EQ(5, Packages.size()); |
f00832cc DK |
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]); | |
1dd20368 DK |
81 | EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[3]); |
82 | EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[4]); | |
f00832cc DK |
83 | EXPECT_EQ(3, Sources.size()); |
84 | EXPECT_EQ(path + "/dists/sid/main/source/", Sources[0]); | |
85 | EXPECT_EQ(path + "/dists/stable/main/source/", Sources[1]); | |
86 | EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[2]); | |
87 | EXPECT_EQ(3, Signatur.size()); | |
88 | EXPECT_EQ(path + "/dists/sid/", Signatur[0]); | |
89 | EXPECT_EQ(path + "/dists/stable/", Signatur[1]); | |
90 | EXPECT_EQ(path + "/dists/unstable/", Signatur[2]); | |
91 | EXPECT_EQ(4, Translation.size()); | |
92 | EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-de", Translation[0]); | |
93 | EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-en", Translation[1]); | |
94 | EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]); | |
95 | EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]); | |
96 | EXPECT_EQ(path + "/.disk/", InfoDir); | |
2c405a44 | 97 | |
f00832cc DK |
98 | cd.DropRepeats(Packages, "Packages"); |
99 | cd.DropRepeats(Sources, "Sources"); | |
100 | _error->PushToStack(); | |
101 | cd.DropRepeats(Signatur, "InRelease"); | |
102 | cd.DropRepeats(Signatur, "Release.gpg"); | |
103 | _error->RevertToStack(); | |
104 | _error->DumpErrors(); | |
105 | cd.DropRepeats(Translation, ""); | |
2c405a44 | 106 | |
1dd20368 | 107 | EXPECT_EQ(4, Packages.size()); |
f00832cc DK |
108 | EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]); |
109 | EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]); | |
1dd20368 DK |
110 | EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[2]); |
111 | EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]); | |
f00832cc DK |
112 | EXPECT_EQ(2, Sources.size()); |
113 | EXPECT_EQ(path + "/dists/stable/main/source/", Sources[0]); | |
114 | EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[1]); | |
115 | EXPECT_EQ(2, Signatur.size()); | |
116 | EXPECT_EQ(path + "/dists/stable/", Signatur[0]); | |
117 | EXPECT_EQ(path + "/dists/unstable/", Signatur[1]); | |
118 | EXPECT_EQ(2, Translation.size()); | |
119 | EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]); | |
120 | EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]); | |
2c405a44 | 121 | |
f00832cc | 122 | removeDirectory(path); |
2c405a44 | 123 | } |