jdk/test/java/dyn/MethodTypeTest.java
changeset 8823 7cd28219a1e4
parent 8717 f75a1efb1412
parent 8822 8145ab9f5f86
child 8824 0762fa26f813
child 9033 a88f5656f05d
equal deleted inserted replaced
8717:f75a1efb1412 8823:7cd28219a1e4
     1 /*
       
     2  * Copyright 2008, 2011 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 /* @test
       
    27  * @summary unit tests for java.dyn.MethodType
       
    28  * @compile MethodTypeTest.java
       
    29  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles test.java.dyn.MethodTypeTest
       
    30  */
       
    31 
       
    32 package test.java.dyn;
       
    33 
       
    34 import sun.dyn.MemberName;
       
    35 import java.dyn.MethodType;
       
    36 import java.lang.reflect.Method;
       
    37 
       
    38 import java.util.*;
       
    39 import org.junit.*;
       
    40 import static org.junit.Assert.*;
       
    41 
       
    42 /**
       
    43  *
       
    44  * @author jrose
       
    45  */
       
    46 public class MethodTypeTest {
       
    47 
       
    48     private Class<?> rtype;
       
    49     private Class<?>[] ptypes;
       
    50     private MethodType mt_viS, mt_OO, mt_OO2, mt_vv, mt_Vv, mt_Ov;
       
    51     private MethodType mt_iSI, mt_ISi, mt_ISI, mt_iSi;
       
    52     private MethodType mt_viO, mt_iO2, mt_OOi, mt_iOi;
       
    53     private MethodType mt_VIO, mt_IO2, mt_OOI, mt_IOI, mt_VIS;
       
    54     private MethodType mt_vOiSzA, mt_OO99;
       
    55     private MethodType[] GALLERY;
       
    56     private Method compareTo;
       
    57 
       
    58     @Before
       
    59     public void setUp() throws Exception {
       
    60         rtype = void.class;
       
    61         ptypes = new Class<?>[] { int.class, String.class };
       
    62 
       
    63         mt_viS = MethodType.methodType(void.class, int.class, String.class);
       
    64         mt_OO = MethodType.methodType(Object.class, Object.class);
       
    65         mt_OO2 = MethodType.methodType(Object.class, Object.class, Object.class);
       
    66         mt_vv = MethodType.methodType(void.class);
       
    67         mt_Vv = MethodType.methodType(Void.class);
       
    68         mt_Ov = MethodType.methodType(Object.class);
       
    69         mt_iSI = MethodType.methodType(int.class, String.class, Integer.class);
       
    70         mt_ISi = MethodType.methodType(Integer.class, String.class, int.class);
       
    71         mt_ISI = MethodType.methodType(Integer.class, String.class, Integer.class);
       
    72         mt_iSi = MethodType.methodType(int.class, String.class, int.class);
       
    73 
       
    74         compareTo = String.class.getDeclaredMethod("compareTo", String.class);
       
    75 
       
    76         mt_viO = MethodType.methodType(void.class, int.class, Object.class);
       
    77         mt_iO2 = MethodType.methodType(int.class, Object.class, Object.class);
       
    78         mt_OOi = MethodType.methodType(Object.class, Object.class, int.class);
       
    79         mt_iOi = MethodType.methodType(int.class, Object.class, int.class);
       
    80 
       
    81         mt_VIO = MethodType.methodType(Void.class, Integer.class, Object.class);
       
    82         mt_IO2 = MethodType.methodType(Integer.class, Object.class, Object.class);
       
    83         mt_OOI = MethodType.methodType(Object.class, Object.class, Integer.class);
       
    84         mt_IOI = MethodType.methodType(Integer.class, Object.class, Integer.class);
       
    85         mt_VIS = MethodType.methodType(Void.class, Integer.class, String.class);
       
    86 
       
    87         mt_vOiSzA = MethodType.methodType(void.class, Object.class, int.class, String.class, boolean.class, Object[].class);
       
    88         mt_OO99 = MethodType.genericMethodType(99);
       
    89 
       
    90         GALLERY = new MethodType[] {
       
    91             mt_viS, mt_OO, mt_OO2, mt_vv, mt_Vv, mt_Ov,
       
    92             mt_iSI, mt_ISi, mt_ISI, mt_iSi,
       
    93             mt_viO, mt_iO2, mt_OOi, mt_iOi,
       
    94             mt_VIO, mt_IO2, mt_OOI, mt_IOI,
       
    95             mt_VIS, mt_vOiSzA, mt_OO99
       
    96         };
       
    97     }
       
    98 
       
    99     @After
       
   100     public void tearDown() throws Exception {
       
   101     }
       
   102 
       
   103     /** Make sure the method types are all distinct. */
       
   104     @Test
       
   105     public void testDistinct() {
       
   106         List<MethodType> gallery2 = new ArrayList<>();
       
   107         for (MethodType mt : GALLERY) {
       
   108             assertFalse(mt.toString(), gallery2.contains(mt));
       
   109             gallery2.add(mt);
       
   110         }
       
   111         // check self-equality also:
       
   112         assertEquals(Arrays.asList(GALLERY), gallery2);
       
   113     }
       
   114 
       
   115     /**
       
   116      * Test of make method, of class MethodType.
       
   117      */
       
   118     @Test
       
   119     public void testMake_Class_ClassArr() {
       
   120         System.out.println("make (from type array)");
       
   121         MethodType result = MethodType.methodType(rtype, ptypes);
       
   122         assertSame(mt_viS, result);
       
   123     }
       
   124 
       
   125     /**
       
   126      * Test of make method, of class MethodType.
       
   127      */
       
   128     @Test
       
   129     public void testMake_Class_List() {
       
   130         System.out.println("make (from type list)");
       
   131         MethodType result = MethodType.methodType(rtype, Arrays.asList(ptypes));
       
   132         assertSame(mt_viS, result);
       
   133     }
       
   134 
       
   135     /**
       
   136      * Test of make method, of class MethodType.
       
   137      */
       
   138     @Test
       
   139     public void testMake_3args() {
       
   140         System.out.println("make (from type with varargs)");
       
   141         MethodType result = MethodType.methodType(rtype, ptypes[0], ptypes[1]);
       
   142         assertSame(mt_viS, result);
       
   143     }
       
   144 
       
   145     /**
       
   146      * Test of make method, of class MethodType.
       
   147      */
       
   148     @Test
       
   149     public void testMake_Class() {
       
   150         System.out.println("make (from single type)");
       
   151         Class<?> rt = Integer.class;
       
   152         MethodType expResult = MethodType.methodType(rt, new Class<?>[0]);
       
   153         MethodType result = MethodType.methodType(rt);
       
   154         assertSame(expResult, result);
       
   155     }
       
   156 
       
   157     @Test
       
   158     public void testMakeGeneric() {
       
   159         System.out.println("makeGeneric");
       
   160         int objectArgCount = 2;
       
   161         MethodType expResult = mt_OO2;
       
   162         MethodType result = MethodType.genericMethodType(objectArgCount);
       
   163         assertSame(expResult, result);
       
   164     }
       
   165 
       
   166     /**
       
   167      * Test of make method, of class MethodType.
       
   168      */
       
   169     @Test
       
   170     public void testMake_Method() {
       
   171         System.out.println("make (via MemberName.getMethodType)");
       
   172         MethodType expResult = MethodType.methodType(int.class, String.class);
       
   173         MemberName name = new MemberName(compareTo);
       
   174         MethodType result = name.getMethodType();
       
   175         assertSame(expResult, result);
       
   176     }
       
   177 
       
   178     /**
       
   179      * Test of make method, of class MethodType.
       
   180      */
       
   181     @Test
       
   182     public void testMake_MethodType() {
       
   183         System.out.println("make (from rtype, MethodType)");
       
   184         MethodType expResult = mt_iO2;
       
   185         MethodType result = MethodType.methodType(int.class, mt_IO2);
       
   186         assertSame(expResult, result);
       
   187     }
       
   188 
       
   189     /**
       
   190      * Test of make method, of class MethodType.
       
   191      */
       
   192     @Test
       
   193     public void testMake_String_ClassLoader() {
       
   194         System.out.println("make (from bytecode signature)");
       
   195         ClassLoader loader = null;
       
   196         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   197         String obj = "Ljava/lang/Object;";
       
   198         assertEquals(obj, concat(Object.class));
       
   199         String[] expResults = {
       
   200             "(ILjava/lang/String;)V",
       
   201             concat("(", obj, 2, ")", Object.class),
       
   202             "()V", "()"+obj,
       
   203             concat("(", String.class, Integer.class, ")I"),
       
   204             concat("(", String.class, "I)", Integer.class),
       
   205             concat("(", String.class, Integer.class, ")", Integer.class),
       
   206             concat("(", String.class, "I)I")
       
   207         };
       
   208         for (int i = 0; i < instances.length; i++) {
       
   209             MethodType instance = instances[i];
       
   210             String result = instance.toMethodDescriptorString();
       
   211             assertEquals("#"+i, expResults[i], result);
       
   212             MethodType parsed = MethodType.fromMethodDescriptorString(result, loader);
       
   213             assertSame("--#"+i, instance, parsed);
       
   214         }
       
   215     }
       
   216     private static String concat(Object... parts) {
       
   217         StringBuilder sb = new StringBuilder();
       
   218         Object prevPart = "";
       
   219         for (Object part : parts) {
       
   220             if (part instanceof Class) {
       
   221                 part = "L"+((Class)part).getName()+";";
       
   222             }
       
   223             if (part instanceof Integer) {
       
   224                 for (int n = (Integer) part; n > 1; n--)
       
   225                     sb.append(prevPart);
       
   226                 part = "";
       
   227             }
       
   228             sb.append(part);
       
   229             prevPart = part;
       
   230         }
       
   231         return sb.toString().replace('.', '/');
       
   232     }
       
   233 
       
   234     @Test
       
   235     public void testHasPrimitives() {
       
   236         System.out.println("hasPrimitives");
       
   237         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   238         boolean[] expResults =   {true,   false,  true,  false, true,   true,   false,  true};
       
   239         for (int i = 0; i < instances.length; i++) {
       
   240             boolean result = instances[i].hasPrimitives();
       
   241             assertEquals("#"+i, expResults[i], result);
       
   242         }
       
   243     }
       
   244 
       
   245     @Test
       
   246     public void testHasWrappers() {
       
   247         System.out.println("hasWrappers");
       
   248         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   249         boolean[] expResults =   {false,  false,  false, false, true,   true,   true,   false};
       
   250         for (int i = 0; i < instances.length; i++) {
       
   251             System.out.println("  hasWrappers "+instances[i]);
       
   252             boolean result = instances[i].hasWrappers();
       
   253             assertEquals("#"+i, expResults[i], result);
       
   254         }
       
   255     }
       
   256 
       
   257     @Test
       
   258     public void testErase() {
       
   259         System.out.println("erase");
       
   260         MethodType[] instances  = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   261         MethodType[] expResults = {mt_viO, mt_OO2, mt_vv, mt_Ov, mt_iO2, mt_OOi, mt_OO2, mt_iOi};
       
   262         for (int i = 0; i < instances.length; i++) {
       
   263             MethodType result = instances[i].erase();
       
   264             assertSame("#"+i, expResults[i], result);
       
   265         }
       
   266     }
       
   267 
       
   268     @Test
       
   269     public void testGeneric() {
       
   270         System.out.println("generic");
       
   271         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   272         MethodType[] expResults = {mt_OO2, mt_OO2, mt_Ov, mt_Ov, mt_OO2, mt_OO2, mt_OO2, mt_OO2};
       
   273         for (int i = 0; i < instances.length; i++) {
       
   274             MethodType result = instances[i].generic();
       
   275             assertSame("#"+i, expResults[i], result);
       
   276         }
       
   277     }
       
   278 
       
   279     @Test
       
   280     public void testWrap() {
       
   281         System.out.println("wrap");
       
   282         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   283         MethodType[] expResults = {mt_VIS, mt_OO2, mt_Vv, mt_Ov, mt_ISI, mt_ISI, mt_ISI, mt_ISI};
       
   284         for (int i = 0; i < instances.length; i++) {
       
   285             MethodType result = instances[i].wrap();
       
   286             assertSame("#"+i, expResults[i], result);
       
   287         }
       
   288     }
       
   289 
       
   290     @Test
       
   291     public void testUnwrap() {
       
   292         System.out.println("unwrap");
       
   293         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   294         MethodType[] expResults = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSi, mt_iSi, mt_iSi, mt_iSi};
       
   295         for (int i = 0; i < instances.length; i++) {
       
   296             MethodType result = instances[i].unwrap();
       
   297             assertSame("#"+i, expResults[i], result);
       
   298         }
       
   299     }
       
   300 
       
   301     /**
       
   302      * Test of parameterType method, of class MethodType.
       
   303      */
       
   304     @Test
       
   305     public void testParameterType() {
       
   306         System.out.println("parameterType");
       
   307         for (int num = 0; num < ptypes.length; num++) {
       
   308             MethodType instance = mt_viS;
       
   309             Class<?> expResult = ptypes[num];
       
   310             Class<?> result = instance.parameterType(num);
       
   311             assertSame(expResult, result);
       
   312         }
       
   313     }
       
   314 
       
   315     /**
       
   316      * Test of parameterCount method, of class MethodType.
       
   317      */
       
   318     @Test
       
   319     public void testParameterCount() {
       
   320         System.out.println("parameterCount");
       
   321         MethodType instance = mt_viS;
       
   322         int expResult = 2;
       
   323         int result = instance.parameterCount();
       
   324         assertEquals(expResult, result);
       
   325     }
       
   326 
       
   327     /**
       
   328      * Test of returnType method, of class MethodType.
       
   329      */
       
   330     @Test
       
   331     public void testReturnType() {
       
   332         System.out.println("returnType");
       
   333         MethodType instance = mt_viS;
       
   334         Class<?> expResult = void.class;
       
   335         Class<?> result = instance.returnType();
       
   336         assertSame(expResult, result);
       
   337     }
       
   338 
       
   339     /**
       
   340      * Test of parameterList method, of class MethodType.
       
   341      */
       
   342     @Test
       
   343     public void testParameterList() {
       
   344         System.out.println("parameterList");
       
   345         MethodType instance = mt_viS;
       
   346         List<Class<?>> expResult = Arrays.asList(ptypes);
       
   347         List<Class<?>> result = instance.parameterList();
       
   348         assertEquals(expResult, result);
       
   349     }
       
   350 
       
   351     /**
       
   352      * Test of parameterArray method, of class MethodType.
       
   353      */
       
   354     @Test
       
   355     public void testParameterArray() {
       
   356         System.out.println("parameterArray");
       
   357         MethodType instance = mt_viS;
       
   358         Class<?>[] expResult = ptypes;
       
   359         Class<?>[] result = instance.parameterArray();
       
   360         assertEquals(Arrays.asList(expResult), Arrays.asList(result));
       
   361     }
       
   362 
       
   363     /**
       
   364      * Test of equals method, of class MethodType.
       
   365      */
       
   366     @Test
       
   367     public void testEquals_Object() {
       
   368         System.out.println("equals");
       
   369         Object x = null;
       
   370         MethodType instance = mt_viS;
       
   371         boolean expResult = false;
       
   372         boolean result = instance.equals(x);
       
   373         assertEquals(expResult, result);
       
   374     }
       
   375 
       
   376     /**
       
   377      * Test of equals method, of class MethodType.
       
   378      */
       
   379     @Test
       
   380     public void testEquals_MethodType() {
       
   381         System.out.println("equals");
       
   382         MethodType that = mt_viS;
       
   383         MethodType instance = mt_viS;
       
   384         boolean expResult = true;
       
   385         boolean result = instance.equals(that);
       
   386         assertEquals(expResult, result);
       
   387     }
       
   388 
       
   389     /**
       
   390      * Test of hashCode method, of class MethodType.
       
   391      */
       
   392     @Test
       
   393     public void testHashCode() {
       
   394         System.out.println("hashCode");
       
   395         MethodType instance = mt_viS;
       
   396         ArrayList<Class<?>> types = new ArrayList<Class<?>>();
       
   397         types.add(instance.returnType());
       
   398         types.addAll(instance.parameterList());
       
   399         int expResult = types.hashCode();
       
   400         int result = instance.hashCode();
       
   401         assertEquals(expResult, result);
       
   402     }
       
   403 
       
   404     /**
       
   405      * Test of toString method, of class MethodType.
       
   406      */
       
   407     @Test
       
   408     public void testToString() {
       
   409         System.out.println("toString");
       
   410         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
       
   411         //String expResult = "void[int, class java.lang.String]";
       
   412         String[] expResults = {
       
   413             "(int,String)void",
       
   414             "(Object,Object)Object",
       
   415             "()void",
       
   416             "()Object",
       
   417             "(String,Integer)int",
       
   418             "(String,int)Integer",
       
   419             "(String,Integer)Integer",
       
   420             "(String,int)int"
       
   421         };
       
   422         for (int i = 0; i < instances.length; i++) {
       
   423             MethodType instance = instances[i];
       
   424             String result = instance.toString();
       
   425             System.out.println("#"+i+":"+result);
       
   426             assertEquals("#"+i, expResults[i], result);
       
   427         }
       
   428     }
       
   429 
       
   430     private static byte[] writeSerial(Object x) throws java.io.IOException {
       
   431         try (java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
       
   432              java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(bout)
       
   433              ) {
       
   434             out.writeObject(x);
       
   435             out.flush();
       
   436             return bout.toByteArray();
       
   437         }
       
   438     }
       
   439     private static Object readSerial(byte[] wire) throws java.io.IOException, ClassNotFoundException {
       
   440         try (java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(wire);
       
   441              java.io.ObjectInputStream in = new java.io.ObjectInputStream(bin)) {
       
   442             return in.readObject();
       
   443         }
       
   444     }
       
   445     private static void testSerializedEquality(Object x) throws java.io.IOException, ClassNotFoundException {
       
   446         if (x instanceof Object[])
       
   447             x = Arrays.asList((Object[]) x);  // has proper equals method
       
   448         byte[] wire = writeSerial(x);
       
   449         Object y = readSerial(wire);
       
   450         assertEquals(x, y);
       
   451     }
       
   452 
       
   453     /** Test (de-)serialization. */
       
   454     @Test
       
   455     public void testSerialization() throws Throwable {
       
   456         System.out.println("serialization");
       
   457         for (MethodType mt : GALLERY) {
       
   458             testSerializedEquality(mt);
       
   459         }
       
   460         testSerializedEquality(GALLERY);
       
   461 
       
   462         // Make a list of mixed objects:
       
   463         List<Object> stuff = new ArrayList<>();
       
   464         Collections.addAll(stuff, GALLERY);  // copy #1
       
   465         Object[] triples = Arrays.copyOfRange(GALLERY, 0, GALLERY.length/2);
       
   466         Collections.addAll(stuff, triples);  // copy #3 (partial)
       
   467         for (MethodType mt : GALLERY) {
       
   468             Collections.addAll(stuff, mt.parameterArray());
       
   469         }
       
   470         Collections.shuffle(stuff, new Random(292));
       
   471         Collections.addAll(stuff, GALLERY);  // copy #2
       
   472         testSerializedEquality(stuff);
       
   473     }
       
   474 
       
   475     /** Test serialization formats. */
       
   476     @Test
       
   477     public void testPortableSerialFormat() throws Throwable {
       
   478         System.out.println("portable serial format");
       
   479         Object[][] cases = {
       
   480             { mt_vv, new byte[] {  // ()void
       
   481                     (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x13,
       
   482                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x64, (byte)0x79, (byte)0x6e,
       
   483                     (byte)0x2e, (byte)0x4d, (byte)0x65, (byte)0x74, (byte)0x68, (byte)0x6f, (byte)0x64, (byte)0x54,
       
   484                     (byte)0x79, (byte)0x70, (byte)0x65, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
       
   485                     (byte)0x00, (byte)0x01, (byte)0x24, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
       
   486                     (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x04, (byte)0x76, (byte)0x6f, (byte)0x69, (byte)0x64,
       
   487                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
       
   488                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00,
       
   489                     (byte)0x12, (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e,
       
   490                     (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x43, (byte)0x6c, (byte)0x61,
       
   491                     (byte)0x73, (byte)0x73, (byte)0x3b, (byte)0xab, (byte)0x16, (byte)0xd7, (byte)0xae, (byte)0xcb,
       
   492                     (byte)0xcd, (byte)0x5a, (byte)0x99, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
       
   493                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78,
       
   494                 } },
       
   495             { mt_OO, new byte[] {  // (Object)Object
       
   496                     (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x13,
       
   497                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x64, (byte)0x79, (byte)0x6e,
       
   498                     (byte)0x2e, (byte)0x4d, (byte)0x65, (byte)0x74, (byte)0x68, (byte)0x6f, (byte)0x64, (byte)0x54,
       
   499                     (byte)0x79, (byte)0x70, (byte)0x65, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
       
   500                     (byte)0x00, (byte)0x01, (byte)0x24, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
       
   501                     (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x10, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61,
       
   502                     (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x4f, (byte)0x62,
       
   503                     (byte)0x6a, (byte)0x65, (byte)0x63, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
       
   504                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78,
       
   505                     (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00, (byte)0x12, (byte)0x5b, (byte)0x4c, (byte)0x6a,
       
   506                     (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67,
       
   507                     (byte)0x2e, (byte)0x43, (byte)0x6c, (byte)0x61, (byte)0x73, (byte)0x73, (byte)0x3b, (byte)0xab,
       
   508                     (byte)0x16, (byte)0xd7, (byte)0xae, (byte)0xcb, (byte)0xcd, (byte)0x5a, (byte)0x99, (byte)0x02,
       
   509                     (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
       
   510                     (byte)0x71, (byte)0x00, (byte)0x7e, (byte)0x00, (byte)0x03, (byte)0x78,
       
   511                 } },
       
   512         };
       
   513         boolean generateData = false;
       
   514         //generateData = true;
       
   515         for (Object[] c : cases) {
       
   516             MethodType mt = (MethodType) c[0];
       
   517             System.out.println("deserialize "+mt);
       
   518             byte[] wire = (byte[]) c[1];
       
   519             if (generateData) {
       
   520                 wire = writeSerial(mt);
       
   521                 final String INDENT = "                ";
       
   522                 System.out.print("{  // "+mt);
       
   523                 for (int i = 0; i < wire.length; i++) {
       
   524                     if (i % 8 == 0) { System.out.println(); System.out.print(INDENT+"   "); }
       
   525                     String hex = Integer.toHexString(wire[i] & 0xFF);
       
   526                     if (hex.length() == 1)  hex = "0"+hex;
       
   527                     System.out.print(" (byte)0x"+hex+",");
       
   528                 }
       
   529                 System.out.println();
       
   530                 System.out.println(INDENT+"}");
       
   531                 System.out.flush();
       
   532             }
       
   533             Object decode;
       
   534             try {
       
   535                 decode = readSerial(wire);
       
   536             } catch (Exception ex) {
       
   537                 decode = ex;  // oops!
       
   538             }
       
   539             assertEquals(mt, decode);
       
   540         }
       
   541     }
       
   542 }