UT_math_agree.java revision 325ca45471862654a70948e09415277d8646c68b
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 17package com.android.rs.test; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.renderscript.*; 22import java.util.Random; 23 24public class UT_math_agree extends UnitTest { 25 private Resources mRes; 26 27 protected UT_math_agree(RSTestCore rstc, Resources res, Context ctx) { 28 super(rstc, "Math Agreement", ctx); 29 mRes = res; 30 } 31 32 private void initializeValues(ScriptC_math_agree s) { 33 Random rand = new Random(); 34 35 float x = rand.nextFloat(); 36 float y = rand.nextFloat(); 37 38 s.set_x(x); 39 s.set_y(y); 40 s.set_result_add(x + y); 41 s.set_result_sub(x - y); 42 s.set_result_mul(x * y); 43 s.set_result_div(x / y); 44 } 45 46 public void run() { 47 RenderScript pRS = RenderScript.create(mCtx); 48 ScriptC_math_agree s = new ScriptC_math_agree(pRS, mRes, 49 R.raw.math_agree); 50 pRS.setMessageHandler(mRsMessage); 51 initializeValues(s); 52 s.invoke_math_agree_test(); 53 pRS.finish(); 54 waitForMessage(); 55 pRS.destroy(); 56 } 57} 58