From 79f6b4823b95b65290a045a59fdd4a8d9b302708 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 21 Jun 2019 21:32:47 -0400 Subject: Convert remaining public classes to use Members pattern Have classes contain only a single private member of type PointerHolder. This makes it safe to change the structure of the Members class without breaking binary compatibility. Many of the classes already follow this pattern quite successfully. This brings in the rest of the class that are part of the public API. --- libtests/buffer.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'libtests/buffer.cc') diff --git a/libtests/buffer.cc b/libtests/buffer.cc index 4713f554..bd28746f 100644 --- a/libtests/buffer.cc +++ b/libtests/buffer.cc @@ -5,6 +5,7 @@ #include #include #include +#include static unsigned char* uc(char const* s) { @@ -13,6 +14,25 @@ static unsigned char* uc(char const* s) int main() { + { + // Test that buffers can be copied by value. + Buffer bc1(2); + unsigned char* bc1p = bc1.getBuffer(); + bc1p[0] = 'Q'; + bc1p[1] = 'W'; + Buffer bc2(bc1); + bc1p[0] = 'R'; + unsigned char* bc2p = bc2.getBuffer(); + assert(bc2p != bc1p); + assert(bc2p[0] == 'Q'); + assert(bc2p[1] == 'W'); + bc2 = bc1; + bc2p = bc2.getBuffer(); + assert(bc2p != bc1p); + assert(bc2p[0] == 'R'); + assert(bc2p[1] == 'W'); + } + try { Pl_Discard discard; @@ -68,6 +88,16 @@ int main() b = bp3.getBuffer(); std::cout << "size: " << b->getSize() << std::endl; delete b; + // Should be able to call getBuffer again and get an empty buffer + b = bp3.getBuffer(); + std::cout << "size: " << b->getSize() << std::endl; + delete b; + // Also can write 0 and do it. + bp3.write(uc(""), 0); + bp3.finish(); + b = bp3.getBuffer(); + std::cout << "size: " << b->getSize() << std::endl; + delete b; } catch (std::exception& e) { -- cgit v1.2.3-54-g00ecf