Refactored doxygen tests

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13261 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-07-07 13:40:41 +00:00
commit 93a02cc728
9 changed files with 131 additions and 403 deletions

View file

@ -0,0 +1,71 @@
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class commentParser {
static HashMap<String, String> parsedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
* This method is called by 'javadoc' and gets the whole parsed java
* file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(),
classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static int check(HashMap<String, String> wantedComments) {
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() < wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
return errorCount;
}
}

View file

@ -2,8 +2,6 @@
import doxygen_basic_translate.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_basic_translate_runme {
static {
@ -14,81 +12,25 @@ public class doxygen_basic_translate_runme {
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_basic_translate runtime test",
"doxygen_basic_translate_runme", new String[]{"-quiet", "doxygen_basic_translate"});
"commentParser", new String[]{"-quiet", "doxygen_basic_translate"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("function", " Brief description. \n The comment text \n" +
" @author\tSome author \n" +
" @return\tSome number \n" +
" @see\tfunction2 \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
" @author\tSome author \n" +
" @return\tSome number \n" +
" @see\tfunction2 \n");
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}
}

View file

@ -2,8 +2,6 @@
import doxygen_parsing_enums_proper.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_proper_runme {
static {
@ -14,80 +12,25 @@ public class doxygen_parsing_enums_proper_runme {
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_proper runtime test",
"doxygen_parsing_enums_proper_runme", new String[]{"-quiet", "doxygen_parsing_enums_proper"});
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_proper"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
wantedComments.put("E_TEST_THREE", " the last item \n");
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}

View file

@ -2,8 +2,6 @@
import doxygen_parsing_enums_simple.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_simple_runme {
static {
@ -14,79 +12,24 @@ public class doxygen_parsing_enums_simple_runme {
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_simple runtime test",
"doxygen_parsing_enums_simple_runme", new String[]{"-quiet", "doxygen_parsing_enums_simple"});
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_simple"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
wantedComments.put("E_TEST_THREE", " the last item \n");
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}

View file

@ -2,8 +2,6 @@
import doxygen_parsing_enums_typesafe.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_typesafe_runme {
static {
@ -14,80 +12,25 @@ public class doxygen_parsing_enums_typesafe_runme {
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typesafe runtime test",
"doxygen_parsing_enums_typesafe_runme", new String[]{"-quiet", "doxygen_parsing_enums_typesafe"});
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_typesafe"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
wantedComments.put("E_TEST_THREE", " the last item \n");
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}

View file

@ -2,8 +2,6 @@
import doxygen_parsing_enums_typeunsafe.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_typeunsafe_runme {
static {
@ -14,80 +12,25 @@ public class doxygen_parsing_enums_typeunsafe_runme {
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typeunsafe runtime test",
"doxygen_parsing_enums_typeunsafe_runme", new String[]{"-quiet", "doxygen_parsing_enums_typeunsafe"});
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_typeunsafe"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
wantedComments.put("E_TEST_THREE", " the last item \n");
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}

View file

@ -2,8 +2,6 @@
import doxygen_parsing.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_runme {
static {
@ -15,55 +13,18 @@ public class doxygen_parsing_runme {
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing runtime test",
"doxygen_parsing_runme", new String[]{"-quiet", "doxygen_parsing"});
"commentParser", new String[]{"-quiet", "doxygen_parsing"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("simpleFunction", " This is simple comment for a function \n");
wantedComments.put("CSimpleClass", " This is simple comment for a class \n");
@ -85,27 +46,7 @@ public class doxygen_parsing_runme {
wantedComments.put("setSimpleVarFive", " This is a post comment \n");
wantedComments.put("getSimpleVarFive", " This is a post comment \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
// and ask the parser to check comments for us
System.exit(parser.check(wantedComments));
}
}