summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-04 20:11:09 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-04 20:11:09 +0000
commit53ae3f24c9458d324572ac8c23f5b8c90c4ac24e (patch)
tree6dfda92116d5f41f6ad9d730785c0694c174e5e2 /test
parentGCC 11 now default (diff)
downloadilt-53ae3f24c9458d324572ac8c23f5b8c90c4ac24e.tar.bz2
ilt-53ae3f24c9458d324572ac8c23f5b8c90c4ac24e.tar.xz
ilt-53ae3f24c9458d324572ac8c23f5b8c90c4ac24e.zip
Refactor wrapped_ptr to include destory function as template param, and possibly constructor function
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam4
-rw-r--r--test/test-collection.cpp38
2 files changed, 42 insertions, 0 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index 8a9843c..82ca894 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -13,6 +13,10 @@ project : requirements
<library>boost_unit_test_framework
<library>..//ilt
<toolset>tidy:<xcheckxx>hicpp-vararg
+ <toolset>tidy:<suppress>accessMoved
+ <toolset>tidy:<xcheckxx>bugprone-use-after-move
+ <toolset>tidy:<xcheckxx>hicpp-invalid-access-moved
+ <toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.Move
;
run test-collection.cpp ;
diff --git a/test/test-collection.cpp b/test/test-collection.cpp
index 1286733..6e54da3 100644
--- a/test/test-collection.cpp
+++ b/test/test-collection.cpp
@@ -4,6 +4,7 @@
#include <collection.hpp>
#include <memory>
+#include <ptr.hpp>
#include <special_members.hpp>
#include <vector>
@@ -64,3 +65,40 @@ BOOST_AUTO_TEST_CASE(a_sub)
}
BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_CASE(wrapped_ptr_file_cons)
+{
+ using FilePtr = wrapped_ptr<FILE, &fclose>;
+ FilePtr fp {fopen, "/dev/null", "r"};
+ BOOST_REQUIRE(fp);
+ BOOST_CHECK_NO_THROW(fflush(fp));
+
+ BOOST_CHECK_EQUAL(fp.get(), fp.operator->());
+ BOOST_CHECK_EQUAL(fp.get(), fp.operator FILE *());
+}
+
+BOOST_AUTO_TEST_CASE(wrapped_ptr_file_move)
+{
+ using FilePtr = wrapped_ptr<FILE, &fclose>;
+ FilePtr fp {fopen, "/dev/null", "r"};
+ BOOST_REQUIRE(fp);
+
+ FilePtr fp2 {std::move(fp)};
+ BOOST_REQUIRE(!fp);
+ BOOST_REQUIRE(fp2);
+
+ fp = std::move(fp2);
+ BOOST_REQUIRE(fp);
+ BOOST_REQUIRE(!fp2);
+
+ FilePtr fp3 {fopen, "/dev/null", "r"};
+ fp = std::move(fp3);
+}
+
+BOOST_AUTO_TEST_CASE(wrapped_ptr_file_typed)
+{
+ using FilePtr = wrapped_ptrt<FILE, &fopen, &fclose>;
+ FilePtr fp {"/dev/null", "r"};
+ BOOST_REQUIRE(fp);
+ BOOST_CHECK_NO_THROW(fflush(fp));
+}