xpcom/tests/TestCallTemplates.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim:cindent:ts=8:et:sw=4:
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 /*
michael@0 9 * This test is NOT intended to be run. It's a test to make sure
michael@0 10 * a group of functions BUILD correctly.
michael@0 11 */
michael@0 12
michael@0 13 #include "nsISupportsUtils.h"
michael@0 14 #include "nsIWeakReference.h"
michael@0 15 #include "nsIComponentManager.h"
michael@0 16 #include "nsIServiceManager.h"
michael@0 17 #include "nsWeakReference.h"
michael@0 18 #include "nsIInterfaceRequestor.h"
michael@0 19 #include "nsIInterfaceRequestorUtils.h"
michael@0 20 #include "nsComponentManagerUtils.h"
michael@0 21 #include "nsServiceManagerUtils.h"
michael@0 22 #include "nsAutoPtr.h"
michael@0 23 #include "mozilla/Attributes.h"
michael@0 24
michael@0 25 #define NS_ITESTSERVICE_IID \
michael@0 26 {0x127b5253, 0x37b1, 0x43c7, \
michael@0 27 { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }}
michael@0 28
michael@0 29 class NS_NO_VTABLE nsITestService : public nsISupports {
michael@0 30 public:
michael@0 31 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID)
michael@0 32 };
michael@0 33
michael@0 34 NS_DEFINE_STATIC_IID_ACCESSOR(nsITestService, NS_ITESTSERVICE_IID)
michael@0 35
michael@0 36 class nsTestService MOZ_FINAL : public nsITestService,
michael@0 37 public nsSupportsWeakReference
michael@0 38 {
michael@0 39 public:
michael@0 40 NS_DECL_ISUPPORTS
michael@0 41 };
michael@0 42
michael@0 43 NS_IMPL_ISUPPORTS(nsTestService, nsITestService, nsISupportsWeakReference)
michael@0 44
michael@0 45 #define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1"
michael@0 46 #define NS_TEST_SERVICE_CID \
michael@0 47 {0xa00c1406, 0x283a, 0x45c9, \
michael@0 48 {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}}
michael@0 49 static NS_DEFINE_CID(kTestServiceCID, NS_TEST_SERVICE_CID);
michael@0 50
michael@0 51 int main()
michael@0 52 {
michael@0 53 /*
michael@0 54 * NOTE: This does NOT demonstrate how these functions are
michael@0 55 * intended to be used. They are intended for filling in out
michael@0 56 * parameters that need to be |AddRef|ed. I'm just too lazy
michael@0 57 * to write lots of little getter functions for a test program
michael@0 58 * when I don't need to.
michael@0 59 */
michael@0 60
michael@0 61 NS_NOTREACHED("This test is not intended to run, only to compile!");
michael@0 62
michael@0 63 /* Test CallQueryInterface */
michael@0 64
michael@0 65 nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000);
michael@0 66
michael@0 67 nsITestService *myITestService = nullptr;
michael@0 68 CallQueryInterface(mySupportsPtr, &myITestService);
michael@0 69
michael@0 70 nsTestService *myTestService =
michael@0 71 reinterpret_cast<nsTestService*>(mySupportsPtr);
michael@0 72 nsISupportsWeakReference *mySupportsWeakRef;
michael@0 73 CallQueryInterface(myTestService, &mySupportsWeakRef);
michael@0 74
michael@0 75 nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr;
michael@0 76 CallQueryInterface(mySupportsCOMPtr, &myITestService);
michael@0 77
michael@0 78 nsRefPtr<nsTestService> myTestServiceRefPtr = myTestService;
michael@0 79 CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef);
michael@0 80
michael@0 81 /* Test CallQueryReferent */
michael@0 82
michael@0 83 nsIWeakReference *myWeakRef =
michael@0 84 static_cast<nsIWeakReference*>(mySupportsPtr);
michael@0 85 CallQueryReferent(myWeakRef, &myITestService);
michael@0 86
michael@0 87 /* Test CallCreateInstance */
michael@0 88
michael@0 89 CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService);
michael@0 90 CallCreateInstance(kTestServiceCID, &myITestService);
michael@0 91 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr,
michael@0 92 &myITestService);
michael@0 93 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService);
michael@0 94
michael@0 95 /* Test CallGetService */
michael@0 96 CallGetService(kTestServiceCID, &myITestService);
michael@0 97 CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService);
michael@0 98
michael@0 99 /* Test CallGetInterface */
michael@0 100 nsIInterfaceRequestor *myInterfaceRequestor =
michael@0 101 static_cast<nsIInterfaceRequestor*>(mySupportsPtr);
michael@0 102 CallGetInterface(myInterfaceRequestor, &myITestService);
michael@0 103
michael@0 104 return 0;
michael@0 105 }

mercurial