1648a1c137663ef7207684d0d7009dd5518942111Stephen Hines/*
2648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * Copyright (C) 2013 The Android Open Source Project
3648a1c137663ef7207684d0d7009dd5518942111Stephen Hines *
4648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * Licensed under the Apache License, Version 2.0 (the "License");
5648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * you may not use this file except in compliance with the License.
6648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * You may obtain a copy of the License at
7648a1c137663ef7207684d0d7009dd5518942111Stephen Hines *
8648a1c137663ef7207684d0d7009dd5518942111Stephen Hines *      http://www.apache.org/licenses/LICENSE-2.0
9648a1c137663ef7207684d0d7009dd5518942111Stephen Hines *
10648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * Unless required by applicable law or agreed to in writing, software
11648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * distributed under the License is distributed on an "AS IS" BASIS,
12648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * See the License for the specific language governing permissions and
14648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * limitations under the License.
15648a1c137663ef7207684d0d7009dd5518942111Stephen Hines */
16648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
17648a1c137663ef7207684d0d7009dd5518942111Stephen Hinespackage com.android.rs.test_compatlegacy;
18648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
19648a1c137663ef7207684d0d7009dd5518942111Stephen Hinesimport android.content.Context;
20648a1c137663ef7207684d0d7009dd5518942111Stephen Hinesimport android.content.res.Resources;
21648a1c137663ef7207684d0d7009dd5518942111Stephen Hinesimport android.support.v8.renderscript.*;
22648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
23648a1c137663ef7207684d0d7009dd5518942111Stephen Hinespublic class UT_array_alloc extends UnitTest {
24648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    private Resources mRes;
25648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
26648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    protected UT_array_alloc(RSTestCore rstc, Resources res, Context ctx) {
27648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        super(rstc, "Array Allocation", ctx);
28648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        mRes = res;
29648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    }
30648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
31648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    public void run() {
32648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        RenderScript pRS = RenderScript.create(mCtx);
33648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        ScriptC_array_alloc s = new ScriptC_array_alloc(pRS);
34648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.setMessageHandler(mRsMessage);
35648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
36648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        int dimX = s.get_dimX();
37648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        Allocation[] Arr = new Allocation[dimX];
38648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        Type.Builder typeBuilder = new Type.Builder(pRS, Element.I32(pRS));
39648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        Type T = typeBuilder.setX(1).create();
40648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        for (int i = 0; i < dimX; i++) {
41648a1c137663ef7207684d0d7009dd5518942111Stephen Hines            Allocation A = Allocation.createTyped(pRS, T);
42648a1c137663ef7207684d0d7009dd5518942111Stephen Hines            Arr[i] = A;
43648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        }
44648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.set_a(Arr);
45648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
46648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.invoke_array_alloc_test();
47648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.finish();
48648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        waitForMessage();
49648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.destroy();
50648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        passTest();
51648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    }
52648a1c137663ef7207684d0d7009dd5518942111Stephen Hines}
53