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 
17 package android.renderscript.cts;
18 
19 import android.content.Context;
20 import android.renderscript.RenderScript;
21 import java.util.Random;
22 
23 public class StructFieldTest extends RSBaseCompute {
24     private Random r;
25 
26     @Override
setUp()27     protected void setUp() throws Exception {
28         super.setUp();
29         r = new Random(0);
30     }
31 
makeInnerOne()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 
makeInnerTwo()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 
testStructField()47     public void testStructField() {
48         ScriptC_struct_field s = new ScriptC_struct_field(mRS);
49 
50         ScriptField_Outer.Item outer = new ScriptField_Outer.Item();
51         outer.innerOneA = makeInnerOne();
52         outer.l = r.nextLong();
53         outer.innerOneB = makeInnerOne();
54         for (int i = 0; i < 3; ++i)
55             outer.innerTwo3[i] = makeInnerTwo();
56         for (int i = 0; i < 2; ++i)
57             outer.innerTwo2[i] = makeInnerTwo();
58         for (int i = 0; i < 4; ++i)
59             outer.innerOne4[i] = makeInnerOne();
60         outer.innerOneC = makeInnerOne();
61         s.set_outer(outer);
62 
63         s.invoke_checkOuter(
64             outer.innerOneA.x, outer.innerOneA.y, outer.innerOneA.f,
65             outer.l,
66             outer.innerOneB.x, outer.innerOneB.y, outer.innerOneB.f,
67             outer.innerTwo3[0].z,
68             outer.innerTwo3[0].innerOne.x, outer.innerTwo3[0].innerOne.y, outer.innerTwo3[0].innerOne.f,
69             outer.innerTwo3[1].z,
70             outer.innerTwo3[1].innerOne.x, outer.innerTwo3[1].innerOne.y, outer.innerTwo3[1].innerOne.f,
71             outer.innerTwo3[2].z,
72             outer.innerTwo3[2].innerOne.x, outer.innerTwo3[2].innerOne.y, outer.innerTwo3[2].innerOne.f,
73             outer.innerTwo2[0].z,
74             outer.innerTwo2[0].innerOne.x, outer.innerTwo2[0].innerOne.y, outer.innerTwo2[0].innerOne.f,
75             outer.innerTwo2[1].z,
76             outer.innerTwo2[1].innerOne.x, outer.innerTwo2[1].innerOne.y, outer.innerTwo2[1].innerOne.f,
77             outer.innerOne4[0].x, outer.innerOne4[0].y, outer.innerOne4[0].f,
78             outer.innerOne4[1].x, outer.innerOne4[1].y, outer.innerOne4[1].f,
79             outer.innerOne4[2].x, outer.innerOne4[2].y, outer.innerOne4[2].f,
80             outer.innerOne4[3].x, outer.innerOne4[3].y, outer.innerOne4[3].f,
81             outer.innerOneC.x, outer.innerOneC.y, outer.innerOneC.f);
82 
83         mRS.finish();
84         waitForMessage();
85         checkForErrors();
86     }
87 }
88