Add a few more tests. (How do you eat a whale? One bite at a time.)
Change-Id: Ib7b1f17a78a5a285e85e0ffcd598596b17b5a79a
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c b/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
index d97c9ea..668dd40 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
+++ b/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
@@ -22,11 +22,18 @@
#include <jni.h>
#include <JNIHelp.h>
+#include <stdbool.h>
+
// public native void nop();
static void InstanceNonce_nop(JNIEnv *env, jobject this) {
// This space intentionally left blank.
}
+// public native boolean returnBoolean();
+static jboolean InstanceNonce_returnBoolean(JNIEnv *env, jobject this) {
+ return (jboolean) false;
+}
+
// public native byte returnByte();
static jbyte InstanceNonce_returnByte(JNIEnv *env, jobject this) {
return (jbyte) 123;
@@ -62,9 +69,25 @@
return 12345678.9;
}
+// public native Object returnNull();
+static jobject InstanceNonce_returnNull(JNIEnv *env, jobject this) {
+ return NULL;
+}
+
+// public native String returnString();
+static jobject InstanceNonce_returnString(JNIEnv *env, jobject this) {
+ return (*env)->NewStringUTF(env, "blort");
+}
+
+// public native Class returnThisClass();
+static jobject InstanceNonce_returnThis(JNIEnv *env, jobject this) {
+ return this;
+}
+
static JNINativeMethod methods[] = {
// name, signature, function
{ "nop", "()V", InstanceNonce_nop },
+ { "returnBoolean","()Z", InstanceNonce_returnBoolean },
{ "returnByte", "()B", InstanceNonce_returnByte },
{ "returnShort", "()S", InstanceNonce_returnShort },
{ "returnChar", "()C", InstanceNonce_returnChar },
@@ -72,6 +95,10 @@
{ "returnLong", "()J", InstanceNonce_returnLong },
{ "returnFloat", "()F", InstanceNonce_returnFloat },
{ "returnDouble", "()D", InstanceNonce_returnDouble },
+ { "returnNull", "()Ljava/lang/Object;", InstanceNonce_returnNull },
+ { "returnString", "()Ljava/lang/String;", InstanceNonce_returnString },
+ { "returnThis", "()Landroid/jni/cts/InstanceNonce;",
+ InstanceNonce_returnThis },
};
int register_InstanceNonce(JNIEnv *env) {
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c b/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
index 64b9f7f..5bd751c 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
+++ b/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
@@ -22,11 +22,18 @@
#include <jni.h>
#include <JNIHelp.h>
+#include <stdbool.h>
+
// public static native void nop();
static void StaticNonce_nop(JNIEnv *env, jclass clazz) {
// This space intentionally left blank.
}
+// public static native boolean returnBoolean();
+static jboolean StaticNonce_returnBoolean(JNIEnv *env, jclass clazz) {
+ return (jboolean) true;
+}
+
// public static native byte returnByte();
static jbyte StaticNonce_returnByte(JNIEnv *env, jclass clazz) {
return (jbyte) 123;
@@ -62,16 +69,35 @@
return 12345678.9;
}
+// public static native Object returnNull();
+static jobject StaticNonce_returnNull(JNIEnv *env, jclass clazz) {
+ return NULL;
+}
+
+// public static native String returnString();
+static jobject StaticNonce_returnString(JNIEnv *env, jclass clazz) {
+ return (*env)->NewStringUTF(env, "blort");
+}
+
+// public static native Class returnThisClass();
+static jclass StaticNonce_returnThisClass(JNIEnv *env, jclass clazz) {
+ return clazz;
+}
+
static JNINativeMethod methods[] = {
// name, signature, function
- { "nop", "()V", StaticNonce_nop },
- { "returnByte", "()B", StaticNonce_returnByte },
- { "returnShort", "()S", StaticNonce_returnShort },
- { "returnChar", "()C", StaticNonce_returnChar },
- { "returnInt", "()I", StaticNonce_returnInt },
- { "returnLong", "()J", StaticNonce_returnLong },
- { "returnFloat", "()F", StaticNonce_returnFloat },
- { "returnDouble", "()D", StaticNonce_returnDouble },
+ { "nop", "()V", StaticNonce_nop },
+ { "returnBoolean", "()Z", StaticNonce_returnBoolean },
+ { "returnByte", "()B", StaticNonce_returnByte },
+ { "returnShort", "()S", StaticNonce_returnShort },
+ { "returnChar", "()C", StaticNonce_returnChar },
+ { "returnInt", "()I", StaticNonce_returnInt },
+ { "returnLong", "()J", StaticNonce_returnLong },
+ { "returnFloat", "()F", StaticNonce_returnFloat },
+ { "returnDouble", "()D", StaticNonce_returnDouble },
+ { "returnNull", "()Ljava/lang/Object;", StaticNonce_returnNull },
+ { "returnString", "()Ljava/lang/String;", StaticNonce_returnString },
+ { "returnThisClass", "()Ljava/lang/Class;", StaticNonce_returnThisClass },
};
int register_StaticNonce(JNIEnv *env) {
diff --git a/tests/tests/jni/src/android/jni/cts/InstanceNonce.java b/tests/tests/jni/src/android/jni/cts/InstanceNonce.java
index 21e5524..63541df 100644
--- a/tests/tests/jni/src/android/jni/cts/InstanceNonce.java
+++ b/tests/tests/jni/src/android/jni/cts/InstanceNonce.java
@@ -35,6 +35,7 @@
// See JniInstanceTest for the expected behavior of these methods.
public native void nop();
+ public native boolean returnBoolean();
public native byte returnByte();
public native short returnShort();
public native char returnChar();
@@ -42,4 +43,7 @@
public native long returnLong();
public native float returnFloat();
public native double returnDouble();
+ public native Object returnNull();
+ public native String returnString();
+ public native InstanceNonce returnThis();
}
diff --git a/tests/tests/jni/src/android/jni/cts/JniInstanceTest.java b/tests/tests/jni/src/android/jni/cts/JniInstanceTest.java
index 4e00597..31986d7 100644
--- a/tests/tests/jni/src/android/jni/cts/JniInstanceTest.java
+++ b/tests/tests/jni/src/android/jni/cts/JniInstanceTest.java
@@ -42,6 +42,13 @@
/**
* Test a simple value-returning (but otherwise no-op) method call.
*/
+ public void test_returnBoolean() {
+ assertEquals(false, target.returnBoolean());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
public void test_returnByte() {
assertEquals(123, target.returnByte());
}
@@ -88,11 +95,31 @@
assertEquals(12345678.9, target.returnDouble());
}
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
+ public void test_returnNull() {
+ assertNull(target.returnNull());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
+ public void test_returnString() {
+ assertEquals("blort", target.returnString());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call,
+ * that returns the implicit {@code this} argument.
+ */
+ public void test_returnThis() {
+ assertSame(target, target.returnThis());
+ }
+
// TODO: Add more tests here. E.g:
- // call to method returning constant Object (null)
- // call to method returning constant String (non-null)
- // call to method returning "this"
// call to method taking "this", returning a "got expected" flag
+ // call to method taking boolean, returning a "got expected" flag
// call to method taking byte, returning a "got expected" flag
// call to method taking char, returning a "got expected" flag
// call to method taking short, returning a "got expected" flag
diff --git a/tests/tests/jni/src/android/jni/cts/JniStaticTest.java b/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
index 98332af..e5ccec2 100644
--- a/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
+++ b/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
@@ -34,6 +34,13 @@
/**
* Test a simple value-returning (but otherwise no-op) method call.
*/
+ public void test_returnBoolean() {
+ assertEquals(true, StaticNonce.returnBoolean());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
public void test_returnByte() {
assertEquals(123, StaticNonce.returnByte());
}
@@ -80,11 +87,32 @@
assertEquals(12345678.9, StaticNonce.returnDouble());
}
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
+ public void test_returnNull() {
+ assertNull(StaticNonce.returnNull());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call.
+ */
+ public void test_returnString() {
+ assertEquals("blort", StaticNonce.returnString());
+ }
+
+ /**
+ * Test a simple value-returning (but otherwise no-op) method call,
+ * that returns the class that the method is defined on.
+ */
+ public void test_returnThisClass() {
+ assertSame(StaticNonce.class, StaticNonce.returnThisClass());
+ }
+
// TODO: Add more tests here. E.g:
- // call to method returning constant Object (null)
- // call to method returning constant String (non-null)
// call to method that instantiates its class (based on received jclass)
// call to method taking "this class", returning a "got expected" flag
+ // call to method taking boolean, returning a "got expected" flag
// call to method taking byte, returning a "got expected" flag
// call to method taking char, returning a "got expected" flag
// call to method taking short, returning a "got expected" flag
diff --git a/tests/tests/jni/src/android/jni/cts/StaticNonce.java b/tests/tests/jni/src/android/jni/cts/StaticNonce.java
index 5ccb7ed..7aedb5d 100644
--- a/tests/tests/jni/src/android/jni/cts/StaticNonce.java
+++ b/tests/tests/jni/src/android/jni/cts/StaticNonce.java
@@ -28,6 +28,7 @@
// See JniStaticTest for the expected behavior of these methods.
public static native void nop();
+ public static native boolean returnBoolean();
public static native byte returnByte();
public static native short returnShort();
public static native char returnChar();
@@ -35,4 +36,7 @@
public static native long returnLong();
public static native float returnFloat();
public static native double returnDouble();
+ public static native Object returnNull();
+ public static native String returnString();
+ public static native Class returnThisClass();
}