X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=test%2Fsocket_test.cc;h=bcdbcd7246f7cde15ffac522d3824260f13f90cb;hp=872136a7196c02f2beaed2b4962425e6bee3475a;hb=6d686ea45f5cd01a0d11f92a903ac77779ad8562;hpb=387488c4d18ce616e3f0f64e8339ca20b843fb7e diff --git a/test/socket_test.cc b/test/socket_test.cc index 872136a71..bcdbcd724 100644 --- a/test/socket_test.cc +++ b/test/socket_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,18 +18,19 @@ */ -#include "lib/server.h" + #include "lib/dcpomatic_socket.h" +#include "lib/server.h" #include -#include #include -#include +#include #include #include +using std::make_shared; +using std::shared_ptr; using std::string; -using boost::shared_ptr; using boost::bind; @@ -42,7 +43,7 @@ class TestServer : public Server public: TestServer (bool digest) : Server (TEST_SERVER_PORT, 30) - , _buffer (new uint8_t[TEST_SERVER_BUFFER_LENGTH]) + , _buffer (TEST_SERVER_BUFFER_LENGTH) , _size (0) , _result (false) , _digest (digest) @@ -57,7 +58,6 @@ public: try { _thread.join (); } catch (...) {} - delete[] _buffer; } void expect (int size) @@ -67,7 +67,7 @@ public: } uint8_t const * buffer() const { - return _buffer; + return _buffer.data(); } void await () @@ -83,18 +83,18 @@ public: } private: - void handle (boost::shared_ptr socket) + void handle (std::shared_ptr socket) override { boost::mutex::scoped_lock lm (_mutex); BOOST_REQUIRE (_size); if (_digest) { Socket::ReadDigestScope ds (socket); - socket->read (_buffer, _size); + socket->read (_buffer.data(), _size); _size = 0; _condition.notify_one (); _result = ds.check(); } else { - socket->read (_buffer, _size); + socket->read (_buffer.data(), _size); _size = 0; _condition.notify_one (); } @@ -103,7 +103,7 @@ private: boost::thread _thread; boost::mutex _mutex; boost::condition _condition; - uint8_t* _buffer; + std::vector _buffer; int _size; bool _result; bool _digest; @@ -116,6 +116,7 @@ send (shared_ptr socket, char const* message) socket->write (reinterpret_cast(message), strlen(message) + 1); } + /** Basic test to see if Socket can send and receive data */ BOOST_AUTO_TEST_CASE (socket_basic_test) { @@ -129,7 +130,7 @@ BOOST_AUTO_TEST_CASE (socket_basic_test) tcp::resolver::query query ("127.0.0.1", dcp::raw_convert(TEST_SERVER_PORT)); tcp::resolver::iterator endpoint_iterator = resolver.resolve (query); - shared_ptr socket (new Socket); + auto socket = make_shared(); socket->connect (*endpoint_iterator); send (socket, "Hello world!");