You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import junit.framework.TestCase;
  14. import org.aspectj.testing.util.TestUtil;
  15. /**
  16. * This is a test case for all the portions of TypeX that don't require a world.
  17. */
  18. public class TypeXTestCase extends TestCase {
  19. public TypeXTestCase(String name) {
  20. super(name);
  21. }
  22. public void testUnresolvedTypes() {
  23. // basic equality
  24. String[] testNames =
  25. new String[] {"int", "long", "int[]", "boolean[][]",
  26. "java.lang.String", "java.lang.String[]", "void" };
  27. String[] testSigs =
  28. new String[] {"I", "J", "[I", "[[Z",
  29. "Ljava/lang/String;", "[Ljava/lang/String;", "V" };
  30. String[] componentNames =
  31. new String[] {null, null, "int", "boolean[]",
  32. null, "java.lang.String", null };
  33. int[] sizes = new int[] {1, 2, 1, 1, 1, 1, 0};
  34. boolean[] isPrimitive =
  35. new boolean[] { true, true, false, false, false, false, true };
  36. nameSignatureTest(testNames, testSigs);
  37. arrayTest(TypeX.forNames(testNames), componentNames);
  38. arrayTest(TypeX.forSignatures(testSigs), componentNames);
  39. sizeTest(TypeX.forNames(testNames), sizes);
  40. sizeTest(TypeX.forSignatures(testSigs), sizes);
  41. isPrimitiveTest(TypeX.forSignatures(testSigs), isPrimitive);
  42. }
  43. public void testNameAndSigWithInners() {
  44. TypeX t = TypeX.forName("java.util.Map$Entry");
  45. assertEquals(t.getName(), "java.util.Map$Entry");
  46. assertEquals(t.getSignature(), "Ljava/util/Map$Entry;");
  47. assertEquals(t.getOutermostType(), TypeX.forName("java.util.Map"));
  48. assertEquals(TypeX.forName("java.util.Map").getOutermostType(), TypeX.forName("java.util.Map"));
  49. }
  50. public void testNameAndSigWithParameters() {
  51. TypeX t = TypeX.forName("java.util.List<java.lang.String>");
  52. assertEquals(t.getName(),"java.util.List<java.lang.String>");
  53. assertEquals(t.getSignature(),"Ljava/util/List<Ljava/lang/String;>;");
  54. t = new TypeX("Ljava/util/List<Ljava/lang/String;>;");
  55. assertEquals(t.getName(),"java.util.List<java.lang.String>");
  56. assertEquals(t.getSignature(),"Ljava/util/List<Ljava/lang/String;>;");
  57. t = TypeX.forName("java.util.Map<java.util.String,java.util.List<java.lang.Integer>>");
  58. assertEquals(t.getName(),"java.util.Map<java.util.String,java.util.List<java.lang.Integer>>");
  59. assertEquals(t.getSignature(),"Ljava/util/Map<Ljava/util/String;Ljava/util/List<Ljava/lang/Integer;>;>;");
  60. t = new TypeX("Ljava/util/Map<Ljava/util/String;Ljava/util/List<Ljava/lang/Integer;>;>;");
  61. assertEquals(t.getName(),"java.util.Map<java.util.String,java.util.List<java.lang.Integer>>");
  62. assertEquals(t.getSignature(),"Ljava/util/Map<Ljava/util/String;Ljava/util/List<Ljava/lang/Integer;>;>;");
  63. }
  64. private void isPrimitiveTest(TypeX[] types, boolean[] isPrimitives) {
  65. for (int i = 0, len = types.length; i < len; i++) {
  66. TypeX type = types[i];
  67. boolean b = isPrimitives[i];
  68. assertEquals(type + " is primitive: ", b, type.isPrimitive());
  69. }
  70. }
  71. private void sizeTest(TypeX[] types, int[] sizes) {
  72. for (int i = 0, len = types.length; i < len; i++) {
  73. TypeX type = types[i];
  74. int size = sizes[i];
  75. assertEquals("size of " + type + ": ", size, type.getSize());
  76. }
  77. }
  78. private void arrayTest(TypeX[] types, String[] components) {
  79. for (int i = 0, len = types.length; i < len; i++) {
  80. TypeX type = types[i];
  81. String component = components[i];
  82. assertEquals(type + " is array: ", component != null, type.isArray());
  83. if (component != null)
  84. assertEquals(type + " componentType: ", component,
  85. type.getComponentType().getName());
  86. }
  87. }
  88. private void nameSignatureTest(String[] ns, String[] ss) {
  89. for (int i = 0, len = ns.length; i < len; i++) {
  90. String n = ns[i];
  91. String s = ss[i];
  92. TypeX tn = TypeX.forName(n);
  93. TypeX ts = TypeX.forSignature(s);
  94. assertEquals("forName(n).getName()", n,
  95. tn.getName());
  96. assertEquals("forSignature(s).getSignature()", s,
  97. ts.getSignature());
  98. assertEquals("forName(n).getSignature()", s,
  99. tn.getSignature());
  100. assertEquals("forSignature(n).getName()", n,
  101. ts.getName());
  102. TestUtil.assertCommutativeEquals(tn, tn, true);
  103. TestUtil.assertCommutativeEquals(ts, ts, true);
  104. TestUtil.assertCommutativeEquals(tn, ts, true);
  105. for (int j = 0; j < len; j++) {
  106. if (i == j) continue;
  107. TypeX tn1 = TypeX.forName(ns[j]);
  108. TypeX ts1 = TypeX.forSignature(ss[j]);
  109. TestUtil.assertCommutativeEquals(tn, tn1, false);
  110. TestUtil.assertCommutativeEquals(ts, tn1, false);
  111. TestUtil.assertCommutativeEquals(tn, ts1, false);
  112. TestUtil.assertCommutativeEquals(ts, ts1, false);
  113. }
  114. }
  115. }
  116. }