File: SessionSerializerTest.cc

package info (click to toggle)
aria2 1.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 14,748 kB
  • ctags: 13,441
  • sloc: cpp: 86,740; ansic: 16,496; sh: 4,916; makefile: 1,312; ruby: 397; yacc: 291; xml: 170; sed: 16
file content (71 lines) | stat: -rw-r--r-- 2,073 bytes parent folder | download
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
66
67
68
69
70
71
#include "SessionSerializer.h"

#include <iostream>
#include <sstream>

#include <cppunit/extensions/HelperMacros.h>

#include "RequestGroupMan.h"
#include "ServerStatMan.h"
#include "array_fun.h"
#include "download_helper.h"
#include "FileEntry.h"
#include "prefs.h"

namespace aria2 {

class SessionSerializerTest:public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(SessionSerializerTest);
  CPPUNIT_TEST(testSave);
  CPPUNIT_TEST_SUITE_END();
public:
  void testSave();
};


CPPUNIT_TEST_SUITE_REGISTRATION(SessionSerializerTest);

void SessionSerializerTest::testSave()
{
#if defined(ENABLE_BITTORRENT) && defined(ENABLE_METALINK)
  const std::string URIs[] =
    { "http://localhost/file",
      "http://mirror/file",
      "test.torrent",
      "serialize_session.meta4",
      "magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C"};
  std::vector<std::string> uris(vbegin(URIs), vend(URIs));
  std::vector<SharedHandle<RequestGroup> > result;
  SharedHandle<Option> option(new Option());
  option->put(PREF_DIR, "/tmp");
  createRequestGroupForUri(result, option, uris);
  CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
  SharedHandle<RequestGroupMan> rgman
    (new RequestGroupMan(result, 1, option.get()));
  SessionSerializer s(rgman);
  std::stringstream ss;
  s.save(ss);
  std::string line;
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(strconcat(uris[0], "\t", uris[1], "\t"), line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(std::string(" dir=/tmp"), line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(uris[2], line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(std::string(" dir=/tmp"), line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(uris[3], line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(std::string(" dir=/tmp"), line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(uris[4], line);
  std::getline(ss, line);
  CPPUNIT_ASSERT_EQUAL(std::string(" dir=/tmp"), line);
  std::getline(ss, line);
  CPPUNIT_ASSERT(!ss);
#endif // defined(ENABLE_BITTORRENT) && defined(ENABLE_METALINK)
}

} // namespace aria2