Expand the multifaceted boolean method test to cover the other variants.
This is a template for how the other return types can be handled.

I'm not sure if it's really worth it to turn this whole enchilada into
yet another layer of macro, or if this is the point where it should just
be copy-pasted eight times. Neither choice is particulary savory.

Change-Id: Idcff2392a5e3c4baadd8c1ede4edef6b90a535f9
diff --git a/tests/tests/jni/libjnitest/helper.c b/tests/tests/jni/libjnitest/helper.c
index 0a8c69a..f974a59 100644
--- a/tests/tests/jni/libjnitest/helper.c
+++ b/tests/tests/jni/libjnitest/helper.c
@@ -21,13 +21,15 @@
 #include <stdarg.h>
 #include <stdlib.h>
 
+#define LOG_TAG "cts"
+
 /* See helper.h for docs. */
 char *failure(const char *format, ...) {
     va_list args;
     char *result;
 
     va_start(args, format);
-    LOG_PRI_VA(ANDROID_LOG_ERROR, "cts", format, args);
+    LOG_PRI_VA(ANDROID_LOG_ERROR, LOG_TAG, format, args);
     va_end(args);
 
     va_start(args, format);
@@ -56,6 +58,8 @@
 
         JniTestFunction *function = va_arg(args, JniTestFunction *);
 
+        LOGI("running %s", name);
+
         char *oneResult = function(env);
         if (oneResult != NULL) {
             char *newResult;
diff --git a/tests/tests/jni/libjnitest/macroized_tests.c b/tests/tests/jni/libjnitest/macroized_tests.c
index d45ce14..8401b6d 100644
--- a/tests/tests/jni/libjnitest/macroized_tests.c
+++ b/tests/tests/jni/libjnitest/macroized_tests.c
@@ -42,8 +42,14 @@
 /** reference to field {@code InstanceFromNative.theOne} */
 static jfieldID InstanceFromNative_theOne;
 
-/** how to call a method: standard, array of args, or with a va_list */
-typedef enum { CALL_PLAIN, CALL_ARRAY, CALL_VA } callType;
+/**
+ * how to call a method: (virtual, direct, static) x (standard, array of
+ * args, va_list) */
+typedef enum {
+    VIRTUAL_PLAIN, VIRTUAL_ARRAY, VIRTUAL_VA,
+    DIRECT_PLAIN, DIRECT_ARRAY, DIRECT_VA,
+    STATIC_PLAIN, STATIC_ARRAY, STATIC_VA,
+} callType;
 
 /*
  * CALL() calls the JNI function with the given name, using a JNIEnv
@@ -142,6 +148,20 @@
     return result;
 }
 
+/**
+ * Looks up either an instance method on InstanceFromNative or a
+ * static method on StaticFromNative, depending on the given
+ * call type.
+ */
+static jmethodID findAppropriateMethod(JNIEnv *env, char **errorMsg,
+        callType ct, const char *name, const char *sig) {
+    if ((ct == STATIC_PLAIN) || (ct == STATIC_ARRAY) ||
+            (ct == STATIC_VA)) {
+        return findStaticMethod(env, errorMsg, name, sig);
+    } else {
+        return findInstanceMethod(env, errorMsg, name, sig);
+    }
+}
 
 
 /*
@@ -152,9 +172,13 @@
 //   AllocObject
 
 static char *help_CallBooleanMethod(JNIEnv *env, callType ct, ...) {
+    va_list args;
+    va_start(args, ct);
+
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findInstanceMethod(env, &msg, "returnBoolean", "()Z");
+    jmethodID method = findAppropriateMethod(env, &msg, ct,
+            "returnBoolean", "()Z");
 
     if (method == NULL) {
         return msg;
@@ -163,19 +187,45 @@
     jboolean result;
 
     switch (ct) {
-        case CALL_PLAIN: {
+        case VIRTUAL_PLAIN: {
             result = CALL(CallBooleanMethod, o, method);
             break;
         }
-        case CALL_ARRAY: {
+        case VIRTUAL_ARRAY: {
             result = CALL(CallBooleanMethodA, o, method, NULL);
             break;
         }
-        case CALL_VA: {
-            va_list args;
-            va_start(args, ct);
+        case VIRTUAL_VA: {
             result = CALL(CallBooleanMethodV, o, method, args);
-            va_end(args);
+            break;
+        }
+        case DIRECT_PLAIN: {
+            result = CALL(CallNonvirtualBooleanMethod, o, InstanceFromNative,
+                    method);
+            break;
+        }
+        case DIRECT_ARRAY: {
+            result = CALL(CallNonvirtualBooleanMethodA, o, InstanceFromNative,
+                    method, NULL);
+            break;
+        }
+        case DIRECT_VA: {
+            result = CALL(CallNonvirtualBooleanMethodV, o, InstanceFromNative,
+                    method, args);
+            break;
+        }
+        case STATIC_PLAIN: {
+            result = CALL(CallStaticBooleanMethod, StaticFromNative, method);
+            break;
+        }
+        case STATIC_ARRAY: {
+            result = CALL(CallStaticBooleanMethodA, StaticFromNative, method,
+                    NULL);
+            break;
+        }
+        case STATIC_VA: {
+            result = CALL(CallStaticBooleanMethodV, StaticFromNative, method,
+                    args);
             break;
         }
         default: {
@@ -183,19 +233,45 @@
         }
     }
     
+    va_end(args);
+
     return FAIL_IF_UNEQUAL("%d", true, result);
 }
 
 TEST_DECLARATION(CallBooleanMethod) {
-    return help_CallBooleanMethod(env, CALL_PLAIN);
+    return help_CallBooleanMethod(env, VIRTUAL_PLAIN);
 }
 
 TEST_DECLARATION(CallBooleanMethodA) {
-    return help_CallBooleanMethod(env, CALL_ARRAY);
+    return help_CallBooleanMethod(env, VIRTUAL_ARRAY);
 }
 
 TEST_DECLARATION(CallBooleanMethodV) {
-    return help_CallBooleanMethod(env, CALL_VA);
+    return help_CallBooleanMethod(env, VIRTUAL_VA);
+}
+
+TEST_DECLARATION(CallNonvirtualBooleanMethod) {
+    return help_CallBooleanMethod(env, DIRECT_PLAIN);
+}
+
+TEST_DECLARATION(CallNonvirtualBooleanMethodA) {
+    return help_CallBooleanMethod(env, DIRECT_ARRAY);
+}
+
+TEST_DECLARATION(CallNonvirtualBooleanMethodV) {
+    return help_CallBooleanMethod(env, DIRECT_VA);
+}
+
+TEST_DECLARATION(CallStaticBooleanMethod) {
+    return help_CallBooleanMethod(env, STATIC_PLAIN);
+}
+
+TEST_DECLARATION(CallStaticBooleanMethodA) {
+    return help_CallBooleanMethod(env, STATIC_ARRAY);
+}
+
+TEST_DECLARATION(CallStaticBooleanMethodV) {
+    return help_CallBooleanMethod(env, STATIC_VA);
 }
 
 // TODO: Missing functions:
@@ -217,9 +293,6 @@
 //   CallLongMethod
 //   CallLongMethodA
 //   CallLongMethodV
-//   CallNonvirtualBooleanMethod
-//   CallNonvirtualBooleanMethodA
-//   CallNonvirtualBooleanMethodV
 //   CallNonvirtualByteMethod
 //   CallNonvirtualByteMethodA
 //   CallNonvirtualByteMethodV
@@ -253,9 +326,6 @@
 //   CallShortMethod
 //   CallShortMethodA
 //   CallShortMethodV
-//   CallStaticBooleanMethod (no args)
-//   CallStaticBooleanMethodA (no args)
-//   CallStaticBooleanMethodV (no args)
 //   CallStaticBooleanMethod (interesting args)
 //   CallStaticBooleanMethodA (interesting args)
 //   CallStaticBooleanMethodV (interesting args)
@@ -470,6 +540,12 @@
                 RUN_TEST(CallBooleanMethod),
                 RUN_TEST(CallBooleanMethodA),
                 RUN_TEST(CallBooleanMethodV),
+                RUN_TEST(CallNonvirtualBooleanMethod),
+                RUN_TEST(CallNonvirtualBooleanMethodA),
+                RUN_TEST(CallNonvirtualBooleanMethodV),
+                RUN_TEST(CallStaticBooleanMethod),
+                RUN_TEST(CallStaticBooleanMethodA),
+                RUN_TEST(CallStaticBooleanMethodV),
                 RUN_TEST(DefineClass),
                 RUN_TEST(GetVersion),
                 NULL);