From a7237c69f7befce7af174087bf770acd0187fb9b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 15 May 2016 23:40:09 +0900 Subject: Refactor BitTorrent message buffer usage --- test/BtHandshakeMessageTest.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/BtHandshakeMessageTest.cc') diff --git a/test/BtHandshakeMessageTest.cc b/test/BtHandshakeMessageTest.cc index a86ae54a..b8569d73 100644 --- a/test/BtHandshakeMessageTest.cc +++ b/test/BtHandshakeMessageTest.cc @@ -73,23 +73,23 @@ void BtHandshakeMessageTest::testCreate() void BtHandshakeMessageTest::testCreateMessage() { - unsigned char infoHash[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - unsigned char peerId[] = {0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, - 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, - 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0}; - - std::shared_ptr msg(new BtHandshakeMessage()); + constexpr unsigned char infoHash[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + constexpr unsigned char peerId[] = {0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0}; + + auto msg = std::make_shared(); msg->setInfoHash(infoHash); msg->setPeerId(peerId); unsigned char data[68]; createHandshakeMessageData(data); - unsigned char* rawmsg = msg->createMessage(); + auto rawmsg = msg->createMessage(); + CPPUNIT_ASSERT_EQUAL((size_t)68, rawmsg.size()); CPPUNIT_ASSERT_EQUAL(util::toHex((const unsigned char*)data, 68), - util::toHex(rawmsg, 68)); - delete[] rawmsg; + util::toHex(rawmsg.data(), 68)); } void BtHandshakeMessageTest::testToString() -- cgit