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 17#include "shared.rsh" 18#include "rs_graphics.rsh" 19 20rs_element simpleElem; 21rs_element complexElem; 22typedef struct ComplexStruct { 23 float subElem0; 24 float subElem1; 25 int subElem2; 26 float arrayElem0[2]; 27 int arrayElem1[5]; 28 char subElem3; 29 float subElem4; 30 float2 subElem5; 31 float3 subElem6; 32 float4 subElem_7; 33} ComplexStruct_t; 34 35ComplexStruct_t *complexStruct; 36 37static const char *subElemNames[] = { 38 "subElem0", 39 "subElem1", 40 "subElem2", 41 "arrayElem0", 42 "arrayElem1", 43 "subElem3", 44 "subElem4", 45 "subElem5", 46 "subElem6", 47 "subElem_7", 48}; 49 50static uint32_t subElemNamesSizes[] = { 51 8, 52 8, 53 8, 54 10, 55 10, 56 8, 57 8, 58 8, 59 8, 60 9, 61}; 62 63static uint32_t subElemArraySizes[] = { 64 1, 65 1, 66 1, 67 2, 68 5, 69 1, 70 1, 71 1, 72 1, 73 1, 74}; 75 76static bool equals(const char *name0, const char * name1, uint32_t len) { 77 for (uint32_t i = 0; i < len; i ++) { 78 if (name0[i] != name1[i]) { 79 return false; 80 } 81 } 82 return true; 83} 84 85static bool test_element_getters() { 86 bool failed = false; 87 88 uint32_t subElemOffsets[10]; 89 uint32_t index = 0; 90 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem0 - (uint32_t)complexStruct; 91 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem1 - (uint32_t)complexStruct; 92 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem2 - (uint32_t)complexStruct; 93 subElemOffsets[index++] = (uint32_t)&complexStruct->arrayElem0 - (uint32_t)complexStruct; 94 subElemOffsets[index++] = (uint32_t)&complexStruct->arrayElem1 - (uint32_t)complexStruct; 95 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem3 - (uint32_t)complexStruct; 96 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem4 - (uint32_t)complexStruct; 97 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem5 - (uint32_t)complexStruct; 98 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem6 - (uint32_t)complexStruct; 99 subElemOffsets[index++] = (uint32_t)&complexStruct->subElem_7 - (uint32_t)complexStruct; 100 101 uint32_t subElemCount = rsElementGetSubElementCount(simpleElem); 102 _RS_ASSERT(subElemCount == 0); 103 _RS_ASSERT(rsElementGetDataKind(simpleElem) == RS_KIND_USER); 104 _RS_ASSERT(rsElementGetDataType(simpleElem) == RS_TYPE_FLOAT_32); 105 _RS_ASSERT(rsElementGetVectorSize(simpleElem) == 3); 106 107 subElemCount = rsElementGetSubElementCount(complexElem); 108 _RS_ASSERT(subElemCount == 10); 109 _RS_ASSERT(rsElementGetDataKind(complexElem) == RS_KIND_USER); 110 _RS_ASSERT(rsElementGetDataType(complexElem) == RS_TYPE_NONE); 111 _RS_ASSERT(rsElementGetVectorSize(complexElem) == 1); 112 _RS_ASSERT(rsElementGetBytesSize(complexElem) == sizeof(*complexStruct)); 113 114 char buffer[64]; 115 for (uint32_t i = 0; i < subElemCount; i ++) { 116 rs_element subElem = rsElementGetSubElement(complexElem, i); 117 _RS_ASSERT(rsIsObject(subElem)); 118 119 _RS_ASSERT(rsElementGetSubElementNameLength(complexElem, i) == subElemNamesSizes[i] + 1); 120 121 uint32_t written = rsElementGetSubElementName(complexElem, i, buffer, 64); 122 _RS_ASSERT(written == subElemNamesSizes[i]); 123 _RS_ASSERT(equals(buffer, subElemNames[i], written)); 124 125 _RS_ASSERT(rsElementGetSubElementArraySize(complexElem, i) == subElemArraySizes[i]); 126 _RS_ASSERT(rsElementGetSubElementOffsetBytes(complexElem, i) == subElemOffsets[i]); 127 } 128 129 // Tests error checking 130 rs_element subElem = rsElementGetSubElement(complexElem, subElemCount); 131 _RS_ASSERT(!rsIsObject(subElem)); 132 133 _RS_ASSERT(rsElementGetSubElementNameLength(complexElem, subElemCount) == 0); 134 135 _RS_ASSERT(rsElementGetSubElementName(complexElem, subElemCount, buffer, 64) == 0); 136 _RS_ASSERT(rsElementGetSubElementName(complexElem, 0, NULL, 64) == 0); 137 _RS_ASSERT(rsElementGetSubElementName(complexElem, 0, buffer, 0) == 0); 138 uint32_t written = rsElementGetSubElementName(complexElem, 0, buffer, 5); 139 _RS_ASSERT(written == 4); 140 _RS_ASSERT(buffer[4] == '\0'); 141 142 _RS_ASSERT(rsElementGetSubElementArraySize(complexElem, subElemCount) == 0); 143 _RS_ASSERT(rsElementGetSubElementOffsetBytes(complexElem, subElemCount) == 0); 144 145 if (failed) { 146 rsDebug("test_element_getters FAILED", 0); 147 } 148 else { 149 rsDebug("test_element_getters PASSED", 0); 150 } 151 152 return failed; 153} 154 155void element_test() { 156 bool failed = false; 157 failed |= test_element_getters(); 158 159 if (failed) { 160 rsSendToClientBlocking(RS_MSG_TEST_FAILED); 161 } 162 else { 163 rsSendToClientBlocking(RS_MSG_TEST_PASSED); 164 } 165} 166 167