/src/mozilla-central/xpcom/tests/gtest/TestCallTemplates.cpp
Line | Count | Source (jump to first uncovered line) |
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 final : public nsITestService, |
37 | | public nsSupportsWeakReference |
38 | | { |
39 | 0 | ~nsTestService() {} |
40 | | public: |
41 | | NS_DECL_ISUPPORTS |
42 | | }; |
43 | | |
44 | | NS_IMPL_ISUPPORTS(nsTestService, nsITestService, nsISupportsWeakReference) |
45 | | |
46 | 0 | #define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1" |
47 | | #define NS_TEST_SERVICE_CID \ |
48 | | {0xa00c1406, 0x283a, 0x45c9, \ |
49 | | {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}} |
50 | | static NS_DEFINE_CID(kTestServiceCID, NS_TEST_SERVICE_CID); |
51 | | |
52 | | void JustTestingCompilation() |
53 | 0 | { |
54 | 0 | /* |
55 | 0 | * NOTE: This does NOT demonstrate how these functions are |
56 | 0 | * intended to be used. They are intended for filling in out |
57 | 0 | * parameters that need to be |AddRef|ed. I'm just too lazy |
58 | 0 | * to write lots of little getter functions for a test program |
59 | 0 | * when I don't need to. |
60 | 0 | */ |
61 | 0 |
|
62 | 0 | MOZ_ASSERT_UNREACHABLE("This test is not intended to run, only to compile!"); |
63 | 0 |
|
64 | 0 | /* Test CallQueryInterface */ |
65 | 0 |
|
66 | 0 | nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000); |
67 | 0 |
|
68 | 0 | nsITestService *myITestService = nullptr; |
69 | 0 | CallQueryInterface(mySupportsPtr, &myITestService); |
70 | 0 |
|
71 | 0 | nsTestService *myTestService = |
72 | 0 | reinterpret_cast<nsTestService*>(mySupportsPtr); |
73 | 0 | nsISupportsWeakReference *mySupportsWeakRef; |
74 | 0 | CallQueryInterface(myTestService, &mySupportsWeakRef); |
75 | 0 |
|
76 | 0 | nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr; |
77 | 0 | CallQueryInterface(mySupportsCOMPtr, &myITestService); |
78 | 0 |
|
79 | 0 | RefPtr<nsTestService> myTestServiceRefPtr = myTestService; |
80 | 0 | CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef); |
81 | 0 |
|
82 | 0 | /* Test CallQueryReferent */ |
83 | 0 |
|
84 | 0 | nsIWeakReference *myWeakRef = |
85 | 0 | static_cast<nsIWeakReference*>(mySupportsPtr); |
86 | 0 | CallQueryReferent(myWeakRef, &myITestService); |
87 | 0 |
|
88 | 0 | /* Test CallCreateInstance */ |
89 | 0 |
|
90 | 0 | CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService); |
91 | 0 | CallCreateInstance(kTestServiceCID, &myITestService); |
92 | 0 | CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr, |
93 | 0 | &myITestService); |
94 | 0 | CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService); |
95 | 0 |
|
96 | 0 | /* Test CallGetService */ |
97 | 0 | CallGetService(kTestServiceCID, &myITestService); |
98 | 0 | CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService); |
99 | 0 |
|
100 | 0 | /* Test CallGetInterface */ |
101 | 0 | nsIInterfaceRequestor *myInterfaceRequestor = |
102 | 0 | static_cast<nsIInterfaceRequestor*>(mySupportsPtr); |
103 | 0 | CallGetInterface(myInterfaceRequestor, &myITestService); |
104 | 0 | } |