File: ProtocolDetectorTest.cc

package info (click to toggle)
aria2 1.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 14,748 kB
  • ctags: 13,441
  • sloc: cpp: 86,740; ansic: 16,496; sh: 4,916; makefile: 1,312; ruby: 397; yacc: 291; xml: 170; sed: 16
file content (71 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "ProtocolDetector.h"

#include <cppunit/extensions/HelperMacros.h>

#include "Exception.h"
#include "util.h"

namespace aria2 {

class ProtocolDetectorTest:public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(ProtocolDetectorTest);
  CPPUNIT_TEST(testIsStreamProtocol);
  CPPUNIT_TEST(testGuessTorrentFile);
  CPPUNIT_TEST(testGuessTorrentMagnet);
  CPPUNIT_TEST(testGuessMetalinkFile);
  CPPUNIT_TEST_SUITE_END();
public:
  void setUp() {}

  void tearDown() {}

  void testIsStreamProtocol();
  void testGuessTorrentFile();
  void testGuessTorrentMagnet();
  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"));
}

void ProtocolDetectorTest::testGuessTorrentMagnet()
{
  ProtocolDetector detector;
#ifdef ENABLE_BITTORRENT
  CPPUNIT_ASSERT
    (detector.guessTorrentMagnet
     ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
  CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
#else // !ENABLE_BITTORRENT
  CPPUNIT_ASSERT
    (!detector.guessTorrentMagnet
     ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
#endif // !ENABLE_BITTORRENT
}

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