xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial