michael@0: /* -*- Mode: C++; tab-width: 12; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsThreadUtils.h" michael@0: #include "mozilla/SyncRunnable.h" michael@0: michael@0: #include "gtest/gtest.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: nsIThread *gThread = nullptr; michael@0: michael@0: class TestRunnable : public nsRunnable { michael@0: public: michael@0: TestRunnable() : ran_(false) {} michael@0: michael@0: NS_IMETHOD Run() michael@0: { michael@0: ran_ = true; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: bool ran() const { return ran_; } michael@0: michael@0: private: michael@0: bool ran_; michael@0: }; michael@0: michael@0: class TestSyncRunnable : public ::testing::Test { michael@0: public: michael@0: static void SetUpTestCase() michael@0: { michael@0: nsresult rv = NS_NewNamedThread("thread", &gThread); michael@0: ASSERT_TRUE(NS_SUCCEEDED(rv)); michael@0: } michael@0: michael@0: static void TearDownTestCase() michael@0: { michael@0: if (gThread) michael@0: gThread->Shutdown(); michael@0: } michael@0: }; michael@0: michael@0: TEST_F(TestSyncRunnable, TestDispatch) michael@0: { michael@0: nsRefPtr r(new TestRunnable()); michael@0: nsRefPtr s(new SyncRunnable(r)); michael@0: s->DispatchToThread(gThread); michael@0: michael@0: ASSERT_TRUE(r->ran()); michael@0: } michael@0: michael@0: TEST_F(TestSyncRunnable, TestDispatchStatic) michael@0: { michael@0: nsRefPtr r(new TestRunnable()); michael@0: SyncRunnable::DispatchToThread(gThread, r); michael@0: ASSERT_TRUE(r->ran()); michael@0: } michael@0: michael@0: michael@0: #include "mtransport_test_utils.h" michael@0: MtransportTestUtils *test_utils; michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: test_utils = new MtransportTestUtils(); michael@0: // Start the tests michael@0: ::testing::InitGoogleTest(&argc, argv); michael@0: michael@0: int rv = RUN_ALL_TESTS(); michael@0: michael@0: delete test_utils; michael@0: return rv; michael@0: }