added dataflowanomaly-analysis test

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4865 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Sven Jacob
2006-12-11 17:24:58 +00:00
parent 64b035b8c7
commit 82debb0fd5
2 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,69 @@
/*
* Created on 11.12.2006
*
* Copyright (c) 2006, PMD for Eclipse Development Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed in part by support from
* the Defense Advanced Research Project Agency (DARPA)"
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package test.net.sourceforge.pmd.rules;
import net.sourceforge.pmd.Rule;
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
/**
*
*
* @author Sven
* @version $Revision$
*
* $Log$
* Revision 1.1 2006/12/11 17:24:58 holobender
* added dataflowanomaly-analysis test
*
*
*/
public class DataflowAnomalyAnalysisTest extends SimpleAggregatorTst {
private Rule rule;
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
rule = findRule("controversial", "DataflowAnomalyAnalysis");
}
public void testAll() {
runTests(rule);
}
}

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<test-code>
<description><![CDATA[
ok
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
void bar() {
for (int i=0;i<10;i++) { }
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
DD anomaly
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
void bar() {
int i=0;
i=1;
if (i==2) {}
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
DU anomaly
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
void bar() {
int i=0;
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
UR anomaly
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
void bar() {
int i;
if (i == 0) {}
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
more komplex anomalysis
]]></description>
<expected-problems>4</expected-problems>
<code><![CDATA[
public class Foo {
void bar(int i) {
int j = 0;
int z = 0;
if (i < 10) {
j = i;
}
}
}
]]></code>
</test-code>
</test-data>