michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Some simple smoke tests of the typelib loader. */ michael@0: michael@0: #include "nscore.h" michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsIInterfaceInfo.h" michael@0: #include "nsIInterfaceInfoManager.h" michael@0: #include "xptinfo.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: michael@0: #include michael@0: michael@0: // This file expects the nsInterfaceInfoManager to be able to discover michael@0: // .xpt files corresponding to those in xpcom/idl. Currently this michael@0: // means setting XPTDIR in the environment to some directory michael@0: // containing these files. michael@0: michael@0: int main (int argc, char **argv) { michael@0: int i; michael@0: nsIID *iid1, *iid2, *iid3; michael@0: char *name1, *name2, *name3; michael@0: nsIInterfaceInfo *info2, *info3, *info4, *info5; michael@0: michael@0: nsCOMPtr iim michael@0: (do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); michael@0: michael@0: fprintf(stderr, "\ngetting iid for 'nsISupports'\n"); michael@0: iim->GetIIDForName("nsISupports", &iid1); michael@0: iim->GetNameForIID(iid1, &name1); michael@0: fprintf(stderr, "%s iid %s\n", name1, iid1->ToString()); michael@0: michael@0: fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n"); michael@0: iim->GetIIDForName("nsIInputStream", &iid2); michael@0: iim->GetNameForIID(iid2, &name2); michael@0: fprintf(stderr, "%s iid %s\n", name2, iid2->ToString()); michael@0: michael@0: fprintf(stderr, "iid: %s, name: %s\n", iid1->ToString(), name1); michael@0: fprintf(stderr, "iid: %s, name: %s\n", iid2->ToString(), name2); michael@0: michael@0: fprintf(stderr, "\ngetting info for iid2 from above\n"); michael@0: iim->GetInfoForIID(iid2, &info2); michael@0: #ifdef DEBUG michael@0: // ((nsInterfaceInfo *)info2)->print(stderr); michael@0: #endif michael@0: michael@0: fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n"); michael@0: iim->GetIIDForName("nsIInputStream", &iid3); michael@0: iim->GetNameForIID(iid3, &name3); michael@0: fprintf(stderr, "%s iid %s\n", name3, iid2->ToString()); michael@0: iim->GetInfoForIID(iid3, &info3); michael@0: #ifdef DEBUG michael@0: // ((nsInterfaceInfo *)info3)->print(stderr); michael@0: #endif michael@0: michael@0: fprintf(stderr, "\ngetting info for name 'nsIBidirectionalEnumerator'\n"); michael@0: iim->GetInfoForName("nsIBidirectionalEnumerator", &info4); michael@0: #ifdef DEBUG michael@0: // ((nsInterfaceInfo *)info4)->print(stderr); michael@0: #endif michael@0: michael@0: fprintf(stderr, "\nparams work?\n"); michael@0: fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n"); michael@0: iim->GetInfoForName("nsIComponentManager", &info5); michael@0: #ifdef DEBUG michael@0: // ((nsInterfaceInfo *)info5)->print(stderr); michael@0: #endif michael@0: michael@0: // XXX: nsIServiceManager is no more; what do we test with? michael@0: if (info5 == nullptr) { michael@0: fprintf(stderr, "\nNo nsIComponentManager; cannot continue.\n"); michael@0: return 1; michael@0: } michael@0: michael@0: uint16_t methodcount; michael@0: info5->GetMethodCount(&methodcount); michael@0: const nsXPTMethodInfo *mi; michael@0: for (i = 0; i < methodcount; i++) { michael@0: info5->GetMethodInfo(i, &mi); michael@0: fprintf(stderr, "method %d, name %s\n", i, mi->GetName()); michael@0: } michael@0: michael@0: // 4 is getServiceByContractID, which has juicy params. michael@0: info5->GetMethodInfo(6, &mi); michael@0: michael@0: const nsXPTParamInfo& param2 = mi->GetParam(1); michael@0: // should be IID for the service michael@0: nsIID *nsISL; michael@0: info5->GetIIDForParam(6, ¶m2, &nsISL); michael@0: fprintf(stderr, "iid assoc'd with param 1 of method 6 - createInstanceByContractID - %s\n", nsISL->ToString()); michael@0: // if we look up the name? michael@0: char *nsISLname; michael@0: iim->GetNameForIID(nsISL, &nsISLname); michael@0: fprintf(stderr, "which is called %s\n", nsISLname); michael@0: michael@0: fprintf(stderr, "\nNow check the last param\n"); michael@0: const nsXPTParamInfo& param3 = mi->GetParam(3); michael@0: michael@0: if (param3.GetType().TagPart() != nsXPTType::T_INTERFACE_IS) { michael@0: fprintf(stderr, "Param 3 is not type interface is\n"); michael@0: // Not returning an error, because this could legitamately change michael@0: } michael@0: // lets see what arg this refers to michael@0: uint8_t argnum; michael@0: info5->GetInterfaceIsArgNumberForParam(6, ¶m3, &argnum); michael@0: fprintf(stderr, "param 3 referrs to param %d of method 6 - createInstanceByContractID\n", (uint32_t)argnum); michael@0: // Get the type of the parameter referred to michael@0: const nsXPTParamInfo& arg_param = mi->GetParam(argnum); michael@0: const nsXPTType& arg_type = arg_param.GetType(); michael@0: // Check to make sure it refers to the proper param michael@0: if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID) { michael@0: fprintf(stderr, "Param 3 of method 6 refers to a non IID parameter\n"); michael@0: // Not returning an error, because this could legitamately change michael@0: } michael@0: michael@0: michael@0: return 0; michael@0: } michael@0: