Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / xpcom / tests / gtest / TestEventTargetQI.cpp
blob6131b5e63e2a748caca7eb428bb5f002c8bc059d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/LazyIdleThread.h"
8 #include "mozilla/SharedThreadPool.h"
9 #include "mozilla/ThrottledEventQueue.h"
10 #include "nsComponentManagerUtils.h"
11 #include "nsCOMPtr.h"
12 #include "nsThreadPool.h"
13 #include "nsThreadUtils.h"
14 #include "nsXPCOM.h"
15 #include "nsXPCOMCIDInternal.h"
16 #include "gtest/gtest.h"
18 using namespace mozilla;
20 // Cast the pointer to nsISupports* through nsIEventTarget* before doing the QI
21 // in order to avoid a static assert intended to prevent trivial QIs, while also
22 // avoiding ambiguous base errors.
23 template <typename TargetInterface, typename SourcePtr>
24 bool TestQITo(SourcePtr& aPtr1) {
25 nsCOMPtr<TargetInterface> aPtr2 = do_QueryInterface(
26 static_cast<nsISupports*>(static_cast<nsIEventTarget*>(aPtr1.get())));
27 return (bool)aPtr2;
30 TEST(TestEventTargetQI, ThreadPool)
32 nsCOMPtr<nsIThreadPool> thing = new nsThreadPool();
34 EXPECT_FALSE(TestQITo<nsISerialEventTarget>(thing));
36 EXPECT_TRUE(TestQITo<nsIEventTarget>(thing));
38 thing->Shutdown();
41 TEST(TestEventTargetQI, SharedThreadPool)
43 nsCOMPtr<nsIThreadPool> thing = SharedThreadPool::Get("TestPool"_ns, 1);
44 EXPECT_TRUE(thing);
46 EXPECT_FALSE(TestQITo<nsISerialEventTarget>(thing));
48 EXPECT_TRUE(TestQITo<nsIEventTarget>(thing));
51 TEST(TestEventTargetQI, Thread)
53 nsCOMPtr<nsIThread> thing = do_GetCurrentThread();
54 EXPECT_TRUE(thing);
56 EXPECT_TRUE(TestQITo<nsISerialEventTarget>(thing));
58 EXPECT_TRUE(TestQITo<nsIEventTarget>(thing));
61 TEST(TestEventTargetQI, ThrottledEventQueue)
63 nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
64 RefPtr<ThrottledEventQueue> thing =
65 ThrottledEventQueue::Create(thread, "test queue");
66 EXPECT_TRUE(thing);
68 EXPECT_TRUE(TestQITo<nsISerialEventTarget>(thing));
70 EXPECT_TRUE(TestQITo<nsIEventTarget>(thing));
73 TEST(TestEventTargetQI, LazyIdleThread)
75 RefPtr<LazyIdleThread> thing = new LazyIdleThread(0, "TestThread");
76 EXPECT_TRUE(thing);
78 EXPECT_TRUE(TestQITo<nsISerialEventTarget>(thing));
80 EXPECT_TRUE(TestQITo<nsIEventTarget>(thing));
82 thing->Shutdown();