summaryrefslogtreecommitdiff
path: root/test/UnitCopyPaste.cpp
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-06-21 23:56:45 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-08-05 21:18:12 -0400
commit9726ce6f774f64eb6d128c1ff3bab1362a925748 (patch)
tree41cb09b679ab76e58059ced56b2dd039eb885908 /test/UnitCopyPaste.cpp
parentc7956349f660f28c70733ace7f99ffb6c3da33e5 (diff)
Various copy/paste fixes, unit test passing, parsing of result.
Change-Id: I9168853dd011e86896c3bd474a4d05ee82c0e336
Diffstat (limited to 'test/UnitCopyPaste.cpp')
-rw-r--r--test/UnitCopyPaste.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/test/UnitCopyPaste.cpp b/test/UnitCopyPaste.cpp
index b46b41ba6..ca38259c8 100644
--- a/test/UnitCopyPaste.cpp
+++ b/test/UnitCopyPaste.cpp
@@ -28,6 +28,46 @@
using namespace Poco::Net;
+struct CopyPasteData
+{
+ std::vector<std::string> _mimeTypes;
+ std::vector<std::string> _content;
+ CopyPasteData()
+ {
+ }
+ bool read(std::istream& inStream)
+ {
+ while (!inStream.eof())
+ {
+ std::string mime, hexLen, newline;
+ std::getline(inStream, mime, '\n');
+ std::getline(inStream, hexLen, '\n');
+ std::cerr << "mime: '" << mime << "' - hexlen '" << hexLen << "'\n";
+ uint64_t len = strtoll( hexLen.c_str(), nullptr, 16 );
+ std::string content(len, ' ');
+ inStream.read(&content[0], len);
+ std::getline(inStream, newline, '\n');
+ if (newline.length() > 0)
+ {
+ std::cerr << "trailing stream content expecting newline: '" << newline <<
+ "' - len " << hexLen << " == " << len << " read - " << content.length() << "\n";
+ return false;
+ }
+ if (mime.length() > 0)
+ {
+ _mimeTypes.push_back(mime);
+ _content.push_back(content);
+ }
+ }
+ return true;
+ }
+ size_t size()
+ {
+ assert(_mimeTypes.size() == _content.size());
+ return _mimeTypes.size();
+ }
+};
+
// Inside the WSD process
class UnitCopyPaste : public UnitWSD
{
@@ -73,7 +113,7 @@ public:
std::unique_ptr<HTTPClientSession> session(helpers::createSession(clipURI));
session->setTimeout(Poco::Timespan(10, 0)); // 10 seconds.
session->sendRequest(request);
- session->receiveResponse(response);
+ std::istream& responseStream = session->receiveResponse(response);
if (response.getStatus() != HTTPResponse::HTTP_OK)
{
@@ -82,6 +122,15 @@ public:
return;
}
+ CPPUNIT_ASSERT_EQUAL(std::string("application/octet-stream"), response.getContentType());
+ CopyPasteData clipboard;
+ CPPUNIT_ASSERT(clipboard.read(responseStream));
+ CPPUNIT_ASSERT_EQUAL(std::string("application/octet-stream"), response.getContentType());
+ std::cerr << "Clipboard with " << clipboard.size() << " entries\n";
+ for (size_t i = 0; i < clipboard.size(); ++i)
+ std::cerr << "\t[" << i << "] - size " << clipboard._content[i].size() <<
+ " type: '" << clipboard._mimeTypes[i] << "'\n";
+
std::cerr << "CopyPaste tests succeeded" << std::endl;
exitTest(TestResult::Ok);
}