Add FlatBufferBuilder move semantics tests to the main test suite (#4902)

* Add FlatBufferBuilder move semantics tests to main

Do not eagerly delete/reset allocators in release and release_raw functions
Update android, vs2010 build files
New tests for various types of FlatBufferBuilders and move semantics

* Improve test failure output with function names
This commit is contained in:
Sumant Tambe
2018-09-24 12:03:31 -07:00
committed by Wouter van Oortmerssen
parent b1a925dfc2
commit 49fed8c4f6
12 changed files with 687 additions and 180 deletions

View File

@@ -89,13 +89,15 @@ class SliceAllocator : public Allocator {
SliceAllocator &operator=(const SliceAllocator &other) = delete;
SliceAllocator(SliceAllocator &&other)
: slice_(other.slice_) {
other.slice_ = grpc_empty_slice();
: slice_(grpc_empty_slice()) {
// default-construct and swap idiom
swap(other);
}
SliceAllocator &operator=(SliceAllocator &&other) {
slice_ = other.slice_;
other.slice_ = grpc_empty_slice();
// move-construct and swap idiom
SliceAllocator temp(std::move(other));
swap(temp);
return *this;
}
@@ -190,6 +192,16 @@ class MessageBuilder : private detail::SliceAllocatorMember,
buf_.swap_allocator(other.buf_);
}
// Releases the ownership of the buffer pointer.
// Returns the size, offset, and the original grpc_slice that
// allocated the buffer. Also see grpc_slice_unref().
uint8_t *ReleaseRaw(size_t &size, size_t &offset, grpc_slice &slice) {
uint8_t *buf = FlatBufferBuilder::ReleaseRaw(size, offset);
slice = slice_allocator_.slice_;
slice_allocator_.slice_ = grpc_empty_slice();
return buf;
}
~MessageBuilder() {}
// GetMessage extracts the subslice of the buffer corresponding to the