Added encoding/decoding tests to TestTorrentFileGenerator.
Additionally, bug fix of finalizing Torrent segments in TorrentFile::generate()

Change-Id: Iad976e3e1c26e7ec2040d41e52a8fb1e5988beeb
diff --git a/src/torrent-file.cpp b/src/torrent-file.cpp
index 2b8fd15..c230401 100644
--- a/src/torrent-file.cpp
+++ b/src/torrent-file.cpp
@@ -284,12 +284,14 @@
 
   // Sign and append the last torrent-file
   security::KeyChain keyChain;
+  currentTorrentFile.finalize();
   keyChain.sign(currentTorrentFile, signingWithSha256());
   torrentSegments.push_back(currentTorrentFile);
 
   for (auto it = torrentSegments.rbegin() + 1; it != torrentSegments.rend(); ++it) {
     auto next = it - 1;
     it->setTorrentFilePtr(next->getFullName());
+    it->finalize();
     keyChain.sign(*it, signingWithSha256());
   }