Metalink2RequestGroupTest.cc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "Metalink2RequestGroup.h"
  2. #include "SingleFileDownloadContext.h"
  3. #include "prefs.h"
  4. #include "Option.h"
  5. #include "RequestGroup.h"
  6. #include <cppunit/extensions/HelperMacros.h>
  7. class Metalink2RequestGroupTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
  9. CPPUNIT_TEST(testGenerate);
  10. CPPUNIT_TEST_SUITE_END();
  11. private:
  12. SharedHandle<Option> _option;
  13. public:
  14. void setUp()
  15. {
  16. _option = new Option();
  17. _option->put(PREF_SPLIT, "1");
  18. }
  19. void testGenerate();
  20. };
  21. CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
  22. void Metalink2RequestGroupTest::testGenerate()
  23. {
  24. RequestGroups groups = Metalink2RequestGroup(_option.get()).generate("test.xml");
  25. // first file
  26. {
  27. RequestGroupHandle rg = groups[0];
  28. Strings uris = rg->getUris();
  29. sort(uris.begin(), uris.end());
  30. CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
  31. CPPUNIT_ASSERT_EQUAL(string("ftp://ftphost/aria2-0.5.2.tar.bz2"), uris[0]);
  32. CPPUNIT_ASSERT_EQUAL(string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
  33. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  34. CPPUNIT_ASSERT(!dctx.isNull());
  35. CPPUNIT_ASSERT_EQUAL((int64_t)0, dctx->getTotalLength());
  36. #ifdef ENABLE_MESSAGE_DIGEST
  37. CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getChecksumHashAlgo());
  38. CPPUNIT_ASSERT_EQUAL(string("a96cf3f0266b91d87d5124cf94326422800b627d"),
  39. dctx->getChecksum());
  40. #endif // ENABLE_MESSAGE_DIGEST
  41. }
  42. // second file
  43. {
  44. RequestGroupHandle rg = groups[1];
  45. Strings uris = rg->getUris();
  46. CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
  47. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  48. CPPUNIT_ASSERT(!dctx.isNull());
  49. #ifdef ENABLE_MESSAGE_DIGEST
  50. CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getPieceHashAlgo());
  51. CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
  52. CPPUNIT_ASSERT_EQUAL((int32_t)262144, dctx->getPieceLength());
  53. CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksumHashAlgo());
  54. CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksum());
  55. #endif // ENABLE_MESSAGE_DIGEST
  56. }
  57. #ifdef ENABLE_BITTORRENT
  58. // fifth file <- downloading .torrent file
  59. {
  60. RequestGroupHandle rg = groups[4];
  61. Strings uris = rg->getUris();
  62. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  63. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated.torrent"),
  64. uris[0]);
  65. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  66. CPPUNIT_ASSERT(!dctx.isNull());
  67. }
  68. #endif // ENABLE_BITTORRENT
  69. // sixth file <- depends on thrid file
  70. {
  71. #ifdef ENABLE_BITTORRENT
  72. RequestGroupHandle rg = groups[5];
  73. #else
  74. RequestGroupHandle rg = groups[4];
  75. #endif // ENABLE_BITTORRENT
  76. Strings uris = rg->getUris();
  77. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  78. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated"), uris[0]);
  79. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  80. CPPUNIT_ASSERT(!dctx.isNull());
  81. }
  82. }