From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- xpcom/tests/gtest/TestEventTargetQI.cpp | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 xpcom/tests/gtest/TestEventTargetQI.cpp (limited to 'xpcom/tests/gtest/TestEventTargetQI.cpp') diff --git a/xpcom/tests/gtest/TestEventTargetQI.cpp b/xpcom/tests/gtest/TestEventTargetQI.cpp new file mode 100644 index 0000000000..bc6378fe34 --- /dev/null +++ b/xpcom/tests/gtest/TestEventTargetQI.cpp @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/LazyIdleThread.h" +#include "mozilla/SharedThreadPool.h" +#include "mozilla/ThrottledEventQueue.h" +#include "nsComponentManagerUtils.h" +#include "nsCOMPtr.h" +#include "nsThreadPool.h" +#include "nsThreadUtils.h" +#include "nsXPCOM.h" +#include "nsXPCOMCIDInternal.h" +#include "gtest/gtest.h" + +using namespace mozilla; + +// Cast the pointer to nsISupports* before doing the QI in order to avoid +// a static assert intended to prevent trivial QIs. +template +bool TestQITo(SourcePtr& aPtr1) { + nsCOMPtr aPtr2 = + do_QueryInterface(static_cast(aPtr1.get())); + return (bool)aPtr2; +} + +TEST(TestEventTargetQI, ThreadPool) +{ + nsCOMPtr thing = new nsThreadPool(); + + EXPECT_FALSE(TestQITo(thing)); + + EXPECT_TRUE(TestQITo(thing)); + + thing->Shutdown(); +} + +TEST(TestEventTargetQI, SharedThreadPool) +{ + nsCOMPtr thing = SharedThreadPool::Get("TestPool"_ns, 1); + EXPECT_TRUE(thing); + + EXPECT_FALSE(TestQITo(thing)); + + EXPECT_TRUE(TestQITo(thing)); +} + +TEST(TestEventTargetQI, Thread) +{ + nsCOMPtr thing = do_GetCurrentThread(); + EXPECT_TRUE(thing); + + EXPECT_TRUE(TestQITo(thing)); + + EXPECT_TRUE(TestQITo(thing)); +} + +TEST(TestEventTargetQI, ThrottledEventQueue) +{ + nsCOMPtr thread = do_GetCurrentThread(); + RefPtr thing = + ThrottledEventQueue::Create(thread, "test queue"); + EXPECT_TRUE(thing); + + EXPECT_TRUE(TestQITo(thing)); + + EXPECT_TRUE(TestQITo(thing)); +} + +TEST(TestEventTargetQI, LazyIdleThread) +{ + nsCOMPtr thing = new LazyIdleThread(0, "TestThread"_ns); + EXPECT_TRUE(thing); + + EXPECT_TRUE(TestQITo(thing)); + + EXPECT_TRUE(TestQITo(thing)); + + thing->Shutdown(); +} -- cgit v1.2.3