Back to index

lightning-sunbird  0.9+nobinonly
xpctest_child.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   John Bandhauer <jband@netscape.com>
00026  *   Pierre Phaneuf <pp@ludusdesign.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 /* implement nsIChild for testing. */
00043 
00044 #include "xpctest_private.h"
00045 
00046 #define USE_MI 0
00047 
00048 #if USE_MI
00049 /***************************************************************************/
00050 
00051 class xpctestOther : public nsIXPCTestOther
00052 {
00053 public:
00054     NS_DECL_ISUPPORTS
00055     NS_DECL_NSIXPCTESTOTHER
00056 
00057     xpctestOther();
00058 };
00059 
00060 class xpctestChild : public nsIXPCTestChild, public xpctestOther
00061 {
00062 public:
00063     NS_DECL_ISUPPORTS_INHERITED
00064     NS_DECL_NSIXPCTESTPARENT
00065     NS_DECL_NSIXPCTESTCHILD
00066 
00067     xpctestChild();
00068 };
00069 
00070 NS_IMPL_ISUPPORTS1(xpctestOther, nsIXPCTestOther)
00071 
00072 xpctestOther::xpctestOther()
00073 {
00074     NS_ADDREF_THIS();
00075 }
00076 
00077 NS_IMETHODIMP xpctestOther::Method3(PRInt16 i, PRInt16 j, PRInt16 k)
00078 {
00079     printf("Method3 called on inherited other\n");
00080     return NS_OK;
00081 }
00082 
00083 NS_IMPL_ISUPPORTS_INHERITED1(xpctestChild, xpctestOther, nsIXPCTestChild)
00084 
00085 xpctestChild::xpctestChild()
00086 {
00087 }
00088 
00089 NS_IMETHODIMP xpctestChild::Method1(PRInt16 i)
00090 {
00091     printf("Method1 called on child\n");
00092     return NS_OK;
00093 }
00094 
00095 NS_IMETHODIMP xpctestChild::Method1a(nsIXPCTestParent *foo)
00096 {
00097     printf("Method1a called on child\n");
00098     return NS_OK;
00099 }
00100 
00101 
00102 NS_IMETHODIMP xpctestChild::Method2(PRInt16 i, PRInt16 j)
00103 {
00104     printf("Method2 called on child\n");
00105     return NS_OK;
00106 }
00107 
00108 #if 0
00109 class xpctestParent : public nsIXPCTestParent
00110 {
00111 public:
00112     NS_DECL_ISUPPORTS
00113     NS_DECL_NSIXPCTESTPARENT
00114 
00115     xpctestParent();
00116 };
00117 
00118 
00119 class xpctestChild : public xpctestParent, public nsIXPCTestChild
00120 {
00121 public:
00122     NS_DECL_ISUPPORTS
00123     NS_DECL_NSIXPCTESTCHILD
00124 
00125     xpctestChild();
00126 };
00127 
00128 NS_IMETHODIMP xpctestParent::Method1(PRInt16 i)
00129 {
00130     printf("Method1 called on parent via child\n");
00131     return NS_OK;
00132 }
00133 NS_IMETHODIMP xpctestParent::Method1a(nsIXPCTestParent *foo)
00134 {
00135     printf("Method1a called on parent via child\n");
00136     return NS_OK;
00137 }
00138 
00139 #endif
00140 
00141 /***************************************************************************/
00142 #else
00143 /***************************************************************************/
00144 class xpctestChild : public nsIXPCTestChild
00145 {
00146 public:
00147     NS_DECL_ISUPPORTS
00148     NS_DECL_NSIXPCTESTPARENT
00149     NS_DECL_NSIXPCTESTCHILD
00150 
00151     xpctestChild();
00152 };
00153 
00154 NS_IMPL_ADDREF(xpctestChild)
00155 NS_IMPL_RELEASE(xpctestChild)
00156 
00157 NS_IMETHODIMP
00158 xpctestChild::QueryInterface(REFNSIID iid, void** result)
00159 {
00160     if (! result)
00161         return NS_ERROR_NULL_POINTER;
00162 
00163     if (iid.Equals(NS_GET_IID(nsIXPCTestChild)) ||
00164         iid.Equals(NS_GET_IID(nsIXPCTestParent)) ||
00165         iid.Equals(NS_GET_IID(nsISupports))) {
00166         *result = NS_STATIC_CAST(nsIXPCTestChild*, this);
00167         NS_ADDREF(this);
00168         return NS_OK;
00169     }
00170     else {
00171         *result = nsnull;
00172         return NS_NOINTERFACE;
00173     }
00174 }
00175 
00176 xpctestChild::xpctestChild()
00177 {
00178     NS_ADDREF_THIS();
00179 }
00180 
00181 NS_IMETHODIMP xpctestChild::Method1(PRInt16 i)
00182 {
00183     printf("Method1 called on child\n");
00184     return NS_OK;
00185 }
00186 
00187 NS_IMETHODIMP xpctestChild::Method1a(nsIXPCTestParent *foo)
00188 {
00189     printf("Method1a called on child\n");
00190     return NS_OK;
00191 }
00192 
00193 NS_IMETHODIMP xpctestChild::Method2(PRInt16 i, PRInt16 j)
00194 {
00195     printf("Method2 called on child\n");
00196     return NS_OK;
00197 }
00198 #endif
00199 /***************************************************************************/
00200 
00201 // static
00202 NS_IMETHODIMP
00203 xpctest::ConstructChild(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00204 {
00205     nsresult rv;
00206     NS_ASSERTION(aOuter == nsnull, "no aggregation");
00207     xpctestChild* obj = new xpctestChild();
00208     if(obj)
00209     {
00210         rv = obj->QueryInterface(aIID, aResult);
00211         NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
00212         NS_RELEASE(obj);
00213     }
00214     else
00215     {
00216         *aResult = nsnull;
00217         rv = NS_ERROR_OUT_OF_MEMORY;
00218     }
00219     return rv;
00220 }
00221 /***************************************************************************/
00222 
00223 
00224 
00225