aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-05 14:15:07 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-05 17:24:56 +0100
commit5f3f78822b5d43e9b02082da5268d186ba7101c0 (patch)
treec7d2407df01e4c622371ad290f9681a5ae99a476 /libtests/qutil.cc
parent88c3d556d552a94aa42eaa2fa43667952e123dc8 (diff)
downloadqpdf-5f3f78822b5d43e9b02082da5268d186ba7101c0.tar.zst
Improve use of std::unique_ptr
* Use unique_ptr in place of shared_ptr in some cases * unique_ptr for arrays does not require a custom deleter * use std::make_unique (c++14) where possible
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index a74ae4fe..dcea9fd6 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -150,7 +150,7 @@ void string_conversion_test()
std::cout << "compare failed" << std::endl;
}
delete [] tmp;
- // Also test with make_shared_cstr
+ // Also test with make_shared_cstr and make_unique_cstr
auto tmp2 = QUtil::make_shared_cstr(embedded_null);
if (memcmp(tmp2.get(), embedded_null.c_str(), 7) == 0)
{
@@ -160,6 +160,15 @@ void string_conversion_test()
{
std::cout << "compare failed" << std::endl;
}
+ auto tmp3 = QUtil::make_unique_cstr(embedded_null);
+ if (memcmp(tmp3.get(), embedded_null.c_str(), 7) == 0)
+ {
+ std::cout << "compare okay" << std::endl;
+ }
+ else
+ {
+ std::cout << "compare failed" << std::endl;
+ }
std::string int_max_str = QUtil::int_to_string(INT_MAX);
std::string int_min_str = QUtil::int_to_string(INT_MIN);
@@ -417,7 +426,7 @@ void transcoding_test()
void print_whoami(char const* str)
{
- auto dup = QUtil::make_shared_cstr(str);
+ auto dup = QUtil::make_unique_cstr(str);
std::cout << QUtil::getWhoami(dup.get()) << std::endl;
}