Skip to content

Commit

Permalink
new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliankaul committed Oct 12, 2021
1 parent 852d449 commit 08d6ff7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,38 @@ internal class WpdsTest : AbstractMarkTest() {
assertFalse(startLineNumbers[18]!!) // EVP_EncryptFinal
}

@Test
@Throws(Exception::class)
fun testWPDSCStyle1() {
val findings = performTest("unittests/wpds_cstyle1.c", "unittests/WPDS_c_cpp_style.mark")

assertTrue { findings.all { !it.isProblem } }
}
@Test
@Throws(Exception::class)
fun testWPDSCppStyle1() {
val findings = performTest("unittests/wpds_cppstyle1.cpp", "unittests/WPDS_c_cpp_style.mark")

assertTrue { findings.all { !it.isProblem } }
}

@Test
@Throws(Exception::class)
fun testWPDSCStyle2() {
// missing call to "finish()"
val findings = performTest("unittests/wpds_cstyle2.c", "unittests/WPDS_c_cpp_style.mark")

assertFalse { findings.all { !it.isProblem } }
}
@Test
@Throws(Exception::class)
fun testWPDSCppStyle2() {
// missing call to "finish()"
val findings = performTest("unittests/wpds_cppstyle2.cpp", "unittests/WPDS_c_cpp_style.mark")

assertFalse { findings.all { !it.isProblem } }
}

init {
// Using WPDS instead of NFA
tsMode = TypestateMode.WPDS
Expand Down
30 changes: 30 additions & 0 deletions src/test/resources/unittests/WPDS_c_cpp_style.mark
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
entity Foo {
op new {
this = Foo_new();
}

op init {
Foo_init(this);
Foo::init();
}

op work {
Foo_work(this, _);
Foo::work(_);
}

op finish {
Foo_finish(this);
Foo::finish();
}
}

rule FooOrder {
using Foo as foo
ensure order
foo.new()?, // only c style
foo.init(),
foo.work()+,
foo.finish()
warn
}
7 changes: 7 additions & 0 deletions src/test/resources/unittests/wpds_cppstyle1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int somefunc () {
Foo f = new Foo();
f.init();
f.work(null);
f.finish();
return 0;
}
7 changes: 7 additions & 0 deletions src/test/resources/unittests/wpds_cppstyle2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int somefunc () {
Foo f = new Foo();
f.init();
f.work(null);
//f.finish();
return 0;
}
7 changes: 7 additions & 0 deletions src/test/resources/unittests/wpds_cstyle1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int somefunc () {
Foo f = Foo_new();
Foo_init(f);
Foo_work(f, null);
Foo_finish(f);
return 0;
}
7 changes: 7 additions & 0 deletions src/test/resources/unittests/wpds_cstyle2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int somefunc () {
Foo f = Foo_new();
Foo_init(f);
Foo_work(f, null);
//Foo_finish(f);
return 0;
}

0 comments on commit 08d6ff7

Please sign in to comment.