1/* 2 * Copyright (C) 2016 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 17package com.android.rs.test; 18 19import android.content.Context; 20import android.renderscript.RenderScript; 21import java.util.Random; 22 23public class UT_struct_field extends UnitTest { 24 25 Random r; 26 27 protected UT_struct_field(RSTestCore rstc, Context ctx) { 28 super(rstc, "Structure-typed Fields", ctx); 29 r = new Random(0); 30 } 31 32 private ScriptField_InnerOne.Item makeInnerOne() { 33 ScriptField_InnerOne.Item innerOne = new ScriptField_InnerOne.Item(); 34 innerOne.x = r.nextInt(); 35 innerOne.y = r.nextInt(); 36 innerOne.f = r.nextFloat(); 37 return innerOne; 38 } 39 40 private ScriptField_InnerTwo.Item makeInnerTwo() { 41 ScriptField_InnerTwo.Item innerTwo = new ScriptField_InnerTwo.Item(); 42 innerTwo.z = (byte)r.nextInt(); 43 innerTwo.innerOne = makeInnerOne(); 44 return innerTwo; 45 } 46 47 public void run() { 48 RenderScript pRS = RenderScript.create(mCtx); 49 ScriptC_struct_field s = new ScriptC_struct_field(pRS); 50 pRS.setMessageHandler(mRsMessage); 51 52 ScriptField_Outer.Item outer = new ScriptField_Outer.Item(); 53 outer.innerOneA = makeInnerOne(); 54 outer.l = r.nextLong(); 55 outer.innerOneB = makeInnerOne(); 56 for (int i = 0; i < 3; ++i) 57 outer.innerTwo3[i] = makeInnerTwo(); 58 for (int i = 0; i < 2; ++i) 59 outer.innerTwo2[i] = makeInnerTwo(); 60 for (int i = 0; i < 4; ++i) 61 outer.innerOne4[i] = makeInnerOne(); 62 outer.innerOneC = makeInnerOne(); 63 s.set_outer(outer); 64 65 s.invoke_checkOuter( 66 outer.innerOneA.x, outer.innerOneA.y, outer.innerOneA.f, 67 outer.l, 68 outer.innerOneB.x, outer.innerOneB.y, outer.innerOneB.f, 69 outer.innerTwo3[0].z, 70 outer.innerTwo3[0].innerOne.x, outer.innerTwo3[0].innerOne.y, outer.innerTwo3[0].innerOne.f, 71 outer.innerTwo3[1].z, 72 outer.innerTwo3[1].innerOne.x, outer.innerTwo3[1].innerOne.y, outer.innerTwo3[1].innerOne.f, 73 outer.innerTwo3[2].z, 74 outer.innerTwo3[2].innerOne.x, outer.innerTwo3[2].innerOne.y, outer.innerTwo3[2].innerOne.f, 75 outer.innerTwo2[0].z, 76 outer.innerTwo2[0].innerOne.x, outer.innerTwo2[0].innerOne.y, outer.innerTwo2[0].innerOne.f, 77 outer.innerTwo2[1].z, 78 outer.innerTwo2[1].innerOne.x, outer.innerTwo2[1].innerOne.y, outer.innerTwo2[1].innerOne.f, 79 outer.innerOne4[0].x, outer.innerOne4[0].y, outer.innerOne4[0].f, 80 outer.innerOne4[1].x, outer.innerOne4[1].y, outer.innerOne4[1].f, 81 outer.innerOne4[2].x, outer.innerOne4[2].y, outer.innerOne4[2].f, 82 outer.innerOne4[3].x, outer.innerOne4[3].y, outer.innerOne4[3].f, 83 outer.innerOneC.x, outer.innerOneC.y, outer.innerOneC.f); 84 85 pRS.finish(); 86 waitForMessage(); 87 pRS.destroy(); 88 } 89} 90