Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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/rgw_torrent.h"
6
7 TEST(Bencode, String)
8 {
9   TorrentBencode decode;
10   bufferlist bl;
11
12   decode.bencode("foo", bl);
13   decode.bencode("bar", bl);
14   decode.bencode("baz", bl);
15
16   string s(bl.c_str(), bl.length());
17
18   ASSERT_STREQ("3:foo3:bar3:baz", s.c_str());
19 }
20
21 TEST(Bencode, Integers)
22 {
23   TorrentBencode decode;
24   bufferlist bl;
25
26   decode.bencode(0, bl);
27   decode.bencode(-3, bl);
28   decode.bencode(7, bl);
29
30   string s(bl.c_str(), bl.length());
31
32   ASSERT_STREQ("i0ei-3ei7e", s.c_str());
33 }
34
35 TEST(Bencode, Dict)
36 {
37   TorrentBencode decode;  
38   bufferlist bl;
39
40   decode.bencode_dict(bl);
41   decode.bencode("foo", 5, bl);
42   decode.bencode("bar", "baz", bl);
43   decode.bencode_end(bl);
44
45   string s(bl.c_str(), bl.length());
46
47   ASSERT_STREQ("d3:fooi5e3:bar3:baze", s.c_str());
48 }
49
50 TEST(Bencode, List)
51 {
52   TorrentBencode decode;
53   bufferlist bl;
54
55   decode.bencode_list(bl);
56   decode.bencode("foo", 5, bl);
57   decode.bencode("bar", "baz", bl);
58   decode.bencode_end(bl);
59
60   string s(bl.c_str(), bl.length());
61
62   ASSERT_STREQ("l3:fooi5e3:bar3:baze", s.c_str());
63 }