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[] F32 = { Element.F32(mRS) }; 187 Element[] F32_2 = { Element.F32_2(mRS), 188 Element.createVector(mRS, Element.DataType.FLOAT_32, 2) }; 189 Element[] F32_3 = { Element.F32_3(mRS), 190 Element.createVector(mRS, Element.DataType.FLOAT_32, 3) }; 191 Element[] F32_4 = { Element.F32_4(mRS), 192 Element.createVector(mRS, Element.DataType.FLOAT_32, 4) }; 193 Element[] F64 = { Element.F64(mRS) }; 194 Element[] I16 = { Element.I16(mRS) }; 195 Element[] I32 = { Element.I32(mRS) }; 196 Element[] I64 = { Element.I64(mRS) }; 197 Element[] I8 = { Element.I8(mRS) }; 198 // MATRIX4X4 is in MATRIX_4X4 199 Element[] MATRIX_2X2 = { Element.MATRIX_2X2(mRS) }; 200 Element[] MATRIX_3X3 = { Element.MATRIX_3X3(mRS) }; 201 Element[] MATRIX_4X4 = { Element.MATRIX4X4(mRS), 202 Element.MATRIX_4X4(mRS) }; 203 Element[] MESH = { Element.MESH(mRS) }; 204 Element[] PROGRAM_FRAGMENT = { Element.PROGRAM_FRAGMENT(mRS) }; 205 Element[] PROGRAM_RASTER = { Element.PROGRAM_RASTER(mRS) }; 206 Element[] PROGRAM_STORE = { Element.PROGRAM_STORE(mRS) }; 207 Element[] PROGRAM_VERTEX = { Element.PROGRAM_VERTEX(mRS) }; 208 Element[] RGBA_4444 = { Element.RGBA_4444(mRS), 209 Element.createPixel(mRS, Element.DataType.UNSIGNED_4_4_4_4, 210 Element.DataKind.PIXEL_RGBA) }; 211 Element[] RGBA_5551 = { Element.RGBA_5551(mRS), 212 Element.createPixel(mRS, Element.DataType.UNSIGNED_5_5_5_1, 213 Element.DataKind.PIXEL_RGBA) }; 214 // RGBA_8888 is in U8_4 215 Element[] RGB_565 = { Element.RGB_565(mRS), 216 Element.createPixel(mRS, Element.DataType.UNSIGNED_5_6_5, 217 Element.DataKind.PIXEL_RGB) }; 218 // RGB_888 is in U8_3 219 Element[] SAMPLER = { Element.SAMPLER(mRS) }; 220 Element[] SCRIPT = { Element.SCRIPT(mRS) }; 221 Element[] TYPE = { Element.TYPE(mRS) }; 222 Element[] U16 = { Element.U16(mRS) }; 223 Element[] U32 = { Element.U32(mRS) }; 224 Element[] U64 = { Element.U64(mRS) }; 225 Element[] U8 = { Element.A_8(mRS), 226 Element.U8(mRS), 227 Element.createPixel(mRS, Element.DataType.UNSIGNED_8, 228 Element.DataKind.PIXEL_A) }; 229 Element[] U8_3 = { Element.RGB_888(mRS), 230 Element.createVector(mRS, Element.DataType.UNSIGNED_8, 3), 231 Element.createPixel(mRS, Element.DataType.UNSIGNED_8, 232 Element.DataKind.PIXEL_RGB) }; 233 Element[] U8_4 = { Element.U8_4(mRS), 234 Element.RGBA_8888(mRS), 235 Element.createVector(mRS, Element.DataType.UNSIGNED_8, 4), 236 Element.createPixel(mRS, Element.DataType.UNSIGNED_8, 237 Element.DataKind.PIXEL_RGBA) }; 238 239 Element[][] ElementArrs = { ALLOCATION, BOOLEAN, ELEMENT, F32, F32_2, 240 F32_3, F32_4, F64, I16, I32, I64, I8, 241 MATRIX_2X2, MATRIX_3X3, MATRIX_4X4, MESH, 242 PROGRAM_FRAGMENT, PROGRAM_RASTER, 243 PROGRAM_STORE, PROGRAM_VERTEX, RGBA_4444, 244 RGBA_5551, RGB_565, SAMPLER, SCRIPT, TYPE, 245 U16, U32, U64, U8, U8_3, U8_4 }; 246 247 int ElementArrsLen = ElementArrs.length; 248 for (int i = 0; i < ElementArrsLen; i++) { 249 for (int j = 0; j < ElementArrsLen; j++) { 250 for (Element el : ElementArrs[i]) { 251 for (Element er : ElementArrs[j]) { 252 if (i == j) { 253 // Elements within a group are compatible 254 assertTrue(el.isCompatible(er)); 255 } else { 256 // Elements from different groups are incompatible 257 assertFalse(el.isCompatible(er)); 258 } 259 } 260 } 261 } 262 } 263 } 264 testElementBuilder()265 public void testElementBuilder() { 266 for (int arraySize = 1; arraySize <= 3; arraySize++) { 267 // Now test array size 268 Element.Builder eb = new Element.Builder(mRS); 269 eb.add(Element.A_8(mRS), "A_8", arraySize); 270 eb.add(Element.RGBA_4444(mRS), "RGBA_4444", arraySize); 271 eb.add(Element.RGBA_5551(mRS), "RGBA_5551", arraySize); 272 eb.add(Element.RGB_565(mRS), "RGB_565", arraySize); 273 eb.add(Element.RGB_888(mRS), "RGB_888", arraySize); 274 eb.add(Element.RGBA_8888(mRS), "RGBA_8888", arraySize); 275 eb.add(Element.F32(mRS), "F32", arraySize); 276 eb.add(Element.F32_2(mRS), "F32_2", arraySize); 277 eb.add(Element.F32_3(mRS), "F32_3", arraySize); 278 eb.add(Element.F32_4(mRS), "F32_4", arraySize); 279 eb.add(Element.F64(mRS), "F64", arraySize); 280 eb.add(Element.F64_2(mRS), "F64_2", arraySize); 281 eb.add(Element.F64_3(mRS), "F64_3", arraySize); 282 eb.add(Element.F64_4(mRS), "F64_4", arraySize); 283 eb.add(Element.I8(mRS), "I8", arraySize); 284 eb.add(Element.I8_2(mRS), "I8_2", arraySize); 285 eb.add(Element.I8_3(mRS), "I8_3", arraySize); 286 eb.add(Element.I8_4(mRS), "I8_4", arraySize); 287 eb.add(Element.I16(mRS), "I16", arraySize); 288 eb.add(Element.I16_2(mRS), "I16_2", arraySize); 289 eb.add(Element.I16_3(mRS), "I16_3", arraySize); 290 eb.add(Element.I16_4(mRS), "I16_4", arraySize); 291 eb.add(Element.I32(mRS), "I32", arraySize); 292 eb.add(Element.I32_2(mRS), "I32_2", arraySize); 293 eb.add(Element.I32_3(mRS), "I32_3", arraySize); 294 eb.add(Element.I32_4(mRS), "I32_4", arraySize); 295 eb.add(Element.I64(mRS), "I64", arraySize); 296 eb.add(Element.I64_2(mRS), "I64_2", arraySize); 297 eb.add(Element.I64_3(mRS), "I64_3", arraySize); 298 eb.add(Element.I64_4(mRS), "I64_4", arraySize); 299 eb.add(Element.U8(mRS), "U8", arraySize); 300 eb.add(Element.U8_2(mRS), "U8_2", arraySize); 301 eb.add(Element.U8_3(mRS), "U8_3", arraySize); 302 eb.add(Element.U8_4(mRS), "U8_4", arraySize); 303 eb.add(Element.U16(mRS), "U16", arraySize); 304 eb.add(Element.U16_2(mRS), "U16_2", arraySize); 305 eb.add(Element.U16_3(mRS), "U16_3", arraySize); 306 eb.add(Element.U16_4(mRS), "U16_4", arraySize); 307 eb.add(Element.U32(mRS), "U32", arraySize); 308 eb.add(Element.U32_2(mRS), "U32_2", arraySize); 309 eb.add(Element.U32_3(mRS), "U32_3", arraySize); 310 eb.add(Element.U32_4(mRS), "U32_4", arraySize); 311 eb.add(Element.U64(mRS), "U64", arraySize); 312 eb.add(Element.U64_2(mRS), "U64_2", arraySize); 313 eb.add(Element.U64_3(mRS), "U64_3", arraySize); 314 eb.add(Element.U64_4(mRS), "U64_4", arraySize); 315 eb.add(Element.MATRIX_2X2(mRS), "MATRIX_2X2", arraySize); 316 eb.add(Element.MATRIX_3X3(mRS), "MATRIX_3X3", arraySize); 317 eb.add(Element.MATRIX_4X4(mRS), "MATRIX_4X4", arraySize); 318 eb.add(Element.MATRIX4X4(mRS), "MATRIX4X4", arraySize); 319 eb.add(Element.MESH(mRS), "MESH", arraySize); 320 eb.add(Element.PROGRAM_FRAGMENT(mRS), "PROGRAM_FRAGMENT", arraySize); 321 eb.add(Element.PROGRAM_RASTER(mRS), "PROGRAM_RASTER", arraySize); 322 eb.add(Element.PROGRAM_STORE(mRS), "PROGRAM_STORE", arraySize); 323 eb.add(Element.PROGRAM_VERTEX(mRS), "PROGRAM_VERTEX", arraySize); 324 eb.add(Element.ALLOCATION(mRS), "ALLOCATION", arraySize); 325 eb.add(Element.SAMPLER(mRS), "SAMPLER", arraySize); 326 eb.add(Element.SCRIPT(mRS), "SCRIPT", arraySize); 327 eb.add(Element.TYPE(mRS), "TYPE", arraySize); 328 eb.add(Element.BOOLEAN(mRS), "BOOLEAN", arraySize); 329 eb.add(Element.ELEMENT(mRS), "ELEMENT", arraySize); 330 assertTrue(eb.create() != null); 331 } 332 } 333 testIsComplex()334 public void testIsComplex() { 335 assertFalse(Element.A_8(mRS).isComplex()); 336 assertFalse(Element.RGBA_4444(mRS).isComplex()); 337 assertFalse(Element.RGBA_5551(mRS).isComplex()); 338 assertFalse(Element.RGB_565(mRS).isComplex()); 339 assertFalse(Element.RGB_888(mRS).isComplex()); 340 assertFalse(Element.RGBA_8888(mRS).isComplex()); 341 assertFalse(Element.F32(mRS).isComplex()); 342 assertFalse(Element.F32_2(mRS).isComplex()); 343 assertFalse(Element.F32_3(mRS).isComplex()); 344 assertFalse(Element.F32_4(mRS).isComplex()); 345 assertFalse(Element.F64(mRS).isComplex()); 346 assertFalse(Element.F64_2(mRS).isComplex()); 347 assertFalse(Element.F64_3(mRS).isComplex()); 348 assertFalse(Element.F64_4(mRS).isComplex()); 349 assertFalse(Element.I8(mRS).isComplex()); 350 assertFalse(Element.I8_2(mRS).isComplex()); 351 assertFalse(Element.I8_3(mRS).isComplex()); 352 assertFalse(Element.I8_4(mRS).isComplex()); 353 assertFalse(Element.I16(mRS).isComplex()); 354 assertFalse(Element.I16_2(mRS).isComplex()); 355 assertFalse(Element.I16_3(mRS).isComplex()); 356 assertFalse(Element.I16_4(mRS).isComplex()); 357 assertFalse(Element.I32(mRS).isComplex()); 358 assertFalse(Element.I32_2(mRS).isComplex()); 359 assertFalse(Element.I32_3(mRS).isComplex()); 360 assertFalse(Element.I32_4(mRS).isComplex()); 361 assertFalse(Element.I64(mRS).isComplex()); 362 assertFalse(Element.I64_2(mRS).isComplex()); 363 assertFalse(Element.I64_3(mRS).isComplex()); 364 assertFalse(Element.I64_4(mRS).isComplex()); 365 assertFalse(Element.U8(mRS).isComplex()); 366 assertFalse(Element.U8_2(mRS).isComplex()); 367 assertFalse(Element.U8_3(mRS).isComplex()); 368 assertFalse(Element.U8_4(mRS).isComplex()); 369 assertFalse(Element.U16(mRS).isComplex()); 370 assertFalse(Element.U16_2(mRS).isComplex()); 371 assertFalse(Element.U16_3(mRS).isComplex()); 372 assertFalse(Element.U16_4(mRS).isComplex()); 373 assertFalse(Element.U32(mRS).isComplex()); 374 assertFalse(Element.U32_2(mRS).isComplex()); 375 assertFalse(Element.U32_3(mRS).isComplex()); 376 assertFalse(Element.U32_4(mRS).isComplex()); 377 assertFalse(Element.U64(mRS).isComplex()); 378 assertFalse(Element.U64_2(mRS).isComplex()); 379 assertFalse(Element.U64_3(mRS).isComplex()); 380 assertFalse(Element.U64_4(mRS).isComplex()); 381 assertFalse(Element.MATRIX_2X2(mRS).isComplex()); 382 assertFalse(Element.MATRIX_3X3(mRS).isComplex()); 383 assertFalse(Element.MATRIX_4X4(mRS).isComplex()); 384 assertFalse(Element.MATRIX4X4(mRS).isComplex()); 385 assertFalse(Element.MESH(mRS).isComplex()); 386 assertFalse(Element.PROGRAM_FRAGMENT(mRS).isComplex()); 387 assertFalse(Element.PROGRAM_RASTER(mRS).isComplex()); 388 assertFalse(Element.PROGRAM_STORE(mRS).isComplex()); 389 assertFalse(Element.PROGRAM_VERTEX(mRS).isComplex()); 390 assertFalse(Element.ALLOCATION(mRS).isComplex()); 391 assertFalse(Element.SAMPLER(mRS).isComplex()); 392 assertFalse(Element.SCRIPT(mRS).isComplex()); 393 assertFalse(Element.TYPE(mRS).isComplex()); 394 assertFalse(Element.BOOLEAN(mRS).isComplex()); 395 assertFalse(Element.ELEMENT(mRS).isComplex()); 396 397 Element.Builder eb = new Element.Builder(mRS); 398 eb.add(Element.F32(mRS), "FLOAT"); 399 eb.add(Element.SAMPLER(mRS), "SAMPLER"); 400 Element e1 = eb.create(); 401 assertFalse(e1.isComplex()); 402 403 eb = new Element.Builder(mRS); 404 eb.add(Element.A_8(mRS), "A_8"); 405 eb.add(Element.RGBA_4444(mRS), "RGBA_4444"); 406 Element e2 = eb.create(); 407 assertFalse(e2.isComplex()); 408 409 eb = new Element.Builder(mRS); 410 eb.add(e1, "e1"); 411 eb.add(e2, "e2"); 412 assertTrue(eb.create().isComplex()); 413 } 414 testDataType()415 public void testDataType() { 416 // Uncomment when NONE is no longer hidden. 417 //assertEquals(DataType.NONE, DataType.valueOf("NONE")); 418 419 assertEquals(DataType.FLOAT_32, DataType.valueOf("FLOAT_32")); 420 assertEquals(DataType.FLOAT_64, DataType.valueOf("FLOAT_64")); 421 assertEquals(DataType.SIGNED_8, DataType.valueOf("SIGNED_8")); 422 assertEquals(DataType.SIGNED_16, DataType.valueOf("SIGNED_16")); 423 assertEquals(DataType.SIGNED_32, DataType.valueOf("SIGNED_32")); 424 assertEquals(DataType.SIGNED_64, DataType.valueOf("SIGNED_64")); 425 assertEquals(DataType.UNSIGNED_8, DataType.valueOf("UNSIGNED_8")); 426 assertEquals(DataType.UNSIGNED_16, DataType.valueOf("UNSIGNED_16")); 427 assertEquals(DataType.UNSIGNED_32, DataType.valueOf("UNSIGNED_32")); 428 assertEquals(DataType.UNSIGNED_64, DataType.valueOf("UNSIGNED_64")); 429 430 assertEquals(DataType.BOOLEAN, DataType.valueOf("BOOLEAN")); 431 432 assertEquals(DataType.UNSIGNED_5_6_5, DataType.valueOf("UNSIGNED_5_6_5")); 433 assertEquals(DataType.UNSIGNED_5_5_5_1, DataType.valueOf("UNSIGNED_5_5_5_1")); 434 assertEquals(DataType.UNSIGNED_4_4_4_4, DataType.valueOf("UNSIGNED_4_4_4_4")); 435 436 assertEquals(DataType.MATRIX_4X4, DataType.valueOf("MATRIX_4X4")); 437 assertEquals(DataType.MATRIX_3X3, DataType.valueOf("MATRIX_3X3")); 438 assertEquals(DataType.MATRIX_2X2, DataType.valueOf("MATRIX_2X2")); 439 440 assertEquals(DataType.RS_ELEMENT, DataType.valueOf("RS_ELEMENT")); 441 assertEquals(DataType.RS_TYPE, DataType.valueOf("RS_TYPE")); 442 assertEquals(DataType.RS_ALLOCATION, DataType.valueOf("RS_ALLOCATION")); 443 assertEquals(DataType.RS_SAMPLER, DataType.valueOf("RS_SAMPLER")); 444 assertEquals(DataType.RS_SCRIPT, DataType.valueOf("RS_SCRIPT")); 445 assertEquals(DataType.RS_MESH, DataType.valueOf("RS_MESH")); 446 assertEquals(DataType.RS_PROGRAM_FRAGMENT, DataType.valueOf("RS_PROGRAM_FRAGMENT")); 447 assertEquals(DataType.RS_PROGRAM_VERTEX, DataType.valueOf("RS_PROGRAM_VERTEX")); 448 assertEquals(DataType.RS_PROGRAM_RASTER, DataType.valueOf("RS_PROGRAM_RASTER")); 449 assertEquals(DataType.RS_PROGRAM_STORE, DataType.valueOf("RS_PROGRAM_STORE")); 450 // Make sure no new enums are added 451 assertEquals(29, DataType.values().length); 452 453 for (DataType dt : DataType.values()) { 454 switch (dt) { 455 case FLOAT_32: 456 case FLOAT_64: 457 case SIGNED_8: 458 case SIGNED_16: 459 case SIGNED_32: 460 case SIGNED_64: 461 case UNSIGNED_8: 462 case UNSIGNED_16: 463 case UNSIGNED_32: 464 case UNSIGNED_64: 465 case BOOLEAN: 466 Element.createVector(mRS, dt, 2); 467 break; 468 469 default: { 470 try { 471 Element.createVector(mRS, dt, 2); 472 fail("should throw RSIllegalArgumentException"); 473 } catch (RSIllegalArgumentException e) { 474 } 475 break; 476 } 477 } 478 } 479 } 480 testDataKind()481 public void testDataKind() { 482 assertEquals(DataKind.USER, DataKind.valueOf("USER")); 483 484 assertEquals(DataKind.PIXEL_L, DataKind.valueOf("PIXEL_L")); 485 assertEquals(DataKind.PIXEL_A, DataKind.valueOf("PIXEL_A")); 486 assertEquals(DataKind.PIXEL_LA, DataKind.valueOf("PIXEL_LA")); 487 assertEquals(DataKind.PIXEL_RGB, DataKind.valueOf("PIXEL_RGB")); 488 assertEquals(DataKind.PIXEL_RGBA, DataKind.valueOf("PIXEL_RGBA")); 489 assertEquals(DataKind.PIXEL_DEPTH, DataKind.valueOf("PIXEL_DEPTH")); 490 assertEquals(DataKind.PIXEL_YUV, DataKind.valueOf("PIXEL_YUV")); 491 // Make sure no new enums are added 492 assertEquals(8, DataKind.values().length); 493 494 for (DataKind dk : DataKind.values()) { 495 if (dk != DataKind.USER && dk != DataKind.PIXEL_YUV) { 496 Element.createPixel(mRS, DataType.UNSIGNED_8, dk); 497 } 498 } 499 } 500 } 501 502 503