You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

115 lines
4.1 KiB

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