1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/test/mtransport_test_utils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// Original author: ekr@rtfm.com 1.11 + 1.12 +#ifndef mtransport_test_utils_h__ 1.13 +#define mtransport_test_utils_h__ 1.14 + 1.15 +#include <iostream> 1.16 + 1.17 +#include "nspr.h" 1.18 +#include "nsCOMPtr.h" 1.19 +#include "nsNetCID.h" 1.20 +#include "nsXPCOMGlue.h" 1.21 +#include "nsXPCOM.h" 1.22 + 1.23 +#include "nsIComponentManager.h" 1.24 +#include "nsIComponentRegistrar.h" 1.25 +#include "nsNetUtil.h" 1.26 +#include "nsIIOService.h" 1.27 +#include "nsIServiceManager.h" 1.28 +#include "nsISocketTransportService.h" 1.29 +#include "nsDirectoryServiceUtils.h" 1.30 +#include "nsDirectoryServiceDefs.h" 1.31 +#ifdef MOZ_CRASHREPORTER 1.32 +#include "nsICrashReporter.h" 1.33 +#endif 1.34 +#include "nsPISocketTransportService.h" 1.35 +#include "nsServiceManagerUtils.h" 1.36 +#include "TestHarness.h" 1.37 + 1.38 +class MtransportTestUtils { 1.39 + public: 1.40 + MtransportTestUtils() : xpcom_("") { 1.41 + if (!sts_) { 1.42 + InitServices(); 1.43 + } 1.44 + } 1.45 + 1.46 + ~MtransportTestUtils() { 1.47 + sts_->Shutdown(); 1.48 + } 1.49 + 1.50 + void InitServices() { 1.51 + nsresult rv; 1.52 + ioservice_ = do_GetIOService(&rv); 1.53 + MOZ_ASSERT(NS_SUCCEEDED(rv)); 1.54 + sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); 1.55 + MOZ_ASSERT(NS_SUCCEEDED(rv)); 1.56 + sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); 1.57 + MOZ_ASSERT(NS_SUCCEEDED(rv)); 1.58 + 1.59 +#ifdef MOZ_CRASHREPORTER 1.60 + char *crashreporter = PR_GetEnv("MOZ_CRASHREPORTER"); 1.61 + if (crashreporter && !strcmp(crashreporter, "1")) { 1.62 + //TODO: move this to an even-more-common location to use in all 1.63 + // C++ unittests 1.64 + crashreporter_ = do_GetService("@mozilla.org/toolkit/crash-reporter;1"); 1.65 + if (crashreporter_) { 1.66 + std::cerr << "Setting up crash reporting" << std::endl; 1.67 + 1.68 + nsCOMPtr<nsIProperties> dirsvc = 1.69 + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); 1.70 + nsCOMPtr<nsIFile> cwd; 1.71 + rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR, 1.72 + NS_GET_IID(nsIFile), 1.73 + getter_AddRefs(cwd)); 1.74 + MOZ_ASSERT(NS_SUCCEEDED(rv)); 1.75 + crashreporter_->SetEnabled(true); 1.76 + crashreporter_->SetMinidumpPath(cwd); 1.77 + } 1.78 + } 1.79 +#endif 1.80 + } 1.81 + 1.82 + nsCOMPtr<nsIEventTarget> sts_target() { return sts_target_; } 1.83 + 1.84 + private: 1.85 + ScopedXPCOM xpcom_; 1.86 + nsCOMPtr<nsIIOService> ioservice_; 1.87 + nsCOMPtr<nsIEventTarget> sts_target_; 1.88 + nsCOMPtr<nsPISocketTransportService> sts_; 1.89 +#ifdef MOZ_CRASHREPORTER 1.90 + nsCOMPtr<nsICrashReporter> crashreporter_; 1.91 +#endif 1.92 +}; 1.93 + 1.94 + 1.95 +MtransportTestUtils *mtransport_test_utils; 1.96 + 1.97 +#define SETUP_MTRANSPORT_TEST_UTILS() \ 1.98 + MtransportTestUtils utils_; mtransport_test_utils = &utils_ 1.99 + 1.100 +#define CHECK_ENVIRONMENT_FLAG(envname) \ 1.101 + char *test_flag = getenv(envname); \ 1.102 + if (!test_flag || strcmp(test_flag, "1")) { \ 1.103 + printf("To run this test set %s=1 in your environment\n", envname); \ 1.104 + exit(0); \ 1.105 + } \ 1.106 + 1.107 + 1.108 +#endif 1.109 +