diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-04-24 17:33:49 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-04-24 17:33:50 +0000 |
commit | e7f29927fd0d650d184c5f8d76db69634185c147 (patch) | |
tree | 5c077d3de233b481e48f7564fae545350863fb79 | |
parent | 3bcf90354b11f59246a03f4e48ac8d2b33659273 (diff) | |
parent | 5bf533dbfe2dc1c92e2fe3e90776eaa1db03771c (diff) | |
download | rs-e7f29927fd0d650d184c5f8d76db69634185c147.tar.gz |
Merge "Added test for Blur input/output validation" into oc-dev
-rw-r--r-- | tests/java_api/RsTest/src/com/android/rs/test/RSTestCore.java | 1 | ||||
-rw-r--r-- | tests/java_api/RsTest/src/com/android/rs/test/UT_blur_validation.java | 96 |
2 files changed, 97 insertions, 0 deletions
diff --git a/tests/java_api/RsTest/src/com/android/rs/test/RSTestCore.java b/tests/java_api/RsTest/src/com/android/rs/test/RSTestCore.java index ac8dad5c..133a48de 100644 --- a/tests/java_api/RsTest/src/com/android/rs/test/RSTestCore.java +++ b/tests/java_api/RsTest/src/com/android/rs/test/RSTestCore.java @@ -66,6 +66,7 @@ public class RSTestCore { unitTests.add(new UT_kernel3d(this, mCtx)); unitTests.add(new UT_kernel2d_oldstyle(this, mCtx)); unitTests.add(new UT_ctxt_default(this, mCtx)); + unitTests.add(new UT_blur_validation(this, mCtx)); unitTests.add(new UT_bug_char(this, mCtx)); unitTests.add(new UT_clamp(this, mCtx)); unitTests.add(new UT_clamp_relaxed(this, mCtx)); diff --git a/tests/java_api/RsTest/src/com/android/rs/test/UT_blur_validation.java b/tests/java_api/RsTest/src/com/android/rs/test/UT_blur_validation.java new file mode 100644 index 00000000..c9f92e23 --- /dev/null +++ b/tests/java_api/RsTest/src/com/android/rs/test/UT_blur_validation.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2017 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 com.android.rs.test; + +import android.content.Context; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.RSIllegalArgumentException; +import android.renderscript.ScriptIntrinsicBlur; +import android.renderscript.Type; +import android.util.Log; + +// Tests that ScriptIntrinsicBlur properly throws exception if input or output +// are set to 1D Allocations. +public class UT_blur_validation extends UnitTest { + private static final String TAG = "ScriptIntrinsicBlur validation"; + private RenderScript RS; + private Allocation input1D, output1D; + private Allocation input2D, output2D; + private ScriptIntrinsicBlur scriptBlur; + + protected UT_blur_validation(RSTestCore rstc, Context ctx) { + super(rstc, TAG, ctx); + } + + private void cleanup() { + RS.finish(); + input1D.destroy(); + input2D.destroy(); + output1D.destroy(); + output2D.destroy(); + scriptBlur.destroy(); + RS.destroy(); + } + + public void run() { + RS = RenderScript.create(mCtx); + + final int width = 100; + final int height = 100; + + input1D = Allocation.createSized(RS, + Element.U8(RS), + width * height, + Allocation.USAGE_SCRIPT); + + output1D = Allocation.createTyped(RS, input1D.getType()); + + Type.Builder typeBuilder = new Type.Builder(RS, Element.U8(RS)); + typeBuilder.setX(width); + typeBuilder.setY(height); + Type ty = typeBuilder.create(); + + input2D = Allocation.createTyped(RS, ty); + output2D = Allocation.createTyped(RS, ty); + + scriptBlur = ScriptIntrinsicBlur.create(RS, Element.U8(RS)); + + scriptBlur.setRadius(25f); + boolean failed = false; + try { + scriptBlur.setInput(input1D); + } catch (RSIllegalArgumentException e) { + scriptBlur.setInput(input2D); + try { + scriptBlur.forEach(output1D); + } catch (RSIllegalArgumentException e1) { + scriptBlur.forEach(output2D); + cleanup(); + passTest(); + return; + } + Log.e(TAG, "setting 1d output does not trigger exception"); + cleanup(); + failTest(); + return; + } + + Log.e(TAG, "setting 1d input does not trigger exception"); + cleanup(); + failTest(); + } +} |