-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for IncompleteOperationErrors
- Loading branch information
Showing
6 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
CryptoAnalysis/src/test/java/test/assertions/IncompleteOperationErrorCountAssertion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package test.assertions; | ||
|
||
import test.Assertion; | ||
|
||
public class IncompleteOperationErrorCountAssertion implements Assertion { | ||
|
||
private int expectedErrorCounts; | ||
private int actualErrorCounts; | ||
|
||
public IncompleteOperationErrorCountAssertion(int numberOfCounts) { | ||
this.expectedErrorCounts = numberOfCounts; | ||
} | ||
|
||
public void increaseCount(){ | ||
actualErrorCounts++; | ||
} | ||
|
||
@Override | ||
public boolean isSatisfied() { | ||
return expectedErrorCounts <= actualErrorCounts; | ||
} | ||
|
||
@Override | ||
public boolean isImprecise() { | ||
return expectedErrorCounts != actualErrorCounts; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Expected " + expectedErrorCounts + " incomplete operation errors, but got " + actualErrorCounts; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
CryptoAnalysis/src/test/java/tests/custom/incompleteoperation/IncompleteOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package tests.custom.incompleteoperation; | ||
|
||
import crypto.analysis.CrySLRulesetSelector.Ruleset; | ||
import org.junit.Test; | ||
import test.UsagePatternTestingFramework; | ||
import test.assertions.Assertions; | ||
|
||
public class IncompleteOperationTest extends UsagePatternTestingFramework { | ||
|
||
@Override | ||
public Ruleset getRuleSet() { | ||
return Ruleset.CustomRules; | ||
} | ||
|
||
@Override | ||
public String getRulesetPath() { | ||
return "incompleteOperation"; | ||
} | ||
|
||
@Test | ||
public void testNoIncompleteOperation() { | ||
Operations operations1 = new Operations(); | ||
operations1.operation1(); | ||
operations1.operation2(); | ||
operations1.operation3(); | ||
operations1.operation4(); | ||
|
||
Operations operations2 = new Operations(); | ||
operations2.operation1(); | ||
operations2.operation2(); | ||
operations2.operation3(); | ||
// operation 4 is optional, i.e. no incomplete operation | ||
|
||
Assertions.incompleteOperationErrors(0); | ||
} | ||
|
||
@Test | ||
public void testMissingOperation() { | ||
Operations operations = new Operations(); | ||
operations.operation1(); | ||
operations.operation2(); | ||
// operation3 is missing | ||
|
||
Assertions.incompleteOperationErrors(1); | ||
} | ||
|
||
@Test | ||
public void testSingleDataflowPathWithIncompleteOperation() { | ||
Operations operations = new Operations(); | ||
operations.operation1(); | ||
operations.operation2(); | ||
|
||
// Dataflow path without operation3 exists => incomplete operation | ||
if (Math.random() > 0.5) { | ||
operations.operation3(); | ||
} | ||
|
||
Assertions.incompleteOperationErrors(1); | ||
} | ||
|
||
@Test | ||
public void testMultipleDataflowPathsWithIncompleteOperations() { | ||
Operations operations = new Operations(); | ||
operations.operation1(); | ||
|
||
// On both dataflow paths a call two operation3 is missing => 2 incomplete operations | ||
if (Math.random() > 0.5) { | ||
operations.operation2(); | ||
} else { | ||
operations.operation2(); | ||
} | ||
|
||
Assertions.incompleteOperationErrors(2); | ||
} | ||
|
||
@Test | ||
public void testMultipleDataflowPathsWithoutIncompleteOperations() { | ||
Operations operations = new Operations(); | ||
operations.operation1(); | ||
|
||
// Both dataflow path are completed with operation3 | ||
if (Math.random() > 0.5) { | ||
operations.operation2(); | ||
} else { | ||
operations.operation2(); | ||
} | ||
operations.operation3(); | ||
|
||
Assertions.incompleteOperationErrors(0); | ||
} | ||
|
||
@Test | ||
public void testIncompleteOperationWithLoops() { | ||
Operations operations1 = new Operations(); | ||
operations1.operation1(); | ||
operations1.operation2(); | ||
|
||
// Dataflow path without call to operation3 | ||
while (Math.random() > 0.5) { | ||
operations1.operation3(); | ||
} | ||
|
||
Operations operations2 = new Operations(); | ||
operations2.operation1(); | ||
operations2.operation2(); | ||
|
||
// Dataflow path without call to operation3 | ||
for (int i = 0; i < 1; i++) { | ||
operations2.operation3(); | ||
} | ||
|
||
Assertions.incompleteOperationErrors(2); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
CryptoAnalysis/src/test/java/tests/custom/incompleteoperation/Operations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tests.custom.incompleteoperation; | ||
|
||
public class Operations { | ||
|
||
public void operation1() {} | ||
|
||
public void operation2() {} | ||
|
||
public void operation3() {} | ||
|
||
public void operation4() {} | ||
} |
11 changes: 11 additions & 0 deletions
11
CryptoAnalysis/src/test/resources/testrules/incompleteOperation/Operations.crysl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SPEC tests.custom.incompleteoperation.Operations | ||
|
||
EVENTS | ||
Con: Operations(); | ||
op1: operation1(); | ||
op2: operation2(); | ||
op3: operation3(); | ||
op4: operation4(); | ||
|
||
ORDER | ||
Con, op1, op2, op3, op4* |