Back to index

lightning-sunbird  0.9+nobinonly
apitest.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Adam Lock <adamlock@netscape.com>
00029  *
00030  * ***** END LICENSE BLOCK ***** */
00031 
00032 #include <stdio.h>
00033 #include <crtdbg.h>
00034 
00035 #include "nsEmbedAPI.h"
00036 
00037 int main(int argc, char *argv[])
00038 {
00039     _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
00040     _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
00041    
00042 
00043     _CrtMemState sBefore, sMiddle, sAfter;
00044 
00045     // Store a memory checkpoint in the s1 memory-state structure
00046     _CrtMemCheckpoint(&sBefore);
00047 
00048        char *pszBinDirPath = nsnull;
00049        if (argc > 1)
00050        {
00051               pszBinDirPath = argv[1];
00052        }
00053        printf("apitest running...\n");
00054        
00055        nsCOMPtr<nsILocalFile> binDir;
00056        NS_NewLocalFile(pszBinDirPath, PR_TRUE, getter_AddRefs(binDir));
00057        
00058        nsresult rv = NS_InitEmbedding(binDir, nsnull);
00059        if (NS_FAILED(rv))
00060        {
00061               printf("NS_InitEmbedding FAILED (rv = 0x%08x)\n", rv);
00062               // DROP THROUGH - NS_TermEmbedding should cope
00063        }
00064     else
00065     {
00066         printf("NS_InitEmbedding SUCCEEDED (rv = 0x%08x)\n", rv);
00067     }
00068 
00069        // TODO put lot's of interesting diagnostic stuff here such as time taken
00070        //      to initialise
00071     // Memory used up etc.
00072     _CrtMemCheckpoint(&sMiddle);
00073 
00074 
00075        rv = NS_TermEmbedding();
00076        if (NS_FAILED(rv))
00077        {
00078               printf("NS_TermEmbedding FAILED (rv = 0x%08x)\n", rv);
00079               // DROP THROUGH
00080        }
00081     else
00082     {
00083         printf("NS_TermEmbedding SUCCEEDED (rv = 0x%08x)\n", rv);
00084     }
00085 
00086        // TODO more interesting stuff. Time to shutdown
00087 
00088     // Dump the leaked memory
00089     printf("FINAL LEAKAGE:\n");
00090     _CrtMemCheckpoint(&sAfter);
00091      _CrtMemState sDifference;
00092     if ( _CrtMemDifference(&sDifference, &sBefore, &sAfter))
00093     {
00094         _CrtMemDumpStatistics(&sDifference);
00095     }
00096 
00097     _CrtDumpMemoryLeaks( );
00098 
00099     printf("apitest complete\n");
00100 
00101        return 0;
00102 }