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