1 18 package org.objectweb.medor.clone; 19 20 import org.objectweb.medor.filter.TestExpressionHelper; 21 import org.objectweb.medor.clone.lib.BasicCloneable; 22 import org.objectweb.medor.expression.api.*; 23 import org.objectweb.medor.expression.lib.*; 24 25 import org.objectweb.jorm.type.api.PTypeSpace; 26 27 31 public class TestExpressionCloning extends TestExpressionHelper { 32 33 public TestExpressionCloning(String n) { 34 super(n); 35 } 36 37 private Object checkClone(Expression obj, boolean withContext) throws Exception { 38 Object clone = (withContext 39 ? ((BasicCloneable) obj).clone() 40 : ((BasicCloneable) obj).clone(null)); 41 assertNotNull("Null clone", clone); 42 assertEquals("Bad class", obj.getClass(), clone.getClass()); 43 assertEquals("Bad type", obj.getType(), ((Expression) clone).getType()); 44 return clone; 45 } 46 47 public void testOperandWithoutContext() throws Exception { 48 testOperand(false); 49 } 50 51 public void testOperandWithContext() throws Exception { 52 testOperand(true); 53 } 54 55 public void testOperand(boolean withContext) throws Exception { 56 BasicOperand bo; 57 Object clone; 58 59 bo = new BasicOperand(true); 61 clone = checkClone(bo, withContext); 62 assertEquals("Bad operand value", bo.getBoolean(), ((BasicOperand) clone).getBoolean()); 63 64 bo = new BasicOperand(12); 65 clone = checkClone(bo, withContext); 66 assertEquals("Bad operand value", bo.getInt(), ((BasicOperand) clone).getInt()); 67 68 bo = new BasicOperand("azerty"); 69 clone = checkClone(bo, withContext); 70 assertEquals("Bad operand value", bo.getString(), ((BasicOperand) clone).getString()); 71 72 bo = new BasicVariableOperand(true); 74 clone = checkClone(bo, withContext); 75 assertEquals("Bad operand value", bo.getBoolean(), ((BasicOperand) clone).getBoolean()); 76 77 bo = new BasicVariableOperand(12); 78 clone = checkClone(bo, withContext); 79 assertEquals("Bad operand value", bo.getInt(), ((BasicOperand) clone).getInt()); 80 81 bo = new BasicVariableOperand("azerty"); 82 clone = checkClone(bo, withContext); 83 assertEquals("Bad operand value", bo.getString(), ((BasicOperand) clone).getString()); 84 85 bo = new BasicParameterOperand(PTypeSpace.BOOLEAN, "p1", true); 87 clone = checkClone(bo, withContext); 88 assertEquals("Bad operand value", bo.getBoolean(), ((BasicOperand) clone).getBoolean()); 89 90 bo = new BasicParameterOperand(PTypeSpace.INT, "p2", 12); 91 clone = checkClone(bo, withContext); 92 assertEquals("Bad operand value", bo.getInt(), ((BasicOperand) clone).getInt()); 93 94 bo = new BasicParameterOperand(PTypeSpace.STRING, "p3", "azerty"); 95 clone = checkClone(bo, withContext); 96 assertEquals("Bad operand value", bo.getString(), ((BasicOperand) clone).getString()); 97 } 98 99 public void testLogicalOperatorwithoutContext() throws Exception { 100 testLogicalOperator(false); 101 } 102 public void testLogicalOperatorwithContext() throws Exception { 103 testLogicalOperator(true); 104 } 105 public void testLogicalOperator(boolean withContext) throws Exception { 106 Object clone; 107 Expression e = new And( 108 new Not(new BasicOperand(true)), 109 new Or( 110 new Equal(new BasicOperand(12), new BasicOperand(13)), 111 new Greater( 112 new BasicParameterOperand(PTypeSpace.BOOLEAN, "p1", true), 113 new Length( 114 new Concat( 115 new StringLower(new BasicOperand("TOTO")), 116 new Like( 117 new BasicOperand("hjklm"), 118 new BasicOperand("M*"), 119 new BasicOperand("k") 120 ) 121 ) 122 ) 123 ) 124 ) 125 ); 126 clone = checkClone(e, withContext); 127 equals("testLogicalOperator(" + withContext +"):", 128 e, (Expression) clone, logger); 129 } 130 131 public void testArithmeticOperatorwithoutContext() throws Exception { 132 testLogicalOperator(false); 133 } 134 public void testArithmeticOperatorwithContext() throws Exception { 135 testLogicalOperator(true); 136 } 137 public void testArithmeticOperator(boolean withContext) throws Exception { 138 Object clone; 139 Expression e = new Mult( 140 new Mod( 141 new BasicOperand(24), 142 new BasicOperand(24) 143 ), 144 new DivideBy( 145 new Plus(new Abs(new BasicOperand(-12)), new BasicOperand(13)), 146 new BasicParameterOperand(PTypeSpace.INT, "p1", 45) 147 ) 148 ); 149 clone = checkClone(e, withContext); 150 equals("testArithmeticOperator(" + withContext +"):", 151 e, (Expression) clone, logger); 152 } 153 } 154 | Popular Tags |