Home | History | Annotate | Download | only in dex
      1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
      2 // for details. All rights reserved. Use of this source code is governed by a
      3 // BSD-style license that can be found in the LICENSE file.
      4 
      5 package com.android.tools.r8.dex;
      6 
      7 import static org.junit.Assert.assertEquals;
      8 import static org.junit.Assert.assertSame;
      9 
     10 import com.android.tools.r8.graph.DexItem;
     11 import com.android.tools.r8.graph.DexItemFactory;
     12 import com.android.tools.r8.graph.DexString;
     13 import com.android.tools.r8.graph.DexType;
     14 import org.junit.Test;
     15 
     16 public class DexItemFactoryTest {
     17 
     18   @Test
     19   public void commonItems() {
     20     DexItemFactory factory = new DexItemFactory();
     21 
     22     Object[] data = new Object[]{
     23         "B", factory.byteDescriptor, factory.byteType,
     24         "C", factory.charDescriptor, factory.charType,
     25         "D", factory.doubleDescriptor, factory.doubleType,
     26         "F", factory.floatDescriptor, factory.floatType,
     27         "I", factory.intDescriptor, factory.intType,
     28         "J", factory.longDescriptor, factory.longType,
     29         "S", factory.shortDescriptor, factory.shortType,
     30         "V", factory.voidDescriptor, factory.voidType,
     31         "Z", factory.booleanDescriptor, factory.booleanType,
     32         "Ljava/lang/String;", factory.stringDescriptor, factory.stringType,
     33         "Ljava/lang/Object;", factory.objectDescriptor, factory.objectType,
     34     };
     35 
     36     for (int i = 0; i < data.length; i += 3) {
     37       DexString string1 = factory.createString((String) data[i]);
     38       DexString string2 = factory.createString((String) data[i]);
     39       DexItem type1 = factory.createType(string1);
     40       DexItem type2 = factory.createType(string2);
     41       DexItem expectedDexString = (DexString) data[i + 1];
     42       DexItem expectedDexType = (DexType) data[i + 2];
     43 
     44       assertSame(expectedDexString, string1);
     45       assertSame(expectedDexString, string2);
     46       assertSame(expectedDexType, type1);
     47       assertSame(expectedDexType, type2);
     48     }
     49   }
     50 
     51   @Test
     52   public void getPrimitiveTypeName() {
     53     DexItemFactory factory = new DexItemFactory();
     54     assertEquals("boolean", factory.booleanType.getName());
     55     assertEquals("byte", factory.byteType.getName());
     56     assertEquals("short", factory.shortType.getName());
     57     assertEquals("char", factory.charType.getName());
     58     assertEquals("int", factory.intType.getName());
     59     assertEquals("float", factory.floatType.getName());
     60     assertEquals("long", factory.longType.getName());
     61     assertEquals("double", factory.doubleType.getName());
     62   }
     63 }
     64