diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-03-09 16:00:39 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-03-09 16:00:39 -0800 |
commit | 15063818726cf3d474d77d9d5586b36a10a3d453 (patch) | |
tree | 35912f8e447722fdbc5f46a8a1500361a9327642 /cpp/test/Ice/stream/Client.cpp | |
parent | fixing leak in Outgoing (diff) | |
download | ice-15063818726cf3d474d77d9d5586b36a10a3d453.tar.bz2 ice-15063818726cf3d474d77d9d5586b36a10a3d453.tar.xz ice-15063818726cf3d474d77d9d5586b36a10a3d453.zip |
ICE-6852 - allow OutputStream to marshal to user-supplied buffer
Diffstat (limited to 'cpp/test/Ice/stream/Client.cpp')
-rw-r--r-- | cpp/test/Ice/stream/Client.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cpp/test/Ice/stream/Client.cpp b/cpp/test/Ice/stream/Client.cpp index 25e0a165976..418dd020c28 100644 --- a/cpp/test/Ice/stream/Client.cpp +++ b/cpp/test/Ice/stream/Client.cpp @@ -1241,6 +1241,39 @@ run(int, char**, const Ice::CommunicatorPtr& communicator) } } + // + // Test marshaling to user-supplied buffer. + // + { + Ice::Byte buf[128]; + pair<Ice::Byte*, Ice::Byte*> p(&buf[0], &buf[0] + sizeof(buf)); + Ice::OutputStream out(communicator, Ice::currentEncoding, p); + vector<Ice::Byte> v; + v.resize(127); + out.write(v); + test(out.pos() == 128); // 127 bytes + leading size (1 byte) + test(out.b.begin() == buf); // Verify the stream hasn't reallocated. + } + { + Ice::Byte buf[128]; + pair<Ice::Byte*, Ice::Byte*> p(&buf[0], &buf[0] + sizeof(buf)); + Ice::OutputStream out(communicator, Ice::currentEncoding, p); + vector<Ice::Byte> v; + v.resize(127); + ::memset(&v[0], 0xFF, v.size()); + out.write(v); + out.write(Ice::Byte(0xFF)); // This extra byte should make the stream reallocate. + test(out.pos() == 129); // 127 bytes + leading size (1 byte) + 1 byte + test(out.b.begin() != buf); // Verify the stream was reallocated. + out.finished(data); + + Ice::InputStream in(communicator, data); + vector<Ice::Byte> v2; + in.read(v2); + test(v2.size() == 127); + test(v == v2); // Make sure the original buffer was preserved. + } + cout << "ok" << endl; return 0; } |