/* * Created on Apr 6, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package fr.lifl.stc.stan.tools.tester; import java.io.IOException; //import fr.lifl.rd2p.jits.tools.ea.signature.PartialSignature; import fr.lifl.stc.stan.link.Link; import fr.lifl.stc.stan.link.TableLink; import fr.lifl.stc.stan.samples.flow.FlowPartialSignature; import fr.lifl.stc.stan.samples.flow.FlowPartialSignatureData; import fr.lifl.stc.stan.signature.Signature; import fr.lifl.stc.stan.signature.SignatureDictionary; /** @author dorina * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class TestSignatures { private SignatureDictionary dictionary; private ClassSign[] classes; int noWarnings, noError, noSignNotFound; public TestSignatures(ClassSign[] classes) throws IOException, ClassNotFoundException { dictionary = new SignatureDictionary("/tmp/newDico.txt"); this.classes = classes; } public void analyze() { //printClasses(); noError = noWarnings = noSignNotFound = 0; for(int i = 0 ; i < classes.length; i++) { if(classes[i]!=null) { String className = classes[i].getClassName(); MethodSign[] m = classes[i].getMethodSign(); for(int j = 0; j < m.length; j++) { String key = SignatureDictionary.key(className, m[j].getMethodName(), m[j].getMethodSignature()); if (dictionary.contains(key)) { Signature sign = dictionary.findSignature(key, false); //PartialSignature FlowPartialSignature ps = (FlowPartialSignature)sign.getPartialSignature("fr.lifl.rd2p.jits.tools.ea.samples.flow.FlowAnnotation"); TableLink data = ((FlowPartialSignatureData)(ps.getComponent())).getData(); System.out.println("-----> Comparing "+key); //TestSignatures.display(data); compare(m[j].getSignature(), data.getTableLinks(), className+"."+m[j].getMethodName()); } else { System.err.println("Signature "+key+" not found in the dictionary"); noSignNotFound++; } } } } System.out.println("\nDone"); System.out.println("Errors:\t\t"+this.noError); System.out.println("Warning:\t"+this.noWarnings); System.out.println("Signatures not found:\t"+noSignNotFound); } public void compare(Link[][]ourSign, Link[][] dicSign, String name) { if(ourSign.length != dicSign.length) { System.err.println("ERROR in "+name+" : Different size ! ourSign="+ourSign.length+" dicSign="+dicSign.length); return; } if(ourSign[0].length != dicSign[0].length) { System.err.println("ERROR in "+name+" : Different number of columns! ourSign="+ourSign[0].length+" dicSign="+dicSign[0].length); return; } for(int i = 0 ; i < ourSign.length; i++) { for(int j = 0; j < ourSign[i].length; j++) { if(!Link.equals(ourSign[i][j], dicSign[i][j])) { if(!dicSign[i][j].compatibleWith(ourSign[i][j])){ System.err.println("Warning in "+name+" : extralink at position ("+i+", "+j+"). it is = "+dicSign[i][j]+" it should be = "+ourSign[i][j] ); noWarnings ++; } else { noError++; System.err.println("ERROR in "+name+" : link missing at position ("+i+", "+j+"). it is = "+dicSign[i][j]+" it should be = "+ourSign[i][j] ); } } } } } public void printClasses() { for(int i = 0; i < classes.length; i++) if(classes[i]!=null){ System.out.println(classes[i]); } } public static void display(Link [][]b) { for(int i =0; i< b.length; i++) { for(int j = 0; j < b[i].length; j++) System.out.print(b[i][j]+" "); System.out.println(""); } } /* public static byte[][]transform(boolean[][] b) { byte [][]res = new byte[b.length][b[0].length]; for(int i = 0;i