bug 1259753 - fix some C++ unittests to use ScopedXPCOM to init XPCOM. r?ms2ger
MozReview-Commit-ID: B6xdlB9Di0y
--- a/netwerk/test/TestCookie.cpp
+++ b/netwerk/test/TestCookie.cpp
@@ -1,14 +1,15 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "TestCommon.h"
+#include "TestHarness.h"
#include "nsIServiceManager.h"
#include "nsICookieService.h"
#include "nsICookieManager.h"
#include "nsICookieManager2.h"
#include "nsICookie2.h"
#include <stdio.h>
#include "plstr.h"
#include "prprf.h"
@@ -181,40 +182,26 @@ InitPrefs(nsIPrefBranch *aPrefBranch)
aPrefBranch->SetIntPref(kCookiesPermissions, 0); // accept all
aPrefBranch->SetBoolPref(kCookiesLifetimeEnabled, true);
aPrefBranch->SetIntPref(kCookiesLifetimeCurrentSession, 0);
aPrefBranch->SetIntPref(kCookiesLifetimeDays, 1);
// Set the base domain limit to 50 so we have a known value.
aPrefBranch->SetIntPref(kCookiesMaxPerHost, 50);
}
-class ScopedXPCOM
-{
-public:
- ScopedXPCOM() : rv(NS_InitXPCOM2(nullptr, nullptr, nullptr)) { }
- ~ScopedXPCOM()
- {
- if (NS_SUCCEEDED(rv))
- NS_ShutdownXPCOM(nullptr);
- }
-
- nsresult rv;
-};
int
main(int32_t argc, char *argv[])
{
if (test_common_init(&argc, &argv) != 0)
return -1;
bool allTestsPassed = true;
- ScopedXPCOM xpcom;
- if (NS_FAILED(xpcom.rv))
- return -1;
+ ScopedXPCOM xpcom("TestCookie");
{
nsresult rv0;
nsCOMPtr<nsICookieService> cookieService =
do_GetService(kCookieServiceCID, &rv0);
if (NS_FAILED(rv0)) return -1;
--- a/security/manager/ssl/tests/compiled/TestCertDB.cpp
+++ b/security/manager/ssl/tests/compiled/TestCertDB.cpp
@@ -2,33 +2,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMPtr.h"
#include "nsIPrefService.h"
#include "nsIX509CertDB.h"
#include "nsServiceManagerUtils.h"
+#include "TestHarness.h"
int
main(int argc, char* argv[])
{
+ ScopedXPCOM xpcom("TestCertDB");
{
- NS_InitXPCOM2(nullptr, nullptr, nullptr);
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs) {
return -1;
}
// When NSS initializes, it attempts to get some localized strings.
// As a result, Android flips out if this isn't set.
nsresult rv = prefs->SetBoolPref("intl.locale.matchOS", true);
if (NS_FAILED(rv)) {
return -1;
}
nsCOMPtr<nsIX509CertDB> certdb(do_GetService(NS_X509CERTDB_CONTRACTID));
if (!certdb) {
return -1;
}
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
- NS_ShutdownXPCOM(nullptr);
return 0;
}
--- a/xpcom/tests/TestTArray.cpp
+++ b/xpcom/tests/TestTArray.cpp
@@ -13,16 +13,17 @@
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "nsStringAPI.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsXPCOM.h"
#include "nsIFile.h"
+#include "TestHarness.h"
using namespace mozilla;
namespace TestTArray {
// Define this so we can use test_basic_array in test_comptr_array
template <class T>
inline bool operator<(const nsCOMPtr<T>& lhs, const nsCOMPtr<T>& rhs) {
@@ -1189,24 +1190,22 @@ static const struct Test {
using namespace TestTArray;
int main(int argc, char **argv) {
int count = 1;
if (argc > 1)
count = atoi(argv[1]);
- if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr)))
- return -1;
+ ScopedXPCOM xpcom("TestTArray");
bool success = true;
while (count--) {
for (const Test* t = tests; t->name != nullptr; ++t) {
bool test_result = t->func();
printf("%25s : %s\n", t->name, test_result ? "SUCCESS" : "FAILURE");
if (!test_result)
success = false;
}
}
-
- NS_ShutdownXPCOM(nullptr);
+
return success ? 0 : -1;
}