/* * Copyright 2016 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Test that the factory can create new weak pointers after a // InvalidateWeakPtrs call, and they remain valid until the next // InvalidateWeakPtrs call.
WeakPtr<int> ptr2 = factory.GetWeakPtr();
EXPECT_EQ(&data, ptr2.get());
EXPECT_TRUE(factory.HasWeakPtrs());
factory.InvalidateWeakPtrs();
EXPECT_EQ(nullptr, ptr2.get());
EXPECT_FALSE(factory.HasWeakPtrs());
}
TEST(WeakPtrTest, ObjectAndWeakPtrOnDifferentThreads) { // Test that it is OK to create an object with a WeakPtrFactory one thread, // but use it on another. This tests that we do not trip runtime checks that // ensure that a WeakPtr is not used by multiple threads.
std::unique_ptr<TargetWithFactory> target(
NewObjectCreatedOnTaskQueue<TargetWithFactory>());
WeakPtr<Target> weak_ptr = target->factory.GetWeakPtr();
EXPECT_EQ(target.get(), weak_ptr.get());
}
TEST(WeakPtrTest, WeakPtrInitiateAndUseOnDifferentThreads) { // Test that it is OK to create a WeakPtr on one thread, but use it on // another. This tests that we do not trip runtime checks that ensure that a // WeakPtr is not used by multiple threads. auto target = std::make_unique<TargetWithFactory>(); // Create weak ptr on main thread
WeakPtr<Target> weak_ptr = target->factory.GetWeakPtr();
webrtc::TaskQueueForTest queue("queue");
queue.SendTask([&] { // Dereference and invalide weak_ptr on another thread.
EXPECT_EQ(weak_ptr.get(), target.get());
target.reset();
});
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.