File: | out/../test/cctest/test_base_object_ptr.cc |
Warning: | line 142, column 3 Method called on moved-from object 'weak_ptr' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include "gtest/gtest.h" | |||
2 | #include "node.h" | |||
3 | #include "base_object-inl.h" | |||
4 | #include "node_test_fixture.h" | |||
5 | ||||
6 | using node::BaseObject; | |||
7 | using node::BaseObjectPtr; | |||
8 | using node::BaseObjectWeakPtr; | |||
9 | using node::Environment; | |||
10 | using node::MakeBaseObject; | |||
11 | using node::MakeDetachedBaseObject; | |||
12 | using v8::HandleScope; | |||
13 | using v8::Isolate; | |||
14 | using v8::Local; | |||
15 | using v8::Object; | |||
16 | ||||
17 | class BaseObjectPtrTest : public EnvironmentTestFixture {}; | |||
18 | ||||
19 | class DummyBaseObject : public BaseObject { | |||
20 | public: | |||
21 | DummyBaseObject(Environment* env, Local<Object> obj) : BaseObject(env, obj) {} | |||
22 | ||||
23 | static Local<Object> MakeJSObject(Environment* env) { | |||
24 | return BaseObject::MakeLazilyInitializedJSTemplate(env) | |||
25 | ->GetFunction(env->context()).ToLocalChecked() | |||
26 | ->NewInstance(env->context()).ToLocalChecked(); | |||
27 | } | |||
28 | ||||
29 | static BaseObjectPtr<DummyBaseObject> NewDetached(Environment* env) { | |||
30 | Local<Object> obj = MakeJSObject(env); | |||
31 | return MakeDetachedBaseObject<DummyBaseObject>(env, obj); | |||
32 | } | |||
33 | ||||
34 | static BaseObjectPtr<DummyBaseObject> New(Environment* env) { | |||
35 | Local<Object> obj = MakeJSObject(env); | |||
36 | return MakeBaseObject<DummyBaseObject>(env, obj); | |||
37 | } | |||
38 | ||||
39 | SET_NO_MEMORY_INFO()inline void MemoryInfo(node::MemoryTracker* tracker) const override {} | |||
40 | SET_MEMORY_INFO_NAME(DummyBaseObject)inline std::string MemoryInfoName() const override { return "DummyBaseObject" ; } | |||
41 | SET_SELF_SIZE(DummyBaseObject)inline size_t SelfSize() const override { return sizeof(DummyBaseObject ); } | |||
42 | }; | |||
43 | ||||
44 | TEST_F(BaseObjectPtrTest, ScopedDetached)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ScopedDetached") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_ScopedDetached_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_ScopedDetached_Test() = default; ~BaseObjectPtrTest_ScopedDetached_Test() override = default; BaseObjectPtrTest_ScopedDetached_Test(BaseObjectPtrTest_ScopedDetached_Test const&) = delete; BaseObjectPtrTest_ScopedDetached_Test& operator=(BaseObjectPtrTest_ScopedDetached_Test const&) = delete; BaseObjectPtrTest_ScopedDetached_Test(BaseObjectPtrTest_ScopedDetached_Test &&) noexcept = delete; BaseObjectPtrTest_ScopedDetached_Test & operator=(BaseObjectPtrTest_ScopedDetached_Test&& ) noexcept = delete; private: void TestBody() override; static ::testing::TestInfo* const test_info_ __attribute__ ((unused )); }; ::testing::TestInfo* const BaseObjectPtrTest_ScopedDetached_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "ScopedDetached", nullptr, nullptr, ::testing::internal::CodeLocation ("../test/cctest/test_base_object_ptr.cc", 44), (::testing::internal ::GetTypeId<BaseObjectPtrTest>()), ::testing::internal:: SuiteApiResolver< BaseObjectPtrTest>::GetSetUpCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 44), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetTearDownCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 44), new ::testing ::internal::TestFactoryImpl<BaseObjectPtrTest_ScopedDetached_Test >); void BaseObjectPtrTest_ScopedDetached_Test::TestBody() { | |||
45 | const HandleScope handle_scope(isolate_); | |||
46 | const Argv argv; | |||
47 | Env env_{handle_scope, argv}; | |||
48 | Environment* env = *env_; | |||
49 | ||||
50 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 50 , gtest_ar.failure_message()) = ::testing::Message(); | |||
51 | { | |||
52 | BaseObjectPtr<DummyBaseObject> ptr = DummyBaseObject::NewDetached(env); | |||
53 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 53 , gtest_ar.failure_message()) = ::testing::Message(); | |||
54 | } | |||
55 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 55 , gtest_ar.failure_message()) = ::testing::Message(); | |||
56 | } | |||
57 | ||||
58 | TEST_F(BaseObjectPtrTest, ScopedDetachedWithWeak)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ScopedDetachedWithWeak") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_ScopedDetachedWithWeak_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_ScopedDetachedWithWeak_Test () = default; ~BaseObjectPtrTest_ScopedDetachedWithWeak_Test( ) override = default; BaseObjectPtrTest_ScopedDetachedWithWeak_Test (BaseObjectPtrTest_ScopedDetachedWithWeak_Test const&) = delete ; BaseObjectPtrTest_ScopedDetachedWithWeak_Test& operator =(BaseObjectPtrTest_ScopedDetachedWithWeak_Test const&) = delete; BaseObjectPtrTest_ScopedDetachedWithWeak_Test(BaseObjectPtrTest_ScopedDetachedWithWeak_Test &&) noexcept = delete; BaseObjectPtrTest_ScopedDetachedWithWeak_Test & operator=(BaseObjectPtrTest_ScopedDetachedWithWeak_Test &&) noexcept = delete; private: void TestBody() override ; static ::testing::TestInfo* const test_info_ __attribute__ ( (unused)); }; ::testing::TestInfo* const BaseObjectPtrTest_ScopedDetachedWithWeak_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "ScopedDetachedWithWeak", nullptr, nullptr, ::testing::internal ::CodeLocation("../test/cctest/test_base_object_ptr.cc", 58), (::testing::internal::GetTypeId<BaseObjectPtrTest>()), ::testing::internal::SuiteApiResolver< BaseObjectPtrTest> ::GetSetUpCaseOrSuite("../test/cctest/test_base_object_ptr.cc" , 58), ::testing::internal::SuiteApiResolver< BaseObjectPtrTest >::GetTearDownCaseOrSuite("../test/cctest/test_base_object_ptr.cc" , 58), new ::testing::internal::TestFactoryImpl<BaseObjectPtrTest_ScopedDetachedWithWeak_Test >); void BaseObjectPtrTest_ScopedDetachedWithWeak_Test::TestBody () { | |||
59 | const HandleScope handle_scope(isolate_); | |||
60 | const Argv argv; | |||
61 | Env env_{handle_scope, argv}; | |||
62 | Environment* env = *env_; | |||
63 | ||||
64 | BaseObjectWeakPtr<DummyBaseObject> weak_ptr; | |||
65 | ||||
66 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 66 , gtest_ar.failure_message()) = ::testing::Message(); | |||
67 | { | |||
68 | BaseObjectPtr<DummyBaseObject> ptr = DummyBaseObject::NewDetached(env); | |||
69 | weak_ptr = ptr; | |||
70 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 70 , gtest_ar.failure_message()) = ::testing::Message(); | |||
71 | } | |||
72 | EXPECT_EQ(weak_ptr.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "nullptr", weak_ptr.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 72, gtest_ar.failure_message()) = ::testing::Message(); | |||
73 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 73 , gtest_ar.failure_message()) = ::testing::Message(); | |||
74 | } | |||
75 | ||||
76 | TEST_F(BaseObjectPtrTest, Undetached)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("Undetached") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_Undetached_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_Undetached_Test() = default; ~BaseObjectPtrTest_Undetached_Test () override = default; BaseObjectPtrTest_Undetached_Test(BaseObjectPtrTest_Undetached_Test const&) = delete; BaseObjectPtrTest_Undetached_Test& operator=(BaseObjectPtrTest_Undetached_Test const&) = delete ; BaseObjectPtrTest_Undetached_Test(BaseObjectPtrTest_Undetached_Test &&) noexcept = delete; BaseObjectPtrTest_Undetached_Test & operator=(BaseObjectPtrTest_Undetached_Test&&) noexcept = delete; private: void TestBody() override; static ::testing ::TestInfo* const test_info_ __attribute__ ((unused)); }; ::testing ::TestInfo* const BaseObjectPtrTest_Undetached_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "Undetached", nullptr, nullptr, ::testing::internal::CodeLocation ("../test/cctest/test_base_object_ptr.cc", 76), (::testing::internal ::GetTypeId<BaseObjectPtrTest>()), ::testing::internal:: SuiteApiResolver< BaseObjectPtrTest>::GetSetUpCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 76), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetTearDownCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 76), new ::testing ::internal::TestFactoryImpl<BaseObjectPtrTest_Undetached_Test >); void BaseObjectPtrTest_Undetached_Test::TestBody() { | |||
77 | const HandleScope handle_scope(isolate_); | |||
78 | const Argv argv; | |||
79 | Env env_{handle_scope, argv}; | |||
80 | Environment* env = *env_; | |||
81 | ||||
82 | node::AddEnvironmentCleanupHook( | |||
83 | isolate_, | |||
84 | [](void* arg) { | |||
85 | EXPECT_EQ(static_cast<Environment*>(arg)->base_object_count(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("static_cast<Environment*>(arg)->base_object_count()" , "0", static_cast<Environment*>(arg)->base_object_count (), 0))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 85, gtest_ar.failure_message()) = ::testing::Message(); | |||
86 | }, | |||
87 | env); | |||
88 | ||||
89 | BaseObjectPtr<DummyBaseObject> ptr = DummyBaseObject::New(env); | |||
90 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 90 , gtest_ar.failure_message()) = ::testing::Message(); | |||
91 | } | |||
92 | ||||
93 | TEST_F(BaseObjectPtrTest, GCWeak)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("GCWeak") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_GCWeak_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_GCWeak_Test() = default; ~BaseObjectPtrTest_GCWeak_Test () override = default; BaseObjectPtrTest_GCWeak_Test(BaseObjectPtrTest_GCWeak_Test const&) = delete; BaseObjectPtrTest_GCWeak_Test& operator =(BaseObjectPtrTest_GCWeak_Test const&) = delete; BaseObjectPtrTest_GCWeak_Test (BaseObjectPtrTest_GCWeak_Test&&) noexcept = delete; BaseObjectPtrTest_GCWeak_Test & operator=(BaseObjectPtrTest_GCWeak_Test&&) noexcept = delete; private: void TestBody() override; static ::testing ::TestInfo* const test_info_ __attribute__ ((unused)); }; ::testing ::TestInfo* const BaseObjectPtrTest_GCWeak_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "GCWeak", nullptr, nullptr, ::testing::internal::CodeLocation ("../test/cctest/test_base_object_ptr.cc", 93), (::testing::internal ::GetTypeId<BaseObjectPtrTest>()), ::testing::internal:: SuiteApiResolver< BaseObjectPtrTest>::GetSetUpCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 93), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetTearDownCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 93), new ::testing ::internal::TestFactoryImpl<BaseObjectPtrTest_GCWeak_Test> ); void BaseObjectPtrTest_GCWeak_Test::TestBody() { | |||
94 | const HandleScope handle_scope(isolate_); | |||
95 | const Argv argv; | |||
96 | Env env_{handle_scope, argv}; | |||
97 | Environment* env = *env_; | |||
98 | ||||
99 | BaseObjectWeakPtr<DummyBaseObject> weak_ptr; | |||
100 | ||||
101 | { | |||
102 | const HandleScope handle_scope(isolate_); | |||
103 | BaseObjectPtr<DummyBaseObject> ptr = DummyBaseObject::New(env); | |||
104 | weak_ptr = ptr; | |||
105 | ptr->MakeWeak(); | |||
106 | ||||
107 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 107 , gtest_ar.failure_message()) = ::testing::Message(); | |||
108 | EXPECT_EQ(weak_ptr.get(), ptr.get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "ptr.get()", weak_ptr.get(), ptr.get()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../test/cctest/test_base_object_ptr.cc", 108, gtest_ar.failure_message ()) = ::testing::Message(); | |||
109 | EXPECT_EQ(weak_ptr->persistent().IsWeak(), false)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr->persistent().IsWeak()" , "false", weak_ptr->persistent().IsWeak(), false))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 109 , gtest_ar.failure_message()) = ::testing::Message(); | |||
110 | ||||
111 | ptr.reset(); | |||
112 | } | |||
113 | ||||
114 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 114 , gtest_ar.failure_message()) = ::testing::Message(); | |||
115 | EXPECT_NE(weak_ptr.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("weak_ptr.get()" , "nullptr", weak_ptr.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 115, gtest_ar.failure_message()) = ::testing::Message(); | |||
116 | EXPECT_EQ(weak_ptr->persistent().IsWeak(), true)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr->persistent().IsWeak()" , "true", weak_ptr->persistent().IsWeak(), true))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../test/cctest/test_base_object_ptr.cc", 116, gtest_ar.failure_message ()) = ::testing::Message(); | |||
117 | ||||
118 | v8::V8::SetFlagsFromString("--expose-gc"); | |||
119 | isolate_->RequestGarbageCollectionForTesting(Isolate::kFullGarbageCollection); | |||
120 | ||||
121 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 121 , gtest_ar.failure_message()) = ::testing::Message(); | |||
122 | EXPECT_EQ(weak_ptr.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "nullptr", weak_ptr.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 122, gtest_ar.failure_message()) = ::testing::Message(); | |||
123 | } | |||
124 | ||||
125 | TEST_F(BaseObjectPtrTest, Moveable)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("Moveable") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_Moveable_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_Moveable_Test() = default; ~BaseObjectPtrTest_Moveable_Test () override = default; BaseObjectPtrTest_Moveable_Test(BaseObjectPtrTest_Moveable_Test const&) = delete; BaseObjectPtrTest_Moveable_Test& operator =(BaseObjectPtrTest_Moveable_Test const&) = delete; BaseObjectPtrTest_Moveable_Test (BaseObjectPtrTest_Moveable_Test&&) noexcept = delete ; BaseObjectPtrTest_Moveable_Test& operator=(BaseObjectPtrTest_Moveable_Test &&) noexcept = delete; private: void TestBody() override ; static ::testing::TestInfo* const test_info_ __attribute__ ( (unused)); }; ::testing::TestInfo* const BaseObjectPtrTest_Moveable_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "Moveable", nullptr, nullptr, ::testing::internal::CodeLocation ("../test/cctest/test_base_object_ptr.cc", 125), (::testing:: internal::GetTypeId<BaseObjectPtrTest>()), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetSetUpCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 125), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetTearDownCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 125), new ::testing ::internal::TestFactoryImpl<BaseObjectPtrTest_Moveable_Test >); void BaseObjectPtrTest_Moveable_Test::TestBody() { | |||
126 | const HandleScope handle_scope(isolate_); | |||
127 | const Argv argv; | |||
128 | Env env_{handle_scope, argv}; | |||
129 | Environment* env = *env_; | |||
130 | ||||
131 | BaseObjectPtr<DummyBaseObject> ptr = DummyBaseObject::NewDetached(env); | |||
132 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 132 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| ||||
133 | BaseObjectWeakPtr<DummyBaseObject> weak_ptr { ptr }; | |||
134 | EXPECT_EQ(weak_ptr.get(), ptr.get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "ptr.get()", weak_ptr.get(), ptr.get()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../test/cctest/test_base_object_ptr.cc", 134, gtest_ar.failure_message ()) = ::testing::Message(); | |||
135 | ||||
136 | BaseObjectPtr<DummyBaseObject> ptr2 = std::move(ptr); | |||
137 | EXPECT_EQ(weak_ptr.get(), ptr2.get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "ptr2.get()", weak_ptr.get(), ptr2.get()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../test/cctest/test_base_object_ptr.cc", 137, gtest_ar.failure_message ()) = ::testing::Message(); | |||
138 | EXPECT_EQ(ptr.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("ptr.get()" , "nullptr", ptr.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 138, gtest_ar.failure_message()) = ::testing::Message(); | |||
139 | ||||
140 | BaseObjectWeakPtr<DummyBaseObject> weak_ptr2 = std::move(weak_ptr); | |||
141 | EXPECT_EQ(weak_ptr2.get(), ptr2.get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr2.get()" , "ptr2.get()", weak_ptr2.get(), ptr2.get()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../test/cctest/test_base_object_ptr.cc", 141, gtest_ar.failure_message ()) = ::testing::Message(); | |||
142 | EXPECT_EQ(weak_ptr.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr.get()" , "nullptr", weak_ptr.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 142, gtest_ar.failure_message()) = ::testing::Message(); | |||
| ||||
143 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "1", env->base_object_created_after_bootstrap(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 143 , gtest_ar.failure_message()) = ::testing::Message(); | |||
144 | ||||
145 | ptr2.reset(); | |||
146 | ||||
147 | EXPECT_EQ(weak_ptr2.get(), nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("weak_ptr2.get()" , "nullptr", weak_ptr2.get(), nullptr))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 147, gtest_ar.failure_message()) = ::testing::Message(); | |||
148 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "0", env->base_object_created_after_bootstrap(), 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 148 , gtest_ar.failure_message()) = ::testing::Message(); | |||
149 | } | |||
150 | ||||
151 | TEST_F(BaseObjectPtrTest, NestedClasses)static_assert(sizeof("BaseObjectPtrTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("NestedClasses") > 1, "test_name must not be empty" ); class BaseObjectPtrTest_NestedClasses_Test : public BaseObjectPtrTest { public: BaseObjectPtrTest_NestedClasses_Test() = default; ~ BaseObjectPtrTest_NestedClasses_Test() override = default; BaseObjectPtrTest_NestedClasses_Test (BaseObjectPtrTest_NestedClasses_Test const&) = delete; BaseObjectPtrTest_NestedClasses_Test & operator=(BaseObjectPtrTest_NestedClasses_Test const& ) = delete; BaseObjectPtrTest_NestedClasses_Test(BaseObjectPtrTest_NestedClasses_Test &&) noexcept = delete; BaseObjectPtrTest_NestedClasses_Test & operator=(BaseObjectPtrTest_NestedClasses_Test&& ) noexcept = delete; private: void TestBody() override; static ::testing::TestInfo* const test_info_ __attribute__ ((unused )); }; ::testing::TestInfo* const BaseObjectPtrTest_NestedClasses_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "BaseObjectPtrTest" , "NestedClasses", nullptr, nullptr, ::testing::internal::CodeLocation ("../test/cctest/test_base_object_ptr.cc", 151), (::testing:: internal::GetTypeId<BaseObjectPtrTest>()), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetSetUpCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 151), ::testing::internal ::SuiteApiResolver< BaseObjectPtrTest>::GetTearDownCaseOrSuite ("../test/cctest/test_base_object_ptr.cc", 151), new ::testing ::internal::TestFactoryImpl<BaseObjectPtrTest_NestedClasses_Test >); void BaseObjectPtrTest_NestedClasses_Test::TestBody() { | |||
152 | class ObjectWithPtr : public BaseObject { | |||
153 | public: | |||
154 | ObjectWithPtr(Environment* env, Local<Object> obj) : BaseObject(env, obj) {} | |||
155 | ||||
156 | BaseObjectPtr<BaseObject> ptr1; | |||
157 | BaseObjectPtr<BaseObject> ptr2; | |||
158 | ||||
159 | SET_NO_MEMORY_INFO()inline void MemoryInfo(node::MemoryTracker* tracker) const override {} | |||
160 | SET_MEMORY_INFO_NAME(ObjectWithPtr)inline std::string MemoryInfoName() const override { return "ObjectWithPtr" ; } | |||
161 | SET_SELF_SIZE(ObjectWithPtr)inline size_t SelfSize() const override { return sizeof(ObjectWithPtr ); } | |||
162 | }; | |||
163 | ||||
164 | const HandleScope handle_scope(isolate_); | |||
165 | const Argv argv; | |||
166 | Env env_{handle_scope, argv}; | |||
167 | Environment* env = *env_; | |||
168 | ||||
169 | node::AddEnvironmentCleanupHook( | |||
170 | isolate_, | |||
171 | [](void* arg) { | |||
172 | EXPECT_EQ(static_cast<Environment*>(arg)->base_object_count(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("static_cast<Environment*>(arg)->base_object_count()" , "0", static_cast<Environment*>(arg)->base_object_count (), 0))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc" , 172, gtest_ar.failure_message()) = ::testing::Message(); | |||
173 | }, | |||
174 | env); | |||
175 | ||||
176 | ObjectWithPtr* obj = | |||
177 | new ObjectWithPtr(env, DummyBaseObject::MakeJSObject(env)); | |||
178 | obj->ptr1 = DummyBaseObject::NewDetached(env); | |||
179 | obj->ptr2 = DummyBaseObject::New(env); | |||
180 | ||||
181 | EXPECT_EQ(env->base_object_created_after_bootstrap(), 3)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("env->base_object_created_after_bootstrap()" , "3", env->base_object_created_after_bootstrap(), 3))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../test/cctest/test_base_object_ptr.cc", 181 , gtest_ar.failure_message()) = ::testing::Message(); | |||
182 | } |