aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/buffer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-22 03:32:47 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-22 16:13:27 +0200
commit79f6b4823b95b65290a045a59fdd4a8d9b302708 (patch)
treeb94d273dd51e64a7144b669cf5ed91d826cc1387 /libtests/buffer.cc
parent864a546af6e1c17e0de2dc2be6da105f454b6e54 (diff)
downloadqpdf-79f6b4823b95b65290a045a59fdd4a8d9b302708.tar.zst
Convert remaining public classes to use Members pattern
Have classes contain only a single private member of type PointerHolder<Members>. 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.
Diffstat (limited to 'libtests/buffer.cc')
-rw-r--r--libtests/buffer.cc30
1 files changed, 30 insertions, 0 deletions
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 <stdlib.h>
#include <stdexcept>
#include <iostream>
+#include <cassert>
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)
{