1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/TestCallTemplates.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim:cindent:ts=8:et:sw=4: 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +/* 1.12 + * This test is NOT intended to be run. It's a test to make sure 1.13 + * a group of functions BUILD correctly. 1.14 + */ 1.15 + 1.16 +#include "nsISupportsUtils.h" 1.17 +#include "nsIWeakReference.h" 1.18 +#include "nsIComponentManager.h" 1.19 +#include "nsIServiceManager.h" 1.20 +#include "nsWeakReference.h" 1.21 +#include "nsIInterfaceRequestor.h" 1.22 +#include "nsIInterfaceRequestorUtils.h" 1.23 +#include "nsComponentManagerUtils.h" 1.24 +#include "nsServiceManagerUtils.h" 1.25 +#include "nsAutoPtr.h" 1.26 +#include "mozilla/Attributes.h" 1.27 + 1.28 +#define NS_ITESTSERVICE_IID \ 1.29 + {0x127b5253, 0x37b1, 0x43c7, \ 1.30 + { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }} 1.31 + 1.32 +class NS_NO_VTABLE nsITestService : public nsISupports { 1.33 + public: 1.34 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID) 1.35 +}; 1.36 + 1.37 +NS_DEFINE_STATIC_IID_ACCESSOR(nsITestService, NS_ITESTSERVICE_IID) 1.38 + 1.39 +class nsTestService MOZ_FINAL : public nsITestService, 1.40 + public nsSupportsWeakReference 1.41 +{ 1.42 + public: 1.43 + NS_DECL_ISUPPORTS 1.44 +}; 1.45 + 1.46 +NS_IMPL_ISUPPORTS(nsTestService, nsITestService, nsISupportsWeakReference) 1.47 + 1.48 +#define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1" 1.49 +#define NS_TEST_SERVICE_CID \ 1.50 + {0xa00c1406, 0x283a, 0x45c9, \ 1.51 + {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}} 1.52 +static NS_DEFINE_CID(kTestServiceCID, NS_TEST_SERVICE_CID); 1.53 + 1.54 +int main() 1.55 +{ 1.56 + /* 1.57 + * NOTE: This does NOT demonstrate how these functions are 1.58 + * intended to be used. They are intended for filling in out 1.59 + * parameters that need to be |AddRef|ed. I'm just too lazy 1.60 + * to write lots of little getter functions for a test program 1.61 + * when I don't need to. 1.62 + */ 1.63 + 1.64 + NS_NOTREACHED("This test is not intended to run, only to compile!"); 1.65 + 1.66 + /* Test CallQueryInterface */ 1.67 + 1.68 + nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000); 1.69 + 1.70 + nsITestService *myITestService = nullptr; 1.71 + CallQueryInterface(mySupportsPtr, &myITestService); 1.72 + 1.73 + nsTestService *myTestService = 1.74 + reinterpret_cast<nsTestService*>(mySupportsPtr); 1.75 + nsISupportsWeakReference *mySupportsWeakRef; 1.76 + CallQueryInterface(myTestService, &mySupportsWeakRef); 1.77 + 1.78 + nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr; 1.79 + CallQueryInterface(mySupportsCOMPtr, &myITestService); 1.80 + 1.81 + nsRefPtr<nsTestService> myTestServiceRefPtr = myTestService; 1.82 + CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef); 1.83 + 1.84 + /* Test CallQueryReferent */ 1.85 + 1.86 + nsIWeakReference *myWeakRef = 1.87 + static_cast<nsIWeakReference*>(mySupportsPtr); 1.88 + CallQueryReferent(myWeakRef, &myITestService); 1.89 + 1.90 + /* Test CallCreateInstance */ 1.91 + 1.92 + CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService); 1.93 + CallCreateInstance(kTestServiceCID, &myITestService); 1.94 + CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr, 1.95 + &myITestService); 1.96 + CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService); 1.97 + 1.98 + /* Test CallGetService */ 1.99 + CallGetService(kTestServiceCID, &myITestService); 1.100 + CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService); 1.101 + 1.102 + /* Test CallGetInterface */ 1.103 + nsIInterfaceRequestor *myInterfaceRequestor = 1.104 + static_cast<nsIInterfaceRequestor*>(mySupportsPtr); 1.105 + CallGetInterface(myInterfaceRequestor, &myITestService); 1.106 + 1.107 + return 0; 1.108 +}