|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* Some simple smoke tests of the typelib loader. */ |
|
7 |
|
8 #include "nscore.h" |
|
9 |
|
10 #include "nsISupports.h" |
|
11 #include "nsIInterfaceInfo.h" |
|
12 #include "nsIInterfaceInfoManager.h" |
|
13 #include "xptinfo.h" |
|
14 #include "nsServiceManagerUtils.h" |
|
15 |
|
16 #include <stdio.h> |
|
17 |
|
18 // This file expects the nsInterfaceInfoManager to be able to discover |
|
19 // .xpt files corresponding to those in xpcom/idl. Currently this |
|
20 // means setting XPTDIR in the environment to some directory |
|
21 // containing these files. |
|
22 |
|
23 int main (int argc, char **argv) { |
|
24 int i; |
|
25 nsIID *iid1, *iid2, *iid3; |
|
26 char *name1, *name2, *name3; |
|
27 nsIInterfaceInfo *info2, *info3, *info4, *info5; |
|
28 |
|
29 nsCOMPtr<nsIInterfaceInfoManager> iim |
|
30 (do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); |
|
31 |
|
32 fprintf(stderr, "\ngetting iid for 'nsISupports'\n"); |
|
33 iim->GetIIDForName("nsISupports", &iid1); |
|
34 iim->GetNameForIID(iid1, &name1); |
|
35 fprintf(stderr, "%s iid %s\n", name1, iid1->ToString()); |
|
36 |
|
37 fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n"); |
|
38 iim->GetIIDForName("nsIInputStream", &iid2); |
|
39 iim->GetNameForIID(iid2, &name2); |
|
40 fprintf(stderr, "%s iid %s\n", name2, iid2->ToString()); |
|
41 |
|
42 fprintf(stderr, "iid: %s, name: %s\n", iid1->ToString(), name1); |
|
43 fprintf(stderr, "iid: %s, name: %s\n", iid2->ToString(), name2); |
|
44 |
|
45 fprintf(stderr, "\ngetting info for iid2 from above\n"); |
|
46 iim->GetInfoForIID(iid2, &info2); |
|
47 #ifdef DEBUG |
|
48 // ((nsInterfaceInfo *)info2)->print(stderr); |
|
49 #endif |
|
50 |
|
51 fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n"); |
|
52 iim->GetIIDForName("nsIInputStream", &iid3); |
|
53 iim->GetNameForIID(iid3, &name3); |
|
54 fprintf(stderr, "%s iid %s\n", name3, iid2->ToString()); |
|
55 iim->GetInfoForIID(iid3, &info3); |
|
56 #ifdef DEBUG |
|
57 // ((nsInterfaceInfo *)info3)->print(stderr); |
|
58 #endif |
|
59 |
|
60 fprintf(stderr, "\ngetting info for name 'nsIBidirectionalEnumerator'\n"); |
|
61 iim->GetInfoForName("nsIBidirectionalEnumerator", &info4); |
|
62 #ifdef DEBUG |
|
63 // ((nsInterfaceInfo *)info4)->print(stderr); |
|
64 #endif |
|
65 |
|
66 fprintf(stderr, "\nparams work?\n"); |
|
67 fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n"); |
|
68 iim->GetInfoForName("nsIComponentManager", &info5); |
|
69 #ifdef DEBUG |
|
70 // ((nsInterfaceInfo *)info5)->print(stderr); |
|
71 #endif |
|
72 |
|
73 // XXX: nsIServiceManager is no more; what do we test with? |
|
74 if (info5 == nullptr) { |
|
75 fprintf(stderr, "\nNo nsIComponentManager; cannot continue.\n"); |
|
76 return 1; |
|
77 } |
|
78 |
|
79 uint16_t methodcount; |
|
80 info5->GetMethodCount(&methodcount); |
|
81 const nsXPTMethodInfo *mi; |
|
82 for (i = 0; i < methodcount; i++) { |
|
83 info5->GetMethodInfo(i, &mi); |
|
84 fprintf(stderr, "method %d, name %s\n", i, mi->GetName()); |
|
85 } |
|
86 |
|
87 // 4 is getServiceByContractID, which has juicy params. |
|
88 info5->GetMethodInfo(6, &mi); |
|
89 |
|
90 const nsXPTParamInfo& param2 = mi->GetParam(1); |
|
91 // should be IID for the service |
|
92 nsIID *nsISL; |
|
93 info5->GetIIDForParam(6, ¶m2, &nsISL); |
|
94 fprintf(stderr, "iid assoc'd with param 1 of method 6 - createInstanceByContractID - %s\n", nsISL->ToString()); |
|
95 // if we look up the name? |
|
96 char *nsISLname; |
|
97 iim->GetNameForIID(nsISL, &nsISLname); |
|
98 fprintf(stderr, "which is called %s\n", nsISLname); |
|
99 |
|
100 fprintf(stderr, "\nNow check the last param\n"); |
|
101 const nsXPTParamInfo& param3 = mi->GetParam(3); |
|
102 |
|
103 if (param3.GetType().TagPart() != nsXPTType::T_INTERFACE_IS) { |
|
104 fprintf(stderr, "Param 3 is not type interface is\n"); |
|
105 // Not returning an error, because this could legitamately change |
|
106 } |
|
107 // lets see what arg this refers to |
|
108 uint8_t argnum; |
|
109 info5->GetInterfaceIsArgNumberForParam(6, ¶m3, &argnum); |
|
110 fprintf(stderr, "param 3 referrs to param %d of method 6 - createInstanceByContractID\n", (uint32_t)argnum); |
|
111 // Get the type of the parameter referred to |
|
112 const nsXPTParamInfo& arg_param = mi->GetParam(argnum); |
|
113 const nsXPTType& arg_type = arg_param.GetType(); |
|
114 // Check to make sure it refers to the proper param |
|
115 if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID) { |
|
116 fprintf(stderr, "Param 3 of method 6 refers to a non IID parameter\n"); |
|
117 // Not returning an error, because this could legitamately change |
|
118 } |
|
119 |
|
120 |
|
121 return 0; |
|
122 } |
|
123 |