Back to index

lightning-sunbird  0.9+nobinonly
TestCallTemplates.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim:cindent:ts=8:et:sw=4:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is Mozilla.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications.
00021  * Portions created by the Initial Developer are Copyright (C) 2001
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   L. David Baron <dbaron@dbaron.org> (original author)
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /*
00042  * This test is NOT intended to be run.  It's a test to make sure
00043  * a group of functions BUILD correctly.
00044  */
00045 
00046 #include "nsISupportsUtils.h"
00047 #include "nsIWeakReference.h"
00048 #include "nsIComponentManager.h"
00049 #include "nsIServiceManager.h"
00050 #include "nsWeakReference.h"
00051 #include "nsIInterfaceRequestor.h"
00052 #include "nsIInterfaceRequestorUtils.h"
00053 
00054 #define NS_ITESTSERVICE_IID \
00055   {0x127b5253, 0x37b1, 0x43c7, \
00056     { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }}
00057 
00058 class NS_NO_VTABLE nsITestService : public nsISupports {
00059   public: 
00060     NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID)
00061 };
00062 
00063 class nsTestService : public nsITestService, public nsSupportsWeakReference
00064 {
00065   public:
00066     NS_DECL_ISUPPORTS
00067 };
00068 
00069 NS_IMPL_ISUPPORTS2(nsTestService, nsITestService, nsISupportsWeakReference)
00070 
00071 #define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1"
00072 #define NS_TEST_SERVICE_CID \
00073   {0xa00c1406, 0x283a, 0x45c9, \
00074     {0xae, 0xd2, 0x1a, 0xb6, 0xdd, 0xba, 0xfe, 0x53}}
00075 static NS_DEFINE_CID(kTestServiceCID, NS_TEST_SERVICE_CID);
00076 
00077 int main()
00078 {
00079     /*
00080      * NOTE:  This does NOT demonstrate how these functions are
00081      * intended to be used.  They are intended for filling in out
00082      * parameters that need to be |AddRef|ed.  I'm just too lazy
00083      * to write lots of little getter functions for a test program
00084      * when I don't need to.
00085      */
00086 
00087     NS_NOTREACHED("This test is not intended to run, only to compile!");
00088 
00089     /* Test CallQueryInterface */
00090 
00091     nsISupports *mySupportsPtr = NS_REINTERPRET_CAST(nsISupports*, 0x1000);
00092 
00093     nsITestService *myITestService = nsnull;
00094     CallQueryInterface(mySupportsPtr, &myITestService);
00095 
00096     nsTestService *myTestService =
00097         NS_REINTERPRET_CAST(nsTestService*, mySupportsPtr);
00098     nsISupportsWeakReference *mySupportsWeakRef;
00099     CallQueryInterface(myTestService, &mySupportsWeakRef);
00100 
00101     /* Test CallQueryReferent */
00102 
00103     nsIWeakReference *myWeakRef =
00104         NS_STATIC_CAST(nsIWeakReference*, mySupportsPtr);
00105     CallQueryReferent(myWeakRef, &myITestService);
00106 
00107     /* Test CallCreateInstance */
00108 
00109     CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService);
00110     CallCreateInstance(kTestServiceCID, &myITestService);
00111     CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr,
00112                        &myITestService);
00113     CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService);
00114 
00115     /* Test CallGetService */
00116     CallGetService(kTestServiceCID, &myITestService);
00117     CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService);
00118 
00119     /* Test CallGetInterface */
00120     nsIInterfaceRequestor *myInterfaceRequestor =
00121         NS_STATIC_CAST(nsIInterfaceRequestor*, mySupportsPtr);
00122     CallGetInterface(myInterfaceRequestor, &myITestService);
00123 
00124     return 0;
00125 }