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