1 23 package org.objectweb.jorm.type; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 import junit.textui.TestRunner; 29 import org.objectweb.jorm.type.api.PTypeSpace; 30 import org.objectweb.jorm.type.api.PType; 31 import org.objectweb.jorm.type.api.PExceptionTyping; 32 import org.objectweb.jorm.type.lib.PTypeSpacePAAH; 33 import org.objectweb.jorm.api.PException; 34 35 40 public class TestPTypeSpace extends TestCase { 41 44 public static void main(String [] args) { 45 TestRunner.run(suite()); 46 } 47 48 51 public static Test suite() { 52 return new TestSuite(TestPTypeSpace.class); 53 } 54 55 protected PTypeSpace ptypeSpace = null; 56 57 60 public TestPTypeSpace(String name) { 61 super(name); 62 } 63 64 protected void setUp() throws Exception { 65 ptypeSpace = new PTypeSpacePAAH(); 66 } 67 68 protected void tearDown() throws Exception { 69 } 70 71 public void testIsa() { 72 PType titi = null; 73 PType toto = null; 74 try { 75 titi = ptypeSpace.createPType("titi", new String [][]{}); 76 assertNotNull("Simple class definition is null", titi); 77 String [] z = new String []{"toto", "titi"}; 78 String [][] r = new String [1][]; 79 r[0] = z; 80 toto = ptypeSpace.createPType("toto", r); 81 assertNotNull("Class definition with inheritance is null", toto); 82 } 83 catch (PExceptionTyping typing) { 84 printException(typing); 85 fail(typing.getMessage()); 86 } 87 assertTrue("same PType", titi.isa(titi)); 88 assertTrue("same PType", toto.isa(toto)); 89 assertTrue("Inheritance does not work", toto.isa(titi)); 91 92 PType a = null; 93 PType b = null; 94 try { 95 a = ptypeSpace.createPType("a", 96 new String [][]{new String []{"a", "b"}}); 97 b = ptypeSpace.createPType("b", new String [][]{}); 98 } 99 catch (PExceptionTyping typing) { 100 printException(typing); 101 fail(typing.getMessage()); 102 } 103 assertNotNull("Class definition with inheritance is null", a); 104 assertNotNull("Simple class definition is null", b); 105 assertTrue("reverse order definition does not work", a.isa(b)); 106 } 107 108 private static void printException(Exception e) { 109 if (e instanceof PException && ((PException) e).getNestedException()!=null) { 110 System.out.println(e.getMessage()); 111 printException(((PException) e).getNestedException()); 112 } 113 else 114 e.printStackTrace(); 115 } 116 } 117 | Popular Tags |