1/* 2 * Copyright (C) 2013 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_compatlegacy; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.support.v8.renderscript.*; 22 23public class UT_element extends UnitTest { 24 private Resources mRes; 25 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 protected UT_element(RSTestCore rstc, Resources res, Context ctx) { 69 super(rstc, "Element", ctx); 70 mRes = res; 71 } 72 73 private void initializeGlobals(RenderScript RS, ScriptC_element s) { 74 simpleElem = Element.F32_3(RS); 75 complexElem = ScriptField_ComplexStruct.createElement(RS); 76 s.set_simpleElem(simpleElem); 77 s.set_complexElem(complexElem); 78 79 ScriptField_ComplexStruct data = new ScriptField_ComplexStruct(RS, 1); 80 s.bind_complexStruct(data); 81 } 82 83 private void testScriptSide(RenderScript pRS) { 84 ScriptC_element s = new ScriptC_element(pRS); 85 pRS.setMessageHandler(mRsMessage); 86 initializeGlobals(pRS, s); 87 s.invoke_element_test(); 88 pRS.finish(); 89 waitForMessage(); 90 } 91 92 private void testJavaSide(RenderScript RS) { 93 94 int subElemCount = simpleElem.getSubElementCount(); 95 _RS_ASSERT("subElemCount == 0", subElemCount == 0); 96 97 subElemCount = complexElem.getSubElementCount(); 98 _RS_ASSERT("subElemCount == 10", subElemCount == 10); 99 _RS_ASSERT("complexElem.getSizeBytes() == ScriptField_ComplexStruct.Item.sizeof", 100 complexElem.getBytesSize() == ScriptField_ComplexStruct.Item.sizeof); 101 102 for (int i = 0; i < subElemCount; i ++) { 103 _RS_ASSERT("complexElem.getSubElement(i) != null", 104 complexElem.getSubElement(i) != null); 105 _RS_ASSERT("complexElem.getSubElementName(i).equals(subElemNames[i])", 106 complexElem.getSubElementName(i).equals(subElemNames[i])); 107 _RS_ASSERT("complexElem.getSubElementArraySize(i) == subElemArraySizes[i]", 108 complexElem.getSubElementArraySize(i) == subElemArraySizes[i]); 109 _RS_ASSERT("complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]", 110 complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]); 111 } 112 } 113 114 public void run() { 115 RenderScript pRS = RenderScript.create(mCtx); 116 testScriptSide(pRS); 117 testJavaSide(pRS); 118 passTest(); 119 pRS.destroy(); 120 } 121} 122