Metalink2RequestGroupTest.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  36. // second file
  37. {
  38. RequestGroupHandle rg = groups[1];
  39. Strings uris = rg->getUris();
  40. CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
  41. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  42. CPPUNIT_ASSERT(!dctx.isNull());
  43. CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getPieceHashAlgo());
  44. CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
  45. CPPUNIT_ASSERT_EQUAL((int32_t)262144, dctx->getPieceLength());
  46. }
  47. // fifth file <- downloading .torrent file
  48. {
  49. RequestGroupHandle rg = groups[4];
  50. Strings uris = rg->getUris();
  51. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  52. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated.torrent"),
  53. uris[0]);
  54. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  55. CPPUNIT_ASSERT(!dctx.isNull());
  56. }
  57. // sixth file <- depends on thrid file
  58. {
  59. RequestGroupHandle rg = groups[5];
  60. Strings uris = rg->getUris();
  61. CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
  62. CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated"), uris[0]);
  63. SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
  64. CPPUNIT_ASSERT(!dctx.isNull());
  65. }
  66. }