From 53acf4349e2a6be3849cbf7306e91ec4fd97b6f9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 5 Mar 2010 06:27:23 +0000 Subject: [PATCH] made some tests rely less on deprecated functions --- test/test_primitives.cpp | 12 +++++++++--- test/test_storage.cpp | 24 ++++++++++++++++++------ test/test_web_seed.cpp | 5 ++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index a7d197469..4f384adf5 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -1014,7 +1014,9 @@ int test_main() entry torrent; torrent["info"] = info; - torrent_info ti(torrent); + std::vector buf; + bencode(std::back_inserter(buf), torrent); + torrent_info ti(&buf[0], buf.size(), ec); std::cerr << ti.name() << std::endl; TEST_CHECK(ti.name() == "test1"); @@ -1024,7 +1026,9 @@ int test_main() info["name.utf-8"] = "/test1/test2/test3"; #endif torrent["info"] = info; - torrent_info ti2(torrent); + buf.clear(); + bencode(std::back_inserter(buf), torrent); + torrent_info ti2(&buf[0], buf.size(), ec); std::cerr << ti2.name() << std::endl; #ifdef TORRENT_WINDOWS TEST_CHECK(ti2.name() == "test1\\test2\\test3"); @@ -1034,7 +1038,9 @@ int test_main() info["name.utf-8"] = "test2/../test3/.././../../test4"; torrent["info"] = info; - torrent_info ti3(torrent); + buf.clear(); + bencode(std::back_inserter(buf), torrent); + torrent_info ti3(&buf[0], buf.size(), ec); std::cerr << ti3.name() << std::endl; #ifdef TORRENT_WINDOWS TEST_CHECK(ti3.name() == "test2\\test3\\test4"); diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 139dd015f..3fd51dd77 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -555,11 +555,14 @@ void test_remove(std::string const& test_path, bool unbuffered) fs.add_file("temp_storage/_folder3/subfolder/test5.tmp", 8); libtorrent::create_torrent t(fs, 4, -1, 0); - char buf[4] = {0, 0, 0, 0}; - sha1_hash h = hasher(buf, 4).final(); + char buf_[4] = {0, 0, 0, 0}; + sha1_hash h = hasher(buf_, 4).final(); for (int i = 0; i < 6; ++i) t.set_hash(i, h); - boost::intrusive_ptr info(new torrent_info(t.generate())); + std::vector buf; + bencode(std::back_inserter(buf), t.generate()); + error_code ec; + boost::intrusive_ptr info(new torrent_info(&buf[0], buf.size(), ec)); session_settings set; set.disk_io_write_mode = set.disk_io_read_mode @@ -642,7 +645,10 @@ void test_check_files(std::string const& test_path f.write(piece2, sizeof(piece2)); f.close(); - info = new torrent_info(t.generate()); + std::vector buf; + error_code ec; + bencode(std::back_inserter(buf), t.generate()); + info = new torrent_info(&buf[0], buf.size(), ec); file_pool fp; libtorrent::asio::io_service ios; @@ -705,7 +711,10 @@ void run_test(std::string const& test_path, bool unbuffered) t.set_hash(1, hasher(piece1, piece_size).final()); t.set_hash(2, hasher(piece2, piece_size).final()); - info = new torrent_info(t.generate()); + std::vector buf; + bencode(std::back_inserter(buf), t.generate()); + error_code ec; + info = new torrent_info(&buf[0], buf.size(), ec); std::cerr << "=== test 1 ===" << std::endl; run_storage_tests(info, fs, test_path, storage_mode_compact, unbuffered); @@ -736,7 +745,10 @@ void run_test(std::string const& test_path, bool unbuffered) t.set_hash(1, hasher(piece1, piece_size).final()); t.set_hash(2, hasher(piece2, piece_size).final()); - info = new torrent_info(t.generate()); + std::vector buf; + bencode(std::back_inserter(buf), t.generate()); + error_code ec; + info = new torrent_info(&buf[0], buf.size(), ec); std::cerr << "=== test 3 ===" << std::endl; diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index 58c1683dc..78973fe0e 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -180,7 +180,10 @@ int test_main() // calculate the hash for all pieces set_piece_hashes(t, "./tmp1_web_seed", ec); - boost::intrusive_ptr torrent_file(new torrent_info(t.generate())); + std::vector buf; + error_code ec; + bencode(std::back_inserter(buf), t.generate()); + boost::intrusive_ptr torrent_file(new torrent_info(&buf[0], buf.size(), ec)); for (int i = 0; i < 6; ++i) test_transfer(torrent_file, i, port);