xpcom/tests/TestShutdown.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/TestShutdown.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsIServiceManager.h"
    1.10 +
    1.11 +// Gee this seems simple! It's for testing for memory leaks with Purify.
    1.12 +
    1.13 +void main(int argc, char* argv[])
    1.14 +{
    1.15 +    nsresult rv;
    1.16 +    nsIServiceManager* servMgr;
    1.17 +    rv = NS_InitXPCOM2(&servMgr, nullptr, nullptr);
    1.18 +    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
    1.19 +
    1.20 +    // try loading a component and releasing it to see if it leaks
    1.21 +    if (argc > 1 && argv[1] != nullptr) {
    1.22 +        char* cidStr = argv[1];
    1.23 +        nsISupports* obj = nullptr;
    1.24 +        if (cidStr[0] == '{') {
    1.25 +            nsCID cid;
    1.26 +            cid.Parse(cidStr);
    1.27 +            rv = CallCreateInstance(cid, &obj);
    1.28 +        }
    1.29 +        else {
    1.30 +            // contractID case:
    1.31 +            rv = CallCreateInstance(cidStr, &obj);
    1.32 +        }
    1.33 +        if (NS_SUCCEEDED(rv)) {
    1.34 +            printf("Successfully created %s\n", cidStr);
    1.35 +            NS_RELEASE(obj);
    1.36 +        }
    1.37 +        else {
    1.38 +            printf("Failed to create %s (%x)\n", cidStr, rv);
    1.39 +        }
    1.40 +    }
    1.41 +
    1.42 +    rv = NS_ShutdownXPCOM(servMgr);
    1.43 +    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
    1.44 +}

mercurial