From 65ecca4bc9c8e043b355c459486870ac1518095d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 21 Sep 2017 15:25:32 -0400 Subject: Move CFX_Observable to Observable This CL renames CFX_Observable to Observable and moves into the fxcrt namespace. The test suite names were updated to ObservedPtr from fxcrt. Bug: pdfium:898 Change-Id: Ia507482bc0a1d6d8bbf12c0c55c4a88f6c8910e2 Reviewed-on: https://pdfium-review.googlesource.com/14615 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- BUILD.gn | 4 +- core/fxcrt/cfx_observable.h | 81 --------------- core/fxcrt/cfx_observable_unittest.cpp | 185 --------------------------------- core/fxcrt/observable.h | 87 ++++++++++++++++ core/fxcrt/observable_unittest.cpp | 185 +++++++++++++++++++++++++++++++++ fpdfsdk/cpdfsdk_annot.h | 4 +- fpdfsdk/cpdfsdk_formfillenvironment.h | 4 +- fpdfsdk/fpdfxfa/cpdfxfa_context.h | 4 +- fpdfsdk/javascript/Field.h | 2 +- fpdfsdk/javascript/cjs_runtime.h | 4 +- fpdfsdk/pwl/cpwl_wnd.cpp | 2 +- fpdfsdk/pwl/cpwl_wnd.h | 6 +- xfa/fgas/font/cfgas_fontmgr.h | 6 +- xfa/fgas/font/cfgas_pdffontmgr.h | 4 +- 14 files changed, 292 insertions(+), 286 deletions(-) delete mode 100644 core/fxcrt/cfx_observable.h delete mode 100644 core/fxcrt/cfx_observable_unittest.cpp create mode 100644 core/fxcrt/observable.h create mode 100644 core/fxcrt/observable_unittest.cpp diff --git a/BUILD.gn b/BUILD.gn index 54dae88c93..9a08d047fd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -821,7 +821,6 @@ static_library("fxcrt") { "core/fxcrt/cfx_fixedbufgrow.h", "core/fxcrt/cfx_memorystream.cpp", "core/fxcrt/cfx_memorystream.h", - "core/fxcrt/cfx_observable.h", "core/fxcrt/cfx_retain_ptr.h", "core/fxcrt/cfx_shared_copy_on_write.h", "core/fxcrt/cfx_string_data_template.h", @@ -857,6 +856,7 @@ static_library("fxcrt") { "core/fxcrt/ifx_fileaccess.h", "core/fxcrt/ifx_pauseindicator.h", "core/fxcrt/maybe_owned.h", + "core/fxcrt/observable.h", "core/fxcrt/string_view_template.h", "core/fxcrt/widestring.cpp", "core/fxcrt/widestring.h", @@ -1920,7 +1920,6 @@ test("pdfium_unittests") { "core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp", "core/fxcodec/jbig2/JBig2_Image_unittest.cpp", "core/fxcrt/bytestring_unittest.cpp", - "core/fxcrt/cfx_observable_unittest.cpp", "core/fxcrt/cfx_retain_ptr_unittest.cpp", "core/fxcrt/cfx_shared_copy_on_write_unittest.cpp", "core/fxcrt/cfx_string_pool_template_unittest.cpp", @@ -1934,6 +1933,7 @@ test("pdfium_unittests") { "core/fxcrt/fx_string_unittest.cpp", "core/fxcrt/fx_system_unittest.cpp", "core/fxcrt/maybe_owned_unittest.cpp", + "core/fxcrt/observable_unittest.cpp", "core/fxcrt/widestring_unittest.cpp", "core/fxge/dib/cstretchengine_unittest.cpp", "fpdfsdk/fpdfdoc_unittest.cpp", diff --git a/core/fxcrt/cfx_observable.h b/core/fxcrt/cfx_observable.h deleted file mode 100644 index 8dc0907cae..0000000000 --- a/core/fxcrt/cfx_observable.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CORE_FXCRT_CFX_OBSERVABLE_H_ -#define CORE_FXCRT_CFX_OBSERVABLE_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "third_party/base/stl_util.h" - -template -class CFX_Observable { - public: - class ObservedPtr { - public: - ObservedPtr() : m_pObservable(nullptr) {} - explicit ObservedPtr(T* pObservable) : m_pObservable(pObservable) { - if (m_pObservable) - m_pObservable->AddObservedPtr(this); - } - ObservedPtr(const ObservedPtr& that) : ObservedPtr(that.Get()) {} - ~ObservedPtr() { - if (m_pObservable) - m_pObservable->RemoveObservedPtr(this); - } - void Reset(T* pObservable = nullptr) { - if (m_pObservable) - m_pObservable->RemoveObservedPtr(this); - m_pObservable = pObservable; - if (m_pObservable) - m_pObservable->AddObservedPtr(this); - } - void OnDestroy() { - ASSERT(m_pObservable); - m_pObservable = nullptr; - } - ObservedPtr& operator=(const ObservedPtr& that) { - Reset(that.Get()); - return *this; - } - bool operator==(const ObservedPtr& that) const { - return m_pObservable == that.m_pObservable; - } - bool operator!=(const ObservedPtr& that) const { return !(*this == that); } - explicit operator bool() const { return !!m_pObservable; } - T* Get() const { return m_pObservable; } - T& operator*() const { return *m_pObservable; } - T* operator->() const { return m_pObservable; } - - private: - T* m_pObservable; - }; - - CFX_Observable() {} - CFX_Observable(const CFX_Observable& that) = delete; - ~CFX_Observable() { NotifyObservedPtrs(); } - void AddObservedPtr(ObservedPtr* pObservedPtr) { - ASSERT(!pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); - m_ObservedPtrs.insert(pObservedPtr); - } - void RemoveObservedPtr(ObservedPtr* pObservedPtr) { - ASSERT(pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); - m_ObservedPtrs.erase(pObservedPtr); - } - void NotifyObservedPtrs() { - for (auto* pObservedPtr : m_ObservedPtrs) - pObservedPtr->OnDestroy(); - m_ObservedPtrs.clear(); - } - CFX_Observable& operator=(const CFX_Observable& that) = delete; - - protected: - size_t ActiveObservedPtrsForTesting() const { return m_ObservedPtrs.size(); } - - private: - std::set m_ObservedPtrs; -}; - -#endif // CORE_FXCRT_CFX_OBSERVABLE_H_ diff --git a/core/fxcrt/cfx_observable_unittest.cpp b/core/fxcrt/cfx_observable_unittest.cpp deleted file mode 100644 index f7c78c1112..0000000000 --- a/core/fxcrt/cfx_observable_unittest.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "core/fxcrt/cfx_observable.h" - -#include -#include - -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class PseudoObservable : public CFX_Observable { - public: - PseudoObservable() {} - int SomeMethod() { return 42; } - size_t ActiveObservedPtrs() const { return ActiveObservedPtrsForTesting(); } -}; - -} // namespace - -TEST(fxcrt, ObservePtrNull) { - PseudoObservable::ObservedPtr ptr; - EXPECT_EQ(nullptr, ptr.Get()); -} - -TEST(fxcrt, ObservePtrLivesLonger) { - PseudoObservable* pObs = new PseudoObservable; - PseudoObservable::ObservedPtr ptr(pObs); - EXPECT_NE(nullptr, ptr.Get()); - EXPECT_EQ(1u, pObs->ActiveObservedPtrs()); - delete pObs; - EXPECT_EQ(nullptr, ptr.Get()); -} - -TEST(fxcrt, ObservePtrLivesShorter) { - PseudoObservable obs; - { - PseudoObservable::ObservedPtr ptr(&obs); - EXPECT_NE(nullptr, ptr.Get()); - EXPECT_EQ(1u, obs.ActiveObservedPtrs()); - } - 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 vec1; - std::vector 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 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); - EXPECT_EQ(1u, obs.ActiveObservedPtrs()); - ptr.Reset(); - EXPECT_EQ(0u, obs.ActiveObservedPtrs()); -} - -TEST(fxcrt, ObservePtrReset) { - PseudoObservable obs1; - PseudoObservable obs2; - PseudoObservable::ObservedPtr ptr(&obs1); - EXPECT_EQ(1u, obs1.ActiveObservedPtrs()); - EXPECT_EQ(0u, obs2.ActiveObservedPtrs()); - ptr.Reset(&obs2); - EXPECT_EQ(0u, obs1.ActiveObservedPtrs()); - EXPECT_EQ(1u, obs2.ActiveObservedPtrs()); -} - -TEST(fxcrt, ObservePtrEquals) { - PseudoObservable obj1; - PseudoObservable obj2; - PseudoObservable::ObservedPtr null_ptr1; - PseudoObservable::ObservedPtr obj1_ptr1(&obj1); - PseudoObservable::ObservedPtr obj2_ptr1(&obj2); - { - PseudoObservable::ObservedPtr null_ptr2; - EXPECT_TRUE(null_ptr1 == null_ptr2); - - PseudoObservable::ObservedPtr obj1_ptr2(&obj1); - EXPECT_TRUE(obj1_ptr1 == obj1_ptr2); - - PseudoObservable::ObservedPtr obj2_ptr2(&obj2); - EXPECT_TRUE(obj2_ptr1 == obj2_ptr2); - } - EXPECT_FALSE(null_ptr1 == obj1_ptr1); - EXPECT_FALSE(null_ptr1 == obj2_ptr1); - EXPECT_FALSE(obj1_ptr1 == obj2_ptr1); -} - -TEST(fxcrt, ObservePtrNotEquals) { - PseudoObservable obj1; - PseudoObservable obj2; - PseudoObservable::ObservedPtr null_ptr1; - PseudoObservable::ObservedPtr obj1_ptr1(&obj1); - PseudoObservable::ObservedPtr obj2_ptr1(&obj2); - { - PseudoObservable::ObservedPtr null_ptr2; - PseudoObservable::ObservedPtr obj1_ptr2(&obj1); - PseudoObservable::ObservedPtr obj2_ptr2(&obj2); - EXPECT_FALSE(null_ptr1 != null_ptr2); - EXPECT_FALSE(obj1_ptr1 != obj1_ptr2); - EXPECT_FALSE(obj2_ptr1 != obj2_ptr2); - } - EXPECT_TRUE(null_ptr1 != obj1_ptr1); - EXPECT_TRUE(null_ptr1 != obj2_ptr1); - EXPECT_TRUE(obj1_ptr1 != obj2_ptr1); -} - -TEST(fxcrt, ObservePtrBool) { - PseudoObservable obj1; - PseudoObservable::ObservedPtr null_ptr; - PseudoObservable::ObservedPtr obj1_ptr(&obj1); - bool null_bool = !!null_ptr; - bool obj1_bool = !!obj1_ptr; - EXPECT_FALSE(null_bool); - EXPECT_TRUE(obj1_bool); -} diff --git a/core/fxcrt/observable.h b/core/fxcrt/observable.h new file mode 100644 index 0000000000..659f8ad5b9 --- /dev/null +++ b/core/fxcrt/observable.h @@ -0,0 +1,87 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CORE_FXCRT_OBSERVABLE_H_ +#define CORE_FXCRT_OBSERVABLE_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "third_party/base/stl_util.h" + +namespace fxcrt { + +template +class Observable { + public: + class ObservedPtr { + public: + ObservedPtr() : m_pObservable(nullptr) {} + explicit ObservedPtr(T* pObservable) : m_pObservable(pObservable) { + if (m_pObservable) + m_pObservable->AddObservedPtr(this); + } + ObservedPtr(const ObservedPtr& that) : ObservedPtr(that.Get()) {} + ~ObservedPtr() { + if (m_pObservable) + m_pObservable->RemoveObservedPtr(this); + } + void Reset(T* pObservable = nullptr) { + if (m_pObservable) + m_pObservable->RemoveObservedPtr(this); + m_pObservable = pObservable; + if (m_pObservable) + m_pObservable->AddObservedPtr(this); + } + void OnDestroy() { + ASSERT(m_pObservable); + m_pObservable = nullptr; + } + ObservedPtr& operator=(const ObservedPtr& that) { + Reset(that.Get()); + return *this; + } + bool operator==(const ObservedPtr& that) const { + return m_pObservable == that.m_pObservable; + } + bool operator!=(const ObservedPtr& that) const { return !(*this == that); } + explicit operator bool() const { return !!m_pObservable; } + T* Get() const { return m_pObservable; } + T& operator*() const { return *m_pObservable; } + T* operator->() const { return m_pObservable; } + + private: + T* m_pObservable; + }; + + Observable() {} + Observable(const Observable& that) = delete; + ~Observable() { NotifyObservedPtrs(); } + void AddObservedPtr(ObservedPtr* pObservedPtr) { + ASSERT(!pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); + m_ObservedPtrs.insert(pObservedPtr); + } + void RemoveObservedPtr(ObservedPtr* pObservedPtr) { + ASSERT(pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); + m_ObservedPtrs.erase(pObservedPtr); + } + void NotifyObservedPtrs() { + for (auto* pObservedPtr : m_ObservedPtrs) + pObservedPtr->OnDestroy(); + m_ObservedPtrs.clear(); + } + Observable& operator=(const Observable& that) = delete; + + protected: + size_t ActiveObservedPtrsForTesting() const { return m_ObservedPtrs.size(); } + + private: + std::set m_ObservedPtrs; +}; + +} // namespace fxcrt + +using fxcrt::Observable; + +#endif // CORE_FXCRT_OBSERVABLE_H_ diff --git a/core/fxcrt/observable_unittest.cpp b/core/fxcrt/observable_unittest.cpp new file mode 100644 index 0000000000..8edc58f613 --- /dev/null +++ b/core/fxcrt/observable_unittest.cpp @@ -0,0 +1,185 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/fxcrt/observable.h" + +#include +#include + +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class PseudoObservable : public Observable { + public: + PseudoObservable() {} + int SomeMethod() { return 42; } + size_t ActiveObservedPtrs() const { return ActiveObservedPtrsForTesting(); } +}; + +} // namespace + +TEST(ObservePtr, Null) { + PseudoObservable::ObservedPtr ptr; + EXPECT_EQ(nullptr, ptr.Get()); +} + +TEST(ObservePtr, LivesLonger) { + PseudoObservable* pObs = new PseudoObservable; + PseudoObservable::ObservedPtr ptr(pObs); + EXPECT_NE(nullptr, ptr.Get()); + EXPECT_EQ(1u, pObs->ActiveObservedPtrs()); + delete pObs; + EXPECT_EQ(nullptr, ptr.Get()); +} + +TEST(ObservePtr, LivesShorter) { + PseudoObservable obs; + { + PseudoObservable::ObservedPtr ptr(&obs); + EXPECT_NE(nullptr, ptr.Get()); + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + } + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); +} + +TEST(ObservePtr, CopyConstruct) { + 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(ObservePtr, CopyAssign) { + 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(ObservePtr, Vector) { + PseudoObservable obs; + { + std::vector vec1; + std::vector 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(ObservePtr, VectorAutoClear) { + std::vector 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(ObservePtr, ResetNull) { + PseudoObservable obs; + PseudoObservable::ObservedPtr ptr(&obs); + EXPECT_EQ(1u, obs.ActiveObservedPtrs()); + ptr.Reset(); + EXPECT_EQ(0u, obs.ActiveObservedPtrs()); +} + +TEST(ObservePtr, Reset) { + PseudoObservable obs1; + PseudoObservable obs2; + PseudoObservable::ObservedPtr ptr(&obs1); + EXPECT_EQ(1u, obs1.ActiveObservedPtrs()); + EXPECT_EQ(0u, obs2.ActiveObservedPtrs()); + ptr.Reset(&obs2); + EXPECT_EQ(0u, obs1.ActiveObservedPtrs()); + EXPECT_EQ(1u, obs2.ActiveObservedPtrs()); +} + +TEST(ObservePtr, Equals) { + PseudoObservable obj1; + PseudoObservable obj2; + PseudoObservable::ObservedPtr null_ptr1; + PseudoObservable::ObservedPtr obj1_ptr1(&obj1); + PseudoObservable::ObservedPtr obj2_ptr1(&obj2); + { + PseudoObservable::ObservedPtr null_ptr2; + EXPECT_TRUE(null_ptr1 == null_ptr2); + + PseudoObservable::ObservedPtr obj1_ptr2(&obj1); + EXPECT_TRUE(obj1_ptr1 == obj1_ptr2); + + PseudoObservable::ObservedPtr obj2_ptr2(&obj2); + EXPECT_TRUE(obj2_ptr1 == obj2_ptr2); + } + EXPECT_FALSE(null_ptr1 == obj1_ptr1); + EXPECT_FALSE(null_ptr1 == obj2_ptr1); + EXPECT_FALSE(obj1_ptr1 == obj2_ptr1); +} + +TEST(ObservePtr, NotEquals) { + PseudoObservable obj1; + PseudoObservable obj2; + PseudoObservable::ObservedPtr null_ptr1; + PseudoObservable::ObservedPtr obj1_ptr1(&obj1); + PseudoObservable::ObservedPtr obj2_ptr1(&obj2); + { + PseudoObservable::ObservedPtr null_ptr2; + PseudoObservable::ObservedPtr obj1_ptr2(&obj1); + PseudoObservable::ObservedPtr obj2_ptr2(&obj2); + EXPECT_FALSE(null_ptr1 != null_ptr2); + EXPECT_FALSE(obj1_ptr1 != obj1_ptr2); + EXPECT_FALSE(obj2_ptr1 != obj2_ptr2); + } + EXPECT_TRUE(null_ptr1 != obj1_ptr1); + EXPECT_TRUE(null_ptr1 != obj2_ptr1); + EXPECT_TRUE(obj1_ptr1 != obj2_ptr1); +} + +TEST(ObservePtr, Bool) { + PseudoObservable obj1; + PseudoObservable::ObservedPtr null_ptr; + PseudoObservable::ObservedPtr obj1_ptr(&obj1); + bool null_bool = !!null_ptr; + bool obj1_bool = !!obj1_ptr; + EXPECT_FALSE(null_bool); + EXPECT_TRUE(obj1_bool); +} diff --git a/fpdfsdk/cpdfsdk_annot.h b/fpdfsdk/cpdfsdk_annot.h index 47049556cc..325b4298ef 100644 --- a/fpdfsdk/cpdfsdk_annot.h +++ b/fpdfsdk/cpdfsdk_annot.h @@ -10,8 +10,8 @@ #include "core/fpdfdoc/cpdf_aaction.h" #include "core/fpdfdoc/cpdf_annot.h" #include "core/fpdfdoc/cpdf_defaultappearance.h" -#include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/observable.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/fsdk_common.h" #include "fpdfsdk/fsdk_define.h" @@ -22,7 +22,7 @@ class CPDF_Page; class CPDF_RenderOptions; class CPDFSDK_PageView; -class CPDFSDK_Annot : public CFX_Observable { +class CPDFSDK_Annot : public Observable { public: explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView); virtual ~CPDFSDK_Annot(); diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index 9e3c92561b..ea7b3c7e38 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -14,7 +14,7 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfdoc/cpdf_occontext.h" -#include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/observable.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/fsdk_define.h" @@ -41,7 +41,7 @@ class IJS_Runtime; // lingering lifetime issues via the memory tools. class CPDFSDK_FormFillEnvironment - : public CFX_Observable { + : public Observable { public: CPDFSDK_FormFillEnvironment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h index a0f90ab37b..0dbc51e54b 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h @@ -10,9 +10,9 @@ #include #include -#include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" +#include "core/fxcrt/observable.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "xfa/fxfa/cxfa_ffdoc.h" @@ -104,7 +104,7 @@ class CPDFXFA_Context : public IXFA_AppProvider { XFA_DocType m_iDocType; std::unique_ptr m_pPDFDoc; std::unique_ptr m_pXFADoc; - CFX_Observable::ObservedPtr m_pFormFillEnv; + Observable::ObservedPtr m_pFormFillEnv; CFX_UnownedPtr m_pXFADocView; std::unique_ptr m_pXFAApp; std::unique_ptr m_pRuntime; diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 2ca1da4491..69e27d0639 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -10,7 +10,7 @@ #include #include -#include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/observable.h" #include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" diff --git a/fpdfsdk/javascript/cjs_runtime.h b/fpdfsdk/javascript/cjs_runtime.h index 39919957f8..0d6951f8c0 100644 --- a/fpdfsdk/javascript/cjs_runtime.h +++ b/fpdfsdk/javascript/cjs_runtime.h @@ -13,7 +13,7 @@ #include #include -#include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/observable.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_EventHandler.h" #include "fpdfsdk/javascript/ijs_runtime.h" @@ -23,7 +23,7 @@ class CJS_EventContext; class CJS_Runtime : public IJS_Runtime, public CFXJS_Engine, - public CFX_Observable { + public Observable { public: using FieldEvent = std::pair; diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index 4e4abd2017..9abe03c3fb 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp @@ -46,7 +46,7 @@ CPWL_Wnd::CreateParams::CreateParams(const CreateParams& other) = default; CPWL_Wnd::CreateParams::~CreateParams() = default; -class CPWL_MsgControl : public CFX_Observable { +class CPWL_MsgControl : public Observable { friend class CPWL_Wnd; public: diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h index 17ed06450a..ecef1e2e10 100644 --- a/fpdfsdk/pwl/cpwl_wnd.h +++ b/fpdfsdk/pwl/cpwl_wnd.h @@ -11,8 +11,8 @@ #include #include "core/fpdfdoc/cpdf_formcontrol.h" -#include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/observable.h" #include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" @@ -100,14 +100,14 @@ inline bool operator!=(const CFX_Color& c1, const CFX_Color& c2) { #define PWL_DEFAULT_BLACKCOLOR CFX_Color(COLORTYPE_GRAY, 0) #define PWL_DEFAULT_WHITECOLOR CFX_Color(COLORTYPE_GRAY, 1) -class CPWL_Wnd : public CPWL_TimerHandler, public CFX_Observable { +class CPWL_Wnd : public CPWL_TimerHandler, public Observable { public: class PrivateData { protected: ~PrivateData() {} }; - class ProviderIface : public CFX_Observable { + class ProviderIface : public Observable { public: virtual ~ProviderIface() {} diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 946486be2a..642ba6fb67 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -14,10 +14,10 @@ #include #include "core/fxcrt/cfx_crtfileaccess.h" -#include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_extension.h" +#include "core/fxcrt/observable.h" #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/fx_freetype.h" #include "core/fxge/ifx_systemfontinfo.h" @@ -81,7 +81,7 @@ typedef void (*FX_LPEnumAllFonts)(std::deque* fonts, FX_LPEnumAllFonts FX_GetDefFontEnumerator(); -class CFGAS_FontMgr : public CFX_Observable { +class CFGAS_FontMgr : public Observable { public: static std::unique_ptr Create(FX_LPEnumAllFonts pEnumerator); @@ -180,7 +180,7 @@ class CFX_FontSourceEnum_File { std::vector m_FolderPaths; }; -class CFGAS_FontMgr : public CFX_Observable { +class CFGAS_FontMgr : public Observable { public: static std::unique_ptr Create( CFX_FontSourceEnum_File* pFontEnum); diff --git a/xfa/fgas/font/cfgas_pdffontmgr.h b/xfa/fgas/font/cfgas_pdffontmgr.h index 8a09a95bd1..a31d865cec 100644 --- a/xfa/fgas/font/cfgas_pdffontmgr.h +++ b/xfa/fgas/font/cfgas_pdffontmgr.h @@ -11,16 +11,16 @@ #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_string.h" +#include "core/fxcrt/observable.h" class CFGAS_FontMgr; class CFGAS_GEFont; class CPDF_Document; class CPDF_Font; -class CFGAS_PDFFontMgr : public CFX_Observable { +class CFGAS_PDFFontMgr : public Observable { public: explicit CFGAS_PDFFontMgr(CPDF_Document* pDoc, CFGAS_FontMgr* pFontMgr); ~CFGAS_PDFFontMgr(); -- cgit v1.2.3