2008-04-13 13:30:12 +00:00
|
|
|
#include "ProtocolDetector.h"
|
2009-12-05 11:35:18 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-04-13 13:30:12 +00:00
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-04-13 13:30:12 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class ProtocolDetectorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(ProtocolDetectorTest);
|
|
|
|
CPPUNIT_TEST(testIsStreamProtocol);
|
|
|
|
CPPUNIT_TEST(testGuessTorrentFile);
|
2009-11-22 14:54:51 +00:00
|
|
|
CPPUNIT_TEST(testGuessTorrentMagnet);
|
2008-04-13 13:30:12 +00:00
|
|
|
CPPUNIT_TEST(testGuessMetalinkFile);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testIsStreamProtocol();
|
|
|
|
void testGuessTorrentFile();
|
2009-11-22 14:54:51 +00:00
|
|
|
void testGuessTorrentMagnet();
|
2008-04-13 13:30:12 +00:00
|
|
|
void testGuessMetalinkFile();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
|
|
|
|
|
|
|
|
void ProtocolDetectorTest::testIsStreamProtocol()
|
|
|
|
{
|
|
|
|
ProtocolDetector detector;
|
|
|
|
CPPUNIT_ASSERT(detector.isStreamProtocol("http://localhost/index.html"));
|
|
|
|
CPPUNIT_ASSERT(detector.isStreamProtocol("ftp://localhost/index.html"));
|
|
|
|
CPPUNIT_ASSERT(!detector.isStreamProtocol("/home/web/localhost/index.html"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolDetectorTest::testGuessTorrentFile()
|
|
|
|
{
|
|
|
|
ProtocolDetector detector;
|
|
|
|
CPPUNIT_ASSERT(detector.guessTorrentFile("test.torrent"));
|
|
|
|
CPPUNIT_ASSERT(!detector.guessTorrentFile("http://localhost/test.torrent"));
|
|
|
|
CPPUNIT_ASSERT(!detector.guessTorrentFile("test.xml"));
|
|
|
|
}
|
|
|
|
|
2009-11-22 14:54:51 +00:00
|
|
|
void ProtocolDetectorTest::testGuessTorrentMagnet()
|
|
|
|
{
|
|
|
|
ProtocolDetector detector;
|
2009-12-05 11:35:18 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2009-11-24 14:47:42 +00:00
|
|
|
CPPUNIT_ASSERT
|
|
|
|
(detector.guessTorrentMagnet
|
|
|
|
("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
|
2009-11-22 14:54:51 +00:00
|
|
|
CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
|
2009-12-05 11:35:18 +00:00
|
|
|
#else // !ENABLE_BITTORRENT
|
|
|
|
CPPUNIT_ASSERT
|
|
|
|
(!detector.guessTorrentMagnet
|
|
|
|
("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
|
|
|
|
#endif // !ENABLE_BITTORRENT
|
2009-11-22 14:54:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 13:30:12 +00:00
|
|
|
void ProtocolDetectorTest::testGuessMetalinkFile()
|
|
|
|
{
|
|
|
|
ProtocolDetector detector;
|
|
|
|
CPPUNIT_ASSERT(detector.guessMetalinkFile("test.xml"));
|
|
|
|
CPPUNIT_ASSERT(!detector.guessMetalinkFile("http://localhost/test.xml"));
|
|
|
|
CPPUNIT_ASSERT(!detector.guessMetalinkFile("test.torrent"));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|