Commit 42d99571 authored by Florian Lugou's avatar Florian Lugou

added Ludovic Tests as JUnit tests

parent b59c3ee9
......@@ -52,3 +52,12 @@ subprojects {
delete "${rootProject.absPath}/bin"
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Xlint:cast" << "-Xlint:divzero" << "-Xlint:empty" << "-Xlint:finally" << "-Xlint:fallthrough"
}
}
}
/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
ludovic.apvrille AT enst.fr
This software is a computer program whose purpose is to allow the
edition of TURTLE analysis, design and deployment diagrams, to
allow the generation of RT-LOTOS or Java code from this diagram,
and at last to allow the analysis of formal validation traces
obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
from INRIA Rhone-Alpes.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
/**
* Class Test
* Runs a set of tests, and returns a summary in case of failure
* Creation: 01/12/2003
* @version 1.0 21/08/2004
* @author Ludovic APVRILLE
* @see
*/
import myutil.BoolExpressionEvaluator;
import myutil.TraceManager;
import ui.graph.AUTGraph;
import ui.graph.AUTTransition;
public class Test {
public static void main(String[] args) {
//testAUTGraph();
testBoolExpr();
}
public static void testBoolExpr() {
int nbOfPb = 0;
/*nbOfPb += evalBool("t or f", true, false);
nbOfPb += evalBool("(t) or f", true, false);
nbOfPb += evalBool("(t) or f)", true, true);
nbOfPb += evalBool("((t) or f)", true, false);
nbOfPb += evalBool("((t) and f)", false, false);
nbOfPb += evalBool("t and f and t", false, false);
nbOfPb += evalBool("(0==0)", false, false);
nbOfPb += evalBool("(2==2)==f", false, false);
nbOfPb += evalBool("(2==1)==f", true, false);
nbOfPb += evalBool("(2>1)==f", false, false);
nbOfPb += evalBool("f==2==2", false, false);
nbOfPb += evalBool("((3>5)or(4<6))and(1>2)", false, false);
nbOfPb += evalBool("((3>5)or(4<6))and(2>1)", true, false);
nbOfPb += evalBool("((3>5)or or (4<6))and(2>1)", true, true);
nbOfPb += evalBool("f or t)", true, true);
nbOfPb += evalBool("f or t and f", false, false);
nbOfPb += evalBool("(3>5)or (4<6) or (1>2)", true, false);*/
/*nbOfPb += evalBool("(0==0)", true, false);
nbOfPb += evalBool("t==t", true, false);
System.out.println("Nb of problems found:" + nbOfPb);*/
nbOfPb += evalBoolInt("1", false, true);
nbOfPb += evalBoolInt("1==0", false, false);
nbOfPb += evalBoolInt("t==t", true, false);
nbOfPb += evalBoolInt("t==", false, true);
nbOfPb += evalBoolInt("t==t==f", false, false);
nbOfPb += evalBoolInt("t==t==t", true, false);
nbOfPb += evalBoolInt("(3==3) == (4==4)", true, false);
nbOfPb += evalBoolInt("(1+2)==4", false, false);
nbOfPb += evalBoolInt("(1+2)==3", true, false);
nbOfPb += evalBoolInt("3==1+2", true, false);
nbOfPb += evalBoolInt("1+2==3", true, false);
nbOfPb += evalBoolInt("1+2+3+4+5==3+7", false, false);
nbOfPb += evalBoolInt("(1+2==3)==(5==4)", false, false);
nbOfPb += evalBoolInt("2*3==6", true, false);
nbOfPb += evalBoolInt("1*4+2==6", true, false);
nbOfPb += evalBoolInt("2+1*4==6", true, false);
nbOfPb += evalBoolInt("2+4/1==6", true, false);
nbOfPb += evalBoolInt("8-4/2==6", true, false);
nbOfPb += evalBoolInt("(3==3) and (3==4)", false, false);
nbOfPb += evalBoolInt("(3==3) or (3==4)", true, false);
nbOfPb += evalBoolInt("not(((1)==(3)))", true, false);
nbOfPb += evalBoolInt("1<3", true, false);
nbOfPb += evalBoolInt("not(1<3)", false, false);
nbOfPb += evalBoolInt("not(1<3<2)", false, true);
nbOfPb += evalBoolInt("(1+2)==4", false, false);
nbOfPb += evalBoolInt("(5>=4)==true", true, false);
nbOfPb += evalBoolInt("(5<=4)==true", false, false);
nbOfPb += evalBoolInt("(1+2==3)==(5>4)", true, false);
//nbOfPb += evalBoolInt("not(1==1)", false, false);
//nbOfPb += evalBoolInt("1+2==3", true, false);
System.out.println("Nb of problems found:" + nbOfPb);
System.exit(-1);
}
public static int evalBool(String s, boolean expectedValue, boolean expectedError) {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
boolean val = bee.getResultOf(s);
boolean err = bee.hasError();
if ((val != expectedValue) || (err != expectedError)) {
System.out.println("\nUnexpected result or error-------------------->Result of " + s + " =" + val);
if (bee.hasError()) {
System.out.println("Error = " + bee.getFullError());
}
System.out.println("\n\n");
return 1;
} else {
System.out.println("all ok\n\n");
}
return 0;
}
public static int evalBoolInt(String s, boolean expectedValue, boolean expectedError) {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
boolean val = bee.getResultOfWithIntExpr(s);
boolean err = bee.hasError();
if ((val != expectedValue) || (err != expectedError)) {
System.out.println("\nUnexpected result or error --------------------> Result of " + s + " : " + val + " / ExpectedValue:" + expectedValue);
if (bee.hasError()) {
System.out.println("--------------> Error = " + bee.getFullError());
}
System.out.println("\n\n");
return 1;
}
return 0;
}
public static void testAUTGraph() {
AUTGraph graph = new AUTGraph();
graph.setNbOfStates(6);
graph.addTransition(new AUTTransition(0, "a", 1));
graph.addTransition(new AUTTransition(0, "b", 3));
graph.addTransition(new AUTTransition(1, "a", 2));
graph.addTransition(new AUTTransition(1, "b", 3));
graph.addTransition(new AUTTransition(1, "b", 4));
graph.addTransition(new AUTTransition(2, "a", 1));
graph.addTransition(new AUTTransition(2, "b", 4));
graph.addTransition(new AUTTransition(3, "c", 5));
graph.addTransition(new AUTTransition(4, "c", 5));
graph.computeStates();
TraceManager.addDev("Graph:" + graph.toFullString());
graph.partitionGraph();
}
} // Class Test
......@@ -56,6 +56,7 @@ import ui.avatarbd.AvatarBDPortConnector;
import ui.avatarbd.AvatarBDPragma;
import ui.avatarsmd.*;
import java.awt.*;
import java.util.*;
//import translator.*;
......@@ -284,7 +285,7 @@ public class TML2AvatarDP {
for (AvatarTransition t: tranSourceMap.keySet()){
TGConnectingPoint p1 = tranSourceMap.get(t);
TGConnectingPoint p2 = locMap.get(tranDestMap.get(t));
Vector points = new Vector();
Vector<Point> points = new Vector<>();
if (p1==null || p2 ==null){
System.out.println("Missing point");
return;
......@@ -308,7 +309,7 @@ public class TML2AvatarDP {
for (String bl1: originDestMap.keySet()){
for (String bl2:originDestMap.get(bl1)){
Vector points=new Vector();
Vector<Point> points=new Vector<>();
//Add Relations to connector
for (AvatarRelation ar:avspec.getRelations()){
......
......@@ -66,7 +66,7 @@ public class TGConnectorMessageAsyncOrSyncSD extends TGConnectorMessageSD {
public TGConnectorMessageAsyncOrSyncSD( int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos,
TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2,
Vector _listPoint ) {
Vector<Point> _listPoint ) {
super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint);
myImageIcon = IconManager.imgic504;
}
......
......@@ -75,17 +75,17 @@ public class JDialogAvatarFirewall extends javax.swing.JDialog implements Action
// Panel1
protected JTextField nodeName;
private Vector rules= new Vector();
private Vector<String> rules= new Vector<>();
// Panel2
protected JTextField latency;
private JList listRules;
private JList<String> listRules;
private JButton addButton,removeButton;
// Main Panel
private JButton closeButton;
private JButton cancelButton;
private JComboBox task1;
private JComboBox task2;
private JComboBox<String> task1;
private JComboBox<String> task2;
/** Creates new form */
public JDialogAvatarFirewall(Frame _frame, String _title, AvatarBDFirewall _node) {
super(_frame, _title, true);
......@@ -142,13 +142,11 @@ public class JDialogAvatarFirewall extends javax.swing.JDialog implements Action
c2.weighty = 1.0;
c2.weightx = 1.0;
c2.fill = GridBagConstraints.HORIZONTAL;
for (String s: node.getRules()){
rules.add(s);
}
rules.addAll(node.getRules());
JLabel rulesLabel = new JLabel("Blocking Rules");
panel2.add(rulesLabel, c2);
listRules = new JList<String>(rules);
listRules = new JList<>(rules);
listRules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listRules.addListSelectionListener(this);
JScrollPane scrollPane = new JScrollPane(listRules);
......@@ -163,7 +161,7 @@ public class JDialogAvatarFirewall extends javax.swing.JDialog implements Action
c2.gridwidth=1;
c2.weighty = 1.0;
c2.weightx = 1.0;
task1 = new JComboBox();
task1 = new JComboBox<>();
if (node.getTDiagramPanel() instanceof AvatarBDPanel){
AvatarBDPanel abdp = (AvatarBDPanel) node.getTDiagramPanel();
for (AvatarBDBlock block: abdp.getFullBlockList()){
......@@ -171,7 +169,7 @@ public class JDialogAvatarFirewall extends javax.swing.JDialog implements Action
}
task1.addItem("*");
task2= new JComboBox();
task2= new JComboBox<>();
for (AvatarBDBlock block: abdp.getFullBlockList()){
task2.addItem(block.getName());
}
......@@ -275,7 +273,7 @@ public class JDialogAvatarFirewall extends javax.swing.JDialog implements Action
public ArrayList<String> getRules(){
ArrayList<String> r = new ArrayList<String>();
for (int i=0; i<rules.size(); i++){
r.add((String) rules.get(i));
r.add(rules.get(i));
}
return r;
}
......
......@@ -54,6 +54,7 @@ import javax.xml.transform.TransformerException;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -109,7 +110,7 @@ public class MultiThreadServer {
cmd = Message.RESULT_SEARCH;
//System.out.println(msg.getValues().get(0));
resultfile = database.GetCVEwithKeywords(msg.getValues());
String resultstring = FileUtils.readFileToString(resultfile);
String resultstring = FileUtils.readFileToString(resultfile, StandardCharsets.UTF_8);
ArrayList<Object> content = new ArrayList<>();
content.add(resultstring);
......@@ -122,7 +123,7 @@ public class MultiThreadServer {
if (msg.getCmd().equals(Message.CMD_DETAIL)) {
cmd = Message.RESULT_DETAIL;
resultfile = database.GetinfofromCVE(msg.getValues().get(0));
String resultstring = FileUtils.readFileToString(resultfile);
String resultstring = FileUtils.readFileToString(resultfile, StandardCharsets.UTF_8);
ArrayList<Object> res = new ArrayList<>();
res.add(resultstring);
answerMessage.createAnswerMessage(cmd, res);
......
package myutil;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class BoolExpressionEvaluatorTest {
@Test
public void testIntegerExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("1"));
assertTrue(bee.hasError());
}
@Test
public void testFalseSimpleExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("1==0"));
assertFalse(bee.hasError());
}
@Test
public void testTrueSimpleExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("t==t"));
assertFalse(bee.hasError());
}
@Test
public void testUnfinishedExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("t=="));
assertTrue(bee.hasError());
}
@Test
public void testFalseMultipleEqualExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("t==t==f"));
assertFalse(bee.hasError());
}
@Test
public void testTrueMultipleEqualExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("t==t==t"));
assertFalse(bee.hasError());
}
@Test
public void testTrueDoubleIntegerEqualityExpr() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("(3==3) == (4==4)"));
assertFalse(bee.hasError());
}
@Test
public void testFalseLeftAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("(1+2)==4"));
assertFalse(bee.hasError());
}
@Test
public void testTrueLeftAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("(1+2)==3"));
assertFalse(bee.hasError());
}
@Test
public void testTrueRightAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("3==1+2"));
assertFalse(bee.hasError());
}
@Test
public void testFalseMultipleAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("1+2+3+4+5==3+7"));
assertFalse(bee.hasError());
}
@Test
public void testFalseAdditionResultsComparison() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("(1+2==3)==(5==4)"));
assertFalse(bee.hasError());
}
@Test
public void testTrueLeftMultiplication() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("2*3==6"));
assertFalse(bee.hasError());
}
@Test
public void testTrueLeftMultiplicationAndAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("2+1*4==6"));
assertFalse(bee.hasError());
}
@Test
public void testTrueDivisionAndAddition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("2+4/1==6"));
assertFalse(bee.hasError());
}
@Test
public void testTrueDivisionAndSoustraction() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("8-4/2==6"));
assertFalse(bee.hasError());
}
@Test
public void testTrueAndCondition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("(3==3) and (4==4)"));
assertFalse(bee.hasError());
}
@Test
public void testFalseAndCondition() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("(3==3) and (3==4)"));
assertFalse(bee.hasError());
}
@Test
public void testTrueNegation() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("not(((1)==(3)))"));
assertFalse(bee.hasError());
}
@Test
public void testTrueLesserThan() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("1<3"));
assertFalse(bee.hasError());
}
@Test
public void testFalseLesserThanAndNegation() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("not(1<3)"));
assertFalse(bee.hasError());
}
@Test
public void testMalformedLesserThan() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("not(1<2<3)"));
assertTrue(bee.hasError());
}
@Test
public void testTrueComplexGreaterThan() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("(5>=4)==true"));
assertFalse(bee.hasError());
}
@Test
public void testFalseComplexLesserThan() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertFalse(bee.getResultOfWithIntExpr("(5<=4)==true"));
assertFalse(bee.hasError());
}
@Test
public void testTrueAdditionAndGreaterThan() {
BoolExpressionEvaluator bee = new BoolExpressionEvaluator();
assertTrue(bee.getResultOfWithIntExpr("(1+2==3)==(5>4)"));
assertFalse(bee.hasError());
}
}
package ui.graph;
import org.junit.Test;
public class AUTGraphTest {
@Test
public void testAUTGraph() {
AUTGraph graph = new AUTGraph();
graph.setNbOfStates(6);
graph.addTransition(new AUTTransition(0, "a", 1));
graph.addTransition(new AUTTransition(0, "b", 3));
graph.addTransition(new AUTTransition(1, "a", 2));
graph.addTransition(new AUTTransition(1, "b", 3));
graph.addTransition(new AUTTransition(1, "b", 4));
graph.addTransition(new AUTTransition(2, "a", 1));
graph.addTransition(new AUTTransition(2, "b", 4));
graph.addTransition(new AUTTransition(3, "c", 5));
graph.addTransition(new AUTTransition(4, "c", 5));
graph.computeStates();
System.out.println("Graph:" + graph.toFullString());
graph.partitionGraph();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment