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
17package com.android.rs.unittest;
18
19import android.content.Context;
20import android.renderscript.RenderScript;
21
22public class UT_array_init extends UnitTest {
23
24    public UT_array_init(Context ctx) {
25        super("Array Init", ctx);
26    }
27
28    private void checkInit(ScriptC_array_init s) {
29        float[] fa = s.get_fa();
30        _RS_ASSERT("fa[0] == 1.0", fa[0] == 1.0);
31        _RS_ASSERT("fa[1] == 9.9999f", fa[1] == 9.9999f);
32        _RS_ASSERT("fa[2] == 0", fa[2] == 0);
33        _RS_ASSERT("fa[3] == 0", fa[3] == 0);
34        _RS_ASSERT("fa.length == 4", fa.length == 4);
35
36        double[] da = s.get_da();
37        _RS_ASSERT("da[0] == 7.0", da[0] == 7.0);
38        _RS_ASSERT("da[1] == 8.88888", da[1] == 8.88888);
39        _RS_ASSERT("da.length == 2", da.length == 2);
40
41        byte[] ca = s.get_ca();
42        _RS_ASSERT("ca[0] == 'a'", ca[0] == 'a');
43        _RS_ASSERT("ca[1] == 7", ca[1] == 7);
44        _RS_ASSERT("ca[2] == 'b'", ca[2] == 'b');
45        _RS_ASSERT("ca[3] == 'c'", ca[3] == 'c');
46        _RS_ASSERT("ca.length == 4", ca.length == 4);
47
48        short[] sa = s.get_sa();
49        _RS_ASSERT("sa[0] == 1", sa[0] == 1);
50        _RS_ASSERT("sa[1] == 1", sa[1] == 1);
51        _RS_ASSERT("sa[2] == 2", sa[2] == 2);
52        _RS_ASSERT("sa[3] == 3", sa[3] == 3);
53        _RS_ASSERT("sa.length == 4", sa.length == 4);
54
55        int[] ia = s.get_ia();
56        _RS_ASSERT("ia[0] == 5", ia[0] == 5);
57        _RS_ASSERT("ia[1] == 8", ia[1] == 8);
58        _RS_ASSERT("ia[2] == 0", ia[2] == 0);
59        _RS_ASSERT("ia[3] == 0", ia[3] == 0);
60        _RS_ASSERT("ia.length == 4", ia.length == 4);
61
62        long[] la = s.get_la();
63        _RS_ASSERT("la[0] == 13", la[0] == 13);
64        _RS_ASSERT("la[1] == 21", la[1] == 21);
65        _RS_ASSERT("la.length == 4", la.length == 2);
66
67        long[] lla = s.get_lla();
68        _RS_ASSERT("lla[0] == 34", lla[0] == 34);
69        _RS_ASSERT("lla[1] == 0", lla[1] == 0);
70        _RS_ASSERT("lla[2] == 0", lla[2] == 0);
71        _RS_ASSERT("lla[3] == 0", lla[3] == 0);
72        _RS_ASSERT("lla.length == 4", lla.length == 4);
73
74        boolean[] ba = s.get_ba();
75        _RS_ASSERT("ba[0] == true", ba[0] == true);
76        _RS_ASSERT("ba[1] == false", ba[1] == false);
77        _RS_ASSERT("ba[2] == false", ba[2] == false);
78        _RS_ASSERT("ba.length == 3", ba.length == 3);
79    }
80
81    public void run() {
82        RenderScript pRS = createRenderScript(true);
83        ScriptC_array_init s = new ScriptC_array_init(pRS);
84        checkInit(s);
85        s.invoke_array_init_test();
86        pRS.finish();
87        s.destroy();
88        pRS.destroy();
89        passTest();
90    }
91}
92