1648a1c137663ef7207684d0d7009dd5518942111Stephen Hines/*
2648a1c137663ef7207684d0d7009dd5518942111Stephen Hines * Copyright (C) 2011-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_noroot extends UnitTest {
24648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    private Resources mRes;
25648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    private Allocation A;
26648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
27648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    protected UT_noroot(RSTestCore rstc, Resources res, Context ctx) {
28648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        super(rstc, "ForEach (no root)", ctx);
29648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        mRes = res;
30648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    }
31648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
32648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    private void initializeGlobals(RenderScript RS, ScriptC_noroot s) {
33648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
34648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        int X = 5;
35648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        int Y = 7;
36648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.set_dimX(X);
37648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.set_dimY(Y);
38648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        typeBuilder.setX(X).setY(Y);
39648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        A = Allocation.createTyped(RS, typeBuilder.create());
40648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.set_aRaw(A);
41648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
42648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        return;
43648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    }
44648a1c137663ef7207684d0d7009dd5518942111Stephen Hines
45648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    public void run() {
46648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        RenderScript pRS = RenderScript.create(mCtx);
47648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        ScriptC_noroot s = new ScriptC_noroot(pRS);
48648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.setMessageHandler(mRsMessage);
49648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        initializeGlobals(pRS, s);
50648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.forEach_foo(A, A);
51648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.invoke_verify_foo();
52648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        s.invoke_noroot_test();
53648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.finish();
54648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        waitForMessage();
55648a1c137663ef7207684d0d7009dd5518942111Stephen Hines        pRS.destroy();
56648a1c137663ef7207684d0d7009dd5518942111Stephen Hines    }
57648a1c137663ef7207684d0d7009dd5518942111Stephen Hines}
58