From 2a477e32170e6f60b0560b8c43d54d994ece596f Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Fri, 30 Sep 2016 15:41:44 +0200 Subject: [PATCH] New tests for shared_ptr --- tstl/test_suite/shared_ptr.cpp | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tstl/test_suite/shared_ptr.cpp b/tstl/test_suite/shared_ptr.cpp index c243524c..2b79c9ee 100644 --- a/tstl/test_suite/shared_ptr.cpp +++ b/tstl/test_suite/shared_ptr.cpp @@ -22,6 +22,28 @@ void test_base(){ check(*a.get() == 99); } +struct foo { + int bar = 0; + + int test(){ + return bar; + } + + void set(int bar){ + this->bar = bar; + } +}; + +void test_struct(){ + std::shared_ptr a(new foo); + + check(a->test() == 0); + + a->set(666); + + check(a->test() == 666); +} + struct kiss { int* ref; kiss(int* ref) : ref(ref) {} @@ -42,9 +64,23 @@ void test_destructor() { check(counter == 1, "destruct: Invalid destructors"); } +void test_make_shared() { + int counter = 0; + + { + auto a = std::make_shared(&counter); + auto b = a; + auto c = a; + } + + check(counter == 1, "make_shared: Invalid destructors"); +} + } //end of anonymous namespace void shared_ptr_tests(){ test_base(); + test_struct(); test_destructor(); + test_make_shared(); }