final test is concluded, bencode implementation is complete and capable

of decoding and encoding torrent files and announces in a way as they
come
This commit is contained in:
mykola2312 2024-10-17 08:27:19 +03:00
parent c978925f70
commit 2d80fc2657

View file

@ -164,6 +164,10 @@ public class BTreeTest {
tree.setRoot(new BString("test"));
assertArrayEquals("4:test".getBytes(), tree.encode());
tree.setRoot(new BDict())
.set(new BInteger(1), new BInteger(2));
assertArrayEquals("di1ei2ee".getBytes(), tree.encode());
});
}
@ -190,4 +194,16 @@ public class BTreeTest {
assertEquals(new BInteger(16777216), pieceLength);
});
}
@Test
public void testDecodeEncodeTorrentFile() throws BError, IOException {
final byte[] data = Files.readAllBytes(Path.of("test", "test.torrent"));
BTree torrent = new BTree();
assertDoesNotThrow(() -> {
torrent.decode(data);
assertArrayEquals(data, torrent.encode());
});
}
}