Skip to content

Commit c97992b

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "Add test for "public final static"-reflected constant fields."
2 parents ff35de8 + 071abd1 commit c97992b

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
6565
unitTests = new ArrayList<UnitTest>();
6666

6767
unitTests.add(new UT_primitives(this, mRes, mCtx));
68+
unitTests.add(new UT_constant(this, mRes, mCtx));
6869
unitTests.add(new UT_vector(this, mRes, mCtx));
6970
unitTests.add(new UT_rsdebug(this, mRes, mCtx));
7071
unitTests.add(new UT_rstime(this, mRes, mCtx));
@@ -93,7 +94,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
9394
for (int i = 0; i < uta.length; i++) {
9495
ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
9596
listElem.text = Allocation.createFromString(mRS, uta[i].name, Allocation.USAGE_SCRIPT);
96-
listElem.result = uta[i].result;
97+
listElem.result = uta[i].getResult();
9798
mListAllocs.set(listElem, i, false);
9899
uta[i].setItem(listElem);
99100
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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_constant extends UnitTest {
24+
private Resources mRes;
25+
26+
protected UT_constant(RSTestCore rstc, Resources res, Context ctx) {
27+
super(rstc, "Const", ctx);
28+
mRes = res;
29+
}
30+
31+
private void Assert(boolean b) {
32+
if (!b) {
33+
failTest();
34+
}
35+
}
36+
37+
public void run() {
38+
Assert(ScriptC_constant.const_floatTest == 1.99f);
39+
Assert(ScriptC_constant.const_doubleTest == 2.05);
40+
Assert(ScriptC_constant.const_charTest == -8);
41+
Assert(ScriptC_constant.const_shortTest == -16);
42+
Assert(ScriptC_constant.const_intTest == -32);
43+
Assert(ScriptC_constant.const_longTest == 17179869184l);
44+
Assert(ScriptC_constant.const_longlongTest == 68719476736l);
45+
46+
Assert(ScriptC_constant.const_ucharTest == 8);
47+
Assert(ScriptC_constant.const_ushortTest == 16);
48+
Assert(ScriptC_constant.const_uintTest == 32);
49+
Assert(ScriptC_constant.const_ulongTest == 4611686018427387904L);
50+
Assert(ScriptC_constant.const_int64_tTest == -17179869184l);
51+
Assert(ScriptC_constant.const_uint64_tTest == 117179869184l);
52+
53+
Assert(ScriptC_constant.const_boolTest == true);
54+
55+
passTest();
56+
}
57+
}

tests/RenderScriptTests/tests/src/com/android/rs/test/UT_primitives.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public void run() {
9292
ScriptC_primitives s = new ScriptC_primitives(pRS, mRes, R.raw.primitives);
9393
pRS.setMessageHandler(mRsMessage);
9494
if (!initializeGlobals(s)) {
95-
// initializeGlobals failed
96-
result = -1;
95+
failTest();
9796
} else {
9897
s.invoke_primitives_test(0, 0);
9998
pRS.finish();

tests/RenderScriptTests/tests/src/com/android/rs/test/UT_vector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void run() {
307307
ScriptC_vector s = new ScriptC_vector(pRS, mRes, R.raw.vector);
308308
pRS.setMessageHandler(mRsMessage);
309309
if (!initializeGlobals(s)) {
310-
result = -1;
310+
failTest();
311311
} else {
312312
s.invoke_vector_test();
313313
pRS.finish();

tests/RenderScriptTests/tests/src/com/android/rs/test/UnitTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class UnitTest extends Thread {
2323
public String name;
24-
public int result;
24+
private int result;
2525
private ScriptField_ListAllocs_s.Item mItem;
2626
private RSTestCore mRSTC;
2727
private boolean msgHandled;
@@ -63,7 +63,7 @@ protected void _RS_ASSERT(String message, boolean b) {
6363
}
6464
}
6565

66-
protected void updateUI() {
66+
private void updateUI() {
6767
if (mItem != null) {
6868
mItem.result = result;
6969
msgHandled = true;
@@ -104,6 +104,22 @@ public void waitForMessage() {
104104
}
105105
}
106106

107+
public int getResult() {
108+
return result;
109+
}
110+
111+
public void failTest() {
112+
result = -1;
113+
updateUI();
114+
}
115+
116+
public void passTest() {
117+
if (result != -1) {
118+
result = 1;
119+
}
120+
updateUI();
121+
}
122+
107123
public void setItem(ScriptField_ListAllocs_s.Item item) {
108124
mItem = item;
109125
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "shared.rsh"
2+
3+
const float floatTest = 1.99f;
4+
const double doubleTest = 2.05;
5+
const char charTest = -8;
6+
const short shortTest = -16;
7+
const int intTest = -32;
8+
const long longTest = 17179869184l; // 1 << 34
9+
const long long longlongTest = 68719476736l; // 1 << 36
10+
11+
const uchar ucharTest = 8;
12+
const ushort ushortTest = 16;
13+
const uint uintTest = 32;
14+
const ulong ulongTest = 4611686018427387904L;
15+
const int64_t int64_tTest = -17179869184l; // - 1 << 34
16+
const uint64_t uint64_tTest = 117179869184l;
17+
18+
const bool boolTest = true;
19+

0 commit comments

Comments
 (0)