]>
git.saurik.com Git - apt.git/blob - test/libapt/cdrom_test.cc
3 #include <apt-pkg/configuration.h>
4 #include <apt-pkg/cdrom.h>
5 #include <apt-pkg/cdromutl.h>
6 #include <apt-pkg/fileutl.h>
12 #include <gtest/gtest.h>
14 #include "file-helpers.h"
16 class Cdrom
: public pkgCdrom
{
18 std::vector
<std::string
> ReduceSourcelist(std::string CD
,std::vector
<std::string
> List
) {
19 pkgCdrom::ReduceSourcelist(CD
, List
);
24 TEST(CDROMTest
,ReduceSourcelist
)
27 std::vector
<std::string
> List
;
28 std::string
CD("/media/cdrom/");
30 std::vector
<std::string
> R
= cd
.ReduceSourcelist(CD
, List
);
31 EXPECT_TRUE(R
.empty());
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]);
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]);
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]);
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]);
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]);
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]);
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]);
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]);
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]);
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]);
92 TEST(CDROMTest
, FindMountPointForDevice
)
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
);
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"));
112 if (tempfile
.empty() == false)
113 unlink(tempfile
.c_str());