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__
17 #include "nsXPCOMGlue.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"
31 #include "nsPISocketTransportService.h"
32 #include "nsServiceManagerUtils.h"
33 #include "TestHarness.h"
35 class MtransportTestUtils
{
37 MtransportTestUtils() : xpcom_("") {
43 ~MtransportTestUtils() {
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
61 crashreporter_
= do_GetService("@mozilla.org/toolkit/crash-reporter;1");
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
,
71 MOZ_ASSERT(NS_SUCCEEDED(rv
));
72 crashreporter_
->SetEnabled(true);
73 crashreporter_
->SetMinidumpPath(cwd
);
79 nsCOMPtr
<nsIEventTarget
> sts_target() { return sts_target_
; }
83 nsCOMPtr
<nsIIOService
> ioservice_
;
84 nsCOMPtr
<nsIEventTarget
> sts_target_
;
85 nsCOMPtr
<nsPISocketTransportService
> sts_
;
86 #ifdef MOZ_CRASHREPORTER
87 nsCOMPtr
<nsICrashReporter
> crashreporter_
;
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); \