1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim:cindent:ts=8:et:sw=4:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
25 * L. David Baron <dbaron@dbaron.org> (original author)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 * This test is NOT intended to be run. It's a test to make sure
43 * a group of functions BUILD correctly.
46 #include "nsISupportsUtils.h"
47 #include "nsIWeakReference.h"
48 #include "nsIComponentManager.h"
49 #include "nsIServiceManager.h"
50 #include "nsWeakReference.h"
51 #include "nsIInterfaceRequestor.h"
52 #include "nsIInterfaceRequestorUtils.h"
53 #include "nsComponentManagerUtils.h"
54 #include "nsServiceManagerUtils.h"
56 #define NS_ITESTSERVICE_IID \
57 {0x127b5253, 0x37b1, 0x43c7, \
58 { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }}
60 class NS_NO_VTABLE nsITestService
: public nsISupports
{
62 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID
)
65 NS_DEFINE_STATIC_IID_ACCESSOR(nsITestService
, NS_ITESTSERVICE_IID
)
67 class nsTestService
: public nsITestService
, public nsSupportsWeakReference
73 NS_IMPL_ISUPPORTS2(nsTestService
, nsITestService
, nsISupportsWeakReference
)
75 #define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1"
76 #define NS_TEST_SERVICE_CID \
77 {0xa00c1406, 0x283a, 0x45c9, \
78 {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}}
79 static NS_DEFINE_CID(kTestServiceCID
, NS_TEST_SERVICE_CID
);
84 * NOTE: This does NOT demonstrate how these functions are
85 * intended to be used. They are intended for filling in out
86 * parameters that need to be |AddRef|ed. I'm just too lazy
87 * to write lots of little getter functions for a test program
88 * when I don't need to.
91 NS_NOTREACHED("This test is not intended to run, only to compile!");
93 /* Test CallQueryInterface */
95 nsISupports
*mySupportsPtr
= reinterpret_cast<nsISupports
*>(0x1000);
97 nsITestService
*myITestService
= nsnull
;
98 CallQueryInterface(mySupportsPtr
, &myITestService
);
100 nsTestService
*myTestService
=
101 reinterpret_cast<nsTestService
*>(mySupportsPtr
);
102 nsISupportsWeakReference
*mySupportsWeakRef
;
103 CallQueryInterface(myTestService
, &mySupportsWeakRef
);
105 /* Test CallQueryReferent */
107 nsIWeakReference
*myWeakRef
=
108 static_cast<nsIWeakReference
*>(mySupportsPtr
);
109 CallQueryReferent(myWeakRef
, &myITestService
);
111 /* Test CallCreateInstance */
113 CallCreateInstance(kTestServiceCID
, mySupportsPtr
, &myITestService
);
114 CallCreateInstance(kTestServiceCID
, &myITestService
);
115 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID
, mySupportsPtr
,
117 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID
, &myITestService
);
119 /* Test CallGetService */
120 CallGetService(kTestServiceCID
, &myITestService
);
121 CallGetService(NS_TEST_SERVICE_CONTRACTID
, &myITestService
);
123 /* Test CallGetInterface */
124 nsIInterfaceRequestor
*myInterfaceRequestor
=
125 static_cast<nsIInterfaceRequestor
*>(mySupportsPtr
);
126 CallGetInterface(myInterfaceRequestor
, &myITestService
);