1/*
2 * Copyright (C) 2010 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.*;
22
23public class UT_primitives extends UnitTest {
24    private Resources mRes;
25
26    protected UT_primitives(RSTestCore rstc, Resources res, Context ctx) {
27        super(rstc, "Primitives", ctx);
28        mRes = res;
29    }
30
31    private boolean initializeGlobals(ScriptC_primitives s) {
32        float pF = s.get_floatTest();
33        if (pF != 1.99f) {
34            return false;
35        }
36        s.set_floatTest(2.99f);
37
38        double pD = s.get_doubleTest();
39        if (pD != 2.05) {
40            return false;
41        }
42        s.set_doubleTest(3.05);
43
44        byte pC = s.get_charTest();
45        if (pC != -8) {
46            return false;
47        }
48        s.set_charTest((byte)-16);
49
50        short pS = s.get_shortTest();
51        if (pS != -16) {
52            return false;
53        }
54        s.set_shortTest((short)-32);
55
56        int pI = s.get_intTest();
57        if (pI != -32) {
58            return false;
59        }
60        s.set_intTest(-64);
61
62        long pL = s.get_longTest();
63        if (pL != 17179869184l) {
64            return false;
65        }
66        s.set_longTest(17179869185l);
67
68        long puL = s.get_ulongTest();
69        if (puL != 4611686018427387904L) {
70            return false;
71        }
72        s.set_ulongTest(4611686018427387903L);
73
74
75        long pLL = s.get_longlongTest();
76        if (pLL != 68719476736L) {
77            return false;
78        }
79        s.set_longlongTest(68719476735L);
80
81        long pu64 = s.get_uint64_tTest();
82        if (pu64 != 117179869184l) {
83            return false;
84        }
85        s.set_uint64_tTest(117179869185l);
86
87        return true;
88    }
89
90    public void run() {
91        RenderScript pRS = RenderScript.create(mCtx);
92        ScriptC_primitives s = new ScriptC_primitives(pRS);
93        pRS.setMessageHandler(mRsMessage);
94        if (!initializeGlobals(s)) {
95            failTest();
96        } else {
97            s.invoke_primitives_test(0, 0);
98            pRS.finish();
99            waitForMessage();
100        }
101        pRS.destroy();
102    }
103}
104