From 71181367c83c7869c3a2a13a850b60ceb7c7f887 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 8 Oct 2016 21:03:01 -0400 Subject: [PATCH] Add a test for ref and owned in std::vector. --- test.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test.cc b/test.cc index 95f749d..2d43d3f 100644 --- a/test.cc +++ b/test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include "zcpointer.h" @@ -120,6 +121,29 @@ void TestNulls() { EXPECT(rr == nullptr); } +void TestVector() { + zc::owned c; + std::vector> vec{ + c.get(), + c.get(), + c.get() + }; + + for (const auto& r : vec) { + EXPECT(r == c.get()); + } + + zc::ref ref; + { + std::vector> vec; + vec.push_back(std::move(zc::owned(new C()))); + vec.push_back(std::move(zc::owned(new C()))); + vec.push_back(std::move(zc::owned(new C()))); + ref = vec[1].get(); + } + EXPECT_UAF(ref->DoThing()); +} + #define TEST_FUNC(fn) { #fn , Test##fn } int main() { @@ -132,6 +156,7 @@ int main() { TEST_FUNC(Ptr), TEST_FUNC(Equality), TEST_FUNC(Nulls), + TEST_FUNC(Vector), }; bool passed = true; -- 2.43.5