From 76c4f78b5cfd786b90069f7256252229444fdecd Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jan 2022 17:33:53 -0500 Subject: Add QUtil::make_shared_cstr Replace most of the calls to QUtil::copy_string with this instead. --- libtests/qtest/qutil/qutil.out | 1 + libtests/qutil.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'libtests') diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out index bcb89def..58cc2334 100644 --- a/libtests/qtest/qutil/qutil.out +++ b/libtests/qtest/qutil/qutil.out @@ -22,6 +22,7 @@ one 7 compare okay +compare okay -2147483648 to int: PASSED 2147483647 to int: PASSED 2147483648 to int threw (integer out of range converting 2147483648 from a 8-byte signed type to a 4-byte signed type): PASSED diff --git a/libtests/qutil.cc b/libtests/qutil.cc index cd2b7796..f59b564d 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -150,6 +150,16 @@ void string_conversion_test() std::cout << "compare failed" << std::endl; } delete [] tmp; + // Also test with make_shared_cstr + auto tmp2 = QUtil::make_shared_cstr(embedded_null); + if (memcmp(tmp2.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); @@ -407,8 +417,8 @@ void transcoding_test() void print_whoami(char const* str) { - PointerHolder dup(true, QUtil::copy_string(str)); - std::cout << QUtil::getWhoami(dup.getPointer()) << std::endl; + auto dup = QUtil::make_shared_cstr(str); + std::cout << QUtil::getWhoami(dup.get()) << std::endl; } void get_whoami_test() -- cgit v1.2.3-54-g00ecf