1 23 package org.objectweb.medor.optim; 24 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 import junit.textui.TestRunner; 28 import org.objectweb.jorm.type.api.PTypeSpace; 29 import org.objectweb.medor.api.MedorException; 30 import org.objectweb.medor.filter.TestExpressionHelper; 31 import org.objectweb.medor.expression.lib.And; 32 import org.objectweb.medor.filter.lib.BasicFieldOperand; 33 import org.objectweb.medor.expression.lib.DivideBy; 34 import org.objectweb.medor.filter.lib.ExpressionPrinter; 35 import org.objectweb.medor.expression.lib.Greater; 36 import org.objectweb.medor.expression.lib.Not; 37 import org.objectweb.medor.expression.lib.Or; 38 import org.objectweb.medor.expression.lib.UMinus; 39 import org.objectweb.medor.expression.lib.BasicOperand; 40 import org.objectweb.medor.expression.api.Expression; 41 import org.objectweb.medor.lib.BasicField; 42 import org.objectweb.medor.lib.Log; 43 import org.objectweb.medor.lib.TestMedorHelper; 44 import org.objectweb.medor.optim.lib.PushNotInExpressionRule; 45 import org.objectweb.util.monolog.api.BasicLevel; 46 47 50 51 public class TestPushNotInExpressionRule extends TestMedorHelper { 52 53 56 public static void main(String [] args) { 57 TestRunner.run(suite()); 58 } 59 60 63 public static Test suite() { 64 return new TestSuite(TestPushNotInExpressionRule.class); 65 } 66 67 public TestPushNotInExpressionRule() { 68 super("TestPushNotInExpressionRule", Log.MEDOR_PREFIX + ".optim.pushnotinexpression"); 69 } 70 71 public TestPushNotInExpressionRule(String testName) { 72 super(testName, Log.MEDOR_PREFIX + ".optim.groupsamedb"); 73 } 74 75 76 protected void setUp() { 77 } 78 79 protected void tearDown() { 80 } 81 82 public void testPushNotInExpression() { 83 Expression e1, e2, e3; 84 e1 = new BasicOperand(true); 85 e2 = new BasicFieldOperand(new BasicField("b", PTypeSpace.BOOLEAN)); 86 e1 = new Or(e1, e2); 87 e1 = new Not(e1); 88 e2 = new BasicFieldOperand(new BasicField("a", PTypeSpace.LONG)); 89 e2 = new UMinus(e2); 90 e3 = new BasicOperand((long) 3); 91 e2 = new DivideBy(e2, e3); 92 e3 = new BasicOperand((long) 12); 93 e2 = new Greater(e2, e3); 94 e1 = new And(e2, e1); 95 96 PushNotInExpressionRule pnier = new PushNotInExpressionRule(); 97 PushNotInExpressionRule.ModifiedExpression me = null; 98 logger.log(BasicLevel.DEBUG, "Before: exp=" + ExpressionPrinter.e2str(e1)); 99 try { 100 me = pnier.pushNotInExpression(e1, false); 101 } 102 catch (MedorException e) { 103 e.printStackTrace(); 104 fail("Impossible to pushNotInExpression" + e.getMessage()); 105 } 106 logger.log(BasicLevel.DEBUG, "After: exp=" + ExpressionPrinter.e2str(me.e)); 107 assertTrue("The expression has not been modified", me.isModified); 108 109 e2 = new BasicFieldOperand(new BasicField("a", PTypeSpace.LONG)); 110 e2 = new UMinus(e2); 111 e3 = new BasicOperand((long) 3); 112 e2 = new DivideBy(e2, e3); 113 e3 = new BasicOperand((long) 12); 114 e1 = new Greater(e2, e3); 115 116 e2 = new BasicOperand(true); 117 e3 = new BasicFieldOperand(new BasicField("b", PTypeSpace.BOOLEAN)); 118 e2 = new And(new Not(e2), new Not(e3)); 119 e1 = new And(e1, e2); 120 121 try { 122 TestExpressionHelper.equals("", me.e, e1, logger); 123 } 124 catch (MedorException e) { 125 fail(e.getMessage()); 126 } 127 } 128 } 129 | Popular Tags |