blob: fcfb6872a3cae53e12e3115a26a94e2592037f60 (
plain)
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
72
73
74
75
76
77
|
#include "MetaFileUtil.h"
#include "Data.h"
#include "Dictionary.h"
#include "List.h"
#include "DlAbortEx.h"
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class MetaFileUtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MetaFileUtilTest);
CPPUNIT_TEST(testParseMetaFile);
CPPUNIT_TEST(testBdecoding);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testParseMetaFile();
void testBdecoding();
};
CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest );
void MetaFileUtilTest::testParseMetaFile() {
MetaEntry* entry = MetaFileUtil::parseMetaFile("test.torrent");
Dictionary* d = dynamic_cast<Dictionary*>(entry);
CPPUNIT_ASSERT(d != NULL);
}
void MetaFileUtilTest::testBdecoding() {
try {
char* str = "5:abcd";
MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
} catch(DlAbortEx* ex) {
delete ex;
} catch(...) {
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
}
try {
char* str = "i1234";
MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
} catch(DlAbortEx* ex) {
delete ex;
} catch(...) {
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
}
try {
char* str = "5abcd";
MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
} catch(DlAbortEx* ex) {
delete ex;
} catch(...) {
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
}
try {
char* str = "d";
MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
} catch(DlAbortEx* ex) {
delete ex;
} catch(...) {
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
}
}
|