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
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "gtest/gtest.h"
#include "rgw_torrent.h"
using namespace std;
TEST(Bencode, String)
{
TorrentBencode decode;
bufferlist bl;
decode.bencode("foo", bl);
decode.bencode("bar", bl);
decode.bencode("baz", bl);
string s(bl.c_str(), bl.length());
ASSERT_STREQ("3:foo3:bar3:baz", s.c_str());
}
TEST(Bencode, Integers)
{
TorrentBencode decode;
bufferlist bl;
decode.bencode(0, bl);
decode.bencode(-3, bl);
decode.bencode(7, bl);
string s(bl.c_str(), bl.length());
ASSERT_STREQ("i0ei-3ei7e", s.c_str());
}
TEST(Bencode, Dict)
{
TorrentBencode decode;
bufferlist bl;
decode.bencode_dict(bl);
decode.bencode("foo", 5, bl);
decode.bencode("bar", "baz", bl);
decode.bencode_end(bl);
string s(bl.c_str(), bl.length());
ASSERT_STREQ("d3:fooi5e3:bar3:baze", s.c_str());
}
TEST(Bencode, List)
{
TorrentBencode decode;
bufferlist bl;
decode.bencode_list(bl);
decode.bencode("foo", 5, bl);
decode.bencode("bar", "baz", bl);
decode.bencode_end(bl);
string s(bl.c_str(), bl.length());
ASSERT_STREQ("l3:fooi5e3:bar3:baze", s.c_str());
}
|