1/*
2 * Copyright (C) 2011 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_v14;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.renderscript.*;
22
23public class UT_vector extends UnitTest {
24    private Resources mRes;
25
26    protected UT_vector(RSTestCore rstc, Resources res, Context ctx) {
27        super(rstc, "Vector", ctx);
28        mRes = res;
29    }
30
31    private boolean initializeGlobals(ScriptC_vector s) {
32        Float2 F2 = s.get_f2();
33        if (F2.x != 1.0f || F2.y != 2.0f) {
34            return false;
35        }
36        F2.x = 2.99f;
37        F2.y = 3.99f;
38        s.set_f2(F2);
39
40        Float3 F3 = s.get_f3();
41        if (F3.x != 1.0f || F3.y != 2.0f || F3.z != 3.0f) {
42            return false;
43        }
44        F3.x = 2.99f;
45        F3.y = 3.99f;
46        F3.z = 4.99f;
47        s.set_f3(F3);
48
49        Float4 F4 = s.get_f4();
50        if (F4.x != 1.0f || F4.y != 2.0f || F4.z != 3.0f || F4.w != 4.0f) {
51            return false;
52        }
53        F4.x = 2.99f;
54        F4.y = 3.99f;
55        F4.z = 4.99f;
56        F4.w = 5.99f;
57        s.set_f4(F4);
58
59        Double2 D2 = s.get_d2();
60        if (D2.x != 1.0 || D2.y != 2.0) {
61            return false;
62        }
63        D2.x = 2.99;
64        D2.y = 3.99;
65        s.set_d2(D2);
66
67        Double3 D3 = s.get_d3();
68        if (D3.x != 1.0 || D3.y != 2.0 || D3.z != 3.0) {
69            return false;
70        }
71        D3.x = 2.99;
72        D3.y = 3.99;
73        D3.z = 4.99;
74        s.set_d3(D3);
75
76        Double4 D4 = s.get_d4();
77        if (D4.x != 1.0 || D4.y != 2.0 || D4.z != 3.0 || D4.w != 4.0) {
78            return false;
79        }
80        D4.x = 2.99;
81        D4.y = 3.99;
82        D4.z = 4.99;
83        D4.w = 5.99;
84        s.set_d4(D4);
85
86        Byte2 B2 = s.get_i8_2();
87        if (B2.x != 1 || B2.y != 2) {
88            return false;
89        }
90        B2.x = 2;
91        B2.y = 3;
92        s.set_i8_2(B2);
93
94        Byte3 B3 = s.get_i8_3();
95        if (B3.x != 1 || B3.y != 2 || B3.z != 3) {
96            return false;
97        }
98        B3.x = 2;
99        B3.y = 3;
100        B3.z = 4;
101        s.set_i8_3(B3);
102
103        Byte4 B4 = s.get_i8_4();
104        if (B4.x != 1 || B4.y != 2 || B4.z != 3 || B4.w != 4) {
105            return false;
106        }
107        B4.x = 2;
108        B4.y = 3;
109        B4.z = 4;
110        B4.w = 5;
111        s.set_i8_4(B4);
112
113        Short2 S2 = s.get_u8_2();
114        if (S2.x != 1 || S2.y != 2) {
115            return false;
116        }
117        S2.x = 2;
118        S2.y = 3;
119        s.set_u8_2(S2);
120
121        Short3 S3 = s.get_u8_3();
122        if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
123            return false;
124        }
125        S3.x = 2;
126        S3.y = 3;
127        S3.z = 4;
128        s.set_u8_3(S3);
129
130        Short4 S4 = s.get_u8_4();
131        if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
132            return false;
133        }
134        S4.x = 2;
135        S4.y = 3;
136        S4.z = 4;
137        S4.w = 5;
138        s.set_u8_4(S4);
139
140        S2 = s.get_i16_2();
141        if (S2.x != 1 || S2.y != 2) {
142            return false;
143        }
144        S2.x = 2;
145        S2.y = 3;
146        s.set_i16_2(S2);
147
148        S3 = s.get_i16_3();
149        if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
150            return false;
151        }
152        S3.x = 2;
153        S3.y = 3;
154        S3.z = 4;
155        s.set_i16_3(S3);
156
157        S4 = s.get_i16_4();
158        if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
159            return false;
160        }
161        S4.x = 2;
162        S4.y = 3;
163        S4.z = 4;
164        S4.w = 5;
165        s.set_i16_4(S4);
166
167        Int2 I2 = s.get_u16_2();
168        if (I2.x != 1 || I2.y != 2) {
169            return false;
170        }
171        I2.x = 2;
172        I2.y = 3;
173        s.set_u16_2(I2);
174
175        Int3 I3 = s.get_u16_3();
176        if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
177            return false;
178        }
179        I3.x = 2;
180        I3.y = 3;
181        I3.z = 4;
182        s.set_u16_3(I3);
183
184        Int4 I4 = s.get_u16_4();
185        if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
186            return false;
187        }
188        I4.x = 2;
189        I4.y = 3;
190        I4.z = 4;
191        I4.w = 5;
192        s.set_u16_4(I4);
193
194        I2 = s.get_i32_2();
195        if (I2.x != 1 || I2.y != 2) {
196            return false;
197        }
198        I2.x = 2;
199        I2.y = 3;
200        s.set_i32_2(I2);
201
202        I3 = s.get_i32_3();
203        if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
204            return false;
205        }
206        I3.x = 2;
207        I3.y = 3;
208        I3.z = 4;
209        s.set_i32_3(I3);
210
211        I4 = s.get_i32_4();
212        if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
213            return false;
214        }
215        I4.x = 2;
216        I4.y = 3;
217        I4.z = 4;
218        I4.w = 5;
219        s.set_i32_4(I4);
220
221        Long2 L2 = s.get_u32_2();
222        if (L2.x != 1 || L2.y != 2) {
223            return false;
224        }
225        L2.x = 2;
226        L2.y = 3;
227        s.set_u32_2(L2);
228
229        Long3 L3 = s.get_u32_3();
230        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
231            return false;
232        }
233        L3.x = 2;
234        L3.y = 3;
235        L3.z = 4;
236        s.set_u32_3(L3);
237
238        Long4 L4 = s.get_u32_4();
239        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
240            return false;
241        }
242        L4.x = 2;
243        L4.y = 3;
244        L4.z = 4;
245        L4.w = 5;
246        s.set_u32_4(L4);
247
248        L2 = s.get_i64_2();
249        if (L2.x != 1 || L2.y != 2) {
250            return false;
251        }
252        L2.x = 2;
253        L2.y = 3;
254        s.set_i64_2(L2);
255
256        L3 = s.get_i64_3();
257        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
258            return false;
259        }
260        L3.x = 2;
261        L3.y = 3;
262        L3.z = 4;
263        s.set_i64_3(L3);
264
265        L4 = s.get_i64_4();
266        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
267            return false;
268        }
269        L4.x = 2;
270        L4.y = 3;
271        L4.z = 4;
272        L4.w = 5;
273        s.set_i64_4(L4);
274
275        L2 = s.get_u64_2();
276        if (L2.x != 1 || L2.y != 2) {
277            return false;
278        }
279        L2.x = 2;
280        L2.y = 3;
281        s.set_u64_2(L2);
282
283        L3 = s.get_u64_3();
284        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
285            return false;
286        }
287        L3.x = 2;
288        L3.y = 3;
289        L3.z = 4;
290        s.set_u64_3(L3);
291
292        L4 = s.get_u64_4();
293        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
294            return false;
295        }
296        L4.x = 2;
297        L4.y = 3;
298        L4.z = 4;
299        L4.w = 5;
300        s.set_u64_4(L4);
301
302        return true;
303    }
304
305    public void run() {
306        RenderScript pRS = RenderScript.create(mCtx);
307        ScriptC_vector s = new ScriptC_vector(pRS);
308        pRS.setMessageHandler(mRsMessage);
309        if (!initializeGlobals(s)) {
310            result = -1;
311        } else {
312            s.invoke_vector_test();
313            pRS.finish();
314            waitForMessage();
315        }
316        pRS.destroy();
317    }
318}
319