TrackerWatcherCommandTest.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "TrackerWatcherCommand.h"
  2. #include "TorrentConsoleDownloadEngine.h"
  3. #include "MetaFileUtil.h"
  4. #include "Exception.h"
  5. #include "prefs.h"
  6. #include "HttpInitiateConnectionCommand.h"
  7. #include "ByteArrayDiskWriter.h"
  8. #include "DefaultBtContext.h"
  9. #include "DefaultBtAnnounce.h"
  10. #include "DefaultPieceStorage.h"
  11. #include "DefaultPeerStorage.h"
  12. #include "BtRegistry.h"
  13. #include <cppunit/extensions/HelperMacros.h>
  14. using namespace std;
  15. class TrackerWatcherCommandTest:public CppUnit::TestFixture {
  16. CPPUNIT_TEST_SUITE(TrackerWatcherCommandTest);
  17. CPPUNIT_TEST(testCreateCommand);
  18. CPPUNIT_TEST_SUITE_END();
  19. private:
  20. public:
  21. void setUp() {
  22. }
  23. void testCreateCommand();
  24. };
  25. CPPUNIT_TEST_SUITE_REGISTRATION( TrackerWatcherCommandTest );
  26. void TrackerWatcherCommandTest::testCreateCommand() {
  27. try {
  28. Option* op = new Option();
  29. op->put(PREF_TRACKER_MAX_TRIES, "10");
  30. BtContextHandle btContext(new DefaultBtContext());
  31. btContext->load("test.torrent");
  32. BtRuntimeHandle btRuntime;
  33. BtRegistry::registerBtRuntime(btContext->getInfoHashAsString(), btRuntime);
  34. PieceStorageHandle pieceStorage(new DefaultPieceStorage(btContext, op));
  35. BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
  36. pieceStorage);
  37. PeerStorageHandle peerStorage(new DefaultPeerStorage(btContext, op));
  38. BtRegistry::registerPeerStorage(btContext->getInfoHashAsString(),
  39. peerStorage);
  40. BtAnnounceHandle btAnnounce(new DefaultBtAnnounce(btContext, op));
  41. BtRegistry::registerBtAnnounce(btContext->getInfoHashAsString(), btAnnounce);
  42. TorrentConsoleDownloadEngine* te = new TorrentConsoleDownloadEngine();
  43. te->option = op;
  44. te->segmentMan = new SegmentMan();
  45. te->segmentMan->option = op;
  46. ByteArrayDiskWriter* byteArrayDiskWriter = new ByteArrayDiskWriter();
  47. te->segmentMan->diskWriter = byteArrayDiskWriter;
  48. TrackerWatcherCommand command(1, te, btContext);
  49. CPPUNIT_ASSERT(dynamic_cast<HttpInitiateConnectionCommand*>(command.createCommand()));
  50. //cerr << btAnnounce->getAnnounceUrl() << endl;
  51. btAnnounce->announceSuccess();
  52. btAnnounce->resetAnnounce();
  53. te->segmentMan->init();
  54. btRuntime->setHalt(true);
  55. CPPUNIT_ASSERT(dynamic_cast<HttpInitiateConnectionCommand*>(command.createCommand()));
  56. //cerr << btAnnounce->getAnnounceUrl() << endl;
  57. btAnnounce->announceSuccess();
  58. btAnnounce->resetAnnounce();
  59. te->segmentMan->init();
  60. CPPUNIT_ASSERT(btAnnounce->noMoreAnnounce());
  61. } catch(Exception* e) {
  62. cerr << e->getMsg() << endl;
  63. delete e;
  64. }
  65. }