2008-02-05 14:15:50 +00:00
|
|
|
#include "DHTUnknownMessage.h"
|
|
|
|
#include "DHTNode.h"
|
|
|
|
#include "Exception.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2008-02-05 14:15:50 +00:00
|
|
|
class DHTUnknownMessageTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DHTUnknownMessageTest);
|
|
|
|
CPPUNIT_TEST(testToString);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testToString();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTUnknownMessageTest);
|
|
|
|
|
|
|
|
void DHTUnknownMessageTest::testToString()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DHTNode> localNode(new DHTNode());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string ipaddr = "192.168.0.1";
|
2008-02-05 14:15:50 +00:00
|
|
|
uint16_t port = 6881;
|
|
|
|
|
|
|
|
{
|
|
|
|
// data.size() > 8
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string data = "chocolate";
|
2008-03-07 12:05:50 +00:00
|
|
|
DHTUnknownMessage msg(localNode,
|
2010-01-05 16:01:46 +00:00
|
|
|
reinterpret_cast<const unsigned char*>(data.c_str()),
|
|
|
|
data.size(),
|
|
|
|
ipaddr, port);
|
2008-02-05 14:15:50 +00:00
|
|
|
|
2011-11-12 09:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1(6881) length=9, first 8 bytes(hex)=63686f636f6c6174"), msg.toString());
|
2008-02-05 14:15:50 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// data.size() == 3
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string data = "foo";
|
2008-03-07 12:05:50 +00:00
|
|
|
DHTUnknownMessage msg(localNode,
|
2010-01-05 16:01:46 +00:00
|
|
|
reinterpret_cast<const unsigned char*>(data.c_str()),
|
|
|
|
data.size(),
|
|
|
|
ipaddr, port);
|
2008-02-05 14:15:50 +00:00
|
|
|
|
2011-11-12 09:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1(6881) length=3, first 8 bytes(hex)=666f6f"), msg.toString());
|
2008-02-05 14:15:50 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|