From d8190eefb0bd56cdbd0c728be20fcf87ad131dca Mon Sep 17 00:00:00 2001 From: Andrea Aime Date: Mon, 26 Dec 2005 21:15:34 +0000 Subject: [PATCH] View support regression testing, test data and reference files --- src/gr/spinellis/umlgraph/test/BasicTest.java | 91 ++++++++++++------- .../spinellis/umlgraph/test/JavaFilter.java | 29 ++++++ src/org/umlgraph/test/BasicTest.java | 91 ++++++++++++------- src/org/umlgraph/test/JavaFilter.java | 29 ++++++ testdata/dot-ref/ViewAll.dot | 11 +++ testdata/dot-ref/ViewAllDetailed.dot | 11 +++ testdata/dot-ref/ViewAtt.dot | 11 +++ testdata/dot-ref/ViewProduct.dot | 17 ++++ .../java/gr/spinellis/invoice/Customer.java | 5 + .../java/gr/spinellis/invoice/Invoice.java | 16 ++++ .../gr/spinellis/invoice/InvoiceItem.java | 12 +++ .../java/gr/spinellis/product/Category.java | 6 ++ .../java/gr/spinellis/product/Product.java | 13 +++ testdata/java/gr/spinellis/views/ViewAll.java | 8 ++ .../gr/spinellis/views/ViewAllDetailed.java | 9 ++ testdata/java/gr/spinellis/views/ViewAtt.java | 9 ++ .../java/gr/spinellis/views/ViewProduct.java | 10 ++ 17 files changed, 312 insertions(+), 66 deletions(-) create mode 100644 src/gr/spinellis/umlgraph/test/JavaFilter.java create mode 100644 src/org/umlgraph/test/JavaFilter.java create mode 100644 testdata/dot-ref/ViewAll.dot create mode 100644 testdata/dot-ref/ViewAllDetailed.dot create mode 100644 testdata/dot-ref/ViewAtt.dot create mode 100644 testdata/dot-ref/ViewProduct.dot create mode 100644 testdata/java/gr/spinellis/invoice/Customer.java create mode 100644 testdata/java/gr/spinellis/invoice/Invoice.java create mode 100644 testdata/java/gr/spinellis/invoice/InvoiceItem.java create mode 100644 testdata/java/gr/spinellis/product/Category.java create mode 100644 testdata/java/gr/spinellis/product/Product.java create mode 100644 testdata/java/gr/spinellis/views/ViewAll.java create mode 100644 testdata/java/gr/spinellis/views/ViewAllDetailed.java create mode 100644 testdata/java/gr/spinellis/views/ViewAtt.java create mode 100644 testdata/java/gr/spinellis/views/ViewProduct.java diff --git a/src/gr/spinellis/umlgraph/test/BasicTest.java b/src/gr/spinellis/umlgraph/test/BasicTest.java index 538d5bc..84c6dd3 100644 --- a/src/gr/spinellis/umlgraph/test/BasicTest.java +++ b/src/gr/spinellis/umlgraph/test/BasicTest.java @@ -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"); - } - } } diff --git a/src/gr/spinellis/umlgraph/test/JavaFilter.java b/src/gr/spinellis/umlgraph/test/JavaFilter.java new file mode 100644 index 0000000..42be70c --- /dev/null +++ b/src/gr/spinellis/umlgraph/test/JavaFilter.java @@ -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"); + } +} \ No newline at end of file diff --git a/src/org/umlgraph/test/BasicTest.java b/src/org/umlgraph/test/BasicTest.java index 538d5bc..84c6dd3 100644 --- a/src/org/umlgraph/test/BasicTest.java +++ b/src/org/umlgraph/test/BasicTest.java @@ -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"); - } - } } diff --git a/src/org/umlgraph/test/JavaFilter.java b/src/org/umlgraph/test/JavaFilter.java new file mode 100644 index 0000000..42be70c --- /dev/null +++ b/src/org/umlgraph/test/JavaFilter.java @@ -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"); + } +} \ No newline at end of file diff --git a/testdata/dot-ref/ViewAll.dot b/testdata/dot-ref/ViewAll.dot new file mode 100644 index 0000000..7be73e3 --- /dev/null +++ b/testdata/dot-ref/ViewAll.dot @@ -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]; +} + diff --git a/testdata/dot-ref/ViewAllDetailed.dot b/testdata/dot-ref/ViewAllDetailed.dot new file mode 100644 index 0000000..7be73e3 --- /dev/null +++ b/testdata/dot-ref/ViewAllDetailed.dot @@ -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]; +} + diff --git a/testdata/dot-ref/ViewAtt.dot b/testdata/dot-ref/ViewAtt.dot new file mode 100644 index 0000000..7be73e3 --- /dev/null +++ b/testdata/dot-ref/ViewAtt.dot @@ -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]; +} + diff --git a/testdata/dot-ref/ViewProduct.dot b/testdata/dot-ref/ViewProduct.dot new file mode 100644 index 0000000..239c2e0 --- /dev/null +++ b/testdata/dot-ref/ViewProduct.dot @@ -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]; +} + diff --git a/testdata/java/gr/spinellis/invoice/Customer.java b/testdata/java/gr/spinellis/invoice/Customer.java new file mode 100644 index 0000000..0317cb8 --- /dev/null +++ b/testdata/java/gr/spinellis/invoice/Customer.java @@ -0,0 +1,5 @@ +package gr.spinellis.invoice; + +public class Customer { + String name; +} diff --git a/testdata/java/gr/spinellis/invoice/Invoice.java b/testdata/java/gr/spinellis/invoice/Invoice.java new file mode 100644 index 0000000..1992bf4 --- /dev/null +++ b/testdata/java/gr/spinellis/invoice/Invoice.java @@ -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) {}; +} diff --git a/testdata/java/gr/spinellis/invoice/InvoiceItem.java b/testdata/java/gr/spinellis/invoice/InvoiceItem.java new file mode 100644 index 0000000..47664fe --- /dev/null +++ b/testdata/java/gr/spinellis/invoice/InvoiceItem.java @@ -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; +} diff --git a/testdata/java/gr/spinellis/product/Category.java b/testdata/java/gr/spinellis/product/Category.java new file mode 100644 index 0000000..cb9816f --- /dev/null +++ b/testdata/java/gr/spinellis/product/Category.java @@ -0,0 +1,6 @@ +package gr.spinellis.product; + +public class Category { + + public String name; +} diff --git a/testdata/java/gr/spinellis/product/Product.java b/testdata/java/gr/spinellis/product/Product.java new file mode 100644 index 0000000..0186898 --- /dev/null +++ b/testdata/java/gr/spinellis/product/Product.java @@ -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; + +} diff --git a/testdata/java/gr/spinellis/views/ViewAll.java b/testdata/java/gr/spinellis/views/ViewAll.java new file mode 100644 index 0000000..526882e --- /dev/null +++ b/testdata/java/gr/spinellis/views/ViewAll.java @@ -0,0 +1,8 @@ +package gr.spinellis.views; + +/** + * @hidden + * @view + */ +public class ViewAll { +} diff --git a/testdata/java/gr/spinellis/views/ViewAllDetailed.java b/testdata/java/gr/spinellis/views/ViewAllDetailed.java new file mode 100644 index 0000000..e714a76 --- /dev/null +++ b/testdata/java/gr/spinellis/views/ViewAllDetailed.java @@ -0,0 +1,9 @@ +package gr.spinellis.views; + +/** + * @hidden + * @view + * @opt_override gr.spinellis.* attributes operations types + */ +public class ViewAllDetailed { +} diff --git a/testdata/java/gr/spinellis/views/ViewAtt.java b/testdata/java/gr/spinellis/views/ViewAtt.java new file mode 100644 index 0000000..4dc179b --- /dev/null +++ b/testdata/java/gr/spinellis/views/ViewAtt.java @@ -0,0 +1,9 @@ +package gr.spinellis.views; + +/** + * @hidden + * @view + * @opt_override gr.spinellis.* attributes nodefontsize=16 nodefillcolor=yellow + */ +public class ViewAtt { +} diff --git a/testdata/java/gr/spinellis/views/ViewProduct.java b/testdata/java/gr/spinellis/views/ViewProduct.java new file mode 100644 index 0000000..1c956f3 --- /dev/null +++ b/testdata/java/gr/spinellis/views/ViewProduct.java @@ -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 { +}