Add very basic allocation copying test for C++.
Change-Id: I1426545958f66e8677dcda40a74f5736c616317b
diff --git a/tests/cppallocation/compute.cpp b/tests/cppallocation/compute.cpp
new file mode 100644
index 0000000..e770ab2
--- /dev/null
+++ b/tests/cppallocation/compute.cpp
@@ -0,0 +1,63 @@
+
+#include "RenderScript.h"
+
+#include "ScriptC_multiply.h"
+
+using namespace android;
+using namespace renderscriptCpp;
+
+int main(int argc, char** argv)
+{
+
+ uint32_t numElems = 1024;
+
+ if (argc >= 2) {
+ int tempNumElems = atoi(argv[1]);
+ if (tempNumElems < 1) {
+ printf("numElems must be greater than 0\n");
+ return 1;
+ }
+ numElems = (uint32_t) tempNumElems;
+ }
+
+ sp<RS> rs = new RS();
+
+ bool r = rs->init();
+
+ sp<const Element> e = Element::U32(rs);
+
+ Type::Builder tb(rs, e);
+ tb.setX(numElems);
+ sp<const Type> t = tb.create();
+
+ sp<Allocation> ain = Allocation::createTyped(rs, t);
+ sp<Allocation> aout = Allocation::createTyped(rs, t);
+
+ sp<ScriptC_multiply> sc = new ScriptC_multiply(rs, NULL, 0);
+
+ uint32_t* buf = new uint32_t[numElems];
+ for (uint32_t ct=0; ct < numElems; ct++) {
+ buf[ct] = (uint32_t)ct;
+ }
+
+ ain->copy1DRangeFromUnchecked(0, numElems, buf, numElems*sizeof(uint32_t));
+
+ sc->forEach_multiply(ain, aout);
+
+ aout->copy1DRangeToUnchecked(0, numElems, buf, numElems*sizeof(uint32_t));
+
+ for (uint32_t ct=0; ct < numElems; ct++) {
+ if (buf[ct] != ct * 2) {
+ printf("Mismatch at location %d: %u\n", ct, buf[ct]);
+ return 1;
+ }
+ }
+
+ printf("Test successful with %u elems!\n", numElems);
+
+ sc.clear();
+ t.clear();
+ e.clear();
+ ain.clear();
+ aout.clear();
+}