blob: d8f78111be68ae9b15e796b6309af00f828fdef8 (
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
|
#include "ShaVisitor.h"
#include "MetaFileUtil.h"
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class ShaVisitorTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ShaVisitorTest);
CPPUNIT_TEST(testVisit);
CPPUNIT_TEST(testVisitCompound);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testVisit();
void testVisitCompound();
};
CPPUNIT_TEST_SUITE_REGISTRATION( ShaVisitorTest );
string hexHash(unsigned char* md, int len) {
char* temp = new char[len*2+1];
for(int i = 0; i < len; i++) {
sprintf(temp+i*2, "%02x", md[i]);
}
temp[len*2] = '\0';
string h(temp);
delete [] temp;
return h;
}
void ShaVisitorTest::testVisit() {
ShaVisitor v;
Data d("test", 4);
d.accept(&v);
unsigned char md[20];
int len = 0;
v.getHash(md, len);
string hashHex = hexHash(md, len);
CPPUNIT_ASSERT_EQUAL(string("20482dadd856f5ac908848f731d9235d2891c41e"),
hashHex);
}
void ShaVisitorTest::testVisitCompound() {
ShaVisitor v;
MetaEntry* e = MetaFileUtil::parseMetaFile("test.torrent");
e->accept(&v);
unsigned char md[20];
int len = 0;
v.getHash(md, len);
string hashHex = hexHash(md, len);
CPPUNIT_ASSERT_EQUAL(string("9d33ba293924df85f6067a81c65b484de04e8efd"),
hashHex);
}
|