1 /*
2  * Copyright (C) 2011-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 android.renderscript.cts;
18 
19 import android.renderscript.Element;
20 import android.renderscript.Element.DataType;
21 import android.renderscript.Element.DataKind;
22 import android.renderscript.RSIllegalArgumentException;
23 
24 public class ElementTest extends RSBaseCompute {
25 
testCreatePixel()26     public void testCreatePixel() {
27         assertTrue(Element.createPixel(mRS,
28                                        DataType.UNSIGNED_8,
29                                        DataKind.PIXEL_A) != null);
30         assertTrue(Element.createPixel(mRS,
31                                        DataType.UNSIGNED_5_6_5,
32                                        DataKind.PIXEL_RGB) != null);
33         assertTrue(Element.createPixel(mRS,
34                                        DataType.UNSIGNED_8,
35                                        DataKind.PIXEL_RGB) != null);
36         assertTrue(Element.createPixel(mRS,
37                                        DataType.UNSIGNED_5_5_5_1,
38                                        DataKind.PIXEL_RGBA) != null);
39         assertTrue(Element.createPixel(mRS,
40                                        DataType.UNSIGNED_4_4_4_4,
41                                        DataKind.PIXEL_RGBA) != null);
42         assertTrue(Element.createPixel(mRS,
43                                        DataType.UNSIGNED_8,
44                                        DataKind.PIXEL_RGBA) != null);
45     }
46 
testCreateVector()47     public void testCreateVector() {
48 
49         Element e = null;
50         for (int len = 2; len <= 4; len ++) {
51             assertTrue(Element.createVector(mRS, DataType.FLOAT_32, len) != null);
52             assertTrue(Element.createVector(mRS, DataType.FLOAT_64, len) != null);
53             assertTrue(Element.createVector(mRS, DataType.SIGNED_8, len) != null);
54             assertTrue(Element.createVector(mRS, DataType.SIGNED_16, len) != null);
55             assertTrue(Element.createVector(mRS, DataType.SIGNED_32, len) != null);
56             assertTrue(Element.createVector(mRS, DataType.SIGNED_64, len) != null);
57             assertTrue(Element.createVector(mRS, DataType.UNSIGNED_8, len) != null);
58             assertTrue(Element.createVector(mRS, DataType.UNSIGNED_16, len) != null);
59             assertTrue(Element.createVector(mRS, DataType.UNSIGNED_32, len) != null);
60             assertTrue(Element.createVector(mRS, DataType.UNSIGNED_64, len) != null);
61         }
62     }
63 
testPrebuiltElements()64     public void testPrebuiltElements() {
65         assertTrue(Element.A_8(mRS) != null);
66         assertTrue(Element.RGBA_4444(mRS) != null);
67         assertTrue(Element.RGBA_5551(mRS) != null);
68         assertTrue(Element.RGB_565(mRS) != null);
69         assertTrue(Element.RGB_888(mRS) != null);
70         assertTrue(Element.RGBA_8888(mRS) != null);
71         assertTrue(Element.F32(mRS) != null);
72         assertTrue(Element.F32_2(mRS) != null);
73         assertTrue(Element.F32_3(mRS) != null);
74         assertTrue(Element.F32_4(mRS) != null);
75         assertTrue(Element.F64(mRS) != null);
76         assertTrue(Element.F64_2(mRS) != null);
77         assertTrue(Element.F64_3(mRS) != null);
78         assertTrue(Element.F64_4(mRS) != null);
79         assertTrue(Element.I8(mRS) != null);
80         assertTrue(Element.I8_2(mRS) != null);
81         assertTrue(Element.I8_3(mRS) != null);
82         assertTrue(Element.I8_4(mRS) != null);
83         assertTrue(Element.I16(mRS) != null);
84         assertTrue(Element.I16_2(mRS) != null);
85         assertTrue(Element.I16_3(mRS) != null);
86         assertTrue(Element.I16_4(mRS) != null);
87         assertTrue(Element.I32(mRS) != null);
88         assertTrue(Element.I32_2(mRS) != null);
89         assertTrue(Element.I32_3(mRS) != null);
90         assertTrue(Element.I32_4(mRS) != null);
91         assertTrue(Element.I64(mRS) != null);
92         assertTrue(Element.I64_2(mRS) != null);
93         assertTrue(Element.I64_3(mRS) != null);
94         assertTrue(Element.I64_4(mRS) != null);
95         assertTrue(Element.U8(mRS) != null);
96         assertTrue(Element.U8_2(mRS) != null);
97         assertTrue(Element.U8_3(mRS) != null);
98         assertTrue(Element.U8_4(mRS) != null);
99         assertTrue(Element.U16(mRS) != null);
100         assertTrue(Element.U16_2(mRS) != null);
101         assertTrue(Element.U16_3(mRS) != null);
102         assertTrue(Element.U16_4(mRS) != null);
103         assertTrue(Element.U32(mRS) != null);
104         assertTrue(Element.U32_2(mRS) != null);
105         assertTrue(Element.U32_3(mRS) != null);
106         assertTrue(Element.U32_4(mRS) != null);
107         assertTrue(Element.U64(mRS) != null);
108         assertTrue(Element.U64_2(mRS) != null);
109         assertTrue(Element.U64_3(mRS) != null);
110         assertTrue(Element.U64_4(mRS) != null);
111         assertTrue(Element.MATRIX_2X2(mRS) != null);
112         assertTrue(Element.MATRIX_3X3(mRS) != null);
113         assertTrue(Element.MATRIX_4X4(mRS) != null);
114         assertTrue(Element.MATRIX4X4(mRS) != null);
115         assertTrue(Element.MESH(mRS) != null);
116         assertTrue(Element.PROGRAM_FRAGMENT(mRS) != null);
117         assertTrue(Element.PROGRAM_RASTER(mRS) != null);
118         assertTrue(Element.PROGRAM_STORE(mRS) != null);
119         assertTrue(Element.PROGRAM_VERTEX(mRS) != null);
120         assertTrue(Element.ALLOCATION(mRS) != null);
121         assertTrue(Element.SAMPLER(mRS) != null);
122         assertTrue(Element.SCRIPT(mRS) != null);
123         assertTrue(Element.TYPE(mRS) != null);
124         assertTrue(Element.BOOLEAN(mRS) != null);
125         assertTrue(Element.ELEMENT(mRS) != null);
126     }
127 
testEquals()128     public void testEquals() {
129         assertTrue(Element.A_8(mRS).equals(Element.A_8(mRS)));
130         assertFalse(Element.A_8(mRS).equals(Element.U8(mRS)));
131 
132         // Compatible elements
133         assertTrue(Element.A_8(mRS).isCompatible(Element.U8(mRS)));
134         assertTrue(Element.U8(mRS).isCompatible(Element.A_8(mRS)));
135 
136         // Verify equivalence of user-built Elements
137         Element.Builder eb1 = new Element.Builder(mRS);
138         eb1.add(Element.I8(mRS), "Test");
139         Element e1 = eb1.add(Element.U8(mRS), "UTest").create();
140 
141         assertTrue(e1.equals(e1));
142 
143         Element.Builder eb2 = new Element.Builder(mRS);
144         eb2.add(Element.I8(mRS), "Test");
145         Element e2 = eb2.add(Element.U8(mRS), "UTest").create();
146 
147         assertTrue(e1.equals(e2));
148         assertTrue(e2.equals(e1));
149         assertTrue(e1.hashCode() == e2.hashCode());
150         assertTrue(e1.isCompatible(e2));
151         assertTrue(e2.isCompatible(e1));
152 
153         // Check name differences
154         Element.Builder eb3 = new Element.Builder(mRS);
155         eb3.add(Element.I8(mRS), "Test");
156         Element e3 = eb3.add(Element.U8(mRS), "NotUTest").create();
157 
158         assertFalse(e1.equals(e3));
159         assertFalse(e3.equals(e1));
160         assertFalse(e1.isCompatible(e3));
161         assertFalse(e3.isCompatible(e1));
162 
163         eb1.add(Element.I8(mRS), "Another");
164         assertFalse(e1.equals(eb1.create()));
165         assertFalse(eb1.create().equals(e1));
166 
167         // Compatible sub-elements but neither equal nor compatible
168         Element.Builder eb4 = new Element.Builder(mRS);
169         eb4.add(Element.I8(mRS), "Test");
170         Element e4 = eb4.add(Element.A_8(mRS), "UTest").create();
171 
172         assertFalse(e1.equals(e4));
173         assertFalse(e4.equals(e1));
174         assertFalse(e1.isCompatible(e4));
175         assertFalse(e4.isCompatible(e1));
176 
177         // Check identity from same builder
178         assertTrue(eb1.create().isCompatible(eb1.create()));
179     }
180 
testIsCompatible()181     public void testIsCompatible() {
182         Element[] ALLOCATION = { Element.ALLOCATION(mRS) };
183         // A_8 is in U8
184         Element[] BOOLEAN = { Element.BOOLEAN(mRS) };
185         Element[] ELEMENT = { Element.ELEMENT(mRS) };
186         Element[] F16 = { Element.F16(mRS) };
187         Element[] F16_2 = { Element.F16_2(mRS),
188             Element.createVector(mRS, Element.DataType.FLOAT_16, 2) };
189         Element[] F16_3 = { Element.F16_3(mRS),
190             Element.createVector(mRS, Element.DataType.FLOAT_16, 3) };
191         Element[] F16_4 = { Element.F16_4(mRS),
192             Element.createVector(mRS, Element.DataType.FLOAT_16, 4) };
193         Element[] F32 = { Element.F32(mRS) };
194         Element[] F32_2 = { Element.F32_2(mRS),
195             Element.createVector(mRS, Element.DataType.FLOAT_32, 2) };
196         Element[] F32_3 = { Element.F32_3(mRS),
197             Element.createVector(mRS, Element.DataType.FLOAT_32, 3) };
198         Element[] F32_4 = { Element.F32_4(mRS),
199             Element.createVector(mRS, Element.DataType.FLOAT_32, 4) };
200         Element[] F64 = { Element.F64(mRS) };
201         Element[] I16 = { Element.I16(mRS) };
202         Element[] I32 = { Element.I32(mRS) };
203         Element[] I64 = { Element.I64(mRS) };
204         Element[] I8 = { Element.I8(mRS) };
205         // MATRIX4X4 is in MATRIX_4X4
206         Element[] MATRIX_2X2 = { Element.MATRIX_2X2(mRS) };
207         Element[] MATRIX_3X3 = { Element.MATRIX_3X3(mRS) };
208         Element[] MATRIX_4X4 = { Element.MATRIX4X4(mRS),
209                                  Element.MATRIX_4X4(mRS) };
210         Element[] MESH = { Element.MESH(mRS) };
211         Element[] PROGRAM_FRAGMENT = { Element.PROGRAM_FRAGMENT(mRS) };
212         Element[] PROGRAM_RASTER = { Element.PROGRAM_RASTER(mRS) };
213         Element[] PROGRAM_STORE = { Element.PROGRAM_STORE(mRS) };
214         Element[] PROGRAM_VERTEX = { Element.PROGRAM_VERTEX(mRS) };
215         Element[] RGBA_4444 = { Element.RGBA_4444(mRS),
216             Element.createPixel(mRS, Element.DataType.UNSIGNED_4_4_4_4,
217                                 Element.DataKind.PIXEL_RGBA) };
218         Element[] RGBA_5551 = { Element.RGBA_5551(mRS),
219             Element.createPixel(mRS, Element.DataType.UNSIGNED_5_5_5_1,
220                                 Element.DataKind.PIXEL_RGBA) };
221         // RGBA_8888 is in U8_4
222         Element[] RGB_565 = { Element.RGB_565(mRS),
223             Element.createPixel(mRS, Element.DataType.UNSIGNED_5_6_5,
224                                 Element.DataKind.PIXEL_RGB) };
225         // RGB_888 is in U8_3
226         Element[] SAMPLER = { Element.SAMPLER(mRS) };
227         Element[] SCRIPT = { Element.SCRIPT(mRS) };
228         Element[] TYPE = { Element.TYPE(mRS) };
229         Element[] U16 = { Element.U16(mRS) };
230         Element[] U32 = { Element.U32(mRS) };
231         Element[] U64 = { Element.U64(mRS) };
232         Element[] U8 = { Element.A_8(mRS),
233                          Element.U8(mRS),
234             Element.createPixel(mRS, Element.DataType.UNSIGNED_8,
235                                 Element.DataKind.PIXEL_A) };
236         Element[] U8_3 = { Element.RGB_888(mRS),
237             Element.createVector(mRS, Element.DataType.UNSIGNED_8, 3),
238             Element.createPixel(mRS, Element.DataType.UNSIGNED_8,
239                                 Element.DataKind.PIXEL_RGB) };
240         Element[] U8_4 = { Element.U8_4(mRS),
241                            Element.RGBA_8888(mRS),
242             Element.createVector(mRS, Element.DataType.UNSIGNED_8, 4),
243             Element.createPixel(mRS, Element.DataType.UNSIGNED_8,
244                                 Element.DataKind.PIXEL_RGBA) };
245 
246         Element[][] ElementArrs = { ALLOCATION, BOOLEAN, ELEMENT,
247                                     F16, F16_2, F16_3, F16_4,
248                                     F32, F32_2, F32_3, F32_4,
249                                     F64, I16, I32, I64, I8,
250                                     MATRIX_2X2, MATRIX_3X3, MATRIX_4X4, MESH,
251                                     PROGRAM_FRAGMENT, PROGRAM_RASTER,
252                                     PROGRAM_STORE, PROGRAM_VERTEX, RGBA_4444,
253                                     RGBA_5551, RGB_565, SAMPLER, SCRIPT, TYPE,
254                                     U16, U32, U64, U8, U8_3, U8_4 };
255 
256         int ElementArrsLen = ElementArrs.length;
257         for (int i = 0; i < ElementArrsLen; i++) {
258             for (int j = 0; j < ElementArrsLen; j++) {
259                 for (Element el : ElementArrs[i]) {
260                     for (Element er : ElementArrs[j]) {
261                         if (i == j) {
262                             // Elements within a group are compatible
263                             assertTrue(el.isCompatible(er));
264                         } else {
265                             // Elements from different groups are incompatible
266                             assertFalse(el.isCompatible(er));
267                         }
268                     }
269                 }
270             }
271         }
272     }
273 
testElementBuilder()274     public void testElementBuilder() {
275         for (int arraySize = 1; arraySize <= 3; arraySize++) {
276             // Now test array size
277             Element.Builder eb = new Element.Builder(mRS);
278             eb.add(Element.A_8(mRS), "A_8", arraySize);
279             eb.add(Element.RGBA_4444(mRS), "RGBA_4444", arraySize);
280             eb.add(Element.RGBA_5551(mRS), "RGBA_5551", arraySize);
281             eb.add(Element.RGB_565(mRS), "RGB_565", arraySize);
282             eb.add(Element.RGB_888(mRS), "RGB_888", arraySize);
283             eb.add(Element.RGBA_8888(mRS), "RGBA_8888", arraySize);
284             eb.add(Element.F16(mRS), "F16", arraySize);
285             eb.add(Element.F16_2(mRS), "F16_2", arraySize);
286             eb.add(Element.F16_3(mRS), "F16_3", arraySize);
287             eb.add(Element.F16_4(mRS), "F16_4", arraySize);
288             eb.add(Element.F32(mRS), "F32", arraySize);
289             eb.add(Element.F32_2(mRS), "F32_2", arraySize);
290             eb.add(Element.F32_3(mRS), "F32_3", arraySize);
291             eb.add(Element.F32_4(mRS), "F32_4", arraySize);
292             eb.add(Element.F64(mRS), "F64", arraySize);
293             eb.add(Element.F64_2(mRS), "F64_2", arraySize);
294             eb.add(Element.F64_3(mRS), "F64_3", arraySize);
295             eb.add(Element.F64_4(mRS), "F64_4", arraySize);
296             eb.add(Element.I8(mRS), "I8", arraySize);
297             eb.add(Element.I8_2(mRS), "I8_2", arraySize);
298             eb.add(Element.I8_3(mRS), "I8_3", arraySize);
299             eb.add(Element.I8_4(mRS), "I8_4", arraySize);
300             eb.add(Element.I16(mRS), "I16", arraySize);
301             eb.add(Element.I16_2(mRS), "I16_2", arraySize);
302             eb.add(Element.I16_3(mRS), "I16_3", arraySize);
303             eb.add(Element.I16_4(mRS), "I16_4", arraySize);
304             eb.add(Element.I32(mRS), "I32", arraySize);
305             eb.add(Element.I32_2(mRS), "I32_2", arraySize);
306             eb.add(Element.I32_3(mRS), "I32_3", arraySize);
307             eb.add(Element.I32_4(mRS), "I32_4", arraySize);
308             eb.add(Element.I64(mRS), "I64", arraySize);
309             eb.add(Element.I64_2(mRS), "I64_2", arraySize);
310             eb.add(Element.I64_3(mRS), "I64_3", arraySize);
311             eb.add(Element.I64_4(mRS), "I64_4", arraySize);
312             eb.add(Element.U8(mRS), "U8", arraySize);
313             eb.add(Element.U8_2(mRS), "U8_2", arraySize);
314             eb.add(Element.U8_3(mRS), "U8_3", arraySize);
315             eb.add(Element.U8_4(mRS), "U8_4", arraySize);
316             eb.add(Element.U16(mRS), "U16", arraySize);
317             eb.add(Element.U16_2(mRS), "U16_2", arraySize);
318             eb.add(Element.U16_3(mRS), "U16_3", arraySize);
319             eb.add(Element.U16_4(mRS), "U16_4", arraySize);
320             eb.add(Element.U32(mRS), "U32", arraySize);
321             eb.add(Element.U32_2(mRS), "U32_2", arraySize);
322             eb.add(Element.U32_3(mRS), "U32_3", arraySize);
323             eb.add(Element.U32_4(mRS), "U32_4", arraySize);
324             eb.add(Element.U64(mRS), "U64", arraySize);
325             eb.add(Element.U64_2(mRS), "U64_2", arraySize);
326             eb.add(Element.U64_3(mRS), "U64_3", arraySize);
327             eb.add(Element.U64_4(mRS), "U64_4", arraySize);
328             eb.add(Element.MATRIX_2X2(mRS), "MATRIX_2X2", arraySize);
329             eb.add(Element.MATRIX_3X3(mRS), "MATRIX_3X3", arraySize);
330             eb.add(Element.MATRIX_4X4(mRS), "MATRIX_4X4", arraySize);
331             eb.add(Element.MATRIX4X4(mRS), "MATRIX4X4", arraySize);
332             eb.add(Element.MESH(mRS), "MESH", arraySize);
333             eb.add(Element.PROGRAM_FRAGMENT(mRS), "PROGRAM_FRAGMENT", arraySize);
334             eb.add(Element.PROGRAM_RASTER(mRS), "PROGRAM_RASTER", arraySize);
335             eb.add(Element.PROGRAM_STORE(mRS), "PROGRAM_STORE", arraySize);
336             eb.add(Element.PROGRAM_VERTEX(mRS), "PROGRAM_VERTEX", arraySize);
337             eb.add(Element.ALLOCATION(mRS), "ALLOCATION", arraySize);
338             eb.add(Element.SAMPLER(mRS), "SAMPLER", arraySize);
339             eb.add(Element.SCRIPT(mRS), "SCRIPT", arraySize);
340             eb.add(Element.TYPE(mRS), "TYPE", arraySize);
341             eb.add(Element.BOOLEAN(mRS), "BOOLEAN", arraySize);
342             eb.add(Element.ELEMENT(mRS), "ELEMENT", arraySize);
343             assertTrue(eb.create() != null);
344         }
345     }
346 
testIsComplex()347     public void testIsComplex() {
348         assertFalse(Element.A_8(mRS).isComplex());
349         assertFalse(Element.RGBA_4444(mRS).isComplex());
350         assertFalse(Element.RGBA_5551(mRS).isComplex());
351         assertFalse(Element.RGB_565(mRS).isComplex());
352         assertFalse(Element.RGB_888(mRS).isComplex());
353         assertFalse(Element.RGBA_8888(mRS).isComplex());
354         assertFalse(Element.F16(mRS).isComplex());
355         assertFalse(Element.F16_2(mRS).isComplex());
356         assertFalse(Element.F16_3(mRS).isComplex());
357         assertFalse(Element.F16_4(mRS).isComplex());
358         assertFalse(Element.F32(mRS).isComplex());
359         assertFalse(Element.F32_2(mRS).isComplex());
360         assertFalse(Element.F32_3(mRS).isComplex());
361         assertFalse(Element.F32_4(mRS).isComplex());
362         assertFalse(Element.F64(mRS).isComplex());
363         assertFalse(Element.F64_2(mRS).isComplex());
364         assertFalse(Element.F64_3(mRS).isComplex());
365         assertFalse(Element.F64_4(mRS).isComplex());
366         assertFalse(Element.I8(mRS).isComplex());
367         assertFalse(Element.I8_2(mRS).isComplex());
368         assertFalse(Element.I8_3(mRS).isComplex());
369         assertFalse(Element.I8_4(mRS).isComplex());
370         assertFalse(Element.I16(mRS).isComplex());
371         assertFalse(Element.I16_2(mRS).isComplex());
372         assertFalse(Element.I16_3(mRS).isComplex());
373         assertFalse(Element.I16_4(mRS).isComplex());
374         assertFalse(Element.I32(mRS).isComplex());
375         assertFalse(Element.I32_2(mRS).isComplex());
376         assertFalse(Element.I32_3(mRS).isComplex());
377         assertFalse(Element.I32_4(mRS).isComplex());
378         assertFalse(Element.I64(mRS).isComplex());
379         assertFalse(Element.I64_2(mRS).isComplex());
380         assertFalse(Element.I64_3(mRS).isComplex());
381         assertFalse(Element.I64_4(mRS).isComplex());
382         assertFalse(Element.U8(mRS).isComplex());
383         assertFalse(Element.U8_2(mRS).isComplex());
384         assertFalse(Element.U8_3(mRS).isComplex());
385         assertFalse(Element.U8_4(mRS).isComplex());
386         assertFalse(Element.U16(mRS).isComplex());
387         assertFalse(Element.U16_2(mRS).isComplex());
388         assertFalse(Element.U16_3(mRS).isComplex());
389         assertFalse(Element.U16_4(mRS).isComplex());
390         assertFalse(Element.U32(mRS).isComplex());
391         assertFalse(Element.U32_2(mRS).isComplex());
392         assertFalse(Element.U32_3(mRS).isComplex());
393         assertFalse(Element.U32_4(mRS).isComplex());
394         assertFalse(Element.U64(mRS).isComplex());
395         assertFalse(Element.U64_2(mRS).isComplex());
396         assertFalse(Element.U64_3(mRS).isComplex());
397         assertFalse(Element.U64_4(mRS).isComplex());
398         assertFalse(Element.MATRIX_2X2(mRS).isComplex());
399         assertFalse(Element.MATRIX_3X3(mRS).isComplex());
400         assertFalse(Element.MATRIX_4X4(mRS).isComplex());
401         assertFalse(Element.MATRIX4X4(mRS).isComplex());
402         assertFalse(Element.MESH(mRS).isComplex());
403         assertFalse(Element.PROGRAM_FRAGMENT(mRS).isComplex());
404         assertFalse(Element.PROGRAM_RASTER(mRS).isComplex());
405         assertFalse(Element.PROGRAM_STORE(mRS).isComplex());
406         assertFalse(Element.PROGRAM_VERTEX(mRS).isComplex());
407         assertFalse(Element.ALLOCATION(mRS).isComplex());
408         assertFalse(Element.SAMPLER(mRS).isComplex());
409         assertFalse(Element.SCRIPT(mRS).isComplex());
410         assertFalse(Element.TYPE(mRS).isComplex());
411         assertFalse(Element.BOOLEAN(mRS).isComplex());
412         assertFalse(Element.ELEMENT(mRS).isComplex());
413 
414         Element.Builder eb = new Element.Builder(mRS);
415         eb.add(Element.F32(mRS), "FLOAT");
416         eb.add(Element.SAMPLER(mRS), "SAMPLER");
417         Element e1 = eb.create();
418         assertFalse(e1.isComplex());
419 
420         eb = new Element.Builder(mRS);
421         eb.add(Element.A_8(mRS), "A_8");
422         eb.add(Element.RGBA_4444(mRS), "RGBA_4444");
423         Element e2 = eb.create();
424         assertFalse(e2.isComplex());
425 
426         eb = new Element.Builder(mRS);
427         eb.add(e1, "e1");
428         eb.add(e2, "e2");
429         assertTrue(eb.create().isComplex());
430     }
431 
testDataType()432     public void testDataType() {
433         // Uncomment when NONE is no longer hidden.
434         //assertEquals(DataType.NONE, DataType.valueOf("NONE"));
435 
436         assertEquals(DataType.FLOAT_16, DataType.valueOf("FLOAT_16"));
437         assertEquals(DataType.FLOAT_32, DataType.valueOf("FLOAT_32"));
438         assertEquals(DataType.FLOAT_64, DataType.valueOf("FLOAT_64"));
439         assertEquals(DataType.SIGNED_8, DataType.valueOf("SIGNED_8"));
440         assertEquals(DataType.SIGNED_16, DataType.valueOf("SIGNED_16"));
441         assertEquals(DataType.SIGNED_32, DataType.valueOf("SIGNED_32"));
442         assertEquals(DataType.SIGNED_64, DataType.valueOf("SIGNED_64"));
443         assertEquals(DataType.UNSIGNED_8, DataType.valueOf("UNSIGNED_8"));
444         assertEquals(DataType.UNSIGNED_16, DataType.valueOf("UNSIGNED_16"));
445         assertEquals(DataType.UNSIGNED_32, DataType.valueOf("UNSIGNED_32"));
446         assertEquals(DataType.UNSIGNED_64, DataType.valueOf("UNSIGNED_64"));
447 
448         assertEquals(DataType.BOOLEAN, DataType.valueOf("BOOLEAN"));
449 
450         assertEquals(DataType.UNSIGNED_5_6_5, DataType.valueOf("UNSIGNED_5_6_5"));
451         assertEquals(DataType.UNSIGNED_5_5_5_1, DataType.valueOf("UNSIGNED_5_5_5_1"));
452         assertEquals(DataType.UNSIGNED_4_4_4_4, DataType.valueOf("UNSIGNED_4_4_4_4"));
453 
454         assertEquals(DataType.MATRIX_4X4, DataType.valueOf("MATRIX_4X4"));
455         assertEquals(DataType.MATRIX_3X3, DataType.valueOf("MATRIX_3X3"));
456         assertEquals(DataType.MATRIX_2X2, DataType.valueOf("MATRIX_2X2"));
457 
458         assertEquals(DataType.RS_ELEMENT, DataType.valueOf("RS_ELEMENT"));
459         assertEquals(DataType.RS_TYPE, DataType.valueOf("RS_TYPE"));
460         assertEquals(DataType.RS_ALLOCATION, DataType.valueOf("RS_ALLOCATION"));
461         assertEquals(DataType.RS_SAMPLER, DataType.valueOf("RS_SAMPLER"));
462         assertEquals(DataType.RS_SCRIPT, DataType.valueOf("RS_SCRIPT"));
463         assertEquals(DataType.RS_MESH, DataType.valueOf("RS_MESH"));
464         assertEquals(DataType.RS_PROGRAM_FRAGMENT, DataType.valueOf("RS_PROGRAM_FRAGMENT"));
465         assertEquals(DataType.RS_PROGRAM_VERTEX, DataType.valueOf("RS_PROGRAM_VERTEX"));
466         assertEquals(DataType.RS_PROGRAM_RASTER, DataType.valueOf("RS_PROGRAM_RASTER"));
467         assertEquals(DataType.RS_PROGRAM_STORE, DataType.valueOf("RS_PROGRAM_STORE"));
468         // Make sure no new enums are added
469         assertEquals(30, DataType.values().length);
470 
471         for (DataType dt : DataType.values()) {
472             switch (dt) {
473             case FLOAT_16:
474             case FLOAT_32:
475             case FLOAT_64:
476             case SIGNED_8:
477             case SIGNED_16:
478             case SIGNED_32:
479             case SIGNED_64:
480             case UNSIGNED_8:
481             case UNSIGNED_16:
482             case UNSIGNED_32:
483             case UNSIGNED_64:
484             case BOOLEAN:
485                 Element.createVector(mRS, dt, 2);
486                 break;
487 
488             default: {
489                 try {
490                     Element.createVector(mRS, dt, 2);
491                     fail("should throw RSIllegalArgumentException");
492                 } catch (RSIllegalArgumentException e) {
493                 }
494                 break;
495             }
496             }
497         }
498     }
499 
testDataKind()500     public void testDataKind() {
501         assertEquals(DataKind.USER, DataKind.valueOf("USER"));
502 
503         assertEquals(DataKind.PIXEL_L, DataKind.valueOf("PIXEL_L"));
504         assertEquals(DataKind.PIXEL_A, DataKind.valueOf("PIXEL_A"));
505         assertEquals(DataKind.PIXEL_LA, DataKind.valueOf("PIXEL_LA"));
506         assertEquals(DataKind.PIXEL_RGB, DataKind.valueOf("PIXEL_RGB"));
507         assertEquals(DataKind.PIXEL_RGBA, DataKind.valueOf("PIXEL_RGBA"));
508         assertEquals(DataKind.PIXEL_DEPTH, DataKind.valueOf("PIXEL_DEPTH"));
509         assertEquals(DataKind.PIXEL_YUV, DataKind.valueOf("PIXEL_YUV"));
510         // Make sure no new enums are added
511         assertEquals(8, DataKind.values().length);
512 
513         for (DataKind dk : DataKind.values()) {
514             if (dk != DataKind.USER && dk != DataKind.PIXEL_YUV) {
515                 Element.createPixel(mRS, DataType.UNSIGNED_8, dk);
516             }
517         }
518     }
519 }
520 
521 
522