~ubuntu-branches/ubuntu/oneiric/libtorrent/oneiric

« back to all changes in this revision

Viewing changes to test/torrent/object_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2011-03-20 01:06:18 UTC
  • mfrom: (1.1.13 upstream) (4.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110320010618-g3wyylccqzqko73c
Tags: 0.12.7-5
* Use Steinar's "real" patch for IPv6. Addresses #490277, #618275,
  and Closes: #617791.
* Adapt libtorrent-0.12.6-ipv6-07.patch. It FTBFS otherwise.
* Add proper attibution to the IPv6 patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include <iostream>
 
4
#include <torrent/object.h>
 
5
 
 
6
#import "object_test.h"
 
7
#import "object_test_utils.h"
 
8
 
 
9
CPPUNIT_TEST_SUITE_REGISTRATION(ObjectTest);
 
10
 
 
11
void object_test_return_void() { }
 
12
 
 
13
// template <typename Ret>
 
14
// struct object_void_wrapper {
 
15
//   typedef 
 
16
 
 
17
//   object_void_wrapper(Slot s) : m_slot(s) {}
 
18
 
 
19
//   torrent::Object operator () () { m_slot(
 
20
 
 
21
//   Slot m_slot;
 
22
// }
 
23
 
 
24
void
 
25
ObjectTest::test_basic() {
 
26
  std::cout << "sizeof(torrent::Object) = " << sizeof(torrent::Object) << std::endl;
 
27
  std::cout << "sizeof(torrent::Object::list_type) = " << sizeof(torrent::Object::list_type) << std::endl;
 
28
  std::cout << "sizeof(torrent::Object::map_type) = " << sizeof(torrent::Object::map_type) << std::endl;
 
29
 
 
30
//   torrent::Object obj_void(object_test_return_void());
 
31
}
 
32
 
 
33
void
 
34
ObjectTest::test_flags() {
 
35
  torrent::Object objectFlagsValue = torrent::Object(int64_t());
 
36
  torrent::Object objectNoFlagsEmpty = torrent::Object();
 
37
  torrent::Object objectNoFlagsValue = torrent::Object(int64_t());
 
38
 
 
39
  objectFlagsValue.set_flags(torrent::Object::flag_static_data | torrent::Object::flag_session_data);
 
40
 
 
41
  CPPUNIT_ASSERT(objectNoFlagsEmpty.flags() == 0);
 
42
  CPPUNIT_ASSERT(objectNoFlagsValue.flags() == 0);
 
43
  CPPUNIT_ASSERT(objectFlagsValue.flags() & torrent::Object::flag_session_data &&
 
44
                 objectFlagsValue.flags() & torrent::Object::flag_static_data);
 
45
 
 
46
  objectFlagsValue.unset_flags(torrent::Object::flag_session_data);
 
47
 
 
48
  CPPUNIT_ASSERT(!(objectFlagsValue.flags() & torrent::Object::flag_session_data) &&
 
49
                 objectFlagsValue.flags() & torrent::Object::flag_static_data);
 
50
}
 
51
 
 
52
void
 
53
ObjectTest::test_merge() {
 
54
}
 
55
 
 
56
#define TEST_VALUE_A "i10e"
 
57
#define TEST_VALUE_B "i20e"
 
58
#define TEST_STRING_A "1:g"
 
59
#define TEST_STRING_B "1:h"
 
60
#define TEST_MAP_A "d1:ai1e1:bi2ee"
 
61
#define TEST_MAP_B "d1:ci4e1:di5ee"
 
62
#define TEST_LIST_A "l1:e1:fe"
 
63
#define TEST_LIST_B "li1ei2ee"
 
64
 
 
65
static bool
 
66
swap_compare(const char* left, const char* right) {
 
67
  torrent::Object obj_left = create_bencode(left);
 
68
  torrent::Object obj_right = create_bencode(right);
 
69
 
 
70
  obj_left.swap(obj_right);
 
71
  if (!compare_bencode(obj_left, right) || !compare_bencode(obj_right, left))
 
72
    return false;
 
73
 
 
74
  obj_left.swap(obj_right);
 
75
  if (!compare_bencode(obj_left, left) || !compare_bencode(obj_right, right))
 
76
    return false;
 
77
 
 
78
  return true;
 
79
}
 
80
 
 
81
void
 
82
ObjectTest::test_swap_and_move() {
 
83
  CPPUNIT_ASSERT(swap_compare(TEST_VALUE_A, TEST_VALUE_B));
 
84
  CPPUNIT_ASSERT(swap_compare(TEST_STRING_A, TEST_STRING_B));
 
85
  CPPUNIT_ASSERT(swap_compare(TEST_MAP_A, TEST_MAP_B));
 
86
  CPPUNIT_ASSERT(swap_compare(TEST_LIST_A, TEST_LIST_B));
 
87
 
 
88
  CPPUNIT_ASSERT(swap_compare(TEST_VALUE_A, TEST_STRING_B));
 
89
  CPPUNIT_ASSERT(swap_compare(TEST_STRING_A, TEST_MAP_B));
 
90
  CPPUNIT_ASSERT(swap_compare(TEST_MAP_A, TEST_LIST_B));
 
91
  CPPUNIT_ASSERT(swap_compare(TEST_LIST_A, TEST_VALUE_B));
 
92
 
 
93
  CPPUNIT_ASSERT(swap_compare("i1e", TEST_VALUE_A));
 
94
  CPPUNIT_ASSERT(swap_compare("i1e", TEST_MAP_A));
 
95
  CPPUNIT_ASSERT(swap_compare("i1e", TEST_LIST_A));
 
96
}
 
97
 
 
98
void
 
99
ObjectTest::test_create_normal() {
 
100
  torrent::Object obj;
 
101
 
 
102
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_bencode_c("i45e")).as_value() == 45);
 
103
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_bencode_c("4:test")).as_string() == "test");
 
104
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_bencode_c("li5ee")).as_list().front().as_value() == 5);
 
105
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_bencode_c("d1:ai6ee")).as_map()["a"].as_value() == 6);
 
106
 
 
107
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_string_c("test")).as_string() == "test");
 
108
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_list_c("i5ei6e")).as_list().back().as_value() == 6);
 
109
  CPPUNIT_ASSERT(torrent::object_create_normal(create_bencode_raw_map_c("1:ai2e1:bi3e")).as_map()["b"].as_value() == 3);
 
110
}