1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package com.android.rs.unittest;
20
21import android.content.Context;
22import android.support.v8.renderscript.Element;
23import android.support.v8.renderscript.Element.DataKind;
24import android.support.v8.renderscript.Element.DataType;
25import android.support.v8.renderscript.RenderScript;
26
27public class UT_element extends UnitTest {
28    Element simpleElem;
29    Element complexElem;
30
31    final String subElemNames[] = {
32            "subElem0",
33            "subElem1",
34            "subElem2",
35            "arrayElem0",
36            "arrayElem1",
37            "subElem3",
38            "subElem4",
39            "subElem5",
40            "subElem6",
41            "subElem_7",
42    };
43
44    final int subElemArraySizes[] = {
45            1,
46            1,
47            1,
48            2,
49            5,
50            1,
51            1,
52            1,
53            1,
54            1,
55    };
56
57    final int subElemOffsets[] = {
58            0,
59            4,
60            8,
61            12,
62            20,
63            40,
64            44,
65            48,
66            64,
67            80,
68    };
69
70    public UT_element(Context ctx) {
71        super("Element", ctx);
72    }
73
74    private void initializeGlobals(RenderScript RS, ScriptC_element s) {
75        simpleElem = Element.F32_3(RS);
76        complexElem = ScriptField_ComplexStruct.createElement(RS);
77        s.set_simpleElem(simpleElem);
78        s.set_complexElem(complexElem);
79
80        ScriptField_ComplexStruct data = new ScriptField_ComplexStruct(RS, 1);
81        s.bind_complexStruct(data);
82    }
83
84    private void testScriptSide(RenderScript pRS) {
85        ScriptC_element s = new ScriptC_element(pRS);
86        initializeGlobals(pRS, s);
87        s.invoke_element_test();
88        pRS.finish();
89        s.get_complexStruct().getAllocation().destroy();
90        s.get_complexStruct().getElement().destroy();
91        s.destroy();
92    }
93
94    private void testJavaSide(RenderScript RS) {
95
96        int subElemCount = simpleElem.getSubElementCount();
97        _RS_ASSERT("subElemCount == 0", subElemCount == 0);
98        _RS_ASSERT("simpleElem.getDataKind() == USER",
99                simpleElem.getDataKind() == DataKind.USER);
100        _RS_ASSERT("simpleElem.getDataType() == FLOAT_32",
101                simpleElem.getDataType() == DataType.FLOAT_32);
102
103        subElemCount = complexElem.getSubElementCount();
104        _RS_ASSERT("subElemCount == 10", subElemCount == 10);
105        _RS_ASSERT("complexElem.getDataKind() == USER",
106                complexElem.getDataKind() == DataKind.USER);
107        _RS_ASSERT("complexElemsimpleElem.getDataType() == NONE",
108                complexElem.getDataType() == DataType.NONE);
109
110        for (int i = 0; i < subElemCount; i++) {
111            _RS_ASSERT("complexElem.getSubElement(i) != null",
112                    complexElem.getSubElement(i) != null);
113            _RS_ASSERT("complexElem.getSubElementName(i).equals(subElemNames[i])",
114                    complexElem.getSubElementName(i).equals(subElemNames[i]));
115            _RS_ASSERT("complexElem.getSubElementArraySize(i) == subElemArraySizes[i]",
116                    complexElem.getSubElementArraySize(i) == subElemArraySizes[i]);
117            _RS_ASSERT("complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]",
118                    complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]);
119        }
120    }
121
122    public void run() {
123        RenderScript pRS = createRenderScript(true);
124        testScriptSide(pRS);
125        testJavaSide(pRS);
126        passTest();
127        pRS.destroy();
128    }
129}
130