]>
Commit | Line | Data |
---|---|---|
f00832cc DK |
1 | #include <config.h> |
2 | ||
3 | #include <apt-pkg/configuration.h> | |
4 | #include <apt-pkg/cdrom.h> | |
5 | #include <apt-pkg/cdromutl.h> | |
6 | #include <apt-pkg/fileutl.h> | |
7 | ||
8 | #include <string> | |
9 | #include <string.h> | |
10 | #include <vector> | |
11 | ||
12 | #include <gtest/gtest.h> | |
13 | ||
14 | #include "file-helpers.h" | |
15 | ||
16 | class Cdrom : public pkgCdrom { | |
17 | public: | |
18 | std::vector<std::string> ReduceSourcelist(std::string CD,std::vector<std::string> List) { | |
19 | pkgCdrom::ReduceSourcelist(CD, List); | |
20 | return List; | |
21 | } | |
22 | }; | |
23 | ||
24 | TEST(CDROMTest,ReduceSourcelist) | |
25 | { | |
26 | Cdrom cd; | |
27 | std::vector<std::string> List; | |
28 | std::string CD("/media/cdrom/"); | |
29 | ||
30 | std::vector<std::string> R = cd.ReduceSourcelist(CD, List); | |
31 | EXPECT_TRUE(R.empty()); | |
32 | ||
33 | List.push_back(" wheezy main"); | |
34 | R = cd.ReduceSourcelist(CD, List); | |
35 | ASSERT_EQ(1, R.size()); | |
36 | EXPECT_EQ(" wheezy main", R[0]); | |
37 | ||
38 | List.push_back(" wheezy main"); | |
39 | R = cd.ReduceSourcelist(CD, List); | |
40 | ASSERT_EQ(1, R.size()); | |
41 | EXPECT_EQ(" wheezy main", R[0]); | |
42 | ||
43 | List.push_back(" wheezy contrib"); | |
44 | R = cd.ReduceSourcelist(CD, List); | |
45 | ASSERT_EQ(1, R.size()); | |
46 | EXPECT_EQ(" wheezy contrib main", R[0]); | |
47 | ||
48 | List.push_back(" wheezy-update contrib"); | |
49 | R = cd.ReduceSourcelist(CD, List); | |
50 | ASSERT_EQ(2, R.size()); | |
51 | EXPECT_EQ(" wheezy contrib main", R[0]); | |
52 | EXPECT_EQ(" wheezy-update contrib", R[1]); | |
53 | ||
54 | List.push_back(" wheezy-update contrib"); | |
55 | R = cd.ReduceSourcelist(CD, List); | |
56 | ASSERT_EQ(2, R.size()); | |
57 | EXPECT_EQ(" wheezy contrib main", R[0]); | |
58 | EXPECT_EQ(" wheezy-update contrib", R[1]); | |
59 | ||
60 | List.push_back(" wheezy-update non-free"); | |
61 | R = cd.ReduceSourcelist(CD, List); | |
62 | ASSERT_EQ(2, R.size()); | |
63 | EXPECT_EQ(" wheezy contrib main", R[0]); | |
64 | EXPECT_EQ(" wheezy-update contrib non-free", R[1]); | |
65 | ||
66 | List.push_back(" wheezy-update main"); | |
67 | R = cd.ReduceSourcelist(CD, List); | |
68 | ASSERT_EQ(2, R.size()); | |
69 | EXPECT_EQ(" wheezy contrib main", R[0]); | |
70 | EXPECT_EQ(" wheezy-update contrib main non-free", R[1]); | |
71 | ||
72 | List.push_back(" wheezy non-free"); | |
73 | R = cd.ReduceSourcelist(CD, List); | |
74 | ASSERT_EQ(2, R.size()); | |
75 | EXPECT_EQ(" wheezy contrib main non-free", R[0]); | |
76 | EXPECT_EQ(" wheezy-update contrib main non-free", R[1]); | |
77 | ||
78 | List.push_back(" sid main"); | |
79 | R = cd.ReduceSourcelist(CD, List); | |
80 | ASSERT_EQ(3, R.size()); | |
81 | EXPECT_EQ(" sid main", R[0]); | |
82 | EXPECT_EQ(" wheezy contrib main non-free", R[1]); | |
83 | EXPECT_EQ(" wheezy-update contrib main non-free", R[2]); | |
84 | ||
85 | List.push_back(" sid main-reduce"); | |
86 | R = cd.ReduceSourcelist(CD, List); | |
87 | ASSERT_EQ(3, R.size()); | |
88 | EXPECT_EQ(" sid main main-reduce", R[0]); | |
89 | EXPECT_EQ(" wheezy contrib main non-free", R[1]); | |
90 | EXPECT_EQ(" wheezy-update contrib main non-free", R[2]); | |
91 | } | |
92 | TEST(CDROMTest, FindMountPointForDevice) | |
93 | { | |
28ba3f89 | 94 | char * tempfile = NULL; |
f00832cc DK |
95 | FileFd fd; |
96 | createTemporaryFile("mountpoints", fd, &tempfile, | |
97 | "rootfs / rootfs rw 0 0\n" | |
98 | "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" | |
99 | "sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" | |
100 | "/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n" | |
101 | "/dev/sda1 /boot/efi vfat rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro 0 0\n" | |
102 | "tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n"); | |
103 | _config->Set("Dir::state::Mountpoints", tempfile); | |
104 | ||
105 | EXPECT_EQ("/", FindMountPointForDevice("rootfs")); | |
106 | EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21")); | |
107 | EXPECT_EQ("/sys", FindMountPointForDevice("sysfs")); | |
108 | EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0")); | |
109 | EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1")); | |
110 | EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs")); | |
111 | ||
4234d90d DK |
112 | if (tempfile != NULL) |
113 | unlink(tempfile); | |
f00832cc DK |
114 | free(tempfile); |
115 | } |