1/* 2 * Copyright (C) 2017 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.unittest; 18 19import android.content.Context; 20import android.renderscript.Element; 21import android.renderscript.Element.DataKind; 22import android.renderscript.Element.DataType; 23import android.renderscript.RenderScript; 24 25public class UT_element extends UnitTest { 26 Element simpleElem; 27 Element complexElem; 28 29 final String subElemNames[] = { 30 "subElem0", 31 "subElem1", 32 "subElem2", 33 "arrayElem0", 34 "arrayElem1", 35 "subElem3", 36 "subElem4", 37 "subElem5", 38 "subElem6", 39 "subElem_7", 40 }; 41 42 final int subElemArraySizes[] = { 43 1, 44 1, 45 1, 46 2, 47 5, 48 1, 49 1, 50 1, 51 1, 52 1, 53 }; 54 55 final int subElemOffsets[] = { 56 0, 57 4, 58 8, 59 12, 60 20, 61 40, 62 44, 63 48, 64 64, 65 80, 66 }; 67 68 public UT_element(Context ctx) { 69 super("Element", ctx); 70 } 71 72 private void initializeGlobals(RenderScript RS, ScriptC_element s) { 73 simpleElem = Element.F32_3(RS); 74 complexElem = ScriptField_ComplexStruct.createElement(RS); 75 s.set_simpleElem(simpleElem); 76 s.set_complexElem(complexElem); 77 78 ScriptField_ComplexStruct data = new ScriptField_ComplexStruct(RS, 1); 79 s.bind_complexStruct(data); 80 } 81 82 private void testScriptSide(RenderScript pRS) { 83 ScriptC_element s = new ScriptC_element(pRS); 84 initializeGlobals(pRS, s); 85 s.invoke_element_test(); 86 pRS.finish(); 87 s.get_complexStruct().getAllocation().destroy(); 88 s.get_complexStruct().getElement().destroy(); 89 s.destroy(); 90 } 91 92 private void testJavaSide(RenderScript RS) { 93 94 int subElemCount = simpleElem.getSubElementCount(); 95 _RS_ASSERT("subElemCount == 0", subElemCount == 0); 96 _RS_ASSERT("simpleElem.getDataKind() == USER", 97 simpleElem.getDataKind() == DataKind.USER); 98 _RS_ASSERT("simpleElem.getDataType() == FLOAT_32", 99 simpleElem.getDataType() == DataType.FLOAT_32); 100 101 subElemCount = complexElem.getSubElementCount(); 102 _RS_ASSERT("subElemCount == 10", subElemCount == 10); 103 _RS_ASSERT("complexElem.getDataKind() == USER", 104 complexElem.getDataKind() == DataKind.USER); 105 _RS_ASSERT("complexElemsimpleElem.getDataType() == NONE", 106 complexElem.getDataType() == DataType.NONE); 107 108 for (int i = 0; i < subElemCount; i++) { 109 _RS_ASSERT("complexElem.getSubElement(i) != null", 110 complexElem.getSubElement(i) != null); 111 _RS_ASSERT("complexElem.getSubElementName(i).equals(subElemNames[i])", 112 complexElem.getSubElementName(i).equals(subElemNames[i])); 113 _RS_ASSERT("complexElem.getSubElementArraySize(i) == subElemArraySizes[i]", 114 complexElem.getSubElementArraySize(i) == subElemArraySizes[i]); 115 _RS_ASSERT("complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]", 116 complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]); 117 } 118 } 119 120 public void run() { 121 RenderScript pRS = createRenderScript(true); 122 testScriptSide(pRS); 123 testJavaSide(pRS); 124 passTest(); 125 pRS.destroy(); 126 } 127} 128