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.*; 20 import android.renderscript.Allocation; 21 import android.renderscript.Element; 22 import android.util.Log; 23 import android.view.SurfaceHolder; 24 25 import junit.framework.Assert; 26 27 public class IsObjectTest extends RSBaseCompute { 28 int ObjectNum = 1; 29 private Allocation mIn; 30 private Allocation mOut; 31 32 Element element; 33 Type type; 34 Allocation allocation; 35 Sampler sampler; 36 Script script; 37 38 private ScriptC_is_object ms_is_object; 39 40 @Override 41 protected void setUp() throws Exception { 42 super.setUp(); 43 44 element = Element.BOOLEAN(mRS); 45 46 type = new Type.Builder(mRS, Element.I8(mRS)).setX(1).create(); 47 allocation = Allocation.createTyped(mRS, type); 48 sampler = new Sampler.Builder(mRS).create(); 49 script = new ScriptC_is_object(mRS); 50 ms_is_object = new ScriptC_is_object(mRS); 51 } 52 53 @Override 54 protected void tearDown() throws Exception { 55 if (mIn != null) { 56 mIn.destroy(); 57 } 58 if (mOut != null) { 59 mOut.destroy(); 60 } 61 allocation.destroy(); 62 ms_is_object.destroy(); 63 super.tearDown(); 64 } 65 66 /** 67 * is object test 68 */ 69 public void testIsObjectElement() { 70 ScriptField__object_element_input filed = new ScriptField__object_element_input( 71 mRS, 1); 72 ScriptField__object_element_input.Item mItem = 73 new ScriptField__object_element_input.Item(); 74 mItem.element = element; 75 filed.set(mItem, 0, true); 76 77 mIn = filed.getAllocation(); 78 mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 79 try { 80 ms_is_object.forEach_is_object_element(mIn, mOut); 81 } catch (RSRuntimeException e) { 82 Log.i("compare", "rsIsObject root fail"); 83 } 84 int[] tmpArray = new int[ObjectNum]; 85 mOut.copyTo(tmpArray); 86 87 Assert.assertTrue("rsIsObject element test fail: " + "Expect 1;value " 88 + tmpArray[0], tmpArray[0] == 1); 89 } 90 91 public void testIsObjectType() { 92 ScriptField__object_type_input filed = new ScriptField__object_type_input(mRS, 1); 93 ScriptField__object_type_input.Item mItem = new ScriptField__object_type_input.Item(); 94 mItem.type = type; 95 filed.set(mItem, 0, true); 96 97 mIn = filed.getAllocation(); 98 mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 99 100 try { 101 ms_is_object.forEach_is_object_type(mIn, mOut); 102 } catch (RSRuntimeException e) { 103 Log.i("compare", "rsIsObject root fail"); 104 } 105 int[] tmpArray = new int[ObjectNum]; 106 mOut.copyTo(tmpArray); 107 108 Assert.assertTrue( 109 "rsIsObject type test fail: " + "Expect 1;value " + tmpArray[0], 110 tmpArray[0] == 1); 111 } 112 113 public void testIsObjectAllocation() { 114 ScriptField__object_allocation_input filed = new ScriptField__object_allocation_input( 115 mRS, 1); 116 ScriptField__object_allocation_input.Item mItem = 117 new ScriptField__object_allocation_input.Item(); 118 mItem.allocation = allocation; 119 filed.set(mItem, 0, true); 120 121 mIn = filed.getAllocation(); 122 mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 123 124 try { 125 ms_is_object.forEach_is_object_allocation(mIn, mOut); 126 } catch (RSRuntimeException e) { 127 Log.i("compare", "rsIsObject root fail"); 128 } 129 int[] tmpArray = new int[ObjectNum]; 130 mOut.copyTo(tmpArray); 131 132 Assert.assertTrue("rsIsObject allocation test fail: " + "Expect 1;value " 133 + tmpArray[0], tmpArray[0] == 1); 134 } 135 136 public void testIsObjectSampler() { 137 ScriptField__object_sampler_input filed = new ScriptField__object_sampler_input( 138 mRS, 1); 139 ScriptField__object_sampler_input.Item mItem = 140 new ScriptField__object_sampler_input.Item(); 141 mItem.sampler = sampler; 142 filed.set(mItem, 0, true); 143 144 mIn = filed.getAllocation(); 145 mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 146 147 try { 148 ms_is_object.forEach_is_object_sampler(mIn, mOut); 149 } catch (RSRuntimeException e) { 150 Log.i("compare", "rsIsObject root fail"); 151 } 152 int[] tmpArray = new int[ObjectNum]; 153 mOut.copyTo(tmpArray); 154 155 Assert.assertTrue("rsIsObject sampler test fail: " + "Expect 1;value " 156 + tmpArray[0], tmpArray[0] == 1); 157 } 158 159 public void testIsObjectScript() { 160 ScriptField__object_script_input filed = new ScriptField__object_script_input( 161 mRS, 1); 162 ScriptField__object_script_input.Item mItem = new ScriptField__object_script_input.Item(); 163 mItem.script = script; 164 filed.set(mItem, 0, true); 165 166 mIn = filed.getAllocation(); 167 mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum); 168 169 try { 170 ms_is_object.forEach_is_object_script(mIn, mOut); 171 } catch (RSRuntimeException e) { 172 Log.i("compare", "rsIsObject root fail"); 173 } 174 int[] tmpArray = new int[ObjectNum]; 175 mOut.copyTo(tmpArray); 176 177 Assert.assertTrue("rsIsObject script test fail: " + "Expect 1;value " 178 + tmpArray[0], tmpArray[0] == 1); 179 } 180 } 181