1/*
2 * Copyright (C) 2013 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.test_compat;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.support.v8.renderscript.*;
22import android.util.Log;
23import java.util.Arrays;
24
25public class UT_bug_char extends UnitTest {
26    private Resources mRes;
27
28    protected UT_bug_char(RSTestCore rstc, Resources res, Context ctx) {
29        super(rstc, "Bug Char", ctx);
30        mRes = res;
31    }
32
33    // packing functions
34    private Byte2 pack_b2(byte[] val) {
35        assert val.length == 2;
36        Log.i("bug_char", "pack_b2 " + val[0] + " " + val[1]);
37        return new Byte2(val[0], val[1]);
38    }
39
40    private byte min(byte v1, byte v2) {
41        return v1 < v2 ? v1 : v2;
42    }
43    private byte[] min(byte[] v1, byte[] v2) {
44        assert v1.length == v2.length;
45        byte[] rv = new byte[v1.length];
46        for (int i = 0; i < v1.length; ++i)
47            rv[i] = min(v1[i], v2[i]);
48        return rv;
49    }
50
51    private void initializeValues(ScriptC_bug_char s) {
52        byte rand_sc1_0 = (byte)7;
53        byte[] rand_sc2_0 = new byte[2];
54        rand_sc2_0[0] = 11;
55        rand_sc2_0[1] = 21;
56        Log.i("bug_char", "Generated sc2_0 to " + Arrays.toString(rand_sc2_0));
57        byte rand_sc1_1 = (byte)10;
58        byte[] rand_sc2_1 = new byte[2];
59        rand_sc2_1[0] = 13;
60        rand_sc2_1[1] = 15;
61        Log.i("bug_char", "Generated sc2_1 to " + Arrays.toString(rand_sc2_1));
62
63        s.set_rand_sc1_0(rand_sc1_0);
64        s.set_rand_sc2_0(pack_b2(rand_sc2_0));
65        s.set_rand_sc1_1(rand_sc1_1);
66        s.set_rand_sc2_1(pack_b2(rand_sc2_1));
67        // Set results for min
68        s.set_min_rand_sc1_sc1(min(rand_sc1_0, rand_sc1_1));
69        byte[] min_rand_sc2_raw = min(rand_sc2_0, rand_sc2_1);
70        Log.i("bug_char", "Generating min_rand_sc2_sc2 to " +
71              Arrays.toString(min_rand_sc2_raw));
72        Byte2 min_rand_sc2 = pack_b2(min_rand_sc2_raw);
73        Log.i("bug_char", "Setting min_rand_sc2_sc2 to [" + min_rand_sc2.x +
74              ", " + min_rand_sc2.y + "]");
75        s.set_min_rand_sc2_sc2(min_rand_sc2);
76    }
77
78    public void run() {
79        RenderScript pRS = RenderScript.create(mCtx);
80        ScriptC_bug_char s = new ScriptC_bug_char(pRS);
81        pRS.setMessageHandler(mRsMessage);
82        initializeValues(s);
83        s.invoke_bug_char_test();
84        pRS.finish();
85        waitForMessage();
86        pRS.destroy();
87    }
88}
89