#include "HandshakeExtensionMessage.h" #include #include #include "Peer.h" #include "Exception.h" #include "FileEntry.h" #include "DownloadContext.h" #include "bittorrent_helper.h" #include "Option.h" #include "RequestGroup.h" namespace aria2 { class HandshakeExtensionMessageTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(HandshakeExtensionMessageTest); CPPUNIT_TEST(testGetExtensionMessageID); CPPUNIT_TEST(testGetExtensionName); CPPUNIT_TEST(testGetBencodedData); CPPUNIT_TEST(testToString); CPPUNIT_TEST(testDoReceivedAction); CPPUNIT_TEST(testCreate); CPPUNIT_TEST(testCreate_stringnum); CPPUNIT_TEST_SUITE_END(); public: void setUp() {} void tearDown() {} void testGetExtensionMessageID(); void testGetExtensionName(); void testGetBencodedData(); void testToString(); void testDoReceivedAction(); void testCreate(); void testCreate_stringnum(); }; CPPUNIT_TEST_SUITE_REGISTRATION(HandshakeExtensionMessageTest); void HandshakeExtensionMessageTest::testGetExtensionMessageID() { HandshakeExtensionMessage msg; CPPUNIT_ASSERT_EQUAL((uint8_t)0, msg.getExtensionMessageID()); } void HandshakeExtensionMessageTest::testGetExtensionName() { HandshakeExtensionMessage msg; CPPUNIT_ASSERT_EQUAL(std::string("handshake"), std::string(msg.getExtensionName())); } void HandshakeExtensionMessageTest::testGetBencodedData() { HandshakeExtensionMessage msg; msg.setClientVersion("aria2"); msg.setTCPPort(6889); msg.setExtension(ExtensionMessageRegistry::UT_PEX, 1); msg.setExtension(ExtensionMessageRegistry::UT_METADATA, 2); msg.setMetadataSize(1024); CPPUNIT_ASSERT_EQUAL (std::string("d" "1:md11:ut_metadatai2e6:ut_pexi1ee" "13:metadata_sizei1024e" "1:pi6889e" "1:v5:aria2" "e"), msg.getPayload()); msg.setMetadataSize(0); CPPUNIT_ASSERT (msg.getPayload().find("metadata_size") == std::string::npos); } void HandshakeExtensionMessageTest::testToString() { HandshakeExtensionMessage msg; msg.setClientVersion("aria2"); msg.setTCPPort(6889); msg.setExtension(ExtensionMessageRegistry::UT_PEX, 1); msg.setExtension(ExtensionMessageRegistry::UT_METADATA, 2); msg.setMetadataSize(1024); CPPUNIT_ASSERT_EQUAL (std::string("handshake client=aria2, tcpPort=6889, metadataSize=1024," " ut_metadata=2, ut_pex=1"), msg.toString()); } void HandshakeExtensionMessageTest::testDoReceivedAction() { auto dctx = std::make_shared(METADATA_PIECE_SIZE, 0); auto op = std::make_shared