Show
Ignore:
Timestamp:
03/06/10 11:35:37 (2 years ago)
Author:
rakshasa
Message:

* Fixed a bug in reading bencoded data. #2112

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/test/torrent/object_static_map_test.cc

    r1140 r1141  
    44#include <torrent/object_stream.h> 
    55#include "torrent/object_static_map.h" 
     6#include "protocol/extensions.h" 
    67 
    78#import "object_test_utils.h" 
     
    150151 
    151152   CPPUNIT_ASSERT(static_map_read_bencode(test_skip_map, test_read_skip_bencode)); 
     153} 
     154 
     155template <> 
     156const torrent::ExtHandshakeMessage::key_list_type torrent::ExtHandshakeMessage::keys = { 
     157  { key_e,            "e" }, 
     158  { key_m_utPex,      "m::ut_pex" }, 
     159  { key_p,            "p" }, 
     160  { key_reqq,         "reqq" }, 
     161  { key_v,            "v" }, 
     162}; 
     163 
     164void 
     165ObjectStaticMapTest::test_read_extensions() { 
     166  torrent::ExtHandshakeMessage test_ext; 
     167 
     168  CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:ai1ee")); 
     169 
     170  CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:mi1ee")); 
     171  CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:mdee")); 
     172  CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d6:ut_pexi0ee")); 
     173  CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:md6:ut_pexi0eee")); 
    152174} 
    153175 
     
    176198enum keys_raw_types { key_raw_types_empty, key_raw_types_list, key_raw_types_map, key_raw_types_str, key_raw_types_LAST}; 
    177199enum keys_multiple { key_multiple_a, key_multiple_b, key_multiple_c, key_multiple_LAST }; 
     200enum keys_dict { key_dict_a_b, key_dict_LAST }; 
    178201 
    179202typedef torrent::static_map_type<keys_empty, key_empty_LAST> test_empty_type; 
     
    182205typedef torrent::static_map_type<keys_raw_types, key_raw_types_LAST> test_raw_types_type; 
    183206typedef torrent::static_map_type<keys_multiple, key_multiple_LAST> test_multiple_type; 
     207typedef torrent::static_map_type<keys_dict, key_dict_LAST> test_dict_type; 
    184208 
    185209template <> const test_empty_type::key_list_type 
     
    196220template <> const test_multiple_type::key_list_type 
    197221test_multiple_type::keys = { { key_multiple_a, "a" }, { key_multiple_b, "b*" }, { key_multiple_c, "c" } }; 
     222template <> const test_dict_type::key_list_type 
     223test_dict_type::keys = { { key_dict_a_b, "a::b" } }; 
    198224 
    199225void 
     
    290316 
    291317void 
     318ObjectStaticMapTest::test_read_dict() { 
     319  test_dict_type map_normal; 
     320 
     321  CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:ai1ee")); 
     322  CPPUNIT_ASSERT(map_normal[key_dict_a_b].is_empty()); 
     323 
     324  CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:adee")); 
     325  CPPUNIT_ASSERT(map_normal[key_dict_a_b].is_empty()); 
     326 
     327  CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:ad1:bi1eee")); 
     328  CPPUNIT_ASSERT(map_normal[key_dict_a_b].as_value() == 1); 
     329} 
     330 
     331void 
    292332ObjectStaticMapTest::test_write_empty() { 
    293333  test_empty_type map_normal;