Bencode2Test.cc 1.08 KB
Newer Older
1 2 3 4 5 6 7 8
#include "bencode2.h"

#include <cppunit/extensions/HelperMacros.h>

#include "RecoverableException.h"

namespace aria2 {

9
class Bencode2Test : public CppUnit::TestFixture {
10 11 12 13 14

  CPPUNIT_TEST_SUITE(Bencode2Test);
  CPPUNIT_TEST(testEncode);
  CPPUNIT_TEST_SUITE_END();

15
private:
16 17 18 19
public:
  void testEncode();
};

20
CPPUNIT_TEST_SUITE_REGISTRATION(Bencode2Test);
21 22 23 24 25

void Bencode2Test::testEncode()
{
  {
    Dict dict;
26 27 28
    dict.put("name", String::g("aria2"));
    dict.put("loc", Integer::g(80000));
    auto files = List::g();
29
    files->append(String::g("aria2c"));
30 31
    dict.put("files", std::move(files));
    auto attrs = Dict::g();
32
    attrs->put("license", String::g("GPL"));
33
    dict.put("attrs", std::move(attrs));
34 35 36 37 38 39 40 41 42 43 44 45

    CPPUNIT_ASSERT_EQUAL(std::string("d"
                                     "5:attrsd7:license3:GPLe"
                                     "5:filesl6:aria2ce"
                                     "3:loci80000e"
                                     "4:name5:aria2"
                                     "e"),
                         bencode2::encode(&dict));
  }
}

} // namespace aria2