2007-07-23 14:09:46 +00:00
|
|
|
#include "common.h"
|
2006-03-21 14:12:51 +00:00
|
|
|
#include "PeerMessageUtil.h"
|
2007-07-31 16:45:16 +00:00
|
|
|
#include "a2netcompat.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <cstring>
|
2006-03-21 14:12:51 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-03-21 14:12:51 +00:00
|
|
|
|
|
|
|
class PeerMessageUtilTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(PeerMessageUtilTest);
|
2008-02-20 13:02:48 +00:00
|
|
|
CPPUNIT_TEST(testCreateCompact);
|
2006-03-21 14:12:51 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
2008-02-20 13:02:48 +00:00
|
|
|
void testCreateCompact();
|
2006-03-21 14:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( PeerMessageUtilTest );
|
|
|
|
|
|
|
|
void setIntParam(char* dest, int param) {
|
|
|
|
int nParam = htonl(param);
|
|
|
|
memcpy(dest, &nParam, 4);
|
|
|
|
}
|
|
|
|
|
2006-05-09 15:54:14 +00:00
|
|
|
void setShortIntParam(char* dest, int param) {
|
|
|
|
short int nParam = htons(param);
|
|
|
|
memcpy(dest, &nParam, 2);
|
|
|
|
}
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void createNLengthMessage(char* msg, int msgLen, int payloadLen, int id) {
|
|
|
|
memset(msg, 0, msgLen);
|
|
|
|
setIntParam(msg, payloadLen);
|
|
|
|
msg[4] = (char)id;
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-02-20 13:02:48 +00:00
|
|
|
void PeerMessageUtilTest::testCreateCompact()
|
|
|
|
{
|
2008-03-07 12:05:50 +00:00
|
|
|
unsigned char compact[6];
|
2008-02-20 13:02:48 +00:00
|
|
|
CPPUNIT_ASSERT(PeerMessageUtil::createcompact(compact, "::ffff:127.0.0.1", 6881));
|
|
|
|
|
|
|
|
std::pair<std::string, uint16_t> p = PeerMessageUtil::unpackcompact(compact);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), p.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, p.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|