Added encoding/decoding tests to TestTorrentFileGenerator.
Additionally, bug fix of finalizing Torrent segments in TorrentFile::generate()
Change-Id: Iad976e3e1c26e7ec2040d41e52a8fb1e5988beeb
diff --git a/tests/unit-tests/torrent-file.t.cpp b/tests/unit-tests/torrent-file.t.cpp
index c946b6c..83e1f2a 100644
--- a/tests/unit-tests/torrent-file.t.cpp
+++ b/tests/unit-tests/torrent-file.t.cpp
@@ -27,6 +27,7 @@
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/signature.hpp>
#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/util/io.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/filesystem.hpp>
@@ -34,6 +35,8 @@
namespace fs = boost::filesystem;
+BOOST_TEST_DONT_PRINT_LOG_VALUE(std::nullptr_t)
+
namespace ndn {
namespace ntorrent {
@@ -387,6 +390,7 @@
Name("/NTORRENT" +
directoryPathName.getSubName(
directoryPathName.size() - 1).toUri()));
+ BOOST_CHECK_EQUAL(*it, TorrentFile(it->wireEncode()));
if (it != torrentFileSegments.end() - 1) {
BOOST_CHECK_EQUAL(it->getCatalog().size(), namesPerSegment);
BOOST_CHECK_EQUAL(*(it->getTorrentFilePtr()), (it+1)->getFullName());
@@ -426,6 +430,27 @@
// confirm that they are equal
BOOST_CHECK_EQUAL_COLLECTIONS(directoryFilesBytes.begin(), directoryFilesBytes.end(),
dataBytes.begin(), dataBytes.end());
+ // test that we can write the torrent file to the disk and read it out again
+ {
+ std::string dirPath = "tests/testdata/temp/";
+ boost::filesystem::create_directory(dirPath);
+ auto fileNum = 0;
+ for (auto &s : torrentFileSegments) {
+ fileNum++;
+ auto filename = dirPath + to_string(fileNum);
+ io::save(s, filename);
+ }
+ // read them back out
+ fileNum = 0;
+ for (auto &s : torrentFileSegments) {
+ fileNum++;
+ auto filename = dirPath + to_string(fileNum);
+ auto torrent_ptr = io::load<TorrentFile>(filename);
+ BOOST_CHECK_NE(torrent_ptr, nullptr);
+ BOOST_CHECK_EQUAL(s, *torrent_ptr);
+ }
+ fs::remove_all(dirPath);
+ }
}
}
}