Home | History | Annotate | Download | only in ClassType
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 package org.apache.harmony.jpda.tests.jdwp.ClassType;
     20 
     21 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     22 import org.apache.harmony.jpda.tests.framework.jdwp.Value;
     23 
     24 import java.util.List;
     25 
     26 /**
     27  * JDWP unit test for ClassType.NewInstance command for particular reference
     28  * types.
     29  *
     30  * <p>Note:
     31  * <ul>
     32  *  <li>we do not test JT_CLASS because we cannot create java.lang.Class objects.</li>
     33  *  <li>We do not test JT_ARRAY because arrays are created with ArrayType.NewInstance.</li>
     34  * </ul></p>
     35  */
     36 public class NewInstanceTagTest extends AbstractNewInstanceTestCase {
     37 
     38     @Override
     39     protected String getDebuggeeClassName() {
     40         return NewInstanceTagDebuggee.class.getName();
     41     }
     42 
     43     /**
     44      * Test ClassType.NewInstance of java.lang.Object returns JT_OBJECT tag.
     45      */
     46     public void testNewInstance_Object() {
     47         checkNewInstanceTag("Ljava/lang/Object;", "()V", new NoConstructorArgumentProvider(),
     48                 new Checker(JDWPConstants.Tag.OBJECT_TAG));
     49     }
     50 
     51     /**
     52      * Test ClassType.NewInstance of a subclass of java.lang.Object returns JT_OBJECT tag.
     53      */
     54     public void testNewInstance_MyObject() {
     55         String subclassSig = getClassSignature(NewInstanceTagDebuggee.MyObject.class);
     56         checkNewInstanceTag(subclassSig, "()V", new NoConstructorArgumentProvider(),
     57                 new Checker(JDWPConstants.Tag.OBJECT_TAG));
     58     }
     59 
     60     /**
     61      * Test ClassType.NewInstance of java.lang.String returns JT_STRING tag.
     62      */
     63     public void testNewInstance_String() {
     64         checkNewInstanceTag("Ljava/lang/String;", "()V", new NoConstructorArgumentProvider(),
     65                 new Checker(JDWPConstants.Tag.STRING_TAG));
     66     }
     67 
     68     /**
     69      * Test ClassType.NewInstance of a subclass of java.lang.ClassLoader returns
     70      * JT_CLASS_LOADER tag.
     71      *
     72      * Note: we use a subclass only because java.lang.ClassLoader is an abstract
     73      * class.
     74      */
     75     public void testNewInstance_ClassLoader() {
     76         String subclassSig = getClassSignature(NewInstanceTagDebuggee.MyClassLoader.class);
     77         checkNewInstanceTag(subclassSig, "()V", new NoConstructorArgumentProvider(),
     78                 new Checker(JDWPConstants.Tag.CLASS_LOADER_TAG));
     79     }
     80 
     81     /**
     82      * Test ClassType.NewInstance of java.lang.Thread returns JT_THREAD tag.
     83      */
     84     public void testNewInstance_Thread() {
     85         checkNewInstanceTag("Ljava/lang/Thread;", "()V", new NoConstructorArgumentProvider(),
     86                 new Checker(JDWPConstants.Tag.THREAD_TAG));
     87     }
     88 
     89     /**
     90      * Test ClassType.NewInstance of a subclass of java.lang.Thread returns
     91      * JT_THREAD tag.
     92      */
     93     public void testNewInstance_MyThread() {
     94         String subclassSig = getClassSignature(NewInstanceTagDebuggee.MyThread.class);
     95         checkNewInstanceTag(subclassSig, "()V", new NoConstructorArgumentProvider(),
     96                 new Checker(JDWPConstants.Tag.THREAD_TAG));
     97     }
     98 
     99     /**
    100      * Test ClassType.NewInstance of java.lang.ThreadGroup returns
    101      * JT_THREAD_GROUP tag.
    102      */
    103     public void testNewInstance_ThreadGroup() {
    104         checkNewInstanceTag("Ljava/lang/ThreadGroup;", "(Ljava/lang/String;)V",
    105                 new ConstructorArgumentsProvider() {
    106                     @Override
    107                     public void provideConstructorArguments(List<Value> constructorArguments) {
    108                         // Create string "foo".
    109                         long stringId = debuggeeWrapper.vmMirror.createString("foo");
    110                         assertTrue("Invalid string id", stringId != -1);
    111                         assertTrue("Null string id", stringId != 0);
    112                         // Pass created string to constructor.
    113                         constructorArguments.add(Value.createObjectValue(JDWPConstants.Tag.STRING_TAG, stringId));
    114                     }
    115                 }, new Checker(JDWPConstants.Tag.THREAD_GROUP_TAG));
    116     }
    117 
    118     /**
    119      * Test ClassType.NewInstance of a subclass of java.lang.ThreadGroup returns
    120      * JT_THREAD_GROUP tag.
    121      */
    122     public void testNewInstance_MyThreadGroup() {
    123         String subclassSig = getClassSignature(NewInstanceTagDebuggee.MyThreadGroup.class);
    124         checkNewInstanceTag(subclassSig, "()V", new NoConstructorArgumentProvider(),
    125                 new Checker(JDWPConstants.Tag.THREAD_GROUP_TAG));
    126     }
    127 }
    128