am 4a66ef4a: Merge "CTS Tests" into honeycomb-mr1
* commit '4a66ef4ace3d9518b519cd5a44b0ce6e6d116930':
CTS Tests
diff --git a/tests/assets/sphere.a3d b/tests/assets/sphere.a3d
new file mode 100644
index 0000000..3d78b01
--- /dev/null
+++ b/tests/assets/sphere.a3d
Binary files differ
diff --git a/tests/res/raw/samplefont.ttf b/tests/res/raw/samplefont.ttf
new file mode 100644
index 0000000..49f1c62
--- /dev/null
+++ b/tests/res/raw/samplefont.ttf
Binary files differ
diff --git a/tests/res/raw/sphere.a3d b/tests/res/raw/sphere.a3d
new file mode 100644
index 0000000..3d78b01
--- /dev/null
+++ b/tests/res/raw/sphere.a3d
Binary files differ
diff --git a/tests/src/android/renderscript/cts/graphics_runner.rs b/tests/src/android/renderscript/cts/graphics_runner.rs
new file mode 100644
index 0000000..b8ec15f
--- /dev/null
+++ b/tests/src/android/renderscript/cts/graphics_runner.rs
@@ -0,0 +1,45 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "shared.rsh"
+#include "rs_graphics.rsh"
+
+#include "structs.rsh"
+
+static void drawQuad() {
+ float startX = 0, startY = 0;
+ float width = 4, height = 4;
+ rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
+ startX, startY + height, 0, 0, 1,
+ startX + width, startY + height, 0, 1, 1,
+ startX + width, startY, 0, 1, 0);
+}
+
+void testProgramVertex(rs_program_vertex pv) {
+ rsDebug("Set Program Vertex, drew quad", 0);
+ rsgBindProgramVertex(pv);
+ drawQuad();
+}
+
+void testProgramFragment(rs_program_fragment pf) {
+ rsDebug("Set Program Fragment, drew quad", 0);
+ rsgBindProgramFragment(pf);
+ drawQuad();
+}
+
+// Just draw a quad with previously setup state
+int root(int launchID) {
+ rsDebug("Running script", 0);
+ return 0;
+}
diff --git a/tests/src/android/renderscript/cts/primitives.rs b/tests/src/android/renderscript/cts/primitives.rs
index d2ffd26..55710cd 100644
--- a/tests/src/android/renderscript/cts/primitives.rs
+++ b/tests/src/android/renderscript/cts/primitives.rs
@@ -1,4 +1,5 @@
#include "shared.rsh"
+#include "structs.rsh"
// Testing primitive types
float floatTest = 1.99f;
@@ -47,9 +48,65 @@
return failed;
}
+static bool test_vector_types() {
+ bool failed = false;
+ start();
+ _RS_ASSERT(avt->b2.x == 1);
+ _RS_ASSERT(avt->b2.y == 2);
+ _RS_ASSERT(avt->b3.x == 1);
+ _RS_ASSERT(avt->b3.y == 2);
+ _RS_ASSERT(avt->b3.z == 3);
+ _RS_ASSERT(avt->b4.x == 1);
+ _RS_ASSERT(avt->b4.y == 2);
+ _RS_ASSERT(avt->b4.z == 3);
+ _RS_ASSERT(avt->b4.w == 4);
+
+ _RS_ASSERT(avt->s2.x == 1);
+ _RS_ASSERT(avt->s2.y == 2);
+ _RS_ASSERT(avt->s3.x == 1);
+ _RS_ASSERT(avt->s3.y == 2);
+ _RS_ASSERT(avt->s3.z == 3);
+ _RS_ASSERT(avt->s4.x == 1);
+ _RS_ASSERT(avt->s4.y == 2);
+ _RS_ASSERT(avt->s4.z == 3);
+ _RS_ASSERT(avt->s4.w == 4);
+
+ _RS_ASSERT(avt->i2.x == 1);
+ _RS_ASSERT(avt->i2.y == 2);
+ _RS_ASSERT(avt->i3.x == 1);
+ _RS_ASSERT(avt->i3.y == 2);
+ _RS_ASSERT(avt->i3.z == 3);
+ _RS_ASSERT(avt->i4.x == 1);
+ _RS_ASSERT(avt->i4.y == 2);
+ _RS_ASSERT(avt->i4.z == 3);
+ _RS_ASSERT(avt->i4.w == 4);
+
+ _RS_ASSERT(avt->f2.x == 1.0f);
+ _RS_ASSERT(avt->f2.y == 2.0f);
+ _RS_ASSERT(avt->f3.x == 1.0f);
+ _RS_ASSERT(avt->f3.y == 2.0f);
+ _RS_ASSERT(avt->f3.z == 3.0f);
+ _RS_ASSERT(avt->f4.x == 1.0f);
+ _RS_ASSERT(avt->f4.y == 2.0f);
+ _RS_ASSERT(avt->f4.z == 3.0f);
+ _RS_ASSERT(avt->f4.w == 4.0f);
+
+ float time = end();
+
+ if (failed) {
+ rsDebug("test_vector_types FAILED", time);
+ }
+ else {
+ rsDebug("test_vector_types PASSED", time);
+ }
+
+ return failed;
+}
+
void test() {
bool failed = false;
failed |= test_primitive_types();
+ failed |= test_vector_types();
if (failed) {
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
diff --git a/tests/src/android/renderscript/cts/structs.rsh b/tests/src/android/renderscript/cts/structs.rsh
new file mode 100755
index 0000000..58f6186
--- /dev/null
+++ b/tests/src/android/renderscript/cts/structs.rsh
@@ -0,0 +1,56 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+typedef struct ConstMatrix {
+ rs_matrix4x4 MVP;
+} ConstMatrix_s;
+ConstMatrix_s *c1;
+
+typedef struct ConstComplex {
+ rs_matrix4x4 MVP;
+ rs_matrix4x4 EXTRA;
+ float extra1;
+ float2 extra2;
+ float3 extra3;
+ float4 extra4;
+} ConstComplex_s;
+ConstComplex_s *c2;
+
+typedef struct ConstExtra {
+ rs_matrix4x4 EXTRA;
+ float extra1;
+ float2 extra2;
+ float3 extra3;
+ float4 extra4;
+} ConstExtra_s;
+ConstExtra_s *c3;
+
+typedef struct AllVectorTypes {
+ char2 b2;
+ char3 b3;
+ char4 b4;
+
+ short2 s2;
+ short3 s3;
+ short4 s4;
+
+ int2 i2;
+ int3 i3;
+ int4 i4;
+
+ float2 f2;
+ float3 f3;
+ float4 f4;
+} AllVectorTypes_s;
+AllVectorTypes_s *avt;
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
index 0f77369..b6afb70 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
@@ -18,11 +18,15 @@
import com.android.cts.stub.R;
+import android.graphics.Bitmap;
import android.renderscript.Allocation;
+import android.renderscript.AllocationAdapter;
import android.renderscript.Allocation.MipmapControl;
import android.renderscript.Element;
+import android.renderscript.RSIllegalArgumentException;
import android.renderscript.Type;
import android.renderscript.Type.Builder;
+import android.renderscript.Type.CubemapFace;
public class AllocationTest extends RSBaseGraphics {
@@ -100,7 +104,9 @@
void createSizedHelper(Element e) {
for (int i = 1; i <= 8; i ++) {
- Allocation.createSized(mRS, e, i);
+ Allocation A = Allocation.createSized(mRS, e, i);
+ assertEquals(A.getType().getElement(), e);
+ assertEquals(A.getType().getX(), i);
}
}
@@ -176,6 +182,236 @@
createSizedHelper(Element.SCRIPT(mRS));
createSizedHelper(Element.TYPE(mRS));
}
+
+ static int bDimX = 48;
+ static int bDimY = 8;
+
+ void helperCreateFromBitmap(Bitmap B,
+ Allocation.MipmapControl mc) {
+ for (int i = 0; i < 1; i++) {
+ for (int j = 0; j < 1; j++) {
+ for (int k = 0; k < 1; k++) {
+ for (int l = 0; l < 1; l++) {
+ int u = 0;
+ u |= (i * Allocation.USAGE_SCRIPT);
+ u |= (j * Allocation.USAGE_GRAPHICS_TEXTURE);
+ u |= (k * Allocation.USAGE_GRAPHICS_VERTEX);
+ u |= (l * Allocation.USAGE_GRAPHICS_CONSTANTS);
+ assertTrue(null !=
+ Allocation.createFromBitmap(mRS, B, mc, u));
+ assertTrue(null !=
+ Allocation.createCubemapFromBitmap(mRS, B, mc, u));
+ }
+ }
+ }
+ }
+ }
+
+ public void testCreateFromBitmap() {
+ Bitmap B = Bitmap.createBitmap(bDimX, bDimY, Bitmap.Config.ARGB_8888);
+ Allocation.createFromBitmap(mRS, B);
+ Allocation.createCubemapFromBitmap(mRS, B);
+ for (Allocation.MipmapControl mc : Allocation.MipmapControl.values()) {
+ helperCreateFromBitmap(B, mc);
+ }
+
+ try {
+ int invalidUsage = 0x0010;
+ Allocation.createFromBitmap(mRS, B,
+ Allocation.MipmapControl.MIPMAP_NONE, invalidUsage);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+
+ try {
+ // width % 6 != 0
+ Bitmap badB = Bitmap.createBitmap(47, 8, Bitmap.Config.ARGB_8888);
+ Allocation.createCubemapFromBitmap(mRS, badB,
+ Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+
+ try {
+ // width / 6 != height
+ Bitmap badB = Bitmap.createBitmap(48, 4, Bitmap.Config.ARGB_8888);
+ Allocation.createCubemapFromBitmap(mRS, badB,
+ Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+
+ try {
+ // height not power of 2
+ Bitmap badB = Bitmap.createBitmap(36, 6, Bitmap.Config.ARGB_8888);
+ Allocation.createCubemapFromBitmap(mRS, badB,
+ Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ }
+
+ public void testAllocationMipmapControl() {
+ assertEquals(MipmapControl.MIPMAP_NONE,
+ MipmapControl.valueOf("MIPMAP_NONE"));
+ assertEquals(MipmapControl.MIPMAP_FULL,
+ MipmapControl.valueOf("MIPMAP_FULL"));
+ assertEquals(MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+ MipmapControl.valueOf("MIPMAP_ON_SYNC_TO_TEXTURE"));
+ // Make sure no new enums are added
+ assertEquals(3, Allocation.MipmapControl.values().length);
+
+ for (Allocation.MipmapControl mc : Allocation.MipmapControl.values()) {
+ Type.Builder b = new Type.Builder(mRS, Element.U8(mRS));
+ b.setX(8).setY(8);
+ Allocation.createTyped(mRS, b.create(), mc,
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+ }
+ }
+
+ public void testCubemapFaces() {
+ Type.Builder b = new Type.Builder(mRS, Element.U8(mRS));
+ b.setX(8).setY(8).setFaces(true);
+ Allocation cubemap = Allocation.createTyped(mRS, b.create(),
+ MipmapControl.MIPMAP_NONE,
+ Allocation.USAGE_SCRIPT);
+ AllocationAdapter adapter = AllocationAdapter.create2D(mRS, cubemap);
+ for (Type.CubemapFace cf : Type.CubemapFace.values()) {
+ adapter.setFace(cf);
+ }
+ }
+
+ /*
+ * Test all copy from/to routines for byte/short/int/float
+ */
+
+ void helperFloatCopy(int nElems) {
+ Allocation A = Allocation.createSized(mRS, Element.F32(mRS), nElems);
+
+ float src[], dst[];
+ src = new float[nElems];
+ dst = new float[nElems];
+ for (int i = 0; i < nElems; i++) {
+ src[i] = (float)i;
+ dst[i] = -1.0f;
+ }
+
+ A.copyFrom(src);
+ A.copyTo(dst);
+
+ for (int i = 0; i < nElems; i++) {
+ assertEquals(dst[i], src[i]);
+ }
+ }
+
+ void helperByteCopy(int nElems) {
+ Allocation A = Allocation.createSized(mRS, Element.I8(mRS), nElems);
+
+ byte src[], dst[];
+ src = new byte[nElems];
+ dst = new byte[nElems];
+ for (int i = 0; i < nElems; i++) {
+ src[i] = (byte)i;
+ dst[i] = -1;
+ }
+
+ A.copyFrom(src);
+ A.copyTo(dst);
+
+ for (int i = 0; i < nElems; i++) {
+ assertEquals(dst[i], src[i]);
+ }
+ }
+
+ void helperShortCopy(int nElems) {
+ Allocation A = Allocation.createSized(mRS, Element.I16(mRS), nElems);
+
+ short src[], dst[];
+ src = new short[nElems];
+ dst = new short[nElems];
+ for (int i = 0; i < nElems; i++) {
+ src[i] = (short)i;
+ dst[i] = -1;
+ }
+
+ A.copyFrom(src);
+ A.copyTo(dst);
+
+ for (int i = 0; i < nElems; i++) {
+ assertEquals(dst[i], src[i]);
+ }
+ }
+
+ void helperIntCopy(int nElems) {
+ Allocation A = Allocation.createSized(mRS, Element.I32(mRS), nElems);
+
+ int src[], dst[];
+ src = new int[nElems];
+ dst = new int[nElems];
+ for (int i = 0; i < nElems; i++) {
+ src[i] = i;
+ dst[i] = -1;
+ }
+
+ A.copyFrom(src);
+ A.copyTo(dst);
+
+ for (int i = 0; i < nElems; i++) {
+ assertEquals(dst[i], src[i]);
+ }
+ }
+
+ void helperBaseObjCopy(int nElems) {
+ Allocation A =
+ Allocation.createSized(mRS, Element.ELEMENT(mRS), nElems);
+ Element E[] = new Element[nElems];
+ for (int i = 0; i < nElems; i++) {
+ E[i] = Element.BOOLEAN(mRS);
+ }
+
+ A.copyFrom(E);
+ }
+
+ void helperBitmapCopy(int x, int y) {
+ Bitmap bSrc = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
+ Bitmap bDst = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
+
+ for (int j = 0; j < y; j++) {
+ for (int i = 0; i < x; i++) {
+ bSrc.setPixel(i, j, 9);
+ bDst.setPixel(i, j, 0);
+ }
+ }
+
+ Type.Builder typeBuilder =
+ new Type.Builder(mRS, Element.RGBA_8888(mRS));
+ typeBuilder.setMipmaps(false);
+ typeBuilder.setFaces(false);
+ typeBuilder.setX(x).setY(y);
+ Allocation A = Allocation.createTyped(mRS, typeBuilder.create());
+
+ A.copyFrom(bSrc);
+ A.copyTo(bDst);
+
+ for (int j = 0; j < y; j++) {
+ for (int i = 0; i < x; i++) {
+ assertEquals(bSrc.getPixel(i, j), bDst.getPixel(i, j));
+ }
+ }
+ }
+
+ static int elemsToTest = 20;
+
+ public void testCopyOperations() {
+ for (int s = 8; s <= elemsToTest; s += 2) {
+ helperFloatCopy(s);
+ helperByteCopy(s);
+ helperShortCopy(s);
+ helperIntCopy(s);
+ helperBaseObjCopy(s);
+ }
+ helperBitmapCopy(bDimX, bDimY);
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java
index a5c4f16..8d24227 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java
@@ -16,15 +16,111 @@
package android.renderscript.cts;
-import android.content.Context;
-import android.content.res.Resources;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.test.AndroidTestCase;
+import android.renderscript.Allocation;
+
+import android.renderscript.Byte2;
+import android.renderscript.Byte3;
+import android.renderscript.Byte4;
+
+import android.renderscript.Float2;
+import android.renderscript.Float3;
+import android.renderscript.Float4;
+
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.Int4;
+
+import android.renderscript.Long2;
+import android.renderscript.Long3;
+import android.renderscript.Long4;
+
+import android.renderscript.Short2;
+import android.renderscript.Short3;
+import android.renderscript.Short4;
+
import com.android.cts.stub.R;
public class ComputeTest extends RSBaseCompute {
+ public void testJavaVectorTypes() {
+ Byte2 b2 = new Byte2();
+ b2.x = 1;
+ b2.y = 2;
+ Byte3 b3 = new Byte3();
+ b3.x = 1;
+ b3.y = 2;
+ b3.z = 2;
+ Byte4 b4 = new Byte4();
+ b4.x = 1;
+ b4.y = 2;
+ b4.x = 3;
+ b4.w = 4;
+
+ Float2 f2 = new Float2();
+ f2.x = 1.0f;
+ f2.y = 2.0f;
+ f2 = new Float2(1.0f, 2.0f);
+ assertTrue(f2.x == 1.0f);
+ assertTrue(f2.y == 2.0f);
+ Float3 f3 = new Float3();
+ f3.x = 1.0f;
+ f3.y = 2.0f;
+ f3.z = 3.0f;
+ f3 = new Float3(1.0f, 2.0f, 3.0f);
+ assertTrue(f3.x == 1.0f);
+ assertTrue(f3.y == 2.0f);
+ assertTrue(f3.z == 3.0f);
+ Float4 f4 = new Float4();
+ f4.x = 1.0f;
+ f4.y = 2.0f;
+ f4.x = 3.0f;
+ f4.w = 4.0f;
+ f4 = new Float4(1.0f, 2.0f, 3.0f, 4.0f);
+ assertTrue(f4.x == 1.0f);
+ assertTrue(f4.y == 2.0f);
+ assertTrue(f4.z == 3.0f);
+ assertTrue(f4.w == 4.0f);
+
+ Int2 i2 = new Int2();
+ i2.x = 1;
+ i2.y = 2;
+ Int3 i3 = new Int3();
+ i3.x = 1;
+ i3.y = 2;
+ i3.z = 3;
+ Int4 i4 = new Int4();
+ i4.x = 1;
+ i4.y = 2;
+ i4.x = 3;
+ i4.w = 4;
+
+ Long2 l2 = new Long2();
+ l2.x = 1;
+ l2.y = 2;
+ Long3 l3 = new Long3();
+ l3.x = 1;
+ l3.y = 2;
+ l3.z = 3;
+ Long4 l4 = new Long4();
+ l4.x = 1;
+ l4.y = 2;
+ l4.x = 3;
+ l4.w = 4;
+
+ Short2 s2 = new Short2();
+ s2.x = 1;
+ s2.y = 2;
+ Short3 s3 = new Short3();
+ s3.x = 1;
+ s3.y = 2;
+ s3.z = 3;
+ Short4 s4 = new Short4();
+ s4.x = 1;
+ s4.y = 2;
+ s4.x = 3;
+ s4.w = 4;
+ }
+
private boolean initializeGlobals(ScriptC_primitives s) {
float pF = s.get_floatTest();
if (pF != 1.99f) {
@@ -68,7 +164,6 @@
}
s.set_ulongTest(4611686018427387903L);
-
long pLL = s.get_longlongTest();
if (pLL != 68719476736L) {
return false;
@@ -81,6 +176,54 @@
}
s.set_uint64_tTest(117179869185l);
+ ScriptField_AllVectorTypes avt;
+ avt = new ScriptField_AllVectorTypes(mRS, 1,
+ Allocation.USAGE_SCRIPT);
+ ScriptField_AllVectorTypes.Item avtItem;
+ avtItem = new ScriptField_AllVectorTypes.Item();
+ avtItem.b2.x = 1;
+ avtItem.b2.y = 2;
+ avtItem.b3.x = 1;
+ avtItem.b3.y = 2;
+ avtItem.b3.z = 3;
+ avtItem.b4.x = 1;
+ avtItem.b4.y = 2;
+ avtItem.b4.z = 3;
+ avtItem.b4.w = 4;
+
+ avtItem.s2.x = 1;
+ avtItem.s2.y = 2;
+ avtItem.s3.x = 1;
+ avtItem.s3.y = 2;
+ avtItem.s3.z = 3;
+ avtItem.s4.x = 1;
+ avtItem.s4.y = 2;
+ avtItem.s4.z = 3;
+ avtItem.s4.w = 4;
+
+ avtItem.i2.x = 1;
+ avtItem.i2.y = 2;
+ avtItem.i3.x = 1;
+ avtItem.i3.y = 2;
+ avtItem.i3.z = 3;
+ avtItem.i4.x = 1;
+ avtItem.i4.y = 2;
+ avtItem.i4.z = 3;
+ avtItem.i4.w = 4;
+
+ avtItem.f2.x = 1.0f;
+ avtItem.f2.y = 2.0f;
+ avtItem.f3.x = 1.0f;
+ avtItem.f3.y = 2.0f;
+ avtItem.f3.z = 3.0f;
+ avtItem.f4.x = 1.0f;
+ avtItem.f4.y = 2.0f;
+ avtItem.f4.z = 3.0f;
+ avtItem.f4.w = 4.0f;
+
+ avt.set(avtItem, 0, true);
+ s.bind_avt(avt);
+
return true;
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java
index 55572a3..7723c20 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java
@@ -16,8 +16,6 @@
package android.renderscript.cts;
-import com.android.cts.stub.R;
-
import android.renderscript.Element;
import android.renderscript.Element.DataType;
import android.renderscript.Element.DataKind;
@@ -86,6 +84,7 @@
assertTrue(Element.MATRIX_2X2(mRS) != null);
assertTrue(Element.MATRIX_3X3(mRS) != null);
assertTrue(Element.MATRIX_4X4(mRS) != null);
+ assertTrue(Element.MATRIX4X4(mRS) != null);
assertTrue(Element.MESH(mRS) != null);
assertTrue(Element.PROGRAM_FRAGMENT(mRS) != null);
assertTrue(Element.PROGRAM_RASTER(mRS) != null);
@@ -126,6 +125,7 @@
eb.add(Element.MATRIX_2X2(mRS), "MATRIX_2X2", arraySize);
eb.add(Element.MATRIX_3X3(mRS), "MATRIX_3X3", arraySize);
eb.add(Element.MATRIX_4X4(mRS), "MATRIX_4X4", arraySize);
+ eb.add(Element.MATRIX4X4(mRS), "MATRIX4X4", arraySize);
eb.add(Element.MESH(mRS), "MESH", arraySize);
eb.add(Element.PROGRAM_FRAGMENT(mRS), "PROGRAM_FRAGMENT", arraySize);
eb.add(Element.PROGRAM_RASTER(mRS), "PROGRAM_RASTER", arraySize);
@@ -165,6 +165,7 @@
assertFalse(Element.MATRIX_2X2(mRS).isComplex());
assertFalse(Element.MATRIX_3X3(mRS).isComplex());
assertFalse(Element.MATRIX_4X4(mRS).isComplex());
+ assertFalse(Element.MATRIX4X4(mRS).isComplex());
assertFalse(Element.MESH(mRS).isComplex());
assertFalse(Element.PROGRAM_FRAGMENT(mRS).isComplex());
assertFalse(Element.PROGRAM_RASTER(mRS).isComplex());
@@ -194,6 +195,64 @@
eb.add(e2, "e2");
assertTrue(eb.create().isComplex());
}
+
+ public void testDataType() {
+ assertEquals(DataType.FLOAT_32, DataType.valueOf("FLOAT_32"));
+ assertEquals(DataType.FLOAT_64, DataType.valueOf("FLOAT_64"));
+ assertEquals(DataType.SIGNED_8, DataType.valueOf("SIGNED_8"));
+ assertEquals(DataType.SIGNED_16, DataType.valueOf("SIGNED_16"));
+ assertEquals(DataType.SIGNED_32, DataType.valueOf("SIGNED_32"));
+ assertEquals(DataType.SIGNED_64, DataType.valueOf("SIGNED_64"));
+ assertEquals(DataType.UNSIGNED_8, DataType.valueOf("UNSIGNED_8"));
+ assertEquals(DataType.UNSIGNED_16, DataType.valueOf("UNSIGNED_16"));
+ assertEquals(DataType.UNSIGNED_32, DataType.valueOf("UNSIGNED_32"));
+ assertEquals(DataType.UNSIGNED_64, DataType.valueOf("UNSIGNED_64"));
+
+ assertEquals(DataType.BOOLEAN, DataType.valueOf("BOOLEAN"));
+
+ assertEquals(DataType.UNSIGNED_5_6_5, DataType.valueOf("UNSIGNED_5_6_5"));
+ assertEquals(DataType.UNSIGNED_5_5_5_1, DataType.valueOf("UNSIGNED_5_5_5_1"));
+ assertEquals(DataType.UNSIGNED_4_4_4_4, DataType.valueOf("UNSIGNED_4_4_4_4"));
+
+ assertEquals(DataType.MATRIX_4X4, DataType.valueOf("MATRIX_4X4"));
+ assertEquals(DataType.MATRIX_3X3, DataType.valueOf("MATRIX_3X3"));
+ assertEquals(DataType.MATRIX_2X2, DataType.valueOf("MATRIX_2X2"));
+
+ assertEquals(DataType.RS_ELEMENT, DataType.valueOf("RS_ELEMENT"));
+ assertEquals(DataType.RS_TYPE, DataType.valueOf("RS_TYPE"));
+ assertEquals(DataType.RS_ALLOCATION, DataType.valueOf("RS_ALLOCATION"));
+ assertEquals(DataType.RS_SAMPLER, DataType.valueOf("RS_SAMPLER"));
+ assertEquals(DataType.RS_SCRIPT, DataType.valueOf("RS_SCRIPT"));
+ assertEquals(DataType.RS_MESH, DataType.valueOf("RS_MESH"));
+ assertEquals(DataType.RS_PROGRAM_FRAGMENT, DataType.valueOf("RS_PROGRAM_FRAGMENT"));
+ assertEquals(DataType.RS_PROGRAM_VERTEX, DataType.valueOf("RS_PROGRAM_VERTEX"));
+ assertEquals(DataType.RS_PROGRAM_RASTER, DataType.valueOf("RS_PROGRAM_RASTER"));
+ assertEquals(DataType.RS_PROGRAM_STORE, DataType.valueOf("RS_PROGRAM_STORE"));
+ // Make sure no new enums are added
+ assertEquals(27, DataType.values().length);
+
+ for (DataType dt : DataType.values()) {
+ Element.createVector(mRS, dt, 2);
+ }
+ }
+
+ public void testDataKind() {
+ assertEquals(DataKind.USER, DataKind.valueOf("USER"));
+
+ assertEquals(DataKind.PIXEL_L, DataKind.valueOf("PIXEL_L"));
+ assertEquals(DataKind.PIXEL_A, DataKind.valueOf("PIXEL_A"));
+ assertEquals(DataKind.PIXEL_LA, DataKind.valueOf("PIXEL_LA"));
+ assertEquals(DataKind.PIXEL_RGB, DataKind.valueOf("PIXEL_RGB"));
+ assertEquals(DataKind.PIXEL_RGBA, DataKind.valueOf("PIXEL_RGBA"));
+ // Make sure no new enums are added
+ assertEquals(6, DataKind.values().length);
+
+ for (DataKind dk : DataKind.values()) {
+ if (dk != DataKind.USER) {
+ Element.createPixel(mRS, DataType.UNSIGNED_8, dk);
+ }
+ }
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ExceptionTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ExceptionTest.java
new file mode 100644
index 0000000..3a9df46
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ExceptionTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import android.renderscript.RSIllegalArgumentException;
+import android.renderscript.RSInvalidStateException;
+import android.renderscript.RSRuntimeException;
+import android.renderscript.RSDriverException;
+
+import android.test.AndroidTestCase;
+
+public class ExceptionTest extends AndroidTestCase {
+ public void testExceptions() {
+ try {
+ throw new RSIllegalArgumentException("IAE");
+ } catch (RSIllegalArgumentException e) {
+ assertEquals(e.getMessage(), "IAE");
+ }
+
+ try {
+ throw new RSInvalidStateException("ISE");
+ } catch (RSInvalidStateException e) {
+ assertEquals(e.getMessage(), "ISE");
+ }
+
+ try {
+ throw new RSRuntimeException("RE");
+ } catch (RSRuntimeException e) {
+ assertEquals(e.getMessage(), "RE");
+ }
+
+ try {
+ throw new RSDriverException("DE");
+ } catch (RSDriverException e) {
+ assertEquals(e.getMessage(), "DE");
+ }
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/FieldPackerTest.java b/tests/tests/renderscript/src/android/renderscript/cts/FieldPackerTest.java
new file mode 100644
index 0000000..f986d4b
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/FieldPackerTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import android.renderscript.Byte2;
+import android.renderscript.Byte3;
+import android.renderscript.Byte4;
+import android.renderscript.FieldPacker;
+import android.renderscript.Float2;
+import android.renderscript.Float3;
+import android.renderscript.Float4;
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.Int4;
+import android.renderscript.Long2;
+import android.renderscript.Long3;
+import android.renderscript.Long4;
+import android.renderscript.Matrix2f;
+import android.renderscript.Matrix3f;
+import android.renderscript.Matrix4f;
+import android.renderscript.Short2;
+import android.renderscript.Short3;
+import android.renderscript.Short4;
+
+public class FieldPackerTest extends RSBaseCompute {
+
+ public void testAddAllTypes() {
+ FieldPacker fp = new FieldPacker(1024);
+ fp.addBoolean(true);
+ fp.addF32(0.1f);
+ fp.addF32(new Float3());
+ fp.addF32(new Float4());
+ fp.addF32(new Float2());
+ fp.addF64(0.2);
+ fp.addI16(new Short3());
+ fp.addI16(new Short2());
+ fp.addI16((short)-2);
+ fp.addI16(new Short4());
+ fp.addI32(new Int3());
+ fp.addI32(-4);
+ fp.addI32(new Int4());
+ fp.addI32(new Int2());
+ fp.addI64(-8);
+ fp.addI8((byte)-1);
+ fp.addI8(new Byte4());
+ fp.addI8(new Byte2());
+ fp.addI8(new Byte3());
+ fp.addMatrix(new Matrix4f());
+ fp.addMatrix(new Matrix3f());
+ fp.addMatrix(new Matrix2f());
+ fp.addObj(null);
+ fp.addU16(new Int2());
+ fp.addU16(new Int4());
+ fp.addU16((short)2);
+ fp.addU16(new Int3());
+ fp.addU32(new Long4());
+ fp.addU32(new Long2());
+ fp.addU32(new Long3());
+ fp.addU32(4);
+ fp.addU64(8);
+ fp.addU8(new Short2());
+ fp.addU8(new Short4());
+ fp.addU8((byte)1);
+ fp.addU8(new Short3());
+ }
+
+ public void testAlign() {
+ /*
+ fp.align(int v);
+ final byte[] getData();
+ fp.reset(int i);
+ fp.reset();
+ fp.skip(int i);
+ */
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/FileA3DTest.java b/tests/tests/renderscript/src/android/renderscript/cts/FileA3DTest.java
new file mode 100644
index 0000000..ca2bb38
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/FileA3DTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import java.io.File;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.RSRuntimeException;
+import android.renderscript.FileA3D;
+import android.renderscript.FileA3D.EntryType;
+import android.renderscript.FileA3D.IndexEntry;
+
+public class FileA3DTest extends RSBaseGraphics {
+
+ public void testCreateFromResource() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ }
+
+ public void testCreateFromAsset() {
+ FileA3D model = FileA3D.createFromAsset(mRS, mRes.getAssets(), "sphere.a3d");
+ assertTrue(model != null);
+ }
+
+ public void testGetIndexEntryCount() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ }
+
+ public void testGetIndexEntry() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ assertTrue(model.getIndexEntry(0) != null);
+ }
+
+ public void testIndexEntryGetEntryType() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ FileA3D.IndexEntry entry = model.getIndexEntry(0);
+ assertTrue(entry != null);
+ assertTrue(entry.getEntryType() == FileA3D.EntryType.MESH);
+ boolean isOneOfEntries = false;
+ for(FileA3D.EntryType et : FileA3D.EntryType.values()) {
+ if (et == entry.getEntryType()) {
+ isOneOfEntries = true;
+ break;
+ }
+ }
+ assertTrue(isOneOfEntries);
+ }
+
+ public void testIndexEntryGetMesh() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ FileA3D.IndexEntry entry = model.getIndexEntry(0);
+ assertTrue(entry != null);
+ assertTrue(entry.getEntryType() == FileA3D.EntryType.MESH);
+ assertTrue(entry.getMesh() != null);
+ }
+
+ public void testIndexEntryGetName() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ FileA3D.IndexEntry entry = model.getIndexEntry(0);
+ assertTrue(entry != null);
+ assertTrue(entry.getName() != null);
+ }
+
+ public void testIndexEntryGetObject() {
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.sphere);
+ assertTrue(model != null);
+ assertTrue(model.getIndexEntryCount() == 1);
+ FileA3D.IndexEntry entry = model.getIndexEntry(0);
+ assertTrue(entry != null);
+ assertTrue(entry.getObject() != null);
+ }
+
+ public void testFileA3DEntryType() {
+ assertEquals(FileA3D.EntryType.UNKNOWN, FileA3D.EntryType.valueOf("UNKNOWN"));
+ assertEquals(FileA3D.EntryType.MESH, FileA3D.EntryType.valueOf("MESH"));
+ // Make sure no new enums are added
+ assertEquals(2, FileA3D.EntryType.values().length);
+ }
+
+ public void testCreateFromFile() {
+ File fileDesc = new File("bogusFile");
+ try {
+ FileA3D model = FileA3D.createFromFile(mRS, fileDesc);
+ fail("should throw RSRuntimeException.");
+ } catch (RSRuntimeException e) {
+ }
+ try {
+ FileA3D model = FileA3D.createFromFile(mRS, "bogus");
+ fail("should throw RSRuntimeException.");
+ } catch (RSRuntimeException e) {
+ }
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/FontTest.java b/tests/tests/renderscript/src/android/renderscript/cts/FontTest.java
new file mode 100644
index 0000000..e2405e8
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/FontTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import java.io.File;
+import com.android.cts.stub.R;
+
+import android.os.Environment;
+import android.renderscript.Font;
+import android.renderscript.Font.Style;
+import android.renderscript.RSIllegalArgumentException;
+
+public class FontTest extends RSBaseGraphics {
+
+ public void testCreate() {
+ for (int fontSize = 8; fontSize <= 12; fontSize += 2) {
+ for (Font.Style style : Font.Style.values()) {
+ Font F = null;
+ F = Font.create(mRS, mRes, "sans-serif", style, fontSize);
+ assertTrue(F != null);
+ F.setName("sans-serif");
+ try {
+ F.setName("sans-serif");
+ fail("set name twice for a font");
+ } catch (RSIllegalArgumentException e) {
+ }
+ F.destroy();
+
+ F = Font.create(mRS, mRes, "serif", style, fontSize);
+ assertTrue(F != null);
+ try {
+ F.setName("");
+ fail("set empty name for a font");
+ } catch (RSIllegalArgumentException e) {
+ }
+ F.setName("serif");
+ F.destroy();
+
+ F = Font.create(mRS, mRes, "mono", style, fontSize);
+ assertTrue(F != null);
+ try {
+ F.setName(null);
+ fail("set name as null string reference for a font");
+ } catch (RSIllegalArgumentException e) {
+ }
+ F.setName("mono");
+ F.destroy();
+ }
+ }
+ }
+
+ public void testCreateFromFile() {
+ String fontFile = "DroidSans.ttf";
+ String fontPath = Environment.getRootDirectory().getAbsolutePath();
+ fontPath += "/fonts/" + fontFile;
+ File fileDesc = new File(fontPath);
+ assertTrue(Font.createFromFile(mRS, mRes, fontPath, 8) != null);
+ assertTrue(Font.createFromFile(mRS, mRes, fileDesc, 8) != null);
+ }
+
+ public void testCreateFromAsset() {
+ assertTrue(Font.createFromAsset(mRS, mRes, "samplefont.ttf", 8) != null);
+ }
+
+ public void testFontStyle() {
+ assertEquals(Font.Style.NORMAL, Font.Style.valueOf("NORMAL"));
+ assertEquals(Font.Style.BOLD, Font.Style.valueOf("BOLD"));
+ assertEquals(Font.Style.ITALIC, Font.Style.valueOf("ITALIC"));
+ assertEquals(Font.Style.BOLD_ITALIC, Font.Style.valueOf("BOLD_ITALIC"));
+ // Make sure no new enums are added
+ assertEquals(4, Font.Style.values().length);
+ }
+
+ public void testCreateFromResource() {
+ assertTrue(Font.createFromResource(mRS, mRes, R.raw.samplefont, 8) != null);
+ }
+}
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/Matrix2fTest.java b/tests/tests/renderscript/src/android/renderscript/cts/Matrix2fTest.java
new file mode 100755
index 0000000..fa7c5d5
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/Matrix2fTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+import android.renderscript.Matrix2f;
+
+public class Matrix2fTest extends RSBaseCompute {
+
+ final float delta = 0.00001f;
+ final float[] setData = {
+ 1.0f, 2.0f,
+ 3.0f, 4.0f
+ };
+
+ void checkIdentity(Matrix2f m, float delta) {
+ for (int i = 0; i < 2; i ++) {
+ for (int j = 0; j < 2; j ++) {
+ if (i == j) {
+ assertEquals(1.0f, m.getArray()[i*2 + j], delta);
+ } else {
+ assertEquals(0.0f, m.getArray()[i*2 + j], delta);
+ }
+ }
+ }
+ }
+
+ String getString(float[] array) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 2; i ++) {
+ builder.append("[");
+ for (int j = 0; j < 2; j ++) {
+ builder.append(array[i*2 + j]);
+ builder.append(" ");
+ }
+ builder.append("]");
+ }
+ return builder.toString();
+ }
+
+ void checkData(Matrix2f m, float[] data, float delta) {
+ for (int i = 0; i < data.length; i ++) {
+ assertEquals(data[i], m.getArray()[i], delta);
+ }
+ }
+
+ void checkData(Matrix2f m, float[] data) {
+ String s1 = getString(m.getArray());
+ String s2 = getString(data);
+ assertEquals(s2, s1);
+ }
+
+ public void testCreation() {
+ Matrix2f m = new Matrix2f();
+ assertTrue(m.getArray() != null);
+ checkIdentity(m, 0.0f);
+
+ m = new Matrix2f(setData);
+ checkData(m, setData);
+ }
+
+ public void testGet() {
+
+ Matrix2f m = new Matrix2f(setData);
+
+ for (int i = 0; i < 2; i ++) {
+ for (int j = 0; j < 2; j ++) {
+ assertEquals(setData[i*2 + j], m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testSet() {
+ Matrix2f m = new Matrix2f();
+ for (int i = 0; i < 2; i ++) {
+ for (int j = 0; j < 2; j ++) {
+ float valToSet = setData[i*2 + j];
+ m.set(i, j, valToSet);
+ assertEquals(valToSet, m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testLoadIdentity() {
+ Matrix2f m = new Matrix2f(setData);
+ m.loadIdentity();
+ checkIdentity(m, 0.0f);
+ }
+
+ public void testLoad() {
+ Matrix2f m1 = new Matrix2f();
+ Matrix2f m2 = new Matrix2f(setData);
+
+ m1.load(m2);
+ checkData(m1, setData);
+ }
+
+ public void testLoadScale() {
+ float[] expectedData = {
+ 2.0f, 0.0f,
+ 0.0f, 3.0f
+ };
+
+ Matrix2f m = new Matrix2f(setData);
+ m.loadScale(2.0f, 3.0f);
+ checkData(m, expectedData);
+ }
+
+ public void testMultiply() {
+ float[] lhsData = {
+ 1.0f, 1.0f,
+ 1.0f, 1.0f
+ };
+
+ float[] rhsData = {
+ 2.0f, 2.0f,
+ 3.0f, 3.0f
+ };
+
+ float[] expected = {
+ 2.0f*2.0f, 2.0f*2.0f,
+ 2.0f*3.0f, 2.0f*3.0f
+ };
+
+ // Due to column major nature of OpenGL,
+ // left hand side and right hand side
+ // are reversed. Premultiplying by row major
+ // and post multiplying by column major
+ // are the same. So lhs and rhs get reversed here.
+ Matrix2f lhs = new Matrix2f(lhsData);
+ Matrix2f rhs = new Matrix2f(rhsData);
+ Matrix2f loadMul = new Matrix2f();
+
+ loadMul.loadMultiply(lhs, rhs);
+ checkData(loadMul, expected);
+
+ lhs.multiply(rhs);
+ checkData(lhs, expected);
+ }
+
+ public void testScale() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+ float scaleX = 2.0f;
+ float scaleY = 3.0f;
+ expectedData[0] *= scaleX;
+ expectedData[1] *= scaleX;
+ expectedData[2] *= scaleY;
+ expectedData[3] *= scaleY;
+
+ Matrix2f m = new Matrix2f(setData);
+ m.scale(scaleX, scaleY);
+ checkData(m, expectedData);
+ }
+
+ public void testTranspose() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+ float temp = expectedData[1];
+ expectedData[1] = expectedData[2];
+ expectedData[2] = temp;
+
+ Matrix2f m = new Matrix2f(setData);
+ m.transpose();
+
+ checkData(m, expectedData);
+ }
+
+ public void testRotateLoadRotate() {
+
+ float theta = 30.0f * (float)(java.lang.Math.PI / 180.0f);
+ float cosTheta = (float)Math.cos((float)theta);
+ float sinTheta = (float)Math.sin((float)theta);
+ float[] rotate = new float[4];
+ rotate[0] = cosTheta;
+ rotate[1] = -sinTheta;
+ rotate[2] = sinTheta;
+ rotate[3] = cosTheta;
+
+ Matrix2f m = new Matrix2f();
+ m.loadRotate(30.0f);
+ checkData(m, rotate);
+
+ m = new Matrix2f();
+ m.rotate(30.0f);
+ checkData(m, rotate);
+
+ float[] sourceData = {
+ 2.0f, 3.0f,
+ 4.0f, 5.0f
+ };
+ float[] rotated = new float[4];
+ rotated[0] = rotate[0] * sourceData[0] + rotate[1] * sourceData[2];
+ rotated[1] = rotate[0] * sourceData[1] + rotate[1] * sourceData[3];
+ rotated[2] = rotate[2] * sourceData[0] + rotate[3] * sourceData[2];
+ rotated[3] = rotate[2] * sourceData[1] + rotate[3] * sourceData[3];
+ m = new Matrix2f(sourceData);
+ m.rotate(30.0f);
+
+ checkData(m, rotated);
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/Matrix3fTest.java b/tests/tests/renderscript/src/android/renderscript/cts/Matrix3fTest.java
new file mode 100755
index 0000000..f817cab
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/Matrix3fTest.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+import android.renderscript.Matrix3f;
+
+public class Matrix3fTest extends RSBaseCompute {
+
+ final float delta = 0.00001f;
+ final float[] setData = {
+ 1.0f, 2.0f, 3.0f,
+ 4.0f, 5.0f, 6.0f,
+ 7.0f, 8.0f, 9.0f
+ };
+
+ void checkIdentity(Matrix3f m, float delta) {
+ for (int i = 0; i < 3; i ++) {
+ for (int j = 0; j < 3; j ++) {
+ if (i == j) {
+ assertEquals(1.0f, m.getArray()[i*3 + j], delta);
+ } else {
+ assertEquals(0.0f, m.getArray()[i*3 + j], delta);
+ }
+ }
+ }
+ }
+
+ String getString(float[] array) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 3; i ++) {
+ builder.append("[");
+ for (int j = 0; j < 3; j ++) {
+ builder.append(array[i*3 + j]);
+ builder.append(" ");
+ }
+ builder.append("]");
+ }
+ return builder.toString();
+ }
+
+ void checkData(Matrix3f m, float[] data, float delta) {
+ for (int i = 0; i < data.length; i ++) {
+ assertEquals(data[i], m.getArray()[i], delta);
+ }
+ }
+
+ void checkData(Matrix3f m, float[] data) {
+ String s1 = getString(m.getArray());
+ String s2 = getString(data);
+ assertEquals(s2, s1);
+ }
+
+ public void testCreation() {
+ Matrix3f m = new Matrix3f();
+ assertTrue(m.getArray() != null);
+ checkIdentity(m, 0.0f);
+
+ m = new Matrix3f(setData);
+ checkData(m, setData);
+ }
+
+ public void testGet() {
+
+ Matrix3f m = new Matrix3f(setData);
+
+ for (int i = 0; i < 3; i ++) {
+ for (int j = 0; j < 3; j ++) {
+ assertEquals(setData[i*3 + j], m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testSet() {
+ Matrix3f m = new Matrix3f();
+ for (int i = 0; i < 3; i ++) {
+ for (int j = 0; j < 3; j ++) {
+ float valToSet = setData[i*3 + j];
+ m.set(i, j, valToSet);
+ assertEquals(valToSet, m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testLoadIdentity() {
+ Matrix3f m = new Matrix3f(setData);
+ m.loadIdentity();
+ checkIdentity(m, 0.0f);
+ }
+
+ public void testLoad() {
+ Matrix3f m1 = new Matrix3f();
+ Matrix3f m2 = new Matrix3f(setData);
+
+ m1.load(m2);
+ checkData(m1, setData);
+ }
+
+ public void testLoadScale() {
+ float[] expectedData = {
+ 2.0f, 0.0f, 0.0f,
+ 0.0f, 3.0f, 0.0f,
+ 0.0f, 0.0f, 4.0f,
+ };
+ float[] expectedData2 = {
+ 2.0f, 0.0f, 0.0f,
+ 0.0f, 3.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ };
+
+ Matrix3f m = new Matrix3f(setData);
+ m.loadScale(2.0f, 3.0f, 4.0f);
+ checkData(m, expectedData);
+
+ m = new Matrix3f(setData);
+ m.loadScale(2.0f, 3.0f);
+ checkData(m, expectedData2);
+ }
+
+ public void testLoadTranslate() {
+ float[] expectedData = {
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 2.0f, 3.0f, 1.0f,
+ };
+
+ Matrix3f m = new Matrix3f(setData);
+ m.loadTranslate(2.0f, 3.0f);
+ checkData(m, expectedData);
+ }
+
+ public void testScale() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+ float scaleX = 2.0f;
+ float scaleY = 3.0f;
+ float scaleZ = 4.0f;
+ expectedData[0] *= scaleX;
+ expectedData[1] *= scaleX;
+ expectedData[2] *= scaleX;
+ expectedData[3] *= scaleY;
+ expectedData[4] *= scaleY;
+ expectedData[5] *= scaleY;
+ expectedData[6] *= scaleZ;
+ expectedData[7] *= scaleZ;
+ expectedData[8] *= scaleZ;
+
+ Matrix3f m = new Matrix3f(setData);
+ m.scale(scaleX, scaleY, scaleZ);
+ checkData(m, expectedData);
+
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+ expectedData[0] *= scaleX;
+ expectedData[1] *= scaleX;
+ expectedData[2] *= scaleX;
+ expectedData[3] *= scaleY;
+ expectedData[4] *= scaleY;
+ expectedData[5] *= scaleY;
+
+ m = new Matrix3f(setData);
+ m.scale(scaleX, scaleY);
+ checkData(m, expectedData);
+ }
+
+ public void testMultiply() {
+ float[] lhsData = {
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f
+ };
+
+ float[] rhsData = {
+ 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f,
+ 4.0f, 4.0f, 4.0f
+ };
+
+ float[] expected = {
+ 3.0f*2.0f, 3.0f*2.0f, 3.0f*2.0f,
+ 3.0f*3.0f, 3.0f*3.0f, 3.0f*3.0f,
+ 3.0f*4.0f, 3.0f*4.0f, 3.0f*4.0f
+ };
+
+ // Due to column major nature of OpenGL,
+ // left hand side and right hand side
+ // are reversed. Premultiplying by row major
+ // and post multiplying by column major
+ // are the same. So lhs and rhs get reversed here.
+ Matrix3f lhs = new Matrix3f(lhsData);
+ Matrix3f rhs = new Matrix3f(rhsData);
+ Matrix3f loadMul = new Matrix3f();
+
+ loadMul.loadMultiply(lhs, rhs);
+ checkData(loadMul, expected);
+
+ lhs.multiply(rhs);
+ checkData(lhs, expected);
+ }
+
+ public void testTranspose() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+
+ for(int i = 0; i < 2; i++) {
+ for(int j = i + 1; j < 3; j++) {
+ float temp = expectedData[i*3 + j];
+ expectedData[i*3 + j] = expectedData[j*3 + i];
+ expectedData[j*3 + i] = temp;
+ }
+ }
+
+ Matrix3f m = new Matrix3f(setData);
+ m.transpose();
+
+ checkData(m, expectedData);
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/Matrix4fTest.java b/tests/tests/renderscript/src/android/renderscript/cts/Matrix4fTest.java
new file mode 100755
index 0000000..8678578
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/Matrix4fTest.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+import android.renderscript.Matrix4f;
+
+public class Matrix4fTest extends RSBaseCompute {
+
+ final float delta = 0.00001f;
+ final float[] setData = {
+ 1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f
+ };
+
+ void checkIdentity(Matrix4f m, float delta) {
+ for (int i = 0; i < 4; i ++) {
+ for (int j = 0; j < 4; j ++) {
+ if (i == j) {
+ assertEquals(1.0f, m.getArray()[i*4 + j], delta);
+ } else {
+ assertEquals(0.0f, m.getArray()[i*4 + j], delta);
+ }
+ }
+ }
+ }
+
+ String getString(float[] array) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 4; i ++) {
+ builder.append("[");
+ for (int j = 0; j < 4; j ++) {
+ builder.append(array[i*4 + j]);
+ builder.append(" ");
+ }
+ builder.append("]");
+ }
+ return builder.toString();
+ }
+
+ void checkData(Matrix4f m, float[] data, float delta) {
+ for (int i = 0; i < data.length; i ++) {
+ assertEquals(data[i], m.getArray()[i], delta);
+ }
+ }
+
+ void checkData(Matrix4f m, float[] data) {
+ String s1 = getString(m.getArray());
+ String s2 = getString(data);
+ assertEquals(s2, s1);
+ }
+
+ public void testCreation() {
+ Matrix4f m = new Matrix4f();
+ assertTrue(m.getArray() != null);
+ checkIdentity(m, 0.0f);
+
+
+ m = new Matrix4f(setData);
+ checkData(m, setData);
+ }
+
+ public void testGet() {
+
+ Matrix4f m = new Matrix4f(setData);
+
+ for (int i = 0; i < 4; i ++) {
+ for (int j = 0; j < 4; j ++) {
+ assertEquals(setData[i*4 + j], m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testSet() {
+ Matrix4f m = new Matrix4f();
+ for (int i = 0; i < 4; i ++) {
+ for (int j = 0; j < 4; j ++) {
+ float valToSet = setData[i*4 + j];
+ m.set(i, j, valToSet);
+ assertEquals(valToSet, m.get(i, j), 0.0f);
+ }
+ }
+ }
+
+ public void testLoadIdentity() {
+ Matrix4f m = new Matrix4f(setData);
+ m.loadIdentity();
+ checkIdentity(m, 0.0f);
+ }
+
+ public void testLoad() {
+ Matrix4f m1 = new Matrix4f();
+ Matrix4f m2 = new Matrix4f(setData);
+
+ m1.load(m2);
+ checkData(m1, setData);
+ }
+
+ public void testLoadScale() {
+ float[] expectedData = {
+ 2.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 3.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 4.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ };
+
+ Matrix4f m = new Matrix4f(setData);
+ m.loadScale(2.0f, 3.0f, 4.0f);
+ checkData(m, expectedData);
+ }
+
+ public void testLoadTranslate() {
+ float[] expectedData = {
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 2.0f, 3.0f, 4.0f, 1.0f
+ };
+
+ Matrix4f m = new Matrix4f(setData);
+ m.loadTranslate(2.0f, 3.0f, 4.0f);
+ checkData(m, expectedData);
+ }
+
+ public void testScale() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+ float scaleX = 2.0f;
+ float scaleY = 3.0f;
+ float scaleZ = 4.0f;
+ expectedData[0] *= scaleX;
+ expectedData[1] *= scaleX;
+ expectedData[2] *= scaleX;
+ expectedData[3] *= scaleX;
+ expectedData[4] *= scaleY;
+ expectedData[5] *= scaleY;
+ expectedData[6] *= scaleY;
+ expectedData[7] *= scaleY;
+ expectedData[8] *= scaleZ;
+ expectedData[9] *= scaleZ;
+ expectedData[10] *= scaleZ;
+ expectedData[11] *= scaleZ;
+
+ Matrix4f m = new Matrix4f(setData);
+ m.scale(scaleX, scaleY, scaleZ);
+ checkData(m, expectedData);
+ }
+
+ public void testTranspose() {
+ float[] expectedData = new float[setData.length];
+ System.arraycopy(setData, 0, expectedData, 0, setData.length);
+
+ for(int i = 0; i < 3; i++) {
+ for(int j = i + 1; j < 4; j++) {
+ float temp = expectedData[i*4 + j];
+ expectedData[i*4 + j] = expectedData[j*4 + i];
+ expectedData[j*4 + i] = temp;
+ }
+ }
+
+ Matrix4f m = new Matrix4f(setData);
+ m.transpose();
+
+ checkData(m, expectedData);
+ }
+
+ public void testMultiply() {
+ float[] lhsData = {
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f
+ };
+
+ float[] rhsData = {
+ 2.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 3.0f,
+ 4.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 5.0f
+ };
+
+ float[] expected = {
+ 4.0f*2.0f, 4.0f*2.0f, 4.0f*2.0f, 4.0f*2.0f,
+ 4.0f*3.0f, 4.0f*3.0f, 4.0f*3.0f, 4.0f*3.0f,
+ 4.0f*4.0f, 4.0f*4.0f, 4.0f*4.0f, 4.0f*4.0f,
+ 4.0f*5.0f, 4.0f*5.0f, 4.0f*5.0f, 4.0f*5.0f
+ };
+
+ // Due to column major nature of OpenGL,
+ // left hand side and right hand side
+ // are reversed. Premultiplying by row major
+ // and post multiplying by column major
+ // are the same. So lhs and rhs get reversed here.
+ Matrix4f lhs = new Matrix4f(lhsData);
+ Matrix4f rhs = new Matrix4f(rhsData);
+ Matrix4f loadMul = new Matrix4f();
+
+ loadMul.loadMultiply(lhs, rhs);
+ checkData(loadMul, expected);
+
+ lhs.multiply(rhs);
+ checkData(lhs, expected);
+ }
+
+ public void testInverse() {
+ Matrix4f m = new Matrix4f();
+ assertTrue(m.inverse());
+ checkIdentity(m, delta);
+
+ m = new Matrix4f();
+ m.scale(2.0f, 2.0f, 2.0f);
+ m.translate(5.0f, 6.0f, 7.0f);
+
+ Matrix4f m2 = new Matrix4f(m.getArray());
+ assertTrue(m2.inverse());
+ m.multiply(m2);
+ checkIdentity(m, delta);
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/MeshTest.java b/tests/tests/renderscript/src/android/renderscript/cts/MeshTest.java
new file mode 100644
index 0000000..ffa733a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/MeshTest.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Type;
+import android.renderscript.Mesh;
+import android.renderscript.Mesh.Primitive;
+import android.renderscript.Mesh.AllocationBuilder;
+import android.renderscript.Mesh.Builder;
+import android.renderscript.Mesh.TriangleMeshBuilder;
+
+public class MeshTest extends RSBaseGraphics {
+
+ Allocation mAttrAlloc;
+ Allocation mIndexAlloc;
+ Element mPosElem;
+ Type mPosType;
+ Type mIndexType;
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Element.Builder eb = new Element.Builder(mRS);
+ eb.add(Element.F32_4(mRS), "position");
+ mPosElem = eb.create();
+ Type.Builder typeB = new Type.Builder(mRS, mPosElem);
+ mPosType = typeB.setX(3).create();
+ typeB = new Type.Builder(mRS, Element.U16(mRS));
+ mIndexType = typeB.setX(3).create();
+
+ mAttrAlloc = Allocation.createSized(mRS, mPosElem, 3);
+ mIndexAlloc = Allocation.createSized(mRS, Element.U16(mRS), 3);
+ }
+
+ public void testMeshAllocationBuilder() {
+ Mesh.AllocationBuilder mab;
+ for(Primitive prim : Primitive.values()) {
+ mab = new Mesh.AllocationBuilder(mRS);
+ mab.addVertexAllocation(mAttrAlloc);
+ mab.getCurrentVertexTypeIndex();
+ mab.addIndexSetType(prim);
+ assertTrue(mab.create() != null);
+
+ mab = new Mesh.AllocationBuilder(mRS);
+ mab.addVertexAllocation(mAttrAlloc);
+ mab.getCurrentVertexTypeIndex();
+ mab.addIndexSetAllocation(mIndexAlloc, prim);
+ mab.getCurrentIndexSetIndex();
+ mab.addIndexSetType(prim);
+
+ Mesh mesh = mab.create();
+ assertTrue(mesh != null);
+ assertTrue(mesh.getVertexAllocationCount() == 1);
+ assertTrue(mesh.getVertexAllocation(0) == mAttrAlloc);
+ assertTrue(mesh.getPrimitiveCount() == 2);
+ assertTrue(mesh.getPrimitive(0) == prim);
+ assertTrue(mesh.getPrimitive(1) == prim);
+ assertTrue(mesh.getIndexSetAllocation(0) == mIndexAlloc);
+ }
+ }
+
+ public void testMeshBuilder() {
+ Mesh.Builder mb;
+ for(Primitive prim : Primitive.values()) {
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosElem, 3);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(prim);
+ Mesh mesh = mb.create();
+ assertTrue(mesh != null);
+ assertTrue(mesh.getVertexAllocationCount() != 0);
+
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosElem, 3);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(Element.U16(mRS), 3, prim);
+ mb.getCurrentIndexSetIndex();
+ mesh = mb.create();
+ assertTrue(mesh != null);
+ assertTrue(mesh.getVertexAllocationCount() != 0);
+ assertTrue(mesh.getPrimitiveCount() != 0);
+
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosElem, 3);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(mIndexType, prim);
+ mb.getCurrentIndexSetIndex();
+ assertTrue(mb.create() != null);
+
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosType);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(prim);
+ assertTrue(mb.create() != null);
+
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosType);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(Element.U16(mRS), 3, prim);
+ mb.getCurrentIndexSetIndex();
+ assertTrue(mb.create() != null);
+
+ mb = new Mesh.Builder(mRS,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_VERTEX);
+ mb.addVertexType(mPosType);
+ mb.getCurrentVertexTypeIndex();
+ mb.addIndexSetType(mIndexType, prim);
+ mb.getCurrentIndexSetIndex();
+ assertTrue(mb.create() != null);
+ }
+ }
+
+ void triangleMeshBuilderHelper(int size, int flags) {
+ // Test various num vertices and triangles
+ for (int numVerts = 3; numVerts < 100; numVerts += 15) {
+ for (int numTries = 1; numTries < 100; numTries += 15) {
+ Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, size, flags);
+ // Append all the vertices
+ for (int numVertsI = 0; numVertsI < numVerts; numVertsI++) {
+ if (size == 2) {
+ tmb.addVertex(1.0f, 1.0f);
+ } else {
+ tmb.addVertex(1.0f, 1.0f, 1.0f);
+ }
+ if ((flags & TriangleMeshBuilder.COLOR) != 0) {
+ tmb.setColor(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+ if ((flags & TriangleMeshBuilder.NORMAL) != 0) {
+ tmb.setNormal(1.0f, 1.0f, 1.0f);
+ }
+ if ((flags & TriangleMeshBuilder.TEXTURE_0) != 0) {
+ tmb.setTexture(1.0f, 1.0f);
+ }
+ }
+ // Add triangles to index them
+ for (int numTriesI = 0; numTriesI < numTries; numTriesI ++) {
+ tmb.addTriangle(0, 1, 2);
+ }
+ assertTrue(tmb.create(false) != null);
+ assertTrue(tmb.create(true) != null);
+ }
+ }
+ }
+
+ public void testMeshTriangleMeshBuilder() {
+ for (int size = 2; size <= 3; size ++) {
+ triangleMeshBuilderHelper(size, 0);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.COLOR);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.COLOR |
+ TriangleMeshBuilder.NORMAL);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.COLOR |
+ TriangleMeshBuilder.TEXTURE_0);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.COLOR |
+ TriangleMeshBuilder.NORMAL |
+ TriangleMeshBuilder.TEXTURE_0);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.NORMAL);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.NORMAL|
+ TriangleMeshBuilder.TEXTURE_0);
+ triangleMeshBuilderHelper(size, TriangleMeshBuilder.TEXTURE_0);
+ }
+ }
+
+ public void testMeshPrimitive() {
+ assertEquals(Mesh.Primitive.POINT, Mesh.Primitive.valueOf("POINT"));
+ assertEquals(Mesh.Primitive.LINE, Mesh.Primitive.valueOf("LINE"));
+ assertEquals(Mesh.Primitive.LINE_STRIP, Mesh.Primitive.valueOf("LINE_STRIP"));
+ assertEquals(Mesh.Primitive.TRIANGLE, Mesh.Primitive.valueOf("TRIANGLE"));
+ assertEquals(Mesh.Primitive.TRIANGLE_STRIP, Mesh.Primitive.valueOf("TRIANGLE_STRIP"));
+ assertEquals(Mesh.Primitive.TRIANGLE_FAN, Mesh.Primitive.valueOf("TRIANGLE_FAN"));
+ // Make sure no new enums are added
+ assertEquals(6, Mesh.Primitive.values().length);
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentFixedFunctionTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentFixedFunctionTest.java
new file mode 100644
index 0000000..ac54b74
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentFixedFunctionTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import com.android.cts.stub.R;
+import android.renderscript.Element;
+import android.renderscript.Type;
+import android.renderscript.Allocation;
+import android.renderscript.Sampler;
+import android.renderscript.ProgramFragment;
+import android.renderscript.ProgramFragmentFixedFunction;
+import android.renderscript.ProgramFragmentFixedFunction.Builder;
+
+public class ProgramFragmentFixedFunctionTest extends RSBaseGraphics {
+
+ ScriptC_graphics_runner mScript;
+
+ Allocation mTex2D;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Type.Builder typeB = new Type.Builder(mRS, Element.RGB_888(mRS));
+ typeB.setX(8).setY(8);
+ mTex2D = Allocation.createTyped(mRS, typeB.create(),
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+
+ mScript = new ScriptC_graphics_runner(mRS, mRes, R.raw.graphics_runner);
+ mRS.bindRootScript(mScript);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mRS.bindRootScript(null);
+ super.tearDown();
+ }
+
+ void testProgramFragmentFixedFunctionBuilder(boolean testBind) {
+ ProgramFragmentFixedFunction.Builder b;
+ for (int tCount = 0; tCount <= Builder.MAX_TEXTURE; tCount ++) {
+ for (int varC = 0; varC <= 1; varC++) {
+ for (int pSprite = 0; pSprite <= 1; pSprite++) {
+ for (Builder.EnvMode env : Builder.EnvMode.values()) {
+ for (Builder.Format format : Builder.Format.values()) {
+ b = new ProgramFragmentFixedFunction.Builder(mRS);
+ b.setVaryingColor(varC == 1);
+ b.setPointSpriteTexCoordinateReplacement(pSprite == 1);
+ for (int t = 0; t < tCount; t++) {
+ b.setTexture(env, format, t);
+ }
+
+ ProgramFragment pf = b.create();
+ assertTrue(pf != null);
+ for (int t = 0; t < tCount; t++) {
+ pf.bindTexture(mTex2D, t);
+ pf.bindSampler(Sampler.CLAMP_NEAREST(mRS), t);
+ }
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void testProgramFragmentFixedFunctionBuilder() {
+ testProgramFragmentFixedFunctionBuilder(false);
+ testProgramFragmentFixedFunctionBuilder(true);
+ }
+
+ public void testBuilderEnvMode() {
+ assertEquals(Builder.EnvMode.DECAL, Builder.EnvMode.valueOf("DECAL"));
+ assertEquals(Builder.EnvMode.MODULATE, Builder.EnvMode.valueOf("MODULATE"));
+ assertEquals(Builder.EnvMode.REPLACE, Builder.EnvMode.valueOf("REPLACE"));
+
+ // Make sure no new enums are added
+ assertEquals(3, Builder.EnvMode.values().length);
+ }
+
+ public void testBuilderFormat() {
+ assertEquals(Builder.Format.ALPHA, Builder.Format.valueOf("ALPHA"));
+ assertEquals(Builder.Format.LUMINANCE_ALPHA, Builder.Format.valueOf("LUMINANCE_ALPHA"));
+ assertEquals(Builder.Format.RGB, Builder.Format.valueOf("RGB"));
+ assertEquals(Builder.Format.RGBA, Builder.Format.valueOf("RGBA"));
+
+ // Make sure no new enums are added
+ assertEquals(4, Builder.Format.values().length);
+ }
+
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentTest.java
new file mode 100644
index 0000000..d6a7f0d
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramFragmentTest.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Program;
+import android.renderscript.ProgramFragment;
+import android.renderscript.Sampler;
+import android.renderscript.Type;
+
+public class ProgramFragmentTest extends RSBaseGraphics {
+
+ ScriptC_graphics_runner mScript;
+
+ Allocation mConstMatrix;
+ Allocation mConstComplex;
+ Allocation mConstExtra;
+
+ Allocation mTex2D;
+ Allocation mTexCube;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Type.Builder typeB = new Type.Builder(mRS, Element.RGB_888(mRS));
+ typeB.setX(8).setY(8);
+ mTex2D = Allocation.createTyped(mRS, typeB.create(),
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+ typeB.setFaces(true);
+ mTexCube = Allocation.createTyped(mRS, typeB.create(),
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+
+ ScriptField_ConstMatrix c1 = new ScriptField_ConstMatrix(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c1.set(new ScriptField_ConstMatrix.Item(), 0, true);
+ mConstMatrix = c1.getAllocation();
+
+ ScriptField_ConstComplex c2 = new ScriptField_ConstComplex(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c2.set(new ScriptField_ConstComplex.Item(), 0, true);
+ mConstComplex = c2.getAllocation();
+
+ ScriptField_ConstExtra c3 = new ScriptField_ConstExtra(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c3.set(new ScriptField_ConstExtra.Item(), 0, true);
+ mConstExtra = c3.getAllocation();
+
+ mScript = new ScriptC_graphics_runner(mRS, mRes, R.raw.graphics_runner);
+ mRS.bindRootScript(mScript);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mRS.bindRootScript(null);
+ super.tearDown();
+ }
+
+ ProgramFragment buildShader(Allocation[] textures, Allocation[] constInput, String shader) {
+ ProgramFragment.Builder pfb = new ProgramFragment.Builder(mRS);
+ Program.BaseProgramBuilder bpb = pfb;
+ if (textures != null) {
+ for (int i = 0; i < textures.length; i++) {
+ Program.TextureType tType = Program.TextureType.TEXTURE_2D;
+ if (textures[i].getType().hasFaces()) {
+ tType = Program.TextureType.TEXTURE_CUBE;
+ }
+ // Add textures through the base program builder
+ bpb.addTexture(tType);
+ bpb.getCurrentTextureIndex();
+ }
+ }
+
+ if (constInput != null) {
+ for (int i = 0; i < constInput.length; i++) {
+ bpb.addConstant(constInput[i].getType());
+ bpb.getCurrentConstantIndex();
+ }
+ }
+
+ bpb.setShader(shader);
+ ProgramFragment pf = pfb.create();
+ if (constInput != null) {
+ for (int i = 0; i < constInput.length; i++) {
+ pf.bindConstants(constInput[i], i);
+ // Test the base class path too
+ Program p = pf;
+ p.bindConstants(constInput[i], i);
+ }
+ }
+ if (textures != null) {
+ for (int i = 0; i < textures.length; i++) {
+ pf.bindTexture(textures[i], i);
+ pf.bindSampler(Sampler.CLAMP_NEAREST(mRS), i);
+ // Test the base class path too
+ Program p = pf;
+ p.bindTexture(textures[i], i);
+ p.bindSampler(Sampler.CLAMP_NEAREST(mRS), i);
+ }
+ }
+ return pf;
+ }
+
+ void testProgramFragmentBuilderHelper(boolean testBind) {
+ String simpleFrag = "void main() {\n"+
+ " vec4 col = vec4(0.1, 0.2, 0.3, 0.4);"+
+ " gl_FragColor = col;\n"+
+ "}";
+
+ String simpleUni = "void main() {\n"+
+ " vec4 col = vec4(0.1, 0.2, 0.3, 0.4);\n"+
+ " col = UNI_MVP * col;\n"+
+ " gl_FragColor = col;\n"+
+ "}";
+
+ String simpleUniTex = "void main() {\n"+
+ " vec4 col = vec4(0.1, 0.2, 0.3, 0.4);"+
+ " col += texture2D(UNI_Tex0, vec2(0.1, 0.1));\n"+
+ " col += textureCube(UNI_Tex1, vec3(0.1, 0.2, 0.3));\n"+
+ " col = UNI_MVP * col;\n"+
+ " gl_FragColor = col;\n"+
+ "}";
+
+ String multiUni = "void main() {\n"+
+ " vec4 col = vec4(0.1, 0.2, 0.3, 0.4);"+
+ " col = UNI_MVP * col;\n"+
+ " col = UNI_EXTRA * col;\n"+
+ " col += UNI_extra4;\n"+
+ " col.xyz += UNI_extra3;\n "+
+ " col.xy += UNI_extra2;\n"+
+ " col.x += UNI_extra1;\n"+
+ " gl_FragColor = col;\n"+
+ "}";
+
+ // Create a series of shaders that do nothing useful
+ // but exercise creation pipeline
+ ProgramFragment pf = buildShader(null, null, simpleFrag);
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ }
+
+ Allocation[] constInput = new Allocation[1];
+ constInput[0] = mConstMatrix;
+ pf = buildShader(null, constInput, simpleUni);
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ mRS.bindProgramFragment(pf);
+ }
+
+ constInput[0] = mConstComplex;
+ pf = buildShader(null, constInput, multiUni);
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ mRS.bindProgramFragment(pf);
+ }
+
+ Allocation[] textures = new Allocation[2];
+ textures[0] = mTex2D;
+ textures[1] = mTexCube;
+ pf = buildShader(textures, constInput, simpleUniTex);
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ mRS.bindProgramFragment(pf);
+ }
+
+ constInput = new Allocation[2];
+ constInput[0] = mConstMatrix;
+ constInput[1] = mConstExtra;
+ pf = buildShader(null, constInput, multiUni);
+ if (testBind) {
+ mScript.invoke_testProgramFragment(pf);
+ mRS.bindProgramFragment(pf);
+ }
+ }
+
+ public void testProgramFragmentBuilder() {
+ testProgramFragmentBuilderHelper(false);
+ }
+
+ public void testProgramFragmentCreation() {
+ testProgramFragmentBuilderHelper(true);
+ }
+
+ public void testProgramTextureType() {
+ assertEquals(Program.TextureType.TEXTURE_2D,
+ Program.TextureType.valueOf("TEXTURE_2D"));
+ assertEquals(Program.TextureType.TEXTURE_CUBE,
+ Program.TextureType.valueOf("TEXTURE_CUBE"));
+ // Make sure no new enums are added
+ assertEquals(2, Program.TextureType.values().length);
+
+ ProgramFragment.Builder pfb = new ProgramFragment.Builder(mRS);
+ for (Program.TextureType tt : Program.TextureType.values()) {
+ pfb.addTexture(tt);
+ }
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java
index bebb8b0..befa926 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java
@@ -16,8 +16,6 @@
package android.renderscript.cts;
-import com.android.cts.stub.R;
-
import android.renderscript.ProgramRaster;
import android.renderscript.ProgramRaster.Builder;
import android.renderscript.ProgramRaster.CullMode;
@@ -31,7 +29,9 @@
b.setPointSpriteEnabled(pSprite);
for (CullMode cull : CullMode.values()) {
b.setCullMode(cull);
- b.create();
+ ProgramRaster pr = b.create();
+ assertTrue(pr != null);
+ mRS.bindProgramRaster(pr);
}
}
}
@@ -39,7 +39,14 @@
public void testPrebuiltProgramRaster() {
assertTrue(ProgramRaster.CULL_BACK(mRS) != null);
assertTrue(ProgramRaster.CULL_FRONT(mRS) != null);
+ assertTrue(ProgramRaster.CULL_NONE(mRS) != null);
+ }
+
+ public void testProgramRasterCullMode() {
+ assertEquals(CullMode.BACK, CullMode.valueOf("BACK"));
+ assertEquals(CullMode.FRONT, CullMode.valueOf("FRONT"));
+ assertEquals(CullMode.NONE, CullMode.valueOf("NONE"));
+ // Make sure no new enums are added
+ assertEquals(3, CullMode.values().length);
}
}
-
-
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java
index 54c5672..b7f5eff 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java
@@ -16,10 +16,7 @@
package android.renderscript.cts;
-import com.android.cts.stub.R;
-
import android.renderscript.ProgramStore;
-import android.renderscript.ProgramStore.Builder;
import android.renderscript.ProgramStore.DepthFunc;
import android.renderscript.ProgramStore.BlendSrcFunc;
import android.renderscript.ProgramStore.BlendDstFunc;
@@ -37,9 +34,11 @@
boolean isA = (a == 1);
for (int dither = 0; dither <= 1; dither++) {
boolean isDither = (dither == 1);
- pb.setDepthMaskEnabled(isDither);
+ pb.setDitherEnabled(isDither);
pb.setColorMaskEnabled(isR, isG, isB, isA);
- pb.create();
+ ProgramStore ps = pb.create();
+ assertTrue(ps != null);
+ mRS.bindProgramStore(ps);
}
}
}
@@ -70,6 +69,68 @@
assertTrue(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS) != null);
assertTrue(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS) != null);
}
+
+ public void testProgramStoreBlendDstFunc() {
+ assertEquals(BlendDstFunc.ZERO,
+ BlendDstFunc.valueOf("ZERO"));
+ assertEquals(BlendDstFunc.ONE,
+ BlendDstFunc.valueOf("ONE"));
+ assertEquals(BlendDstFunc.SRC_COLOR,
+ BlendDstFunc.valueOf("SRC_COLOR"));
+ assertEquals(BlendDstFunc.ONE_MINUS_SRC_COLOR,
+ BlendDstFunc.valueOf("ONE_MINUS_SRC_COLOR"));
+ assertEquals(BlendDstFunc.SRC_ALPHA,
+ BlendDstFunc.valueOf("SRC_ALPHA"));
+ assertEquals(BlendDstFunc.ONE_MINUS_SRC_ALPHA,
+ BlendDstFunc.valueOf("ONE_MINUS_SRC_ALPHA"));
+ assertEquals(BlendDstFunc.DST_ALPHA,
+ BlendDstFunc.valueOf("DST_ALPHA"));
+ assertEquals(BlendDstFunc.ONE_MINUS_DST_ALPHA,
+ BlendDstFunc.valueOf("ONE_MINUS_DST_ALPHA"));
+ // Make sure no new enums are added
+ assertEquals(8, BlendDstFunc.values().length);
+ }
+
+ public void testProgramStoreBlendSrcFunc() {
+ assertEquals(BlendSrcFunc.ZERO,
+ BlendSrcFunc.valueOf("ZERO"));
+ assertEquals(BlendSrcFunc.ONE,
+ BlendSrcFunc.valueOf("ONE"));
+ assertEquals(BlendSrcFunc.DST_COLOR,
+ BlendSrcFunc.valueOf("DST_COLOR"));
+ assertEquals(BlendSrcFunc.ONE_MINUS_DST_COLOR,
+ BlendSrcFunc.valueOf("ONE_MINUS_DST_COLOR"));
+ assertEquals(BlendSrcFunc.SRC_ALPHA,
+ BlendSrcFunc.valueOf("SRC_ALPHA"));
+ assertEquals(BlendSrcFunc.ONE_MINUS_SRC_ALPHA,
+ BlendSrcFunc.valueOf("ONE_MINUS_SRC_ALPHA"));
+ assertEquals(BlendSrcFunc.DST_ALPHA,
+ BlendSrcFunc.valueOf("DST_ALPHA"));
+ assertEquals(BlendSrcFunc.ONE_MINUS_DST_ALPHA,
+ BlendSrcFunc.valueOf("ONE_MINUS_DST_ALPHA"));
+ assertEquals(BlendSrcFunc.SRC_ALPHA_SATURATE,
+ BlendSrcFunc.valueOf("SRC_ALPHA_SATURATE"));
+ // Make sure no new enums are added
+ assertEquals(9, BlendSrcFunc.values().length);
+ }
+ public void testProgramStoreDepthFunc() {
+ assertEquals(DepthFunc.ALWAYS,
+ DepthFunc.valueOf("ALWAYS"));
+ assertEquals(DepthFunc.LESS,
+ DepthFunc.valueOf("LESS"));
+ assertEquals(DepthFunc.LESS_OR_EQUAL,
+ DepthFunc.valueOf("LESS_OR_EQUAL"));
+ assertEquals(DepthFunc.GREATER,
+ DepthFunc.valueOf("GREATER"));
+ assertEquals(DepthFunc.GREATER_OR_EQUAL,
+ DepthFunc.valueOf("GREATER_OR_EQUAL"));
+ assertEquals(DepthFunc.EQUAL,
+ DepthFunc.valueOf("EQUAL"));
+ assertEquals(DepthFunc.NOT_EQUAL,
+ DepthFunc.valueOf("NOT_EQUAL"));
+ // Make sure no new enums are added
+ assertEquals(7, DepthFunc.values().length);
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexFixedFunctionTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexFixedFunctionTest.java
new file mode 100644
index 0000000..0adab9a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexFixedFunctionTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.ProgramVertexFixedFunction;
+import android.renderscript.ProgramVertexFixedFunction.Builder;
+import android.renderscript.ScriptC;
+import android.renderscript.Matrix4f;
+
+public class ProgramVertexFixedFunctionTest extends RSBaseGraphics {
+
+ ScriptC_graphics_runner mScript;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mScript = new ScriptC_graphics_runner(mRS, mRes, R.raw.graphics_runner);
+ mRS.bindRootScript(mScript);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mRS.bindRootScript(null);
+ super.tearDown();
+ }
+
+ public void testConstants() {
+ ProgramVertexFixedFunction.Constants pva;
+ for (int isM = 0; isM <= 1; isM++) {
+ for (int isP = 0; isP <= 1; isP++) {
+ for (int isT = 0; isT <= 1; isT++) {
+ pva = new ProgramVertexFixedFunction.Constants(mRS);
+ if (isM == 1) {
+ pva.setModelview(new Matrix4f());
+ }
+ if (isP == 1) {
+ pva.setProjection(new Matrix4f());
+ }
+ if (isT == 1) {
+ pva.setTexture(new Matrix4f());
+ }
+ pva.destroy();
+ }
+ }
+ }
+ }
+
+ void testProgramVertexFixedFunctionBuilder(boolean testBind) {
+ ProgramVertexFixedFunction.Constants pva;
+ pva = new ProgramVertexFixedFunction.Constants(mRS);
+
+ ProgramVertexFixedFunction.Builder b;
+ b = new ProgramVertexFixedFunction.Builder(mRS);
+ b.setTextureMatrixEnable(false);
+ ProgramVertexFixedFunction pv = b.create();
+ assertTrue(pv != null);
+ pv.bindConstants(pva);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ }
+ pv.destroy();
+ b.setTextureMatrixEnable(true);
+ pv = b.create();
+ assertTrue(pv != null);
+ pv.bindConstants(pva);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ }
+ pv.destroy();
+ }
+
+ public void testProgramVertexFixedFunctionBuilder() {
+ testProgramVertexFixedFunctionBuilder(false);
+ testProgramVertexFixedFunctionBuilder(true);
+ }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexTest.java
new file mode 100644
index 0000000..0a5c60e
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramVertexTest.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Program;
+import android.renderscript.ProgramVertex;
+
+public class ProgramVertexTest extends RSBaseGraphics {
+
+ ScriptC_graphics_runner mScript;
+ Element mAttrPosElem;
+ Element mAttrNormTexElem;
+ Element mAttrPosNormTexElem;
+ Element mAttrExtra;
+
+ Allocation mConstMatrix;
+ Allocation mConstComplex;
+ Allocation mConstExtra;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Build elements for shader inputs
+ Element.Builder eb = new Element.Builder(mRS);
+ eb.add(Element.F32_4(mRS), "position");
+ mAttrPosElem = eb.create();
+
+ eb = new Element.Builder(mRS);
+ eb.add(Element.F32_3(mRS), "normal");
+ eb.add(Element.F32_2(mRS), "texture0");
+ mAttrNormTexElem = eb.create();
+
+ eb = new Element.Builder(mRS);
+ eb.add(Element.F32_4(mRS), "position");
+ eb.add(Element.F32_3(mRS), "normal");
+ eb.add(Element.F32_2(mRS), "texture0");
+ mAttrPosNormTexElem = eb.create();
+
+ eb.add(Element.F32(mRS), "extra1");
+ eb.add(Element.F32_2(mRS), "extra2");
+ eb.add(Element.F32_3(mRS), "extra3");
+ eb.add(Element.F32_4(mRS), "extra4");
+ mAttrExtra = eb.create();
+
+ ScriptField_ConstMatrix c1 = new ScriptField_ConstMatrix(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c1.set(new ScriptField_ConstMatrix.Item(), 0, true);
+ mConstMatrix = c1.getAllocation();
+
+ ScriptField_ConstComplex c2 = new ScriptField_ConstComplex(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c2.set(new ScriptField_ConstComplex.Item(), 0, true);
+ mConstComplex = c2.getAllocation();
+
+ ScriptField_ConstExtra c3 = new ScriptField_ConstExtra(mRS, 1,
+ Allocation.USAGE_SCRIPT |
+ Allocation.USAGE_GRAPHICS_CONSTANTS);
+ c3.set(new ScriptField_ConstExtra.Item(), 0, true);
+ mConstExtra = c3.getAllocation();
+
+ mScript = new ScriptC_graphics_runner(mRS, mRes, R.raw.graphics_runner);
+ mRS.bindRootScript(mScript);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mRS.bindRootScript(null);
+ super.tearDown();
+ }
+
+ ProgramVertex buildShader(Element[] input, Allocation[] constInput, String shader) {
+ ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS);
+ Program.BaseProgramBuilder bpb = pvb;
+ if (input != null) {
+ for (int i = 0; i < input.length; i++) {
+ pvb.addInput(input[i]);
+ }
+ }
+ if (constInput != null) {
+ for (int i = 0; i < constInput.length; i++) {
+ // Add constants through the base builder class to
+ // tick cts test coverage (doesn't register through subclass)
+ bpb.addConstant(constInput[i].getType());
+ bpb.getCurrentConstantIndex();
+ }
+ }
+
+ bpb.setShader(shader);
+ ProgramVertex pv = pvb.create();
+ if (constInput != null) {
+ for (int i = 0; i < constInput.length; i++) {
+ pv.bindConstants(constInput[i], i);
+ // Go through the base class code as well
+ Program p = pv;
+ p.bindConstants(constInput[i], i);
+ }
+ }
+ return pv;
+ }
+
+ void testProgramVertexBuilderHelper(boolean testBind) {
+ String simpleAttr = "void main() {\n"+
+ " gl_Position = ATTRIB_position;\n"+
+ "}";
+
+ String multiAttr = "void main() {\n"+
+ " vec4 temp = ATTRIB_position;\n"+
+ " temp.xyz += ATTRIB_normal;\n"+
+ " temp.xy += ATTRIB_texture0;\n"+
+ " gl_Position = temp;\n"+
+ "}";
+
+ String multiAttr2 = "void main() {\n"+
+ " vec4 temp = ATTRIB_position;\n"+
+ " temp.xyz += ATTRIB_normal;\n"+
+ " temp.xy += ATTRIB_texture0;\n"+
+ " temp += ATTRIB_extra4;\n"+
+ " temp.xyz += ATTRIB_extra3;\n "+
+ " temp.xy += ATTRIB_extra2;\n"+
+ " temp.x += ATTRIB_extra1;\n"+
+ " gl_Position = temp;\n"+
+ "}";
+
+ String simpleAttrSimpleUni = "void main() {\n"+
+ " gl_Position = UNI_MVP * ATTRIB_position;\n"+
+ "}";
+
+ String multiAttrMultiUni = "void main() {\n"+
+ " vec4 temp = UNI_MVP * ATTRIB_position;\n"+
+ " temp = UNI_EXTRA * temp;\n"+
+ " temp.xyz += ATTRIB_normal;\n"+
+ " temp.xy += ATTRIB_texture0;\n"+
+ " temp += UNI_extra4;\n"+
+ " temp.xyz += UNI_extra3;\n "+
+ " temp.xy += UNI_extra2;\n"+
+ " temp.x += UNI_extra1;\n"+
+ " gl_Position = temp;\n"+
+ "}";
+
+ // Create a series of shaders that do nothing useful
+ // but exercise creation pipeline
+ Element[] inputs = new Element[1];
+ inputs[0] = mAttrPosElem;
+ ProgramVertex pv = buildShader(inputs, null, simpleAttr);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ inputs[0] = mAttrPosNormTexElem;
+ pv = buildShader(inputs, null, multiAttr);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ inputs[0] = mAttrExtra;
+ pv = buildShader(inputs, null, multiAttr2);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ // Now with constant inputs
+ Allocation[] constInput = new Allocation[1];
+ inputs[0] = mAttrPosElem;
+ constInput[0] = mConstMatrix;
+ pv = buildShader(inputs, constInput, simpleAttrSimpleUni);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ inputs[0] = mAttrPosNormTexElem;
+ constInput[0] = mConstComplex;
+ pv = buildShader(inputs, constInput, multiAttrMultiUni);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ // Now with multiple input and const structs
+ constInput = new Allocation[2];
+ constInput[0] = mConstMatrix;
+ constInput[1] = mConstExtra;
+ inputs[0] = mAttrPosNormTexElem;
+ pv = buildShader(inputs, constInput, multiAttrMultiUni);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ inputs = new Element[2];
+ inputs[0] = mAttrPosElem;
+ inputs[1] = mAttrNormTexElem;
+ pv = buildShader(inputs, null, multiAttr);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+
+ constInput[0] = mConstMatrix;
+ constInput[1] = mConstExtra;
+ inputs[0] = mAttrPosElem;
+ inputs[1] = mAttrNormTexElem;
+ pv = buildShader(inputs, constInput, multiAttrMultiUni);
+ if (testBind) {
+ mScript.invoke_testProgramVertex(pv);
+ mRS.bindProgramVertex(pv);
+ }
+ }
+
+ public void testProgramVertexBuilder() {
+ testProgramVertexBuilderHelper(false);
+ }
+
+ public void testProgramVertexCreation() {
+ testProgramVertexBuilderHelper(true);
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java
index 10aa8e6..56838e1 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java
@@ -20,7 +20,6 @@
import android.content.res.Resources;
import android.renderscript.RenderScript.RSMessageHandler;
import android.test.AndroidTestCase;
-import com.android.cts.stub.R;
/**
* Base RenderScript test class. This class provides a message handler and a
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
index 84616ca..3278113 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
@@ -16,12 +16,7 @@
package android.renderscript.cts;
-import android.content.Context;
-import android.content.res.Resources;
import android.renderscript.RenderScript;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.test.AndroidTestCase;
-import com.android.cts.stub.R;
/**
* Base RenderScript test class. This class provides a message handler and a
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java
index 83a2744..986a50d 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java
@@ -16,14 +16,8 @@
package android.renderscript.cts;
-import android.content.Context;
-import android.content.res.Resources;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScript.RSMessageHandler;
import android.renderscript.RenderScriptGL;
import android.renderscript.RenderScriptGL.SurfaceConfig;
-import android.test.AndroidTestCase;
-import com.android.cts.stub.R;
/**
* Base RenderScript test class. This class provides a message handler and a
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSSurfaceViewTest.java b/tests/tests/renderscript/src/android/renderscript/cts/RSSurfaceViewTest.java
new file mode 100644
index 0000000..9cf8f65
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSSurfaceViewTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScriptGL;
+import android.renderscript.RenderScriptGL.SurfaceConfig;
+import android.util.AttributeSet;
+
+public class RSSurfaceViewTest extends RSBaseGraphics {
+
+ public void testCreation() {
+ RSSurfaceView view = new RSSurfaceView(mCtx);
+ view = new RSSurfaceView(mCtx, null);
+ }
+
+ public void testCreateRenderScriptGL() {
+ RSSurfaceView view = new RSSurfaceView(mCtx);
+ RenderScriptGL rs = view.createRenderScriptGL(new SurfaceConfig());
+ assertTrue(rs != null);
+ }
+
+ public void testGetSetRenderScriptGL() {
+ RSSurfaceView view = new RSSurfaceView(mCtx);
+ RenderScriptGL rs = view.createRenderScriptGL(new SurfaceConfig());
+ assertTrue(rs != null);
+ assertEquals(view.getRenderScriptGL(), rs);
+
+ view = new RSSurfaceView(mCtx);
+ view.setRenderScriptGL(mRS);
+ assertEquals(view.getRenderScriptGL(), mRS);
+ }
+
+ public void testDestroyRenderScriptGL() {
+ RSSurfaceView view = new RSSurfaceView(mCtx);
+ RenderScriptGL rs = view.createRenderScriptGL(new SurfaceConfig());
+ assertTrue(rs != null);
+ view.destroyRenderScriptGL();
+ assertTrue(view.getRenderScriptGL() == null);
+ }
+
+ public void testPauseResume() {
+ RSSurfaceView view = new RSSurfaceView(mCtx);
+ view.pause();
+ view.resume();
+
+ view.setRenderScriptGL(mRS);
+ view.pause();
+ view.resume();
+ }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java b/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java
index e2d7968..9e61526 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java
@@ -59,4 +59,34 @@
mRS.destroy();
}
+ /**
+ * Verify Priority enum properties.
+ */
+ public void testPriority() {
+ assertEquals(RenderScript.Priority.LOW,
+ RenderScript.Priority.valueOf("LOW"));
+ assertEquals(RenderScript.Priority.NORMAL,
+ RenderScript.Priority.valueOf("NORMAL"));
+ assertEquals(2, RenderScript.Priority.values().length);
+ }
+
+ /**
+ * Create a base RSMessageHandler object and run() it.
+ * Note that most developers will subclass RSMessageHandler and use
+ * their own non-empty implementation.
+ */
+ public void testRSMessageHandler() {
+ RenderScript.RSMessageHandler mMH = new RenderScript.RSMessageHandler();
+ mMH.run();
+ }
+
+ /**
+ * Create a base RSErrorHandler object and run() it.
+ * Note that most developers will subclass RSErrorHandler and use
+ * their own non-empty implementation.
+ */
+ public void testRSErrorHandler() {
+ RenderScript.RSErrorHandler mEH = new RenderScript.RSErrorHandler();
+ mEH.run();
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java
index 7f2b052..35e813e 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java
@@ -16,10 +16,7 @@
package android.renderscript.cts;
-import com.android.cts.stub.R;
-
import android.renderscript.Sampler;
-import android.renderscript.Sampler.Builder;
import android.renderscript.Sampler.Value;
public class SamplerTest extends RSBaseGraphics {
@@ -119,6 +116,18 @@
assertTrue(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS) != null);
assertTrue(Sampler.WRAP_NEAREST(mRS) != null);
}
+
+ public void testSamplerValue() {
+ assertEquals(Value.NEAREST, Value.valueOf("NEAREST"));
+ assertEquals(Value.LINEAR, Value.valueOf("LINEAR"));
+ assertEquals(Value.LINEAR_MIP_LINEAR, Value.valueOf("LINEAR_MIP_LINEAR"));
+ assertEquals(Value.LINEAR_MIP_NEAREST, Value.valueOf("LINEAR_MIP_NEAREST"));
+ assertEquals(Value.WRAP, Value.valueOf("WRAP"));
+ assertEquals(Value.CLAMP, Value.valueOf("CLAMP"));
+
+ // Make sure no new enums are added
+ assertEquals(6, Value.values().length);
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SurfaceConfigTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SurfaceConfigTest.java
new file mode 100644
index 0000000..94d784e
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SurfaceConfigTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+import android.test.AndroidTestCase;
+
+import android.renderscript.RSIllegalArgumentException;
+import android.renderscript.RenderScriptGL.SurfaceConfig;
+
+public class SurfaceConfigTest extends AndroidTestCase {
+
+ public void testSimpleCreate() {
+ SurfaceConfig sc = new SurfaceConfig();
+ }
+
+ public void testSetColor() {
+ SurfaceConfig sc = new SurfaceConfig();
+ try {
+ sc.setColor(-1, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setColor(9, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setColor(5, -1);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ sc.setColor(5, 8);
+ sc = new SurfaceConfig();
+ sc.setColor(8, 8);
+ }
+
+ public void testSetAlpha() {
+ SurfaceConfig sc = new SurfaceConfig();
+ try {
+ sc.setAlpha(-1, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setAlpha(9, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setAlpha(0, -1);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ sc.setAlpha(0, 8);
+ sc = new SurfaceConfig();
+ sc.setAlpha(8, 8);
+ }
+
+ public void testSetDepth() {
+ SurfaceConfig sc = new SurfaceConfig();
+ try {
+ sc.setDepth(-1, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setDepth(45, 8);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setDepth(0, -1);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ sc.setDepth(0, 16);
+ sc = new SurfaceConfig();
+ sc.setDepth(16, 24);
+ sc = new SurfaceConfig();
+ sc.setDepth(24, 24);
+ }
+
+ public void testSetSamples() {
+ SurfaceConfig sc = new SurfaceConfig();
+ try {
+ sc.setSamples(-1, 8, 1.0f);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setSamples(45, 8, 1.0f);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setSamples(1, -1, 1.0f);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setSamples(1, 1, -1.0f);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ try {
+ sc.setSamples(1, 1, 10.0f);
+ fail("should throw RSIllegalArgumentException.");
+ } catch (RSIllegalArgumentException e) {
+ }
+ sc = new SurfaceConfig();
+ sc.setSamples(1, 4, 1.0f);
+ sc = new SurfaceConfig();
+ sc.setSamples(4, 32, 1.0f);
+ sc = new SurfaceConfig();
+ sc.setSamples(4, 64, 0.5f);
+ }
+
+ public void testCopyConstructor() {
+ SurfaceConfig sc = new SurfaceConfig();
+ sc.setAlpha(1, 7);
+ sc.setColor(5, 8);
+ sc.setDepth(0, 16);
+ sc.setSamples(1, 4, 0.71f);
+ SurfaceConfig sc2 = new SurfaceConfig(sc);
+ }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java b/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java
index 82c7a79..928abaf 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java
@@ -16,13 +16,8 @@
package android.renderscript.cts;
-import com.android.cts.stub.R;
-
import android.renderscript.Element;
-import android.renderscript.Element.DataType;
-import android.renderscript.Element.DataKind;
import android.renderscript.Type;
-import android.renderscript.Type.Builder;
public class TypeTest extends RSBaseCompute {
@@ -127,6 +122,59 @@
expectedCount = 7*3 + 3*1 + 1;
assertTrue(t.getCount() == expectedCount);
}
+
+ public void testGetElement() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(1);
+ assertTrue(b.create().getElement() == Element.F32(mRS));
+ }
+
+ public void testGetX() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(3);
+ assertTrue(b.create().getX() == 3);
+ }
+
+ public void testGetY() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(3).setY(4);
+ Type t = b.create();
+ assertTrue(t.getX() == 3);
+ assertTrue(t.getY() == 4);
+ }
+
+ public void testGetZ() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(3).setY(4);
+ assertTrue(b.create().getZ() == 0);
+ }
+
+ public void testHasFaces() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(4).setY(4).setFaces(true);
+ assertTrue(b.create().hasFaces());
+ b.setFaces(false);
+ assertFalse(b.create().hasFaces());
+ }
+
+ public void testGetMipmaps() {
+ Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+ b.setX(4).setY(4).setMipmaps(true);
+ assertTrue(b.create().hasMipmaps());
+ b.setMipmaps(false);
+ assertFalse(b.create().hasMipmaps());
+ }
+
+ public void testTypeCubemapFace() {
+ assertEquals(Type.CubemapFace.NEGATIVE_X, Type.CubemapFace.valueOf("NEGATIVE_X"));
+ assertEquals(Type.CubemapFace.NEGATIVE_Y, Type.CubemapFace.valueOf("NEGATIVE_Y"));
+ assertEquals(Type.CubemapFace.NEGATIVE_Z, Type.CubemapFace.valueOf("NEGATIVE_Z"));
+ assertEquals(Type.CubemapFace.POSITVE_X, Type.CubemapFace.valueOf("POSITVE_X"));
+ assertEquals(Type.CubemapFace.POSITVE_Y, Type.CubemapFace.valueOf("POSITVE_Y"));
+ assertEquals(Type.CubemapFace.POSITVE_Z, Type.CubemapFace.valueOf("POSITVE_Z"));
+ // Make sure no new enums are added
+ assertEquals(6, Type.CubemapFace.values().length);
+ }
}