Back to index

lightning-sunbird  0.9+nobinonly
TestInterfaceInfo.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* Some simple smoke tests of the typelib loader. */
00039 
00040 #include "nscore.h"
00041 
00042 #include "nsISupports.h"
00043 #include "nsIInterfaceInfo.h"
00044 #include "nsIInterfaceInfoManager.h"
00045 #include "xptinfo.h"
00046 
00047 #include <stdio.h>
00048 
00049 // This file expects the nsInterfaceInfoManager to be able to discover
00050 // .xpt files corresponding to those in xpcom/idl.  Currently this
00051 // means setting XPTDIR in the environment to some directory
00052 // containing these files.
00053 
00054 int main (int argc, char **argv) {
00055     int i;
00056     nsIID *iid1, *iid2, *iid3;
00057     char *name1, *name2, *name3;
00058     nsIInterfaceInfo *info2, *info3, *info4, *info5;
00059 
00060     nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
00061 
00062     fprintf(stderr, "\ngetting iid for 'nsISupports'\n");
00063     iim->GetIIDForName("nsISupports", &iid1);
00064     iim->GetNameForIID(iid1, &name1);
00065     fprintf(stderr, "%s iid %s\n", name1, iid1->ToString());
00066 
00067     fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n");
00068     iim->GetIIDForName("nsIInputStream", &iid2);
00069     iim->GetNameForIID(iid2, &name2);
00070     fprintf(stderr, "%s iid %s\n", name2, iid2->ToString());
00071 
00072     fprintf(stderr, "iid: %s, name: %s\n", iid1->ToString(), name1);
00073     fprintf(stderr, "iid: %s, name: %s\n", iid2->ToString(), name2);
00074 
00075     fprintf(stderr, "\ngetting info for iid2 from above\n");
00076     iim->GetInfoForIID(iid2, &info2);
00077 #ifdef DEBUG
00078 //    ((nsInterfaceInfo *)info2)->print(stderr);
00079 #endif
00080 
00081     fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n");
00082     iim->GetIIDForName("nsIInputStream", &iid3);
00083     iim->GetNameForIID(iid3, &name3);
00084     fprintf(stderr, "%s iid %s\n", name3, iid2->ToString());
00085     iim->GetInfoForIID(iid3, &info3);
00086 #ifdef DEBUG
00087 //    ((nsInterfaceInfo *)info3)->print(stderr);
00088 #endif
00089 
00090     fprintf(stderr, "\ngetting info for name 'nsIBidirectionalEnumerator'\n");
00091     iim->GetInfoForName("nsIBidirectionalEnumerator", &info4);
00092 #ifdef DEBUG
00093 //    ((nsInterfaceInfo *)info4)->print(stderr);
00094 #endif
00095 
00096     fprintf(stderr, "\nparams work?\n");
00097     fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n");
00098     iim->GetInfoForName("nsIServiceManager", &info5);
00099 #ifdef DEBUG
00100 //    ((nsInterfaceInfo *)info5)->print(stderr);
00101 #endif
00102 
00103     // XXX: nsIServiceManager is no more; what do we test with?
00104     if (info5 == NULL) {
00105         fprintf(stderr, "\nNo nsIServiceManager; cannot continue.\n");
00106         return 1;
00107     }
00108 
00109     uint16 methodcount;
00110     info5->GetMethodCount(&methodcount);
00111     const nsXPTMethodInfo *mi;
00112     for (i = 0; i < methodcount; i++) {
00113         info5->GetMethodInfo(i, &mi);
00114         fprintf(stderr, "method %d, name %s\n", i, mi->GetName());
00115     }
00116 
00117     // 7 is GetServiceWithListener, which has juicy params.
00118     info5->GetMethodInfo(7, &mi);
00119 //    uint8 paramcount = mi->GetParamCount();
00120 
00121     nsXPTParamInfo param2 = mi->GetParam(2);
00122     // should be IID for nsIShutdownListener
00123     nsIID *nsISL;
00124     info5->GetIIDForParam(7, &param2, &nsISL);
00125 //      const nsIID *nsISL = param2.GetInterfaceIID(info5);
00126     fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
00127     // if we look up the name?
00128     char *nsISLname;
00129     iim->GetNameForIID(nsISL, &nsISLname);
00130     fprintf(stderr, "which is called %s\n", nsISLname);
00131 
00132     fprintf(stderr, "\nhow about one defined in a different typelib\n");
00133     nsXPTParamInfo param3 = mi->GetParam(3);
00134     // should be IID for nsIShutdownListener
00135     nsIID *nsISS;
00136     info5->GetIIDForParam(7, &param3, &nsISS);
00137 //      const nsIID *nsISS = param3.GetInterfaceIID(info5);
00138     fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
00139     // if we look up the name?
00140     char *nsISSname;
00141     iim->GetNameForIID(nsISS, &nsISSname);
00142     fprintf(stderr, "which is called %s\n", nsISSname);
00143 
00144     return 0;
00145 }    
00146