diff options
author | tsepez <tsepez@chromium.org> | 2016-12-28 11:16:15 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-28 11:16:15 -0800 |
commit | d0bbccdd32113baf95ae16565c0314166d989638 (patch) | |
tree | 08d7c16a7a29919efc8b6c91fbde3baef835e533 /core/fxcrt/cfx_observable_unittest.cpp | |
parent | 04a407093c135cdf08644a03c210ae2182869254 (diff) | |
download | pdfium-d0bbccdd32113baf95ae16565c0314166d989638.tar.xz |
Make CFX_Observable copy constructable.chromium/2969chromium/2968chromium/2967chromium/2966
Fix some naming to make things clearer.
Review-Url: https://codereview.chromium.org/2587233002
Diffstat (limited to 'core/fxcrt/cfx_observable_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_observable_unittest.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_observable_unittest.cpp b/core/fxcrt/cfx_observable_unittest.cpp index 15c76495cf..3c0fabb13e 100644 --- a/core/fxcrt/cfx_observable_unittest.cpp +++ b/core/fxcrt/cfx_observable_unittest.cpp @@ -5,6 +5,7 @@ #include "core/fxcrt/cfx_observable.h" #include <utility> +#include <vector> #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -44,6 +45,77 @@ TEST(fxcrt, ObservePtrLivesShorter) { EXPECT_EQ(0u, obs.ActiveObservedPtrs()); } +TEST(fxcrt, ObserveCopyConstruct) { + PseudoObservable obs; + { + PseudoObservable::ObservedPtr ptr(&obs); + EXPECT_NE(nullptr, ptr.Get()); + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + { + PseudoObservable::ObservedPtr ptr2(ptr); + EXPECT_NE(nullptr, ptr2.Get()); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); +} + +TEST(fxcrt, ObserveCopyAssign) { + PseudoObservable obs; + { + PseudoObservable::ObservedPtr ptr(&obs); + EXPECT_NE(nullptr, ptr.Get()); + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + { + PseudoObservable::ObservedPtr ptr2; + ptr2 = ptr; + EXPECT_NE(nullptr, ptr2.Get()); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); +} + +TEST(fxcrt, ObserveVector) { + PseudoObservable obs; + { + std::vector<PseudoObservable::ObservedPtr> vec1; + std::vector<PseudoObservable::ObservedPtr> vec2; + vec1.emplace_back(&obs); + vec1.emplace_back(&obs); + EXPECT_NE(nullptr, vec1[0].Get()); + EXPECT_NE(nullptr, vec1[1].Get()); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + vec2 = vec1; + EXPECT_NE(nullptr, vec2[0].Get()); + EXPECT_NE(nullptr, vec2[1].Get()); + EXPECT_EQ(4u, obs.ActiveObservedPtrs()); + vec1.clear(); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + vec2.resize(10000); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + vec2.resize(0); + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); +} + +TEST(fxcrt, ObserveVectorAutoClear) { + std::vector<PseudoObservable::ObservedPtr> vec1; + { + PseudoObservable obs; + vec1.emplace_back(&obs); + vec1.emplace_back(&obs); + EXPECT_NE(nullptr, vec1[0].Get()); + EXPECT_NE(nullptr, vec1[1].Get()); + EXPECT_EQ(2u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(nullptr, vec1[0].Get()); + EXPECT_EQ(nullptr, vec1[1].Get()); +} + TEST(fxcrt, ObservePtrResetNull) { PseudoObservable obs; PseudoObservable::ObservedPtr ptr(&obs); |