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