Added test case to check Doxygen comments parsing, including java and python runtime tests

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13150 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-06-04 18:11:29 +00:00
commit e3f41f32a6
5 changed files with 195 additions and 2 deletions

View file

@ -187,6 +187,7 @@ CPP_TEST_CASES += \
director_using \
director_wombat \
disown \
doxygen_parsing \
dynamic_cast \
empty \
enum_rename \

View file

@ -0,0 +1,84 @@
%module doxygen_parsing
%inline %{
/**
* This is simple comment for a var
*/
int simpleVar=42;
/*!
* This is another type of comment for a var
*/
int simpleVarTwo=42;
/// This is again another type of comment for a var
int simpleVarThree=42;
//! This is the last type of comment for a var
int simpleVarFour=42;
/*
We assume that all this comment types are ok,
and later we only use the first-type comments.
*/
/**
* This is simple comment for a function
*/
void simpleFunction(int arg)
{
}
/**
* This is simple comment for a class
*/
class CSimpleClass
{
private:
/** Some member var */
int simpleVar;
public:
/**
* Simple method
*/
void simpleMethod(int asd)
{
}
/**
* Simple method with parameter
*/
void simpleMethodWithParameter(
int param /**< Some test param */
)
{
}
};
/** Test enumeration */
enum E_TEST
{
/** the first item */
E_TEST_ONE,
E_TEST_TWO = 2, /**< the second */
E_TEST_THREE = 2+1
};
/**
* Comment for template class
*/
template <typename T>
class CTemplateClass
{
public:
/**
* Template method
*/
void templateMethod(T arg)
{
}
};
%}
%template(CTemplateClassInt) CTemplateClass<int>;

View file

@ -79,8 +79,8 @@ setup = \
run_testcase = \
cd $(JAVA_PACKAGE) && $(COMPILETOOL) $(JAVAC) -classpath . `find . -name "*.java"` && cd .. && \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(COMPILETOOL) $(JAVAC) -classpath . -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
env LD_LIBRARY_PATH="$(JAVA_PACKAGE):$$LD_LIBRARY_PATH" PATH="$(JAVA_PACKAGE):$$PATH" SHLIB_PATH="$(JAVA_PACKAGE):$$SHLIB_PATH" DYLD_LIBRARY_PATH="$(JAVA_PACKAGE):$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) $(JAVAFLAGS) -classpath . $*_runme; \
$(COMPILETOOL) $(JAVAC) -classpath $(JAVA_HOME)/lib/tools.jar:. -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
env LD_LIBRARY_PATH="$(JAVA_PACKAGE):$$LD_LIBRARY_PATH" PATH="$(JAVA_PACKAGE):$$PATH" SHLIB_PATH="$(JAVA_PACKAGE):$$SHLIB_PATH" DYLD_LIBRARY_PATH="$(JAVA_PACKAGE):$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) $(JAVAFLAGS) -classpath $(JAVA_HOME)/lib/tools.jar:. $*_runme; \
fi
# Clean: remove testcase directories

View file

@ -0,0 +1,89 @@
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 {
try {
System.loadLibrary("doxygen_parsing");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
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();
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.
*/
com.sun.tools.javadoc.Main.execute("doxygen_parsing runtime test",
"doxygen_parsing_runme", new String[]{"-quiet", "doxygen_parsing"});
wantedComments.put("simpleFunction", " This is simple comment for a function \n");
wantedComments.put("CSimpleClass", " This is simple comment for a class \n");
wantedComments.put("simpleMethod", " Simple method \n");
wantedComments.put("simpleMethodWithParameter", " Simple method with parameter \n @param\tparam Some test param \n");
wantedComments.put("CTemplateClassInt", " Comment for template class \n");
wantedComments.put("templateMethod", " Template method \n");
wantedComments.put("setSimpleVar", " This is simple comment for a var \n");
wantedComments.put("getSimpleVar", " This is simple comment for a var \n");
wantedComments.put("setSimpleVarTwo", " This is another type of comment for a var \n");
wantedComments.put("getSimpleVarTwo", " This is another type of comment for a var \n");
wantedComments.put("setSimpleVarThree", " This is again another type of comment for a var \n");
wantedComments.put("getSimpleVarThree", " This is again another type of comment for a var \n");
wantedComments.put("setSimpleVarFour", " This is the last type of comment for a var \n");
wantedComments.put("getSimpleVarFour", " This is the last type of comment for a var \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++;
}
}
System.exit(errorCount);
}
}

View file

@ -0,0 +1,19 @@
#!/usr/bin/python
import doxygen_parsing
import sys
import re
def check(got, expected):
if not re.match(str(expected), str(got)):
raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]")
check(doxygen_parsing.simpleFunction.__doc__, '\s+This is simple comment for a function\s+')
check(doxygen_parsing.CSimpleClass.__doc__, '\s+This is simple comment for a class\s+')
check(doxygen_parsing.CSimpleClass.simpleMethod.__doc__, '\s+Simple method\s+')
check(doxygen_parsing.CSimpleClass.simpleMethodWithParameter.__doc__, ''
'\s+Simple method with parameter'
'\s+Arguments:\s+param \(int\)\s+-- Some test param\s+'
)
check(doxygen_parsing.CTemplateClassInt.__doc__, '\s+Comment for template class\s+')
check(doxygen_parsing.CTemplateClassInt.templateMethod.__doc__, '\s+Template method\s+')