NativeTest.h

00001 /*
00002  * @(#)NativeTest.h  0.2.0 / 2007-12-31
00003  *
00004  * Copyright (c) 2007, ETF and contributors. All rights reserved.
00005  *
00006  * This software is licensed under the LGPL, version 2.1, license.
00007  * A copy of the license is included in the file LICENSE-LGPL.txt.
00008  */
00009 #ifndef NATIVETEST_H
00010 #define NATIVETEST_H
00011 
00012 #ifdef JAVAQX_TEST
00013 
00014 #include "JavaQxCore.h"
00015 
00016 /*^**************************************************************************^*/
00017 /*- NativeTest Class.                                                        -*/
00018 /*^**************************************************************************^*/
00019 
00026 class JAVAQX_EXPORT NativeTest : public QObject
00027 {
00028   Q_OBJECT
00029 public:
00030   jobjectArray getTestMethods(JNIEnv *env);
00031   void setUp(JNIEnv *env);
00032   void tearDown(JNIEnv *env);
00033   bool invokeMethod(JNIEnv *env, jobject obj, jstring methodName);
00034 public:
00035   static void initialize(JNIEnv *env, jclass cls);
00036 protected:
00037   virtual void setUp();
00038   virtual void tearDown();
00039 protected:
00040   jobject createJObject(const char *className);
00041   jobject createJObject(const char *className, const char *ctorSig, ...);
00042   void *nativeObjectPointer(jobject obj);
00043   void *nativeObjectPointer(jobject obj, const char *fieldName);
00044   template<typename T> T nativePointer(jobject obj) {
00045     return reinterpret_cast<T>(nativeObjectPointer(obj));
00046   }
00047   template<typename T> T nativePointer(jobject obj, const char *fieldName) {
00048     return reinterpret_cast<T>(nativeObjectPointer(obj, fieldName));
00049   }
00050   void failCondition(const char *condition = 0, const char *fileName = 0,
00051                      int lineNumber = -1);
00052 protected:
00053   inline JNIEnv *env() const;
00054 private:
00055   JNIEnv *m_env;
00056   jweak m_obj;
00057 private:
00058   static jmethodID sm_failConditionMID;
00059 };
00060 
00061 /*^**************************************************************************^*/
00062 /*- NativeTest :: Protected Inline Member Function.                          -*/
00063 /*^**************************************************************************^*/
00064 
00070 inline JNIEnv *NativeTest::env() const
00071 {
00072   return m_env;
00073 }
00074 
00075 /*^**************************************************************************^*/
00076 /*- Macro Definition.                                                        -*/
00077 /*^**************************************************************************^*/
00078 
00079 #define nativeTest (reinterpret_cast<NativeTest *>(testCase))
00080 
00081 #endif // JAVAQX_TEST
00082 
00083 #endif // NATIVETEST_H
00084 
00085 /*^*****************************************************************************
00086   File History:
00087 
00088  - 2007-12-31 11:15:54 Slobodan
00089    Initial version
00090 
00091 *****************************************************************************^*/

Copyright © 2007 ETF and contributors. All Rights Reserved.