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.
 
 
 
 
 
 

110 lines
4.0 KiB

  1. #include <config.h>
  2. #include <apt-pkg/configuration.h>
  3. #include <apt-pkg/aptconfiguration.h>
  4. #include <apt-pkg/indexcopy.h>
  5. #include <string>
  6. #include <stdio.h>
  7. #include <gtest/gtest.h>
  8. class NoCopy : private IndexCopy {
  9. public:
  10. std::string ConvertToSourceList(std::string const &CD,std::string &&Path) {
  11. IndexCopy::ConvertToSourceList(CD, Path);
  12. return Path;
  13. }
  14. bool GetFile(std::string &/*Filename*/, unsigned long long &/*Size*/) APT_OVERRIDE { return false; }
  15. bool RewriteEntry(FileFd & /*Target*/, std::string const &/*File*/) APT_OVERRIDE { return false; }
  16. const char *GetFileName() APT_OVERRIDE { return NULL; }
  17. const char *Type() APT_OVERRIDE { return NULL; }
  18. };
  19. TEST(IndexCopyTest, ConvertToSourceList)
  20. {
  21. NoCopy ic;
  22. std::string const CD("/media/cdrom/");
  23. char const * Releases[] = { "unstable", "wheezy-updates", NULL };
  24. char const * Components[] = { "main", "non-free", NULL };
  25. for (char const ** Release = Releases; *Release != NULL; ++Release)
  26. {
  27. SCOPED_TRACE(std::string("Release ") + *Release);
  28. for (char const ** Component = Components; *Component != NULL; ++Component)
  29. {
  30. SCOPED_TRACE(std::string("Component ") + *Component);
  31. std::string const Path = std::string("dists/") + *Release + "/" + *Component + "/";
  32. std::string const Binary = Path + "binary-";
  33. std::string const A = Binary + "armel/";
  34. std::string const B = Binary + "mips/";
  35. std::string const C = Binary + "kfreebsd-mips/";
  36. std::string const S = Path + "source/";
  37. std::string const List = std::string(*Release) + " " + *Component;
  38. {
  39. SCOPED_TRACE("no archs configured");
  40. _config->Clear("APT");
  41. _config->Set("APT::Architecture", "all");
  42. _config->Set("APT::Architectures::", "all");
  43. APT::Configuration::getArchitectures(false);
  44. EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
  45. EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
  46. EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
  47. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
  48. }
  49. {
  50. SCOPED_TRACE("mips configured");
  51. _config->Clear("APT");
  52. _config->Set("APT::Architecture", "mips");
  53. _config->Set("APT::Architectures::", "mips");
  54. APT::Configuration::getArchitectures(false);
  55. EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
  56. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
  57. EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
  58. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
  59. }
  60. {
  61. SCOPED_TRACE("kfreebsd-mips configured");
  62. _config->Clear("APT");
  63. _config->Set("APT::Architecture", "kfreebsd-mips");
  64. _config->Set("APT::Architectures::", "kfreebsd-mips");
  65. APT::Configuration::getArchitectures(false);
  66. EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
  67. EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
  68. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + C));
  69. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
  70. }
  71. {
  72. SCOPED_TRACE("armel configured");
  73. _config->Clear("APT");
  74. _config->Set("APT::Architecture", "armel");
  75. _config->Set("APT::Architectures::", "armel");
  76. APT::Configuration::getArchitectures(false);
  77. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
  78. EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
  79. EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
  80. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
  81. }
  82. {
  83. SCOPED_TRACE("armel+mips configured");
  84. _config->Clear("APT");
  85. _config->Set("APT::Architecture", "armel");
  86. _config->Set("APT::Architectures::", "armel");
  87. _config->Set("APT::Architectures::", "mips");
  88. APT::Configuration::getArchitectures(false);
  89. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
  90. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
  91. EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
  92. EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
  93. }
  94. }
  95. }
  96. }