TrackerWatcherCommandTest.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <cppunit/extensions/HelperMacros.h>
  9. using namespace std;
  10. class TrackerWatcherCommandTest:public CppUnit::TestFixture {
  11. CPPUNIT_TEST_SUITE(TrackerWatcherCommandTest);
  12. CPPUNIT_TEST(testCreateCommand);
  13. CPPUNIT_TEST_SUITE_END();
  14. private:
  15. public:
  16. void setUp() {
  17. }
  18. void testCreateCommand();
  19. };
  20. CPPUNIT_TEST_SUITE_REGISTRATION( TrackerWatcherCommandTest );
  21. void TrackerWatcherCommandTest::testCreateCommand() {
  22. try {
  23. Option* op = new Option();
  24. op->put(PREF_TRACKER_MAX_TRIES, "10");
  25. TorrentConsoleDownloadEngine* te = new TorrentConsoleDownloadEngine();
  26. te->option = op;
  27. te->segmentMan = new SegmentMan();
  28. te->segmentMan->option = op;
  29. ByteArrayDiskWriter* byteArrayDiskWriter = new ByteArrayDiskWriter();
  30. te->segmentMan->diskWriter = byteArrayDiskWriter;
  31. te->torrentMan = new TorrentMan();
  32. te->torrentMan->option = op;
  33. te->torrentMan->setup("test.torrent", Strings());
  34. TrackerWatcherCommand command(1, te);
  35. CPPUNIT_ASSERT(dynamic_cast<HttpInitiateConnectionCommand*>(command.createCommand()));
  36. cerr << te->torrentMan->getAnnounceUrl() << endl;
  37. te->torrentMan->announceSuccess();
  38. te->torrentMan->resetAnnounce();
  39. te->segmentMan->init();
  40. te->torrentMan->setHalt(true);
  41. CPPUNIT_ASSERT(dynamic_cast<HttpInitiateConnectionCommand*>(command.createCommand()));
  42. cerr << te->torrentMan->getAnnounceUrl() << endl;
  43. te->torrentMan->announceSuccess();
  44. te->torrentMan->resetAnnounce();
  45. te->segmentMan->init();
  46. CPPUNIT_ASSERT(te->torrentMan->noMoreAnnounce());
  47. } catch(Exception* e) {
  48. cerr << e->getMsg() << endl;
  49. delete e;
  50. }
  51. }