PeerMessageUtilTest.cc 781 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "common.h"
  2. #include "PeerMessageUtil.h"
  3. #include "a2netcompat.h"
  4. #include <cstring>
  5. #include <cppunit/extensions/HelperMacros.h>
  6. namespace aria2 {
  7. class PeerMessageUtilTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(PeerMessageUtilTest);
  9. CPPUNIT_TEST_SUITE_END();
  10. private:
  11. public:
  12. void setUp() {
  13. }
  14. };
  15. CPPUNIT_TEST_SUITE_REGISTRATION( PeerMessageUtilTest );
  16. void setIntParam(char* dest, int param) {
  17. int nParam = htonl(param);
  18. memcpy(dest, &nParam, 4);
  19. }
  20. void setShortIntParam(char* dest, int param) {
  21. short int nParam = htons(param);
  22. memcpy(dest, &nParam, 2);
  23. }
  24. void createNLengthMessage(char* msg, int msgLen, int payloadLen, int id) {
  25. memset(msg, 0, msgLen);
  26. setIntParam(msg, payloadLen);
  27. msg[4] = (char)id;
  28. }
  29. } // namespace aria2