| /* |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include "shared.rsh" |
| |
| static const int dimX = 1024; |
| static const int dimY = 768; |
| static const int dimZ = 0; |
| |
| // Tests an object returned via a local variable is valid to the caller. |
| static rs_allocation test1() { |
| rs_allocation retValue = {}; |
| rs_element element = rsCreateVectorElement(RS_TYPE_FLOAT_32, 4); |
| if (!rsIsObject(element)) { |
| rsDebug("element is null.", element.p); |
| return retValue; |
| } |
| |
| rs_type type = rsCreateType(element, dimX, dimY, dimZ); |
| if (!rsIsObject(type)) { |
| rsDebug("type is null.", type.p); |
| return retValue; |
| } |
| |
| retValue = rsCreateAllocation(type); |
| if (!rsIsObject(retValue)) { |
| rsDebug("rs_allocation retValue is null.", retValue.p); |
| } |
| |
| return retValue; |
| } |
| |
| // Tests an object returned via an expression is valid to the caller. |
| static rs_allocation test2() { |
| rs_allocation empty = {}; |
| rs_element element = rsCreateVectorElement(RS_TYPE_FLOAT_32, 4); |
| if (!rsIsObject(element)) { |
| rsDebug("element is null.", element.p); |
| return empty; |
| } |
| |
| rs_type type = rsCreateType(element, dimX, dimY, dimZ); |
| if (!rsIsObject(type)) { |
| rsDebug("type is null.", type.p); |
| return empty; |
| } |
| |
| return rsCreateAllocation(type); |
| } |
| |
| static struct testS { |
| rs_allocation (*fp)(); |
| const char* name; |
| } tests[] = { |
| { test1, "test1" }, |
| { test2, "test2" }, |
| { NULL, NULL } |
| }; |
| |
| void entrypoint() { |
| int failed = 0; |
| |
| for (int i = 0; tests[i].fp; i++) { |
| rsDebug(tests[i].name, 0); |
| rs_allocation allocation = tests[i].fp(); |
| if (!rsIsObject(allocation)) { |
| failed++; |
| rsDebug("failed.", 0); |
| } else { |
| rsDebug("passed.", 0); |
| } |
| } |
| |
| if (failed) { |
| rsDebug("Reference counting tests failed: ", failed); |
| rsSendToClientBlocking(RS_MSG_TEST_FAILED); |
| } else { |
| rsDebug("All reference counting tests passed.", 0); |
| rsSendToClientBlocking(RS_MSG_TEST_PASSED); |
| } |
| } |