Back to index

lightning-sunbird  0.9+nobinonly
ojiapitests.h
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: 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  * Sun Microsystems, Inc.
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 the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 #ifndef ojiapitests_h___
00038 #define ojiapitests_h___
00039 
00040 //mozilla specific headers
00041 #include "nspr.h"
00042 #include "nsString.h"
00043 
00044 #define OJI_TEST_RESULTS "OJITestResults.txt"
00045 #define OJI_TESTS_LIST   "OJITests.lst"
00046 #ifdef XP_UNIX
00047 #define OJI_JNI_TESTS   "libojiapijnitests.so"
00048 #define OJI_JM_TESTS    "libojiapijmtests.so"
00049 #define OJI_TM_TESTS    "libojiapitmtests.so"
00050 #define OJI_LCM_TESTS   "libojiapilcmtests.so"
00051 #define OJI_JMPTI_TESTS "libojiapijmptitests.so"
00052 #else
00053 #define OJI_JNI_TESTS   "ojiapijnitests.dll"
00054 #define OJI_JM_TESTS    "ojiapijmtests.dll"
00055 #define OJI_TM_TESTS    "ojiapitmtests.dll"
00056 #define OJI_LCM_TESTS   "ojiapilcmtests.dll"
00057 #define OJI_JMPTI_TESTS "ojiapijmptitests.dll"
00058 #endif
00059 
00060 
00061 class TestResult;
00062 
00063 typedef TestResult* (*TYPEOF_OJIAPITest)();
00064 
00065 //may be used latter
00066 typedef TestResult* (*TYPEOF_JNI_OJIAPITest)();
00067 typedef TestResult* (*TYPEOF_JM_OJIAPITest)();
00068 typedef TestResult* (*TYPEOF_LCM_OJIAPITest)();
00069 typedef TestResult* (*TYPEOF_TM_OJIAPITest)();
00070 
00071 //headers for tests
00072 #define JNI_OJIAPITest(TestName)             \
00073 extern "C" NS_EXPORT TestResult*             \
00074 TestName()
00075 
00076 #define TM_OJIAPITest(TestName)             \
00077 extern "C" NS_EXPORT TestResult*             \
00078 TestName()
00079 
00080 #define JM_OJIAPITest(TestName)             \
00081 extern "C" NS_EXPORT TestResult*             \
00082 TestName()
00083 
00084 #define LCM_OJIAPITest(TestName)             \
00085 extern "C" NS_EXPORT TestResult*             \
00086 TestName()
00087 
00088 #define GET_JNI_FOR_TEST     \
00089 JNIEnv* env;                 \
00090 if (NS_FAILED(GetJNI(&env)) || !env) \
00091        return TestResult::FAIL("Can't get JNIEnv !");
00092 
00093 #define GET_TM_FOR_TEST                      \
00094 nsIThreadManager* threadMgr;                 \
00095 if (NS_FAILED(GetThreadManager(&threadMgr)) || !threadMgr) \
00096        return TestResult::FAIL("Can't get TM !");
00097 
00098 
00099 #define GET_JM_FOR_TEST                      \
00100 nsIJVMManager* jvmMgr;                       \
00101 if (NS_FAILED(GetJVMManager(&jvmMgr)) || !jvmMgr)       \
00102        return TestResult::FAIL("Can't get JNIEnv !");
00103 
00104 #define GET_LCM_FOR_TEST                      \
00105 nsILiveConnectManager* lcMgr;                 \
00106 if (NS_FAILED(GetLiveConnectManager(&lcMgr)) || !lcMgr) \
00107        return TestResult::FAIL("Can't get JNIEnv !");
00108 
00109 
00110 enum StatusValue {
00111   FAIL_value = 0,
00112   PASS_value = 1
00113 };
00114 
00115 class TestResult {
00116 public:
00117   
00118 /*
00119   static TestResult* PASS(nsString comment) {
00120     return new TestResult(PASS_value, comment); 
00121   }
00122 */
00123 
00125   static TestResult* PASS(char *comment) {
00126     char *msg = (char*)calloc(1, PL_strlen(comment)+1024);
00127     sprintf(msg, "Method %s", comment);
00128     CBufDescriptor *bufDescr = new CBufDescriptor((const char*)msg, PR_FALSE, PL_strlen(msg)+1, PL_strlen(msg));
00129     nsString *str = new nsAutoString(*bufDescr);
00130     return new TestResult(PASS_value, *str); 
00131   }
00132 
00133   static TestResult* FAIL(nsString comment) {
00134     return new TestResult(FAIL_value, comment); 
00135   }
00136 
00137   static TestResult* FAIL(char *method, nsresult rc) {
00138     char *comment = (char*)calloc(1, PL_strlen(method)+1024);
00139     sprintf(comment, "Method %s returned %X", method, rc);
00140     CBufDescriptor *bufDescr = new CBufDescriptor((const char*)comment, PR_FALSE, PL_strlen(comment)+1, PL_strlen(comment));
00141     nsString *str = new nsAutoString(*bufDescr);
00142     return new TestResult(FAIL_value, *str); 
00143   }
00144 
00145   static TestResult* FAIL(char *method, char* comment, nsresult rc) {
00146     char *outComment = (char*)calloc(1, PL_strlen(method)+1024);
00147     sprintf(outComment, "Method %s returned %X: %s", method, rc, comment);
00148     CBufDescriptor *bufDescr = new CBufDescriptor((const char*)comment, PR_FALSE, PL_strlen(comment)+1, PL_strlen(comment));
00149     nsString *str = new nsAutoString(*bufDescr);
00150     return new TestResult(FAIL_value, *str); 
00151   }
00152 
00153   static TestResult* FAIL(char *comment) {
00154       CBufDescriptor *bufDescr = new CBufDescriptor((const char*)comment, PR_FALSE, PL_strlen(comment)+1, PL_strlen(comment));
00155       nsString *str = new nsAutoString(*bufDescr);
00156       return new TestResult(FAIL_value, *str); 
00157   }
00158 
00159   TestResult ( StatusValue status, nsString comment) {
00160     this->status = status;
00161     this->comment = comment;
00162   }
00163 
00164   StatusValue status;
00165   nsString comment;
00166 
00167 };
00168 
00169 #endif //ojiapitests_h__