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.Allocation;
     20 import android.renderscript.Element;
     21 import android.renderscript.RSRuntimeException;
     22 import java.util.Random;
     23 
     24 public class GetAllocationTest extends RSBaseCompute {
     25 
     26     public void testGetAllocation () {
     27         Random random = new Random(0x827492ab);
     28         int[] tempArray = new int[INPUTSIZE];
     29         for (int i = 0; i < INPUTSIZE; ++i) {
     30             tempArray[i] = random.nextInt();
     31         }
     32         ScriptC_get_allocation ms =
     33                 new ScriptC_get_allocation(mRS);
     34 
     35         Allocation mTemp = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE);
     36         mTemp.copyFrom(tempArray);
     37         Allocation mOut = Allocation.createTyped(mRS, mTemp.getType());
     38 
     39         ms.bind_pointer(mTemp);
     40         ms.set_alloc_out(mOut);
     41         ms.invoke_start();
     42 
     43         int [] out = new int[INPUTSIZE];
     44         mOut.copyTo(out);
     45         for (int i = 0; i < tempArray.length; i++) {
     46             assertEquals("Incorrect value @ idx = " + i + " | ",
     47             tempArray[i],
     48             out[i]);
     49         }
     50 
     51         mTemp.destroy();
     52         mOut.destroy();
     53         ms.destroy();
     54     }
     55 
     56 }
     57