xpcom/tests/TestShutdown.cpp

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:371e38d051d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "nsIServiceManager.h"
7
8 // Gee this seems simple! It's for testing for memory leaks with Purify.
9
10 void main(int argc, char* argv[])
11 {
12 nsresult rv;
13 nsIServiceManager* servMgr;
14 rv = NS_InitXPCOM2(&servMgr, nullptr, nullptr);
15 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
16
17 // try loading a component and releasing it to see if it leaks
18 if (argc > 1 && argv[1] != nullptr) {
19 char* cidStr = argv[1];
20 nsISupports* obj = nullptr;
21 if (cidStr[0] == '{') {
22 nsCID cid;
23 cid.Parse(cidStr);
24 rv = CallCreateInstance(cid, &obj);
25 }
26 else {
27 // contractID case:
28 rv = CallCreateInstance(cidStr, &obj);
29 }
30 if (NS_SUCCEEDED(rv)) {
31 printf("Successfully created %s\n", cidStr);
32 NS_RELEASE(obj);
33 }
34 else {
35 printf("Failed to create %s (%x)\n", cidStr, rv);
36 }
37 }
38
39 rv = NS_ShutdownXPCOM(servMgr);
40 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
41 }

mercurial