Added tests of getting info assoc'd with params to TestInterfaceInfo.cpp, which uncovered an off-by-one problem due to magic typelib offsets for nsXPTParamInfo. Which makes me wonder if we shouldn't have just said #define XPT_INDEX_NO_PARENT 0xFFFF.

This commit is contained in:
mccabe%netscape.com 1999-03-10 10:36:13 +00:00
parent 139ea2e06f
commit b625b6aa37
4 changed files with 104 additions and 16 deletions

View File

@ -30,8 +30,6 @@
#include "xpt_cpp.h"
#include "xptinfo.h"
// Placeholder - this implementation just returns NULL.
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
{
@ -40,7 +38,6 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
@ -52,7 +49,10 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
// can't use IID, because it could be null for this entry.
char *interface_name;
interface_name = which_header->interface_directory[type.type.interface].name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIInterfaceInfo *ii;
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
@ -82,7 +82,10 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
// can't use IID, because it could be null for this entry.
char *interface_name;
interface_name = which_header->interface_directory[type.type.interface].name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIID* iid;
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);

View File

@ -37,12 +37,14 @@ static void RegAllocator();
// containing these files.
int main (int argc, char **argv) {
int i;
nsIID *iid1, *iid2, *iid3, *iid4, *iid5, *iid6;
char *name1, *name2, *name3, *name4, *name5, *name6;
nsIInterfaceInfo *info1, *info2, *info3, *info4, *info5, *info6;;
RegAllocator();
nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
nsIID *iid1, *iid2, *iid3, *iid4;
char *name1, *name2, *name3, *name4;
nsIInterfaceInfo *info1, *info2, *info3, *info4;
fprintf(stderr, "\ngetting iid for 'nsISupports'\n");
iim->GetIIDForName("nsISupports", &iid1);
@ -78,6 +80,45 @@ int main (int argc, char **argv) {
((nsInterfaceInfo *)info4)->print(stderr);
#endif
fprintf(stderr, "\nparams work?\n");
fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n");
iim->GetInfoForName("nsIServiceManager", &info5);
#ifdef DEBUG
((nsInterfaceInfo *)info5)->print(stderr);
#endif
uint16 methodcount;
info5->GetMethodCount(&methodcount);
const nsXPTMethodInfo *mi;
for (i = 0; i < methodcount; i++) {
info5->GetMethodInfo(i, &mi);
char *methodname;
fprintf(stderr, "method %d, name %s\n", i, mi->GetName());
}
// 7 is GetServiceWithListener, which has juicy params.
info5->GetMethodInfo(7, &mi);
uint8 paramcount = mi->GetParamCount();
nsXPTParamInfo param2 = mi->GetParam(2);
// should be IID for nsIShutdownListener
nsIID *nsISL = param2.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
// if we look up the name?
char *nsISLname;
iim->GetNameForIID(nsISL, &nsISLname);
fprintf(stderr, "which is called %s\n", nsISLname);
fprintf(stderr, "\nhow about one defined in a different typelib\n");
nsXPTParamInfo param3 = mi->GetParam(3);
// should be IID for nsIShutdownListener
nsIID *nsISS = param3.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
// if we look up the name?
char *nsISSname;
iim->GetNameForIID(nsISS, &nsISSname);
fprintf(stderr, "which is called %s\n", nsISSname);
return 0;
}

View File

@ -30,8 +30,6 @@
#include "xpt_cpp.h"
#include "xptinfo.h"
// Placeholder - this implementation just returns NULL.
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
{
@ -40,7 +38,6 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
@ -52,7 +49,10 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
// can't use IID, because it could be null for this entry.
char *interface_name;
interface_name = which_header->interface_directory[type.type.interface].name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIInterfaceInfo *ii;
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
@ -82,7 +82,10 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
// can't use IID, because it could be null for this entry.
char *interface_name;
interface_name = which_header->interface_directory[type.type.interface].name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIID* iid;
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);

View File

@ -37,12 +37,14 @@ static void RegAllocator();
// containing these files.
int main (int argc, char **argv) {
int i;
nsIID *iid1, *iid2, *iid3, *iid4, *iid5, *iid6;
char *name1, *name2, *name3, *name4, *name5, *name6;
nsIInterfaceInfo *info1, *info2, *info3, *info4, *info5, *info6;;
RegAllocator();
nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
nsIID *iid1, *iid2, *iid3, *iid4;
char *name1, *name2, *name3, *name4;
nsIInterfaceInfo *info1, *info2, *info3, *info4;
fprintf(stderr, "\ngetting iid for 'nsISupports'\n");
iim->GetIIDForName("nsISupports", &iid1);
@ -78,6 +80,45 @@ int main (int argc, char **argv) {
((nsInterfaceInfo *)info4)->print(stderr);
#endif
fprintf(stderr, "\nparams work?\n");
fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n");
iim->GetInfoForName("nsIServiceManager", &info5);
#ifdef DEBUG
((nsInterfaceInfo *)info5)->print(stderr);
#endif
uint16 methodcount;
info5->GetMethodCount(&methodcount);
const nsXPTMethodInfo *mi;
for (i = 0; i < methodcount; i++) {
info5->GetMethodInfo(i, &mi);
char *methodname;
fprintf(stderr, "method %d, name %s\n", i, mi->GetName());
}
// 7 is GetServiceWithListener, which has juicy params.
info5->GetMethodInfo(7, &mi);
uint8 paramcount = mi->GetParamCount();
nsXPTParamInfo param2 = mi->GetParam(2);
// should be IID for nsIShutdownListener
nsIID *nsISL = param2.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
// if we look up the name?
char *nsISLname;
iim->GetNameForIID(nsISL, &nsISLname);
fprintf(stderr, "which is called %s\n", nsISLname);
fprintf(stderr, "\nhow about one defined in a different typelib\n");
nsXPTParamInfo param3 = mi->GetParam(3);
// should be IID for nsIShutdownListener
nsIID *nsISS = param3.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
// if we look up the name?
char *nsISSname;
iim->GetNameForIID(nsISS, &nsISSname);
fprintf(stderr, "which is called %s\n", nsISSname);
return 0;
}