/src/mozilla-central/media/mtransport/test/TestSyncRunnable.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 12; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "nsThreadUtils.h" |
7 | | #include "mozilla/SyncRunnable.h" |
8 | | |
9 | | #include "gtest/gtest.h" |
10 | | |
11 | | using namespace mozilla; |
12 | | |
13 | | nsIThread *gThread = nullptr; |
14 | | |
15 | | class TestRunnable : public Runnable { |
16 | | public: |
17 | 0 | TestRunnable() : Runnable("TestRunnable"), ran_(false) {} |
18 | | |
19 | | NS_IMETHOD Run() override |
20 | 0 | { |
21 | 0 | ran_ = true; |
22 | 0 |
|
23 | 0 | return NS_OK; |
24 | 0 | } |
25 | | |
26 | 0 | bool ran() const { return ran_; } |
27 | | |
28 | | private: |
29 | | bool ran_; |
30 | | }; |
31 | | |
32 | | class TestSyncRunnable : public ::testing::Test { |
33 | | public: |
34 | | static void SetUpTestCase() |
35 | 0 | { |
36 | 0 | nsresult rv = NS_NewNamedThread("thread", &gThread); |
37 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)); |
38 | 0 | } |
39 | | |
40 | | static void TearDownTestCase() |
41 | 0 | { |
42 | 0 | if (gThread) |
43 | 0 | gThread->Shutdown(); |
44 | 0 | } |
45 | | }; |
46 | | |
47 | | TEST_F(TestSyncRunnable, TestDispatch) |
48 | 0 | { |
49 | 0 | RefPtr<TestRunnable> r(new TestRunnable()); |
50 | 0 | RefPtr<SyncRunnable> s(new SyncRunnable(r)); |
51 | 0 | s->DispatchToThread(gThread); |
52 | 0 |
|
53 | 0 | ASSERT_TRUE(r->ran()); |
54 | 0 | } |
55 | | |
56 | | TEST_F(TestSyncRunnable, TestDispatchStatic) |
57 | 0 | { |
58 | 0 | RefPtr<TestRunnable> r(new TestRunnable()); |
59 | 0 | SyncRunnable::DispatchToThread(gThread, r); |
60 | 0 | ASSERT_TRUE(r->ran()); |
61 | 0 | } |