View support regression testing, test data and reference files

This commit is contained in:
Andrea Aime 2005-12-26 21:15:34 +00:00
parent 956673ffb7
commit d8190eefb0
17 changed files with 312 additions and 66 deletions

View File

@ -21,7 +21,6 @@
package gr.spinellis.umlgraph.test;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@ -37,14 +36,42 @@ public class BasicTest {
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String[] javaFiles = new File(testSourceFolder).list(new JavaFilter());
// String[] javaFiles = new String[] {"MyVector.java"};
File outFolder = new File(testDestFolder);
boolean equal = true;
File outFolder = new File(testDestFolder);
if (!outFolder.exists())
outFolder.mkdirs();
equal = performBasicTests();
equal &= performViewTests(outFolder);
boolean equal = true;
if (!equal)
System.out.println("ERROR, some files are not structurally equal");
else
System.out.println("GOOD, all files are structurally equal");
}
private static boolean performViewTests(File outFolder) throws IOException {
String[] options = new String[] { "-docletpath", "build", "-hide", "Hidden", "-private",
"-d", outFolder.getAbsolutePath(), "-sourcepath", "testdata/java", "-subpackages", "gr.spinellis", "-views" };
runDoclet(options);
String[] javaFiles = new File(testSourceFolder, "gr/spinellis/views").list(new JavaFilter());
boolean equal = true;
for (int i = 0; i < javaFiles.length; i++) {
String viewName = javaFiles[i].substring(0, javaFiles[i].length() - 5);
File dotFile = new File(testDestFolder, viewName + ".dot");
String dotPath = dotFile.getAbsolutePath();
String refPath = new File(testRefFolder, viewName + ".dot").getAbsolutePath();
equal &= checkForDifferences(dotPath, refPath);
}
return true;
}
private static boolean performBasicTests() throws IOException {
String[] javaFiles = new File(testSourceFolder).list(new JavaFilter());
// String[] javaFiles = new String[] {"MyVector.java"};
boolean equal = true;
for (int i = 0; i < javaFiles.length; i++) {
String javaFileName = javaFiles[i].substring(0, javaFiles[i].length() - 5);
File dotFile = new File(testDestFolder, javaFileName + ".dot");
@ -55,29 +82,33 @@ public class BasicTest {
String[] options = new String[] { "-docletpath", "build", "-hide", "Hidden", "-private", "-output", dotPath,
javaPath };
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw, "gr.spinellis.umlgraph.doclet.UmlGraph", options);
System.out.println("Performing diff:\nout:" + dotPath + "\nref:" + refPath);
DotDiff differ = new DotDiff(new File(dotPath), new File(refPath));
if (differ.graphEquals()) {
System.out.println("File contents are structurally equal");
} else {
equal = false;
System.out.println("File contents are structurally not equal");
printList("# Lines in out but not in ref", differ.getExtraLines1());
printList("# Lines in ref but not in out", differ.getExtraLines2());
printList("# Nodes in out but not in ref", differ.getNodes1());
printList("# Nodes in ref but not in out", differ.getNodes2());
printList("# Arcs in out but not in ref", differ.getArcs1());
printList("# Arcs in ref but not in out", differ.getArcs2());
}
System.out.println("\n\n");
runDoclet(options);
equal &= checkForDifferences(dotPath, refPath);
}
return equal;
}
if (!equal)
System.out.println("ERROR, some file are not structurally equal");
else
System.out.println("GOOD, all files are structurally equal");
private static void runDoclet(String[] options) {
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw, "gr.spinellis.umlgraph.doclet.UmlGraph", options);
}
private static boolean checkForDifferences(String dotPath, String refPath) throws IOException {
System.out.println("Performing diff:\nout:" + dotPath + "\nref:" + refPath);
DotDiff differ = new DotDiff(new File(dotPath), new File(refPath));
boolean equal = differ.graphEquals();
if (equal) {
System.out.println("File contents are structurally equal");
} else {
System.out.println("File contents are structurally not equal");
printList("# Lines in out but not in ref", differ.getExtraLines1());
printList("# Lines in ref but not in out", differ.getExtraLines2());
printList("# Nodes in out but not in ref", differ.getNodes1());
printList("# Nodes in ref but not in out", differ.getNodes2());
printList("# Arcs in out but not in ref", differ.getArcs1());
printList("# Arcs in ref but not in out", differ.getArcs2());
}
System.out.println("\n\n");
return equal;
}
private static void printList(String message, List extraOut) {
@ -88,10 +119,4 @@ public class BasicTest {
}
}
}
private static final class JavaFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".java");
}
}
}

View File

@ -0,0 +1,29 @@
/*
* UmlGraph class diagram testing framework
*
* Contibuted by Andrea Aime
* (C) Copyright 2005 Diomidis Spinellis
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
*
*/
package gr.spinellis.umlgraph.test;
import java.io.File;
import java.io.FilenameFilter;
class JavaFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".java");
}
}

View File

@ -21,7 +21,6 @@
package gr.spinellis.umlgraph.test;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@ -37,14 +36,42 @@ public class BasicTest {
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String[] javaFiles = new File(testSourceFolder).list(new JavaFilter());
// String[] javaFiles = new String[] {"MyVector.java"};
File outFolder = new File(testDestFolder);
boolean equal = true;
File outFolder = new File(testDestFolder);
if (!outFolder.exists())
outFolder.mkdirs();
equal = performBasicTests();
equal &= performViewTests(outFolder);
boolean equal = true;
if (!equal)
System.out.println("ERROR, some files are not structurally equal");
else
System.out.println("GOOD, all files are structurally equal");
}
private static boolean performViewTests(File outFolder) throws IOException {
String[] options = new String[] { "-docletpath", "build", "-hide", "Hidden", "-private",
"-d", outFolder.getAbsolutePath(), "-sourcepath", "testdata/java", "-subpackages", "gr.spinellis", "-views" };
runDoclet(options);
String[] javaFiles = new File(testSourceFolder, "gr/spinellis/views").list(new JavaFilter());
boolean equal = true;
for (int i = 0; i < javaFiles.length; i++) {
String viewName = javaFiles[i].substring(0, javaFiles[i].length() - 5);
File dotFile = new File(testDestFolder, viewName + ".dot");
String dotPath = dotFile.getAbsolutePath();
String refPath = new File(testRefFolder, viewName + ".dot").getAbsolutePath();
equal &= checkForDifferences(dotPath, refPath);
}
return true;
}
private static boolean performBasicTests() throws IOException {
String[] javaFiles = new File(testSourceFolder).list(new JavaFilter());
// String[] javaFiles = new String[] {"MyVector.java"};
boolean equal = true;
for (int i = 0; i < javaFiles.length; i++) {
String javaFileName = javaFiles[i].substring(0, javaFiles[i].length() - 5);
File dotFile = new File(testDestFolder, javaFileName + ".dot");
@ -55,29 +82,33 @@ public class BasicTest {
String[] options = new String[] { "-docletpath", "build", "-hide", "Hidden", "-private", "-output", dotPath,
javaPath };
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw, "gr.spinellis.umlgraph.doclet.UmlGraph", options);
System.out.println("Performing diff:\nout:" + dotPath + "\nref:" + refPath);
DotDiff differ = new DotDiff(new File(dotPath), new File(refPath));
if (differ.graphEquals()) {
System.out.println("File contents are structurally equal");
} else {
equal = false;
System.out.println("File contents are structurally not equal");
printList("# Lines in out but not in ref", differ.getExtraLines1());
printList("# Lines in ref but not in out", differ.getExtraLines2());
printList("# Nodes in out but not in ref", differ.getNodes1());
printList("# Nodes in ref but not in out", differ.getNodes2());
printList("# Arcs in out but not in ref", differ.getArcs1());
printList("# Arcs in ref but not in out", differ.getArcs2());
}
System.out.println("\n\n");
runDoclet(options);
equal &= checkForDifferences(dotPath, refPath);
}
return equal;
}
if (!equal)
System.out.println("ERROR, some file are not structurally equal");
else
System.out.println("GOOD, all files are structurally equal");
private static void runDoclet(String[] options) {
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw, "gr.spinellis.umlgraph.doclet.UmlGraph", options);
}
private static boolean checkForDifferences(String dotPath, String refPath) throws IOException {
System.out.println("Performing diff:\nout:" + dotPath + "\nref:" + refPath);
DotDiff differ = new DotDiff(new File(dotPath), new File(refPath));
boolean equal = differ.graphEquals();
if (equal) {
System.out.println("File contents are structurally equal");
} else {
System.out.println("File contents are structurally not equal");
printList("# Lines in out but not in ref", differ.getExtraLines1());
printList("# Lines in ref but not in out", differ.getExtraLines2());
printList("# Nodes in out but not in ref", differ.getNodes1());
printList("# Nodes in ref but not in out", differ.getNodes2());
printList("# Arcs in out but not in ref", differ.getArcs1());
printList("# Arcs in ref but not in out", differ.getArcs2());
}
System.out.println("\n\n");
return equal;
}
private static void printList(String message, List extraOut) {
@ -88,10 +119,4 @@ public class BasicTest {
}
}
}
private static final class JavaFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".java");
}
}
}

View File

@ -0,0 +1,29 @@
/*
* UmlGraph class diagram testing framework
*
* Contibuted by Andrea Aime
* (C) Copyright 2005 Diomidis Spinellis
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
*
*/
package gr.spinellis.umlgraph.test;
import java.io.File;
import java.io.FilenameFilter;
class JavaFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".java");
}
}

11
testdata/dot-ref/ViewAll.dot vendored Normal file
View File

@ -0,0 +1,11 @@
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UmlGraph version 4.1 (http://www.spinellis.gr/sw/umlgraph)
#
digraph G {
edge [fontname="Helvetica",fontsize=10,labelfontname="Helvetica",labelfontsize=10];
node [fontname="Helvetica",fontsize=10,shape=record];
}

11
testdata/dot-ref/ViewAllDetailed.dot vendored Normal file
View File

@ -0,0 +1,11 @@
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UmlGraph version 4.1 (http://www.spinellis.gr/sw/umlgraph)
#
digraph G {
edge [fontname="Helvetica",fontsize=10,labelfontname="Helvetica",labelfontsize=10];
node [fontname="Helvetica",fontsize=10,shape=record];
}

11
testdata/dot-ref/ViewAtt.dot vendored Normal file
View File

@ -0,0 +1,11 @@
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UmlGraph version 4.1 (http://www.spinellis.gr/sw/umlgraph)
#
digraph G {
edge [fontname="Helvetica",fontsize=10,labelfontname="Helvetica",labelfontsize=10];
node [fontname="Helvetica",fontsize=10,shape=record];
}

17
testdata/dot-ref/ViewProduct.dot vendored Normal file
View File

@ -0,0 +1,17 @@
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UmlGraph version 4.1 (http://www.spinellis.gr/sw/umlgraph)
#
digraph G {
edge [fontname="Helvetica",fontsize=10,labelfontname="Helvetica",labelfontsize=10];
node [fontname="Helvetica",fontsize=10,shape=record];
// gr.spinellis.product.Product
c98 [label="{Product\n|name\lstock\lprice\lcategory\l|}", fontname="Helvetica", fontcolor="black", fontsize=10.0];
// gr.spinellis.product.Category
c99 [label="{Category\n|name\l|}", fontname="Helvetica", fontcolor="black", fontsize=10.0];
// gr.spinellis.product.Product assoc gr.spinellis.product.Category
c98 -> c99 [taillabel="*", label="", headlabel="1", fontname="Helvetica", fontcolor="black", fontsize=10.0, color="black", arrowhead=none];
}

View File

@ -0,0 +1,5 @@
package gr.spinellis.invoice;
public class Customer {
String name;
}

View File

@ -0,0 +1,16 @@
package gr.spinellis.invoice;
import java.util.List;
import gr.spinellis.product.*;
/**
* @composed 1 - * gr.spinellis.invoice.InvoiceItem
* @assoc * - 1 gr.spinellis.invoice.Customer
*/
public class Invoice {
public double total;
public InvoiceItem[] items;
public Customer customer;
public void addItem(Product p, int quantity) {};
}

View File

@ -0,0 +1,12 @@
package gr.spinellis.invoice;
import gr.spinellis.product.*;
/**
* @assoc * - 1 gr.spinellis.product.Product
*/
public class InvoiceItem {
public Product product;
public int quantity;
}

View File

@ -0,0 +1,6 @@
package gr.spinellis.product;
public class Category {
public String name;
}

View File

@ -0,0 +1,13 @@
package gr.spinellis.product;
/**
* @assoc * - 1 gr.spinellis.product.Category
*/
public class Product {
public String name;
public int stock;
public double price;
public Category category;
}

View File

@ -0,0 +1,8 @@
package gr.spinellis.views;
/**
* @hidden
* @view
*/
public class ViewAll {
}

View File

@ -0,0 +1,9 @@
package gr.spinellis.views;
/**
* @hidden
* @view
* @opt_override gr.spinellis.* attributes operations types
*/
public class ViewAllDetailed {
}

View File

@ -0,0 +1,9 @@
package gr.spinellis.views;
/**
* @hidden
* @view
* @opt_override gr.spinellis.* attributes nodefontsize=16 nodefillcolor=yellow
*/
public class ViewAtt {
}

View File

@ -0,0 +1,10 @@
package gr.spinellis.views;
/**
* @hidden
* @view
* @opt_override gr.spinellis.* hideall
* @opt_override gr.spinellis.product.* !hideall attributes
*/
public class ViewProduct {
}