]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/rgw/test_rgw_bencode.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / rgw / test_rgw_bencode.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #include "gtest/gtest.h"
4
5 #include "rgw_torrent.h"
6
7 using namespace std;
8
9 TEST(Bencode, String)
10 {
11 TorrentBencode decode;
12 bufferlist bl;
13
14 decode.bencode("foo", bl);
15 decode.bencode("bar", bl);
16 decode.bencode("baz", bl);
17
18 string s(bl.c_str(), bl.length());
19
20 ASSERT_STREQ("3:foo3:bar3:baz", s.c_str());
21 }
22
23 TEST(Bencode, Integers)
24 {
25 TorrentBencode decode;
26 bufferlist bl;
27
28 decode.bencode(0, bl);
29 decode.bencode(-3, bl);
30 decode.bencode(7, bl);
31
32 string s(bl.c_str(), bl.length());
33
34 ASSERT_STREQ("i0ei-3ei7e", s.c_str());
35 }
36
37 TEST(Bencode, Dict)
38 {
39 TorrentBencode decode;
40 bufferlist bl;
41
42 decode.bencode_dict(bl);
43 decode.bencode("foo", 5, bl);
44 decode.bencode("bar", "baz", bl);
45 decode.bencode_end(bl);
46
47 string s(bl.c_str(), bl.length());
48
49 ASSERT_STREQ("d3:fooi5e3:bar3:baze", s.c_str());
50 }
51
52 TEST(Bencode, List)
53 {
54 TorrentBencode decode;
55 bufferlist bl;
56
57 decode.bencode_list(bl);
58 decode.bencode("foo", 5, bl);
59 decode.bencode("bar", "baz", bl);
60 decode.bencode_end(bl);
61
62 string s(bl.c_str(), bl.length());
63
64 ASSERT_STREQ("l3:fooi5e3:bar3:baze", s.c_str());
65 }