]> git.saurik.com Git - apt.git/blame - test/libapt/indexcopytosourcelist_test.cc
debian/gbp.conf: point debian-branch to master
[apt.git] / test / libapt / indexcopytosourcelist_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
d29a5330
DK
3#include <apt-pkg/configuration.h>
4#include <apt-pkg/aptconfiguration.h>
5#include <apt-pkg/indexcopy.h>
6
7#include <string>
453b82a3 8#include <stdio.h>
d29a5330 9
f00832cc 10#include <gtest/gtest.h>
d29a5330
DK
11
12class NoCopy : public IndexCopy {
f00832cc
DK
13 public:
14 std::string ConvertToSourceList(std::string CD,std::string Path) {
15 IndexCopy::ConvertToSourceList(CD, Path);
16 return Path;
17 }
3b302846
DK
18 bool GetFile(std::string &/*Filename*/, unsigned long long &/*Size*/) APT_OVERRIDE { return false; }
19 bool RewriteEntry(FileFd & /*Target*/, std::string const &/*File*/) APT_OVERRIDE { return false; }
20 const char *GetFileName() APT_OVERRIDE { return NULL; }
21 const char *Type() APT_OVERRIDE { return NULL; }
d29a5330
DK
22
23};
24
f00832cc
DK
25TEST(IndexCopyTest, ConvertToSourceList)
26{
d29a5330
DK
27 NoCopy ic;
28 std::string const CD("/media/cdrom/");
29
30 char const * Releases[] = { "unstable", "wheezy-updates", NULL };
31 char const * Components[] = { "main", "non-free", NULL };
32
f00832cc
DK
33 for (char const ** Release = Releases; *Release != NULL; ++Release)
34 {
35 SCOPED_TRACE(std::string("Release ") + *Release);
36 for (char const ** Component = Components; *Component != NULL; ++Component)
37 {
38 SCOPED_TRACE(std::string("Component ") + *Component);
d29a5330
DK
39 std::string const Path = std::string("dists/") + *Release + "/" + *Component + "/";
40 std::string const Binary = Path + "binary-";
41 std::string const A = Binary + "armel/";
42 std::string const B = Binary + "mips/";
43 std::string const C = Binary + "kfreebsd-mips/";
44 std::string const S = Path + "source/";
45 std::string const List = std::string(*Release) + " " + *Component;
46
47 _config->Clear("APT");
48 APT::Configuration::getArchitectures(false);
f00832cc
DK
49 EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
50 EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
51 EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
52 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
d29a5330
DK
53
54 _config->Clear("APT");
55 _config->Set("APT::Architecture", "mips");
56 _config->Set("APT::Architectures::", "mips");
57 APT::Configuration::getArchitectures(false);
f00832cc
DK
58 EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
59 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
60 EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
61 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
d29a5330
DK
62
63 _config->Clear("APT");
64 _config->Set("APT::Architecture", "kfreebsd-mips");
65 _config->Set("APT::Architectures::", "kfreebsd-mips");
66 APT::Configuration::getArchitectures(false);
f00832cc
DK
67 EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
68 EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
69 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + C));
70 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
d29a5330
DK
71
72 _config->Clear("APT");
73 _config->Set("APT::Architecture", "armel");
74 _config->Set("APT::Architectures::", "armel");
75 APT::Configuration::getArchitectures(false);
f00832cc
DK
76 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
77 EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
78 EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
79 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
d29a5330
DK
80
81 _config->Clear("APT");
82 _config->Set("APT::Architecture", "armel");
83 _config->Set("APT::Architectures::", "armel");
84 _config->Set("APT::Architectures::", "mips");
85 APT::Configuration::getArchitectures(false);
f00832cc
DK
86 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
87 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
88 EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
89 EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
d29a5330
DK
90 }
91 }
d29a5330 92}