1 // This file is automatically generated from 2 // frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py 3 /* 4 * Copyright (C) 2017 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7 * in compliance with the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the License 12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 13 * or implied. See the License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.rs.unittest; 18 19 import android.content.Context; 20 import android.support.v8.renderscript.Allocation; 21 import android.support.v8.renderscript.Element; 22 import android.support.v8.renderscript.RenderScript; 23 import android.support.v8.renderscript.RSIllegalArgumentException; 24 import android.support.v8.renderscript.ScriptIntrinsicBlur; 25 import android.support.v8.renderscript.Type; 26 import android.util.Log; 27 28 // Tests that ScriptIntrinsicBlur properly throws exception if input or output 29 // are set to 1D Allocations. 30 public class UT_blur_validation extends UnitTest { 31 private static final String TAG = "ScriptIntrinsicBlur validation"; 32 private RenderScript RS; 33 private Allocation input1D, output1D; 34 private Allocation input2D, output2D; 35 private ScriptIntrinsicBlur scriptBlur; 36 37 public UT_blur_validation(Context ctx) { 38 super(TAG, ctx); 39 } 40 41 private void cleanup() { 42 RS.finish(); 43 input1D.destroy(); 44 input2D.destroy(); 45 output1D.destroy(); 46 output2D.destroy(); 47 scriptBlur.destroy(); 48 RS.destroy(); 49 } 50 51 public void run() { 52 RS = createRenderScript(false); 53 54 final int width = 100; 55 final int height = 100; 56 57 input1D = Allocation.createSized(RS, 58 Element.U8(RS), 59 width * height, 60 Allocation.USAGE_SCRIPT); 61 62 output1D = Allocation.createTyped(RS, input1D.getType()); 63 64 Type.Builder typeBuilder = new Type.Builder(RS, Element.U8(RS)); 65 typeBuilder.setX(width); 66 typeBuilder.setY(height); 67 Type ty = typeBuilder.create(); 68 69 input2D = Allocation.createTyped(RS, ty); 70 output2D = Allocation.createTyped(RS, ty); 71 72 scriptBlur = ScriptIntrinsicBlur.create(RS, Element.U8(RS)); 73 74 scriptBlur.setRadius(25f); 75 boolean failed = false; 76 try { 77 scriptBlur.setInput(input1D); 78 } catch (RSIllegalArgumentException e) { 79 scriptBlur.setInput(input2D); 80 try { 81 scriptBlur.forEach(output1D); 82 } catch (RSIllegalArgumentException e1) { 83 scriptBlur.forEach(output2D); 84 cleanup(); 85 passTest(); 86 return; 87 } 88 Log.e(TAG, "setting 1d output does not trigger exception"); 89 cleanup(); 90 failTest(); 91 return; 92 } 93 94 Log.e(TAG, "setting 1d input does not trigger exception"); 95 cleanup(); 96 failTest(); 97 } 98 } 99