Skip to content
Permalink
Browse files

Activate more tests and fix oversized frames.

  • Loading branch information
Thrameos committed Feb 15, 2020
1 parent 80c80f8 commit 37425742485309340617e6772976130857827786
Showing with 44 additions and 174 deletions.
  1. +1 −1 .travis.yml
  2. +1 −0 appveyor/install.sh
  3. +4 −20 native/common/include/jp_jniutil.h
  4. +29 −21 native/common/jp_class.cpp
  5. +8 −132 native/common/jp_jniutil.cpp
  6. +1 −0 test-requirements.txt
@@ -47,7 +47,7 @@ matrix:
- $PYTHON setup.py --enable-coverage --enable-build-jar build_ext --inplace
- $PYTHON setup.py install
- $PIP install -e .
- $PIP install gcovr pytest-cov
- $PIP install gcovr pytest-cov jedi
- mvn -f project/coverage package
- ant -f test/build.xml
script:
@@ -33,6 +33,7 @@ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$PYTHON get-pip.py
$PYTHON -m pip install setuptools
$PYTHON -m pip install mock
$PYTHON -m pip install jedi
git clone --depth=1 https://github.com/pypa/setuptools.git
cd setuptools
$PYTHON ./bootstrap.py
@@ -67,38 +67,22 @@ bool isFinal(jclass cls);
/**
* java.lang.Class.getInterfaces()
*/
vector<jclass> getInterfaces(JPJavaFrame& frame, jclass cls);
jobjectArray getInterfaces(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getDeclaredFields()
*/
vector<jobject> getDeclaredFields(JPJavaFrame& frame, jclass cls);


/**
* java.lang.Class.getConstructors()
*/
vector<jobject> getConstructors(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getFields()
*/
vector<jobject> getFields(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getDeclaredMethods()
*/
vector<jobject> getDeclaredMethods(JPJavaFrame& frame, jclass cls);
jobjectArray getDeclaredFields(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getDeclaredMethods()
*/
vector<jobject> getMethods(JPJavaFrame& frame, jclass cls);
jobjectArray getMethods(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getDeclaredMethods()
*/
vector<jobject> getDeclaredConstructors(JPJavaFrame& frame, jclass cls);
jobjectArray getDeclaredConstructors(JPJavaFrame& frame, jclass cls);

/**
* java.lang.Class.getModifiers()
@@ -441,12 +441,14 @@ const JPClass::ClassList& JPClass::getInterfaces()
JPJavaFrame frame;
JP_TRACE_IN("JPClass::loadInterfaces");
// Super interfaces
vector<jclass> intf = JPJni::getInterfaces(frame, m_Class.get());

for (vector<jclass>::iterator it = intf.begin(); it != intf.end(); it++)
jobjectArray intf = JPJni::getInterfaces(frame, m_Class.get());
int len = frame.GetArrayLength(intf);
for (int i = 0; i < len; i++)
{
JPClass* interface = JPTypeManager::findClass(*it);
jclass c = (jclass) frame.GetObjectArrayElement(intf, i);
JPClass* interface = JPTypeManager::findClass(c);
m_SuperInterfaces.push_back(interface);
frame.DeleteLocalRef(c);
}
return m_SuperInterfaces;
JP_TRACE_OUT;
@@ -467,33 +469,37 @@ void JPClass::postLoad()

void JPClass::loadFields()
{
JPJavaFrame frame(512);
JPJavaFrame frame;
JP_TRACE_IN("JPClass::loadFields");
// fields
vector<jobject> fields = JPJni::getDeclaredFields(frame, m_Class.get());
jobjectArray fields = JPJni::getDeclaredFields(frame, m_Class.get());

for (vector<jobject>::iterator it = fields.begin(); it != fields.end(); it++)
int len = frame.GetArrayLength(fields);
for (int i = 0; i < len; i++)
{
// Skip private fields
if (!JPJni::isFieldPublic(*it))
jobject c = frame.GetObjectArrayElement(fields, i);
if (!JPJni::isFieldPublic(c))
continue;
m_Fields.push_back(new JPField(this, *it));
m_Fields.push_back(new JPField(this, c));
frame.DeleteLocalRef(c);
}
JP_TRACE_OUT;
}

void JPClass::loadMethods()
{
JPJavaFrame frame(512);
JPJavaFrame frame;
JP_TRACE_IN("JPClass::loadMethods");

// methods
MethodMap methodMap;
vector<jobject> methods = JPJni::getMethods(frame, m_Class.get());
jobjectArray methods = JPJni::getMethods(frame, m_Class.get());

for (vector<jobject>::iterator iter1 = methods.begin(); iter1 != methods.end(); iter1++)
int len = frame.GetArrayLength(methods);
for (int i = 0; i < len; i++)
{
const string& name = JPJni::getMemberName(*iter1);
jobject c = frame.GetObjectArrayElement(methods, i);
const string& name = JPJni::getMemberName(c);
JPMethod* method = NULL;
MethodMap::iterator iter2 = methodMap.find(name);
if (iter2 == methodMap.end())
@@ -504,7 +510,8 @@ void JPClass::loadMethods()
{
method = iter2->second;
}
method->addOverload(this, *iter1);
method->addOverload(this, c);
frame.DeleteLocalRef(c);
}

int i = 0;
@@ -527,15 +534,16 @@ void JPClass::loadConstructors()
return;
}


vector<jobject> methods = JPJni::getDeclaredConstructors(frame, m_Class.get());

for (vector<jobject>::iterator it = methods.begin(); it != methods.end(); it++)
jobjectArray methods = JPJni::getDeclaredConstructors(frame, m_Class.get());
int len = frame.GetArrayLength(methods);
for (int i = 0; i < len; i++)
{
if (JPJni::isMemberPublic(*it))
jobject c = frame.GetObjectArrayElement(methods, i);
if (JPJni::isMemberPublic(c))
{
m_Constructors->addOverload(this, *it);
m_Constructors->addOverload(this, c);
}
frame.DeleteLocalRef(c);
}
JP_TRACE_OUT;
}
@@ -27,12 +27,9 @@ jmethodID s_Object_EqualsID;
jmethodID s_Class_GetNameID;
jmethodID s_Class_GetComponentTypeID;
jmethodID s_Class_GetDeclaredFieldsID;
jmethodID s_Class_GetDeclaredMethodsID;
jmethodID s_Class_GetInterfacesID;
jmethodID s_Class_GetFieldsID;
jmethodID s_Class_GetMethodsID;
jmethodID s_Class_GetDeclaredConstructorsID;
jmethodID s_Class_GetConstructorsID;
jmethodID s_Class_IsArrayID;
jmethodID s_Class_IsInterfaceID;
jmethodID s_Class_GetModifiersID;
@@ -106,11 +103,8 @@ void JPJni::init()

s_Class_GetComponentTypeID = frame.GetMethodID(s_ClassClass, "getComponentType", "()Ljava/lang/Class;");
s_Class_GetDeclaredFieldsID = frame.GetMethodID(s_ClassClass, "getDeclaredFields", "()[Ljava/lang/reflect/Field;");
s_Class_GetDeclaredMethodsID = frame.GetMethodID(s_ClassClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
s_Class_GetMethodsID = frame.GetMethodID(s_ClassClass, "getMethods", "()[Ljava/lang/reflect/Method;");
s_Class_GetFieldsID = frame.GetMethodID(s_ClassClass, "getFields", "()[Ljava/lang/reflect/Field;");
s_Class_GetDeclaredConstructorsID = frame.GetMethodID(s_ClassClass, "getDeclaredConstructors", "()[Ljava/lang/reflect/Constructor;");
s_Class_GetConstructorsID = frame.GetMethodID(s_ClassClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;");
s_Class_IsArrayID = frame.GetMethodID(s_ClassClass, "isArray", "()Z");
s_Class_IsInterfaceID = frame.GetMethodID(s_ClassClass, "isInterface", "()Z");
s_Class_GetModifiersID = frame.GetMethodID(s_ClassClass, "getModifiers", "()I");
@@ -200,18 +194,6 @@ jobject JPJni::stringToCharArray(jstring str)
return frame.keep(res);
}

//JPTypeName JPJni::getTypeNameForObject(jobject o)
//{
// if (o == NULL)
// {
// return JPTypeName::fromSimpleName("java.lang.Object");
// }
//
// JPJavaFrame frame;
// jclass c = getClass(o);
// return getTypeNameForClass(c);
//}

jclass JPJni::getClass(jobject o)
{
JPJavaFrame frame;
@@ -301,130 +283,24 @@ bool JPJni::isFieldPublic(jobject field)
return (res ? true : false);
}

//JPTypeName JPJni::getTypeNameForClass(jclass clazz)
//{
// string simpleName = convertToSimpleName(clazz);
// return JPTypeName::fromSimpleName(simpleName.c_str());
//}

// Returns multiple local references, must have a suitable local frame

vector<jclass> JPJni::getInterfaces(JPJavaFrame& frame, jclass clazz)
{
jobjectArray interfaces = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetInterfacesID);

int len = frame.GetArrayLength(interfaces);
vector<jclass> res;
for (int i = 0; i < len; i++)
{
jclass c = (jclass) frame.GetObjectArrayElement(interfaces, i);
res.push_back(c);
}

return res;
}

// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getDeclaredFields(JPJavaFrame& frame, jclass clazz)
{
jobjectArray fields = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetDeclaredFieldsID);

int len = frame.GetArrayLength(fields);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(fields, i);
res.push_back(c);
}

return res;
}

// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getFields(JPJavaFrame& frame, jclass clazz)
{
jobjectArray fields = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetFieldsID);

int len = frame.GetArrayLength(fields);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(fields, i);
res.push_back(c);
}

return res;
}

// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getDeclaredMethods(JPJavaFrame& frame, jclass clazz)
jobjectArray JPJni::getInterfaces(JPJavaFrame& frame, jclass clazz)
{
jobjectArray methods = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetDeclaredMethodsID);

int len = frame.GetArrayLength(methods);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(methods, i);
res.push_back(c);
}

return res;
return (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetInterfacesID);
}


// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getDeclaredConstructors(JPJavaFrame& frame, jclass clazz)
jobjectArray JPJni::getDeclaredFields(JPJavaFrame& frame, jclass clazz)
{
jobjectArray methods = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetDeclaredConstructorsID);

int len = frame.GetArrayLength(methods);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(methods, i);
res.push_back(c);
}

return res;
return (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetDeclaredFieldsID);
}

// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getConstructors(JPJavaFrame& frame, jclass clazz)
jobjectArray JPJni::getDeclaredConstructors(JPJavaFrame& frame, jclass clazz)
{
jobjectArray methods = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetConstructorsID);

int len = frame.GetArrayLength(methods);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(methods, i);
res.push_back(c);
}

return res;
return (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetDeclaredConstructorsID);
}

// Returns multiple local references, must have a suitable local frame

vector<jobject> JPJni::getMethods(JPJavaFrame& frame, jclass clazz)
jobjectArray JPJni::getMethods(JPJavaFrame& frame, jclass clazz)
{
jobjectArray methods = (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetMethodsID);

int len = frame.GetArrayLength(methods);
vector<jobject> res;
for (int i = 0; i < len; i++)
{
jobject c = frame.GetObjectArrayElement(methods, i);
res.push_back(c);
}

return res;
return (jobjectArray) frame.CallObjectMethod(clazz, s_Class_GetMethodsID);
}

// Returns local reference
@@ -1,3 +1,4 @@
unittest2==1.1
mock==3.0.5
pytest==4.6.9
jedi

0 comments on commit 3742574

Please sign in to comment.
You can’t perform that action at this time.