tests/libjava-mauve/src/gnu/testlet/javax/management/openmbean/ArrayType/Constructor1.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.5
       
     2 
       
     3 // Copyright (C) 2007 Andrew John Hughes <gnu_andrew@member.fsf.org>
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.
       
    21 
       
    22 package gnu.testlet.javax.management.openmbean.ArrayType;
       
    23 
       
    24 import gnu.testlet.TestHarness;
       
    25 import gnu.testlet.Testlet;
       
    26 
       
    27 import javax.management.openmbean.ArrayType;
       
    28 import javax.management.openmbean.CompositeData;
       
    29 import javax.management.openmbean.CompositeType;
       
    30 import javax.management.openmbean.OpenDataException;
       
    31 import javax.management.openmbean.OpenType;
       
    32 import javax.management.openmbean.SimpleType;
       
    33 import javax.management.openmbean.TabularData;
       
    34 import javax.management.openmbean.TabularType;
       
    35 
       
    36 /**
       
    37  * Tests {@link ArrayType(int,javax.management.openmbean.OpenType} constructor.
       
    38  *
       
    39  * @author <a href="mailto:gnu_andrew@member.fsf.org">Andrew John Hughes</a>
       
    40  */
       
    41 public class Constructor1
       
    42   implements Testlet
       
    43 {
       
    44   
       
    45   public void test(TestHarness h)
       
    46   {
       
    47     try
       
    48       {
       
    49 	ArrayType type = new ArrayType(0, SimpleType.INTEGER);
       
    50 	h.fail("Didn't catch dimensions < 1");
       
    51       }
       
    52     catch (IllegalArgumentException e)
       
    53       {
       
    54 	h.check(true, "Threw exception for dimensions of 0");
       
    55       }
       
    56     catch (OpenDataException e)
       
    57       {
       
    58 	h.debug(e);
       
    59       }
       
    60     try
       
    61       {
       
    62 	ArrayType type = new ArrayType(-1, SimpleType.INTEGER);
       
    63 	h.fail("Didn't catch dimensions < 1");
       
    64       }
       
    65     catch (IllegalArgumentException e)
       
    66       {
       
    67 	h.check(true, "Threw exception for dimensions of -1");
       
    68       }
       
    69     catch (OpenDataException e)
       
    70       {
       
    71 	h.debug(e);
       
    72       }
       
    73     try
       
    74       {
       
    75 	h.checkPoint("1-dimensional String array");
       
    76 	ArrayType type = new ArrayType(1, SimpleType.STRING);
       
    77 	h.check(type.getClassName(), "[Ljava.lang.String;");
       
    78 	h.check(type.getTypeName(), "[Ljava.lang.String;");
       
    79 	h.check(type.getElementOpenType().getClassName(), "java.lang.String");
       
    80 	h.check(type.getDescription(), "1-dimension array of java.lang.String");
       
    81 	h.checkPoint("2-dimensional String array");
       
    82 	ArrayType type2 = new ArrayType(2, SimpleType.STRING);
       
    83 	h.check(type2.getClassName(), "[[Ljava.lang.String;");
       
    84 	h.check(type2.getTypeName(), "[[Ljava.lang.String;");
       
    85 	h.check(type2.getElementOpenType().getClassName(), "java.lang.String");
       
    86 	h.check(type2.getDescription(), "2-dimension array of java.lang.String");
       
    87 	h.checkPoint("4-dimensional String array (one constructor)");
       
    88 	ArrayType type3 = new ArrayType(4, SimpleType.STRING);
       
    89 	h.check(type3.getClassName(), "[[[[Ljava.lang.String;");
       
    90 	h.check(type3.getTypeName(), "[[[[Ljava.lang.String;");
       
    91 	h.check(type3.getElementOpenType().getClassName(), "java.lang.String");
       
    92 	h.check(type3.getDescription(), "4-dimension array of java.lang.String");
       
    93 	h.checkPoint("4-dimensional String array (two constructors)");
       
    94 	ArrayType type4 = new ArrayType(2, type2);
       
    95 	h.check(type4.getClassName(), "[[[[Ljava.lang.String;");
       
    96 	h.check(type4.getTypeName(), "[[[[Ljava.lang.String;");
       
    97 	h.check(type4.getElementOpenType().getClassName(), "java.lang.String");
       
    98 	h.check(type4.getDescription(), "4-dimension array of java.lang.String");
       
    99 	h.checkPoint("Composite Type Array");
       
   100 	CompositeType ctype = new CompositeType("Test","Test",new String[]{"name"},
       
   101 						new String[]{"Name"},
       
   102 						new OpenType[] { SimpleType.STRING});
       
   103 	ArrayType type5 = new ArrayType(1, ctype);
       
   104 	String className = CompositeData.class.getName();
       
   105 	h.check(type5.getClassName(), "[L" + className + ";");
       
   106 	h.check(type5.getTypeName(), "[L" + className + ";");
       
   107 	h.check(type5.getElementOpenType().getClassName(), className);
       
   108 	h.check(type5.getDescription(), "1-dimension array of " + className);
       
   109 	h.checkPoint("Tabular Type Array");
       
   110 	TabularType ttype = new TabularType("Test","Test",ctype,new String[]{"name"});
       
   111 	ArrayType type6 = new ArrayType(1, ttype);
       
   112 	className = TabularData.class.getName();
       
   113 	h.check(type6.getClassName(), "[L" + className + ";");
       
   114 	h.check(type6.getTypeName(), "[L" + className + ";");
       
   115 	h.check(type6.getElementOpenType().getClassName(), className);
       
   116 	h.check(type6.getDescription(), "1-dimension array of " + className);	
       
   117       }
       
   118     catch (OpenDataException e)
       
   119       {
       
   120 	h.debug(e);
       
   121       }
       
   122     try
       
   123       {
       
   124 	ArrayType type = new ArrayType(-1, new OpenType("Mauve","Mauve","Mauve")
       
   125 	  {
       
   126 	    public boolean equals(Object obj)
       
   127 	    {
       
   128 	      return false;
       
   129 	    }
       
   130 
       
   131 	    public int hashCode()
       
   132 	    {
       
   133 	      return 42;
       
   134 	    }
       
   135 
       
   136 	    public boolean isValue(Object obj)
       
   137 	    {
       
   138 	      return false;
       
   139 	    }
       
   140 
       
   141 	    public String toString()
       
   142 	    {
       
   143 	      return "Mauve";
       
   144 	    }
       
   145 	  });
       
   146 	h.fail("Didn't catch our own OpenType");
       
   147       }
       
   148     catch (OpenDataException e)
       
   149       {
       
   150 	h.check(true, "Threw exception for invalid OpenType");
       
   151       }
       
   152     
       
   153   }
       
   154   
       
   155 }