Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2247e3f0 authored by Stephen Hines's avatar Stephen Hines Committed by Android (Google) Code Review
Browse files

Merge "Test RS struct writing/reading."

parents df92772f b1ea64ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class RSTestCore {
        unitTests.add(new UT_refcount(this, mRes, mCtx));
        unitTests.add(new UT_foreach(this, mRes, mCtx));
        unitTests.add(new UT_atomic(this, mRes, mCtx));
        unitTests.add(new UT_struct(this, mRes, mCtx));
        unitTests.add(new UT_math(this, mRes, mCtx));
        unitTests.add(new UT_fp_mad(this, mRes, mCtx));
        /*
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.test;

import android.content.Context;
import android.content.res.Resources;
import android.renderscript.*;

public class UT_struct extends UnitTest {
    private Resources mRes;

    protected UT_struct(RSTestCore rstc, Resources res, Context ctx) {
        super(rstc, "Struct", ctx);
        mRes = res;
    }

    public void run() {
        RenderScript pRS = RenderScript.create(mCtx);
        ScriptC_struct s = new ScriptC_struct(pRS, mRes, R.raw.struct);
        pRS.setMessageHandler(mRsMessage);

        ScriptField_Point2 p = new ScriptField_Point2(pRS, 1);
        ScriptField_Point2.Item i = new ScriptField_Point2.Item();
        int val = 100;
        i.x = val;
        i.y = val;
        p.set(i, 0, true);
        s.bind_point2(p);
        s.invoke_struct_test(val);
        pRS.finish();
        waitForMessage();

        val = 200;
        p.set_x(0, val, true);
        p.set_y(0, val, true);
        s.invoke_struct_test(val);
        pRS.finish();
        waitForMessage();
        pRS.destroy();
    }
}
+37 −0
Original line number Diff line number Diff line
#include "shared.rsh"

typedef struct Point2 {
   int x;
   int y;
} Point_2;
Point_2 *point2;

static bool test_Point_2(int expected) {
    bool failed = false;

    rsDebug("Point: ", point2[0].x, point2[0].y);
    _RS_ASSERT(point2[0].x == expected);
    _RS_ASSERT(point2[0].y == expected);

    if (failed) {
        rsDebug("test_Point_2 FAILED", 0);
    }
    else {
        rsDebug("test_Point_2 PASSED", 0);
    }

    return failed;
}

void struct_test(int expected) {
    bool failed = false;
    failed |= test_Point_2(expected);

    if (failed) {
        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
    }
    else {
        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
    }
}