Metalink2RequestGroupTest.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
  30. CPPUNIT_ASSERT_EQUAL(string("ftp://ftphost/aria2-0.5.2.tar.bz2"), uris[0]);
  31. CPPUNIT_ASSERT_EQUAL(string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
  32. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  33. CPPUNIT_ASSERT(!dctx.isNull());
  34. CPPUNIT_ASSERT_EQUAL((int64_t)0, dctx->getTotalLength());
  35. #ifdef ENABLE_MESSAGE_DIGEST
  36. CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getChecksumHashAlgo());
  37. CPPUNIT_ASSERT_EQUAL(string("a96cf3f0266b91d87d5124cf94326422800b627d"),
  38. dctx->getChecksum());
  39. #endif // ENABLE_MESSAGE_DIGEST
  40. }
  41. // second file
  42. {
  43. RequestGroupHandle rg = groups[1];
  44. Strings uris = rg->getUris();
  45. CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
  46. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  47. CPPUNIT_ASSERT(!dctx.isNull());
  48. #ifdef ENABLE_MESSAGE_DIGEST
  49. CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getPieceHashAlgo());
  50. CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
  51. CPPUNIT_ASSERT_EQUAL((int32_t)262144, dctx->getPieceLength());
  52. CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksumHashAlgo());
  53. CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksum());
  54. #endif // ENABLE_MESSAGE_DIGEST
  55. }
  56. #ifdef ENABLE_BITTORRENT
  57. // fifth file <- downloading .torrent file
  58. {
  59. RequestGroupHandle rg = groups[4];
  60. Strings uris = rg->getUris();
  61. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  62. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated.torrent"),
  63. uris[0]);
  64. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  65. CPPUNIT_ASSERT(!dctx.isNull());
  66. }
  67. #endif // ENABLE_BITTORRENT
  68. // sixth file <- depends on thrid file
  69. {
  70. #ifdef ENABLE_BITTORRENT
  71. RequestGroupHandle rg = groups[5];
  72. #else
  73. RequestGroupHandle rg = groups[4];
  74. #endif // ENABLE_BITTORRENT
  75. Strings uris = rg->getUris();
  76. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  77. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated"), uris[0]);
  78. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  79. CPPUNIT_ASSERT(!dctx.isNull());
  80. }
  81. }