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.
 
 
 
 
 
 

126 lines
5.2 KiB

  1. #include <config.h>
  2. #include <apt-pkg/cdrom.h>
  3. #include <apt-pkg/error.h>
  4. #include <apt-pkg/fileutl.h>
  5. #include <algorithm>
  6. #include <string>
  7. #include <vector>
  8. #include <stddef.h>
  9. #include <iostream>
  10. #include <gtest/gtest.h>
  11. #include "file-helpers.h"
  12. class Cdrom : public pkgCdrom {
  13. public:
  14. bool FindPackages(std::string const &CD,
  15. std::vector<std::string> &List,
  16. std::vector<std::string> &SList,
  17. std::vector<std::string> &SigList,
  18. std::vector<std::string> &TransList,
  19. std::string &InfoDir) {
  20. std::string const startdir = SafeGetCWD();
  21. EXPECT_FALSE(startdir.empty());
  22. EXPECT_TRUE(InfoDir.empty());
  23. bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
  24. EXPECT_FALSE(InfoDir.empty());
  25. std::sort(List.begin(), List.end());
  26. std::sort(SList.begin(), SList.end());
  27. std::sort(SigList.begin(), SigList.end());
  28. std::sort(TransList.begin(), TransList.end());
  29. EXPECT_EQ(0, chdir(startdir.c_str()));
  30. return result;
  31. }
  32. using pkgCdrom::DropRepeats;
  33. };
  34. TEST(CDROMTest,FindPackages)
  35. {
  36. std::string path;
  37. createTemporaryDirectory("findpackage", path);
  38. createDirectory(path, ".disk");
  39. createDirectory(path, "pool");
  40. createDirectory(path, "dists/stable/main/binary-i386");
  41. createDirectory(path, "dists/stable/main/source");
  42. createDirectory(path, "dists/stable/contrib/binary-amd64");
  43. createDirectory(path, "dists/stable/non-free/binary-all");
  44. createDirectory(path, "dists/unstable/main/binary-i386");
  45. createDirectory(path, "dists/unstable/main/i18n");
  46. createDirectory(path, "dists/unstable/main/source");
  47. createDirectory(path, "dists/broken/non-free/source");
  48. createFile(path, "dists/broken/.aptignr");
  49. createFile(path, "dists/stable/main/binary-i386/Packages");
  50. createFile(path, "dists/stable/main/binary-i386/Packages.bz2");
  51. createFile(path, "dists/stable/main/source/Sources.xz");
  52. createFile(path, "dists/stable/contrib/binary-amd64/Packages");
  53. createFile(path, "dists/stable/contrib/binary-amd64/Packages.gz");
  54. createFile(path, "dists/stable/non-free/binary-all/Packages");
  55. createFile(path, "dists/unstable/main/binary-i386/Packages.xz");
  56. createFile(path, "dists/unstable/main/binary-i386/Packages.lzma");
  57. createFile(path, "dists/unstable/main/i18n/Translation-en");
  58. createFile(path, "dists/unstable/main/i18n/Translation-de.bz2");
  59. createFile(path, "dists/unstable/main/source/Sources.xz");
  60. createFile(path, "dists/broken/non-free/source/Sources.gz");
  61. createFile(path, "dists/stable/Release.gpg");
  62. createFile(path, "dists/stable/Release");
  63. createFile(path, "dists/unstable/InRelease");
  64. createFile(path, "dists/broken/Release.gpg");
  65. createLink(path, "dists/unstable", "dists/sid");
  66. Cdrom cd;
  67. std::vector<std::string> Packages, Sources, Signatur, Translation;
  68. std::string InfoDir;
  69. EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
  70. EXPECT_EQ(5, Packages.size());
  71. EXPECT_EQ(path + "/dists/sid/main/binary-i386/", Packages[0]);
  72. EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
  73. EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[2]);
  74. EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[3]);
  75. EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[4]);
  76. EXPECT_EQ(3, Sources.size());
  77. EXPECT_EQ(path + "/dists/sid/main/source/", Sources[0]);
  78. EXPECT_EQ(path + "/dists/stable/main/source/", Sources[1]);
  79. EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[2]);
  80. EXPECT_EQ(3, Signatur.size());
  81. EXPECT_EQ(path + "/dists/sid/", Signatur[0]);
  82. EXPECT_EQ(path + "/dists/stable/", Signatur[1]);
  83. EXPECT_EQ(path + "/dists/unstable/", Signatur[2]);
  84. EXPECT_EQ(4, Translation.size());
  85. EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
  86. EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
  87. EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
  88. EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
  89. EXPECT_EQ(path + "/.disk/", InfoDir);
  90. cd.DropRepeats(Packages, "Packages");
  91. cd.DropRepeats(Sources, "Sources");
  92. _error->PushToStack();
  93. cd.DropRepeats(Signatur, "InRelease");
  94. cd.DropRepeats(Signatur, "Release.gpg");
  95. _error->RevertToStack();
  96. _error->DumpErrors();
  97. cd.DropRepeats(Translation, "");
  98. EXPECT_EQ(4, Packages.size());
  99. EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
  100. EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]);
  101. EXPECT_EQ(path + "/dists/stable/non-free/binary-all/", Packages[2]);
  102. EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]);
  103. EXPECT_EQ(2, Sources.size());
  104. EXPECT_EQ(path + "/dists/stable/main/source/", Sources[0]);
  105. EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[1]);
  106. EXPECT_EQ(2, Signatur.size());
  107. EXPECT_EQ(path + "/dists/stable/", Signatur[0]);
  108. EXPECT_EQ(path + "/dists/unstable/", Signatur[1]);
  109. EXPECT_EQ(2, Translation.size());
  110. EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
  111. EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
  112. removeDirectory(path);
  113. }