summaryrefslogtreecommitdiffstats
path: root/test/libapt/cdrom_test.cc
blob: 364971e2a8353fc4f4f7f37124392daa46c8d2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <config.h>

#include <apt-pkg/cdrom.h>
#include <apt-pkg/cdromutl.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/fileutl.h>

#include <cstring>
#include <string>
#include <vector>

#include <gtest/gtest.h>

#include "file-helpers.h"

class Cdrom : public pkgCdrom {
public:
   std::vector<std::string> ReduceSourcelist(std::string CD,std::vector<std::string> List) {
      pkgCdrom::ReduceSourcelist(CD, List);
      return List;
   }
};

TEST(CDROMTest,ReduceSourcelist)
{
   Cdrom cd;
   std::vector<std::string> List;
   std::string CD("/media/cdrom/");

   std::vector<std::string> R = cd.ReduceSourcelist(CD, List);
   EXPECT_TRUE(R.empty());

   List.push_back(" wheezy main");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(1u, R.size());
   EXPECT_EQ(" wheezy main", R[0]);

   List.push_back(" wheezy main");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(1u, R.size());
   EXPECT_EQ(" wheezy main", R[0]);

   List.push_back(" wheezy contrib");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(1u, R.size());
   EXPECT_EQ(" wheezy contrib main", R[0]);

   List.push_back(" wheezy-update contrib");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(2u, R.size());
   EXPECT_EQ(" wheezy contrib main", R[0]);
   EXPECT_EQ(" wheezy-update contrib", R[1]);

   List.push_back(" wheezy-update contrib");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(2u, R.size());
   EXPECT_EQ(" wheezy contrib main", R[0]);
   EXPECT_EQ(" wheezy-update contrib", R[1]);

   List.push_back(" wheezy-update non-free");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(2u, R.size());
   EXPECT_EQ(" wheezy contrib main", R[0]);
   EXPECT_EQ(" wheezy-update contrib non-free", R[1]);

   List.push_back(" wheezy-update main");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(2u, R.size());
   EXPECT_EQ(" wheezy contrib main", R[0]);
   EXPECT_EQ(" wheezy-update contrib main non-free", R[1]);

   List.push_back(" wheezy non-free");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(2u, R.size());
   EXPECT_EQ(" wheezy contrib main non-free", R[0]);
   EXPECT_EQ(" wheezy-update contrib main non-free", R[1]);

   List.push_back(" sid main");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(3u, R.size());
   EXPECT_EQ(" sid main", R[0]);
   EXPECT_EQ(" wheezy contrib main non-free", R[1]);
   EXPECT_EQ(" wheezy-update contrib main non-free", R[2]);

   List.push_back(" sid main-reduce");
   R = cd.ReduceSourcelist(CD, List);
   ASSERT_EQ(3u, R.size());
   EXPECT_EQ(" sid main main-reduce", R[0]);
   EXPECT_EQ(" wheezy contrib main non-free", R[1]);
   EXPECT_EQ(" wheezy-update contrib main non-free", R[2]);
}
TEST(CDROMTest, FindMountPointForDevice)
{
   auto const file = createTemporaryFile("mountpoints",
	 "rootfs / rootfs rw 0 0\n"
	 "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
	 "sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
	 "/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n"
	 "/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"
	 "tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n");
   _config->Set("Dir::state::Mountpoints", file.Name());

   EXPECT_EQ("/", FindMountPointForDevice("rootfs"));
   EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21"));
   EXPECT_EQ("/sys", FindMountPointForDevice("sysfs"));
   EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0"));
   EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
   EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));
}