Add tests for C++ vector reflection in RenderScript.

Bug: 22098789

There is a bug in the original implementation of C++ reflection where
vector size is not emitted for any of the types. I have a separate
change to slang that properly allows the vector C++ reflected types to
be emitted.

I also replaced a LOGE with a LOGV, since it is a progress indicator,
and not a failure.

Change-Id: I4dfeee93e7f2547299ae0142f44a39d4efa5c1a4
(cherry picked from commit a03e24d38637e40352aa5b5c64acb3f7c6264736)
diff --git a/tests/tests/rscpp/librscpptest/Android.mk b/tests/tests/rscpp/librscpptest/Android.mk
index 65a5e2a..df8ce29f 100644
--- a/tests/tests/rscpp/librscpptest/Android.mk
+++ b/tests/tests/rscpp/librscpptest/Android.mk
@@ -38,7 +38,8 @@
     clear_object.rs \
     foreach.rs \
     fe_all.rs \
-    noroot.rs
+    noroot.rs \
+    vector.rs
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 LOCAL_C_INCLUDES += frameworks/rs/cpp
diff --git a/tests/tests/rscpp/librscpptest/rs_jni.cpp b/tests/tests/rscpp/librscpptest/rs_jni.cpp
index b362c99..4e60f4b 100644
--- a/tests/tests/rscpp/librscpptest/rs_jni.cpp
+++ b/tests/tests/rscpp/librscpptest/rs_jni.cpp
@@ -24,8 +24,7 @@
 #include <RenderScript.h>
 
 #define  LOG_TAG    "rscpptest"
-#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
-#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+#define  LOGV(...)  __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
 
 using namespace android::RSC;
 
@@ -72,7 +71,7 @@
     for (int i = 0; i < 1000; i++) {
         sp<RS> rs = new RS();
         r &= rs->init(path);
-        LOGE("Native iteration %i, returned %i", i, (int)r);
+        LOGV("Native iteration %i, returned %i", i, (int)r);
     }
     env->ReleaseStringUTFChars(pathObj, path);
     return r;
diff --git a/tests/tests/rscpp/librscpptest/rs_jni_script.cpp b/tests/tests/rscpp/librscpptest/rs_jni_script.cpp
index fd31112..1888341 100644
--- a/tests/tests/rscpp/librscpptest/rs_jni_script.cpp
+++ b/tests/tests/rscpp/librscpptest/rs_jni_script.cpp
@@ -29,6 +29,7 @@
 
 #include <ScriptC_primitives.h>
 #include <ScriptC_instance.h>
+#include <ScriptC_vector.h>
 
 using namespace android::RSC;
 
@@ -134,3 +135,50 @@
     return passed;
 }
 
+// Define some reasonable types for use with the vector invoke testing.
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+#define TEST_VECTOR_INVOKE(L, U) \
+L temp_##L = 0; \
+vector->invoke_vector_test_##L(temp_##L); \
+U##2 temp_##L##2; \
+vector->invoke_vector_test_##L##2(temp_##L##2); \
+U##3 temp_##L##3; \
+vector->invoke_vector_test_##L##3(temp_##L##3); \
+U##4 temp_##L##4; \
+vector->invoke_vector_test_##L##4(temp_##L##4);
+
+
+/*
+ * Test that vector invoke C++ reflection is working/present.
+ */
+extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSScriptTest_testVector(JNIEnv * env,
+                                                                                     jclass obj,
+                                                                                     jstring pathObj)
+{
+    const char * path = env->GetStringUTFChars(pathObj, nullptr);
+    sp<RS> mRS = new RS();
+    mRS->init(path);
+    env->ReleaseStringUTFChars(pathObj, path);
+    MessageHandlerFunc_t mHandler = rsMsgHandler;
+    mRS->setMessageHandler(mHandler);
+
+    bool passed = true;
+    sp<ScriptC_vector> vector = new ScriptC_vector(mRS);
+
+    TEST_VECTOR_INVOKE(float, Float)
+    TEST_VECTOR_INVOKE(double, Double)
+    TEST_VECTOR_INVOKE(char, Byte)
+    TEST_VECTOR_INVOKE(uchar, UByte)
+    TEST_VECTOR_INVOKE(short, Short)
+    TEST_VECTOR_INVOKE(ushort, UShort)
+    TEST_VECTOR_INVOKE(int, Int)
+    TEST_VECTOR_INVOKE(uint, UInt)
+    TEST_VECTOR_INVOKE(long, Long)
+    TEST_VECTOR_INVOKE(ulong, ULong)
+
+    return passed;
+}
diff --git a/tests/tests/rscpp/librscpptest/vector.rs b/tests/tests/rscpp/librscpptest/vector.rs
new file mode 100644
index 0000000..cdea9b8
--- /dev/null
+++ b/tests/tests/rscpp/librscpptest/vector.rs
@@ -0,0 +1,19 @@
+#include "shared.rsh"
+
+#define MAKE_TEST(T) \
+void vector_test_##T(T t) {} \
+void vector_test_##T##2(T##2 t) {} \
+void vector_test_##T##3(T##3 t) {} \
+void vector_test_##T##4(T##4 t) {} \
+
+MAKE_TEST(float)
+MAKE_TEST(double)
+MAKE_TEST(char)
+MAKE_TEST(uchar)
+MAKE_TEST(short)
+MAKE_TEST(ushort)
+MAKE_TEST(int)
+MAKE_TEST(uint)
+MAKE_TEST(long)
+MAKE_TEST(ulong)
+
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSScriptTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSScriptTest.java
index 72f4a17..fe45b33 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSScriptTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSScriptTest.java
@@ -36,4 +36,9 @@
     public void testRSScriptTestInstance() {
         assertTrue(testInstance(this.getContext().getCacheDir().toString()));
     }
+
+    native boolean testVector(String path);
+    public void testRSScriptTestVector() {
+        assertTrue(testVector(this.getContext().getCacheDir().toString()));
+    }
 }