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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 /* Some simple smoke tests of the typelib loader. */
42 #include "nsISupports.h"
43 #include "nsIInterfaceInfo.h"
44 #include "nsIInterfaceInfoManager.h"
46 #include "nsServiceManagerUtils.h"
50 // This file expects the nsInterfaceInfoManager to be able to discover
51 // .xpt files corresponding to those in xpcom/idl. Currently this
52 // means setting XPTDIR in the environment to some directory
53 // containing these files.
55 int main (int argc
, char **argv
) {
57 nsIID
*iid1
, *iid2
, *iid3
;
58 char *name1
, *name2
, *name3
;
59 nsIInterfaceInfo
*info2
, *info3
, *info4
, *info5
;
61 nsCOMPtr
<nsIInterfaceInfoManager
> iim
62 (do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID
));
64 fprintf(stderr
, "\ngetting iid for 'nsISupports'\n");
65 iim
->GetIIDForName("nsISupports", &iid1
);
66 iim
->GetNameForIID(iid1
, &name1
);
67 fprintf(stderr
, "%s iid %s\n", name1
, iid1
->ToString());
69 fprintf(stderr
, "\ngetting iid for 'nsIInputStream'\n");
70 iim
->GetIIDForName("nsIInputStream", &iid2
);
71 iim
->GetNameForIID(iid2
, &name2
);
72 fprintf(stderr
, "%s iid %s\n", name2
, iid2
->ToString());
74 fprintf(stderr
, "iid: %s, name: %s\n", iid1
->ToString(), name1
);
75 fprintf(stderr
, "iid: %s, name: %s\n", iid2
->ToString(), name2
);
77 fprintf(stderr
, "\ngetting info for iid2 from above\n");
78 iim
->GetInfoForIID(iid2
, &info2
);
80 // ((nsInterfaceInfo *)info2)->print(stderr);
83 fprintf(stderr
, "\ngetting iid for 'nsIInputStream'\n");
84 iim
->GetIIDForName("nsIInputStream", &iid3
);
85 iim
->GetNameForIID(iid3
, &name3
);
86 fprintf(stderr
, "%s iid %s\n", name3
, iid2
->ToString());
87 iim
->GetInfoForIID(iid3
, &info3
);
89 // ((nsInterfaceInfo *)info3)->print(stderr);
92 fprintf(stderr
, "\ngetting info for name 'nsIBidirectionalEnumerator'\n");
93 iim
->GetInfoForName("nsIBidirectionalEnumerator", &info4
);
95 // ((nsInterfaceInfo *)info4)->print(stderr);
98 fprintf(stderr
, "\nparams work?\n");
99 fprintf(stderr
, "\ngetting info for name 'nsIServiceManager'\n");
100 iim
->GetInfoForName("nsIServiceManager", &info5
);
102 // ((nsInterfaceInfo *)info5)->print(stderr);
105 // XXX: nsIServiceManager is no more; what do we test with?
107 fprintf(stderr
, "\nNo nsIServiceManager; cannot continue.\n");
112 info5
->GetMethodCount(&methodcount
);
113 const nsXPTMethodInfo
*mi
;
114 for (i
= 0; i
< methodcount
; i
++) {
115 info5
->GetMethodInfo(i
, &mi
);
116 fprintf(stderr
, "method %d, name %s\n", i
, mi
->GetName());
119 // 7 is GetServiceWithListener, which has juicy params.
120 info5
->GetMethodInfo(7, &mi
);
121 // uint8 paramcount = mi->GetParamCount();
123 nsXPTParamInfo param2
= mi
->GetParam(2);
124 // should be IID for nsIShutdownListener
126 info5
->GetIIDForParam(7, ¶m2
, &nsISL
);
127 // const nsIID *nsISL = param2.GetInterfaceIID(info5);
128 fprintf(stderr
, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL
->ToString());
129 // if we look up the name?
131 iim
->GetNameForIID(nsISL
, &nsISLname
);
132 fprintf(stderr
, "which is called %s\n", nsISLname
);
134 fprintf(stderr
, "\nhow about one defined in a different typelib\n");
135 nsXPTParamInfo param3
= mi
->GetParam(3);
136 // should be IID for nsIShutdownListener
138 info5
->GetIIDForParam(7, ¶m3
, &nsISS
);
139 // const nsIID *nsISS = param3.GetInterfaceIID(info5);
140 fprintf(stderr
, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS
->ToString());
141 // if we look up the name?
143 iim
->GetNameForIID(nsISS
, &nsISSname
);
144 fprintf(stderr
, "which is called %s\n", nsISSname
);