1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1999
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
26 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /* Some simple smoke tests of the typelib loader. */
|
---|
39 |
|
---|
40 | #include "nscore.h"
|
---|
41 |
|
---|
42 | #include "nsISupports.h"
|
---|
43 | #include "nsIInterfaceInfo.h"
|
---|
44 | #include "nsIInterfaceInfoManager.h"
|
---|
45 | #include "xptinfo.h"
|
---|
46 |
|
---|
47 | #include <stdio.h>
|
---|
48 |
|
---|
49 | // This file expects the nsInterfaceInfoManager to be able to discover
|
---|
50 | // .xpt files corresponding to those in xpcom/idl. Currently this
|
---|
51 | // means setting XPTDIR in the environment to some directory
|
---|
52 | // containing these files.
|
---|
53 |
|
---|
54 | int main (int argc, char **argv) {
|
---|
55 | int i;
|
---|
56 | nsIID *iid1, *iid2, *iid3;
|
---|
57 | char *name1, *name2, *name3;
|
---|
58 | nsIInterfaceInfo *info2, *info3, *info4, *info5;
|
---|
59 |
|
---|
60 | nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
|
---|
61 |
|
---|
62 | fprintf(stderr, "\ngetting iid for 'nsISupports'\n");
|
---|
63 | iim->GetIIDForName("nsISupports", &iid1);
|
---|
64 | iim->GetNameForIID(iid1, &name1);
|
---|
65 | fprintf(stderr, "%s iid %s\n", name1, iid1->ToString());
|
---|
66 |
|
---|
67 | fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n");
|
---|
68 | iim->GetIIDForName("nsIInputStream", &iid2);
|
---|
69 | iim->GetNameForIID(iid2, &name2);
|
---|
70 | fprintf(stderr, "%s iid %s\n", name2, iid2->ToString());
|
---|
71 |
|
---|
72 | fprintf(stderr, "iid: %s, name: %s\n", iid1->ToString(), name1);
|
---|
73 | fprintf(stderr, "iid: %s, name: %s\n", iid2->ToString(), name2);
|
---|
74 |
|
---|
75 | fprintf(stderr, "\ngetting info for iid2 from above\n");
|
---|
76 | iim->GetInfoForIID(iid2, &info2);
|
---|
77 | #ifdef DEBUG
|
---|
78 | // ((nsInterfaceInfo *)info2)->print(stderr);
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n");
|
---|
82 | iim->GetIIDForName("nsIInputStream", &iid3);
|
---|
83 | iim->GetNameForIID(iid3, &name3);
|
---|
84 | fprintf(stderr, "%s iid %s\n", name3, iid2->ToString());
|
---|
85 | iim->GetInfoForIID(iid3, &info3);
|
---|
86 | #ifdef DEBUG
|
---|
87 | // ((nsInterfaceInfo *)info3)->print(stderr);
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | fprintf(stderr, "\ngetting info for name 'nsIBidirectionalEnumerator'\n");
|
---|
91 | iim->GetInfoForName("nsIBidirectionalEnumerator", &info4);
|
---|
92 | #ifdef DEBUG
|
---|
93 | // ((nsInterfaceInfo *)info4)->print(stderr);
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | fprintf(stderr, "\nparams work?\n");
|
---|
97 | fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n");
|
---|
98 | iim->GetInfoForName("nsIServiceManager", &info5);
|
---|
99 | #ifdef DEBUG
|
---|
100 | // ((nsInterfaceInfo *)info5)->print(stderr);
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | // XXX: nsIServiceManager is no more; what do we test with?
|
---|
104 | if (info5 == NULL) {
|
---|
105 | fprintf(stderr, "\nNo nsIServiceManager; cannot continue.\n");
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | uint16 methodcount;
|
---|
110 | info5->GetMethodCount(&methodcount);
|
---|
111 | const nsXPTMethodInfo *mi;
|
---|
112 | for (i = 0; i < methodcount; i++) {
|
---|
113 | info5->GetMethodInfo(i, &mi);
|
---|
114 | fprintf(stderr, "method %d, name %s\n", i, mi->GetName());
|
---|
115 | }
|
---|
116 |
|
---|
117 | // 7 is GetServiceWithListener, which has juicy params.
|
---|
118 | info5->GetMethodInfo(7, &mi);
|
---|
119 | // uint8 paramcount = mi->GetParamCount();
|
---|
120 |
|
---|
121 | nsXPTParamInfo param2 = mi->GetParam(2);
|
---|
122 | // should be IID for nsIShutdownListener
|
---|
123 | nsIID *nsISL;
|
---|
124 | info5->GetIIDForParam(7, ¶m2, &nsISL);
|
---|
125 | // const nsIID *nsISL = param2.GetInterfaceIID(info5);
|
---|
126 | fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
|
---|
127 | // if we look up the name?
|
---|
128 | char *nsISLname;
|
---|
129 | iim->GetNameForIID(nsISL, &nsISLname);
|
---|
130 | fprintf(stderr, "which is called %s\n", nsISLname);
|
---|
131 |
|
---|
132 | fprintf(stderr, "\nhow about one defined in a different typelib\n");
|
---|
133 | nsXPTParamInfo param3 = mi->GetParam(3);
|
---|
134 | // should be IID for nsIShutdownListener
|
---|
135 | nsIID *nsISS;
|
---|
136 | info5->GetIIDForParam(7, ¶m3, &nsISS);
|
---|
137 | // const nsIID *nsISS = param3.GetInterfaceIID(info5);
|
---|
138 | fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
|
---|
139 | // if we look up the name?
|
---|
140 | char *nsISSname;
|
---|
141 | iim->GetNameForIID(nsISS, &nsISSname);
|
---|
142 | fprintf(stderr, "which is called %s\n", nsISSname);
|
---|
143 |
|
---|
144 | return 0;
|
---|
145 | }
|
---|
146 |
|
---|