michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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 file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Original author: ekr@rtfm.com michael@0: michael@0: #ifndef mtransport_test_utils_h__ michael@0: #define mtransport_test_utils_h__ michael@0: michael@0: #include michael@0: michael@0: #include "nspr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsNetCID.h" michael@0: #include "nsXPCOMGlue.h" michael@0: #include "nsXPCOM.h" michael@0: michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIComponentRegistrar.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsIIOService.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsISocketTransportService.h" michael@0: #include "nsDirectoryServiceUtils.h" michael@0: #include "nsDirectoryServiceDefs.h" michael@0: #ifdef MOZ_CRASHREPORTER michael@0: #include "nsICrashReporter.h" michael@0: #endif michael@0: #include "nsPISocketTransportService.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "TestHarness.h" michael@0: michael@0: class MtransportTestUtils { michael@0: public: michael@0: MtransportTestUtils() : xpcom_("") { michael@0: if (!sts_) { michael@0: InitServices(); michael@0: } michael@0: } michael@0: michael@0: ~MtransportTestUtils() { michael@0: sts_->Shutdown(); michael@0: } michael@0: michael@0: void InitServices() { michael@0: nsresult rv; michael@0: ioservice_ = do_GetIOService(&rv); michael@0: MOZ_ASSERT(NS_SUCCEEDED(rv)); michael@0: sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); michael@0: MOZ_ASSERT(NS_SUCCEEDED(rv)); michael@0: sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); michael@0: MOZ_ASSERT(NS_SUCCEEDED(rv)); michael@0: michael@0: #ifdef MOZ_CRASHREPORTER michael@0: char *crashreporter = PR_GetEnv("MOZ_CRASHREPORTER"); michael@0: if (crashreporter && !strcmp(crashreporter, "1")) { michael@0: //TODO: move this to an even-more-common location to use in all michael@0: // C++ unittests michael@0: crashreporter_ = do_GetService("@mozilla.org/toolkit/crash-reporter;1"); michael@0: if (crashreporter_) { michael@0: std::cerr << "Setting up crash reporting" << std::endl; michael@0: michael@0: nsCOMPtr dirsvc = michael@0: do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); michael@0: nsCOMPtr cwd; michael@0: rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR, michael@0: NS_GET_IID(nsIFile), michael@0: getter_AddRefs(cwd)); michael@0: MOZ_ASSERT(NS_SUCCEEDED(rv)); michael@0: crashreporter_->SetEnabled(true); michael@0: crashreporter_->SetMinidumpPath(cwd); michael@0: } michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: nsCOMPtr sts_target() { return sts_target_; } michael@0: michael@0: private: michael@0: ScopedXPCOM xpcom_; michael@0: nsCOMPtr ioservice_; michael@0: nsCOMPtr sts_target_; michael@0: nsCOMPtr sts_; michael@0: #ifdef MOZ_CRASHREPORTER michael@0: nsCOMPtr crashreporter_; michael@0: #endif michael@0: }; michael@0: michael@0: michael@0: MtransportTestUtils *mtransport_test_utils; michael@0: michael@0: #define SETUP_MTRANSPORT_TEST_UTILS() \ michael@0: MtransportTestUtils utils_; mtransport_test_utils = &utils_ michael@0: michael@0: #define CHECK_ENVIRONMENT_FLAG(envname) \ michael@0: char *test_flag = getenv(envname); \ michael@0: if (!test_flag || strcmp(test_flag, "1")) { \ michael@0: printf("To run this test set %s=1 in your environment\n", envname); \ michael@0: exit(0); \ michael@0: } \ michael@0: michael@0: michael@0: #endif michael@0: