1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package com.android.rs.unittest;
20
21import android.content.Context;
22import android.support.v8.renderscript.Byte2;
23import android.support.v8.renderscript.RenderScript;
24import android.util.Log;
25
26import java.util.Arrays;
27
28public class UT_bug_char extends UnitTest {
29
30    public UT_bug_char(Context ctx) {
31        super("Bug Char", ctx);
32    }
33
34    // packing functions
35    private Byte2 pack_b2(byte[] val) {
36        assert val.length == 2;
37        Log.i("bug_char", "pack_b2 " + val[0] + " " + val[1]);
38        return new Byte2(val[0], val[1]);
39    }
40
41    private byte min(byte v1, byte v2) {
42        return v1 < v2 ? v1 : v2;
43    }
44
45    private byte[] min(byte[] v1, byte[] v2) {
46        assert v1.length == v2.length;
47        byte[] rv = new byte[v1.length];
48        for (int i = 0; i < v1.length; ++i)
49            rv[i] = min(v1[i], v2[i]);
50        return rv;
51    }
52
53    private void initializeValues(ScriptC_bug_char s) {
54        byte rand_sc1_0 = (byte) 7;
55        byte[] rand_sc2_0 = new byte[2];
56        rand_sc2_0[0] = 11;
57        rand_sc2_0[1] = 21;
58        Log.i("bug_char", "Generated sc2_0 to " + Arrays.toString(rand_sc2_0));
59        byte rand_sc1_1 = (byte) 10;
60        byte[] rand_sc2_1 = new byte[2];
61        rand_sc2_1[0] = 13;
62        rand_sc2_1[1] = 15;
63        Log.i("bug_char", "Generated sc2_1 to " + Arrays.toString(rand_sc2_1));
64
65        s.set_rand_sc1_0(rand_sc1_0);
66        s.set_rand_sc2_0(pack_b2(rand_sc2_0));
67        s.set_rand_sc1_1(rand_sc1_1);
68        s.set_rand_sc2_1(pack_b2(rand_sc2_1));
69        // Set results for min
70        s.set_min_rand_sc1_sc1(min(rand_sc1_0, rand_sc1_1));
71        byte[] min_rand_sc2_raw = min(rand_sc2_0, rand_sc2_1);
72        Log.i("bug_char", "Generating min_rand_sc2_sc2 to " +
73                Arrays.toString(min_rand_sc2_raw));
74        Byte2 min_rand_sc2 = pack_b2(min_rand_sc2_raw);
75        Log.i("bug_char", "Setting min_rand_sc2_sc2 to [" + min_rand_sc2.x +
76                ", " + min_rand_sc2.y + "]");
77        s.set_min_rand_sc2_sc2(min_rand_sc2);
78    }
79
80    public void run() {
81        RenderScript pRS = createRenderScript(true);
82        ScriptC_bug_char s = new ScriptC_bug_char(pRS);
83        initializeValues(s);
84        s.invoke_bug_char_test();
85        pRS.finish();
86        s.destroy();
87        pRS.destroy();
88    }
89}
90