VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/tests/TestCallTemplates.cpp@ 65902

最後變更 在這個檔案從65902是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.7 KB
 
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim:cindent:ts=8:et:sw=4:
3 *
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
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/
11 *
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
15 * License.
16 *
17 * The Original Code is Mozilla.
18 *
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.
23 *
24 * Contributor(s):
25 * L. David Baron <[email protected]> (original author)
26 *
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.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41/*
42 * This test is NOT intended to be run. It's a test to make sure
43 * a group of functions BUILD correctly.
44 */
45
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
54#define NS_ITESTSERVICE_IID \
55 {0x127b5253, 0x37b1, 0x43c7, \
56 { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }}
57
58class NS_NO_VTABLE nsITestService : public nsISupports {
59 public:
60 NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID)
61};
62
63class nsTestService : public nsITestService, public nsSupportsWeakReference
64{
65 public:
66 NS_DECL_ISUPPORTS
67};
68
69NS_IMPL_ISUPPORTS2(nsTestService, nsITestService, nsISupportsWeakReference)
70
71#define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1"
72#define NS_TEST_SERVICE_CID \
73 {0xa00c1406, 0x283a, 0x45c9, \
74 {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}}
75static NS_DEFINE_CID(kTestServiceCID, NS_TEST_SERVICE_CID);
76
77int main()
78{
79 /*
80 * NOTE: This does NOT demonstrate how these functions are
81 * intended to be used. They are intended for filling in out
82 * parameters that need to be |AddRef|ed. I'm just too lazy
83 * to write lots of little getter functions for a test program
84 * when I don't need to.
85 */
86
87 NS_NOTREACHED("This test is not intended to run, only to compile!");
88
89 /* Test CallQueryInterface */
90
91 nsISupports *mySupportsPtr = NS_REINTERPRET_CAST(nsISupports*, 0x1000);
92
93 nsITestService *myITestService = nsnull;
94 CallQueryInterface(mySupportsPtr, &myITestService);
95
96 nsTestService *myTestService =
97 NS_REINTERPRET_CAST(nsTestService*, mySupportsPtr);
98 nsISupportsWeakReference *mySupportsWeakRef;
99 CallQueryInterface(myTestService, &mySupportsWeakRef);
100
101 /* Test CallQueryReferent */
102
103 nsIWeakReference *myWeakRef =
104 NS_STATIC_CAST(nsIWeakReference*, mySupportsPtr);
105 CallQueryReferent(myWeakRef, &myITestService);
106
107 /* Test CallCreateInstance */
108
109 CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService);
110 CallCreateInstance(kTestServiceCID, &myITestService);
111 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr,
112 &myITestService);
113 CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService);
114
115 /* Test CallGetService */
116 nsIShutdownListener *myShutdownListener = nsnull;
117 CallGetService(kTestServiceCID, &myITestService);
118 CallGetService(kTestServiceCID, myShutdownListener, &myITestService);
119 CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService);
120 CallGetService(NS_TEST_SERVICE_CONTRACTID, myShutdownListener,
121 &myITestService);
122
123 /* Test CallGetInterface */
124 nsIInterfaceRequestor *myInterfaceRequestor =
125 NS_STATIC_CAST(nsIInterfaceRequestor*, mySupportsPtr);
126 CallGetInterface(myInterfaceRequestor, &myITestService);
127
128 return 0;
129}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette