1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.renderscript.cts; 18 19 import android.renderscript.Allocation; 20 import android.renderscript.Element; 21 import android.renderscript.Type; 22 import android.renderscript.Sampler; 23 import android.renderscript.Script; 24 import android.renderscript.RSRuntimeException; 25 26 public class ClearObjectTest extends RSBaseCompute { 27 int ObjectNum = 1; 28 static final int TEST_ID_ELEMENT = 0; 29 static final int TEST_ID_TYPE = 1; 30 static final int TEST_ID_ALLOCATION = 2; 31 static final int TEST_ID_SAMPLER = 3; 32 static final int TEST_ID_SCRIPT = 4; 33 private ScriptC_clear_object ms_clear; 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 ms_clear = new ScriptC_clear_object(mRS); 39 } 40 41 @Override 42 public void forEach(int testId, Allocation mIn, Allocation mOut) throws RSRuntimeException { 43 switch (testId) { 44 case TEST_ID_ELEMENT: 45 ms_clear.forEach_clear_element(mOut); 46 break; 47 case TEST_ID_TYPE: 48 ms_clear.forEach_clear_type(mOut); 49 break; 50 case TEST_ID_ALLOCATION: 51 ms_clear.forEach_clear_allocation(mOut); 52 break; 53 case TEST_ID_SAMPLER: 54 ms_clear.forEach_clear_sampler(mOut); 55 break; 56 case TEST_ID_SCRIPT: 57 ms_clear.forEach_clear_script(mOut); 58 break; 59 } 60 } 61 62 public void testClearObjectElement() { 63 Element element = Element.BOOLEAN(mRS); 64 Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 65 Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 66 ms_clear.set_element(element); 67 try { 68 forEach(TEST_ID_ELEMENT, mIn, mOut); 69 } catch (RSRuntimeException e) { 70 } 71 int[] tmpArray = new int[ObjectNum]; 72 mOut.copyTo(tmpArray); 73 74 for(int i = 0; i < ObjectNum; i++) 75 assertEquals(tmpArray[i], 1); 76 77 mIn.destroy(); 78 mOut.destroy(); 79 } 80 81 public void testclearObjectType() { 82 Type type= new Type.Builder(mRS, Element.I8(mRS)).setX(1).create(); 83 Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 84 Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 85 ms_clear.set_type(type); 86 87 try { 88 forEach(TEST_ID_TYPE, mIn, mOut); 89 } catch (RSRuntimeException e) { 90 } 91 int[] tmpArray = new int[ObjectNum]; 92 mOut.copyTo(tmpArray); 93 94 for(int i = 0; i < ObjectNum; i++) 95 assertEquals(tmpArray[i], 1); 96 97 mIn.destroy(); 98 mOut.destroy(); 99 } 100 101 public void testclearObjectAllocation() { 102 Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 103 Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 104 Allocation allocation = Allocation.createTyped(mRS, mIn.getType()); 105 ms_clear.set_allocation(allocation); 106 try { 107 forEach(TEST_ID_ALLOCATION, mIn, mOut); 108 } catch (RSRuntimeException e) { 109 } 110 int[] tmpArray = new int[ObjectNum]; 111 mOut.copyTo(tmpArray); 112 113 for(int i = 0; i < ObjectNum; i++) 114 assertEquals(tmpArray[i], 1); 115 116 mIn.destroy(); 117 mOut.destroy(); 118 allocation.destroy(); 119 } 120 121 public void testclearObjectSampler() { 122 Sampler sampler = new Sampler.Builder(mRS).create(); 123 Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 124 Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 125 ms_clear.set_sampler(sampler); 126 try { 127 forEach(TEST_ID_SAMPLER, mIn, mOut); 128 } catch (RSRuntimeException e) { 129 } 130 int[] tmpArray = new int[ObjectNum]; 131 mOut.copyTo(tmpArray); 132 133 for(int i = 0; i < ObjectNum; i++) 134 assertEquals(tmpArray[i], 1); 135 136 mIn.destroy(); 137 mOut.destroy(); 138 } 139 140 public void testclearObjectScript() { 141 Script script = new ScriptC_clear_object(mRS); 142 Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 143 Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 144 ms_clear.set_script(script); 145 try { 146 forEach(TEST_ID_SCRIPT, mIn, mOut); 147 } catch (RSRuntimeException e) { 148 } 149 int[] tmpArray = new int[ObjectNum]; 150 mOut.copyTo(tmpArray); 151 152 for(int i = 0; i < ObjectNum; i++) 153 assertEquals(tmpArray[i], 1); 154 155 mIn.destroy(); 156 mOut.destroy(); 157 } 158 } 159