2012-02-08 16:51:42 +00:00
|
|
|
#include "PeerConnection.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include "Peer.h"
|
|
|
|
#include "SocketCore.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class PeerConnectionTest : public CppUnit::TestFixture {
|
2012-02-08 16:51:42 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(PeerConnectionTest);
|
|
|
|
CPPUNIT_TEST(testReserveBuffer);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
2015-12-27 09:39:47 +00:00
|
|
|
|
2012-02-08 16:51:42 +00:00
|
|
|
public:
|
|
|
|
void testReserveBuffer();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(PeerConnectionTest);
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
void PeerConnectionTest::testReserveBuffer()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
PeerConnection con(1, std::shared_ptr<Peer>(), std::shared_ptr<SocketCore>());
|
2012-02-08 16:51:42 +00:00
|
|
|
con.presetBuffer((unsigned char*)"foo", 3);
|
2012-06-25 12:29:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)MAX_BUFFER_CAPACITY, con.getBufferCapacity());
|
2012-02-08 16:51:42 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, con.getBufferLength());
|
|
|
|
|
2016-07-20 13:42:29 +00:00
|
|
|
constexpr size_t newLength = 128_k;
|
2012-02-08 16:51:42 +00:00
|
|
|
con.reserveBuffer(newLength);
|
|
|
|
|
2012-06-25 12:29:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(newLength, con.getBufferCapacity());
|
2012-02-08 16:51:42 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, con.getBufferLength());
|
|
|
|
CPPUNIT_ASSERT(memcmp("foo", con.getBuffer(), 3) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|