Bumping manifests a=b2g-bump
[gecko.git] / media / mtransport / test / mtransport_test_utils.h
blob80c6253cc06bb2394ee8bf1b1424008f230bc531
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Original author: ekr@rtfm.com
9 #ifndef mtransport_test_utils_h__
10 #define mtransport_test_utils_h__
12 #include <iostream>
14 #include "nspr.h"
15 #include "nsCOMPtr.h"
16 #include "nsNetCID.h"
17 #include "nsXPCOMGlue.h"
18 #include "nsXPCOM.h"
20 #include "nsIComponentManager.h"
21 #include "nsIComponentRegistrar.h"
22 #include "nsNetUtil.h"
23 #include "nsIIOService.h"
24 #include "nsIServiceManager.h"
25 #include "nsISocketTransportService.h"
26 #include "nsDirectoryServiceUtils.h"
27 #include "nsDirectoryServiceDefs.h"
28 #ifdef MOZ_CRASHREPORTER
29 #include "nsICrashReporter.h"
30 #endif
31 #include "nsPISocketTransportService.h"
32 #include "nsServiceManagerUtils.h"
33 #include "TestHarness.h"
35 class MtransportTestUtils {
36 public:
37 MtransportTestUtils() : xpcom_("") {
38 if (!sts_) {
39 InitServices();
43 ~MtransportTestUtils() {
44 sts_->Shutdown();
47 void InitServices() {
48 nsresult rv;
49 ioservice_ = do_GetIOService(&rv);
50 MOZ_ASSERT(NS_SUCCEEDED(rv));
51 sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
52 MOZ_ASSERT(NS_SUCCEEDED(rv));
53 sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
54 MOZ_ASSERT(NS_SUCCEEDED(rv));
56 #ifdef MOZ_CRASHREPORTER
57 char *crashreporter = PR_GetEnv("MOZ_CRASHREPORTER");
58 if (crashreporter && !strcmp(crashreporter, "1")) {
59 //TODO: move this to an even-more-common location to use in all
60 // C++ unittests
61 crashreporter_ = do_GetService("@mozilla.org/toolkit/crash-reporter;1");
62 if (crashreporter_) {
63 std::cerr << "Setting up crash reporting" << std::endl;
65 nsCOMPtr<nsIProperties> dirsvc =
66 do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
67 nsCOMPtr<nsIFile> cwd;
68 rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR,
69 NS_GET_IID(nsIFile),
70 getter_AddRefs(cwd));
71 MOZ_ASSERT(NS_SUCCEEDED(rv));
72 crashreporter_->SetEnabled(true);
73 crashreporter_->SetMinidumpPath(cwd);
76 #endif
79 nsCOMPtr<nsIEventTarget> sts_target() { return sts_target_; }
81 private:
82 ScopedXPCOM xpcom_;
83 nsCOMPtr<nsIIOService> ioservice_;
84 nsCOMPtr<nsIEventTarget> sts_target_;
85 nsCOMPtr<nsPISocketTransportService> sts_;
86 #ifdef MOZ_CRASHREPORTER
87 nsCOMPtr<nsICrashReporter> crashreporter_;
88 #endif
92 MtransportTestUtils *mtransport_test_utils;
94 #define SETUP_MTRANSPORT_TEST_UTILS() \
95 MtransportTestUtils utils_; mtransport_test_utils = &utils_
97 #define CHECK_ENVIRONMENT_FLAG(envname) \
98 char *test_flag = getenv(envname); \
99 if (!test_flag || strcmp(test_flag, "1")) { \
100 printf("To run this test set %s=1 in your environment\n", envname); \
101 exit(0); \
105 #endif