Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright 2014, Google Inc.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      9  *     * Redistributions of source code must retain the above copyright
     10  * notice, this list of conditions and the following disclaimer.
     11  *     * Redistributions in binary form must reproduce the above
     12  * copyright notice, this list of conditions and the following disclaimer
     13  * in the documentation and/or other materials provided with the
     14  * distribution.
     15  *     * Neither the name of Google Inc. nor the names of its
     16  * contributors may be used to endorse or promote products derived from
     17  * this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 package org.jf.smalidea.util;
     33 
     34 import junit.framework.Assert;
     35 import org.junit.Test;
     36 
     37 public class NameUtilsTest {
     38 
     39     @Test
     40     public void testConversions() {
     41         testConversion("boolean", "Z");
     42         testConversion("byte", "B");
     43         testConversion("char", "C");
     44         testConversion("short", "S");
     45         testConversion("int", "I");
     46         testConversion("long", "J");
     47         testConversion("float", "F");
     48         testConversion("double", "D");
     49 
     50         testConversion("blah", "Lblah;");
     51         testConversion("my.blah", "Lmy/blah;");
     52 
     53         testConversion("boolean[]", "[Z");
     54         testConversion("byte[]", "[B");
     55         testConversion("char[]", "[C");
     56         testConversion("short[]", "[S");
     57         testConversion("int[]", "[I");
     58         testConversion("long[]", "[J");
     59         testConversion("float[]", "[F");
     60         testConversion("double[]", "[D");
     61 
     62         testConversion("blah[]", "[Lblah;");
     63         testConversion("my.blah[]", "[Lmy/blah;");
     64 
     65         testConversion("boolean[][][][]", "[[[[Z");
     66         testConversion("byte[][][][]", "[[[[B");
     67         testConversion("char[][][][]", "[[[[C");
     68         testConversion("short[][][][]", "[[[[S");
     69         testConversion("int[][][][]", "[[[[I");
     70         testConversion("long[][][][]", "[[[[J");
     71         testConversion("float[][][][]", "[[[[F");
     72         testConversion("double[][][][]", "[[[[D");
     73 
     74         testConversion("blah[][][][]", "[[[[Lblah;");
     75         testConversion("my.blah[][][][]", "[[[[Lmy/blah;");
     76     }
     77 
     78     private static void testConversion(String javaType, String smaliType) {
     79         Assert.assertEquals(javaType, NameUtils.smaliToJavaType(smaliType));
     80         Assert.assertEquals(smaliType, NameUtils.javaToSmaliType(javaType));
     81     }
     82 
     83     public void testShortNameFromQualifiedName() {
     84         Assert.assertEquals("blah", NameUtils.shortNameFromQualifiedName("org.blah.blah"));
     85         Assert.assertEquals("blah", NameUtils.shortNameFromQualifiedName("blah"));
     86     }
     87 }
     88