2011-07-25 20:13:37 +08:00
|
|
|
import sys, os, re
|
|
|
|
|
2011-07-26 21:40:26 +08:00
|
|
|
classes_ignore_list = (
|
|
|
|
'OpenCV(Test)?Case',
|
|
|
|
'OpenCV(Test)?Runner',
|
|
|
|
'CvException',
|
|
|
|
)
|
|
|
|
|
|
|
|
funcs_ignore_list = (
|
|
|
|
'\w+--HashCode',
|
|
|
|
'Mat--MatLong',
|
2011-08-05 21:04:14 +08:00
|
|
|
'\w+--Equals',
|
|
|
|
'Core--MinMaxLocResult',
|
2011-07-26 21:40:26 +08:00
|
|
|
)
|
|
|
|
|
2011-07-25 20:13:37 +08:00
|
|
|
class JavaParser:
|
|
|
|
def __init__(self):
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.mdict = {}
|
|
|
|
self.tdict = {}
|
2011-08-05 21:04:14 +08:00
|
|
|
self.mwhere = {}
|
|
|
|
self.twhere = {}
|
2011-07-26 15:50:44 +08:00
|
|
|
self.empty_stubs_cnt = 0
|
2011-07-25 20:13:37 +08:00
|
|
|
self.r1 = re.compile("\s*public\s+(?:static\s+)?(\w+)\(([^)]*)\)") # c-tor
|
2011-07-29 22:06:02 +08:00
|
|
|
self.r2 = re.compile("\s*(?:(?:public|static|final)\s+){1,3}\S+\s+(\w+)\(([^)]*)\)")
|
2011-07-26 15:50:44 +08:00
|
|
|
self.r3 = re.compile('\s*fail\("Not yet implemented"\);') # empty test stub
|
|
|
|
|
2011-07-25 20:13:37 +08:00
|
|
|
|
|
|
|
def dict2set(self, d):
|
|
|
|
s = set()
|
|
|
|
for f in d.keys():
|
|
|
|
if len(d[f]) == 1:
|
|
|
|
s.add(f)
|
|
|
|
else:
|
|
|
|
s |= set(d[f])
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
2011-07-26 15:50:44 +08:00
|
|
|
def get_tests_count(self):
|
|
|
|
return len(self.tdict)
|
|
|
|
|
|
|
|
def get_empty_stubs_count(self):
|
|
|
|
return self.empty_stubs_cnt
|
|
|
|
|
|
|
|
def get_funcs_count(self):
|
|
|
|
return len(self.dict2set(self.mdict)), len(self.mdict)
|
|
|
|
|
2011-07-25 20:13:37 +08:00
|
|
|
def get_not_tested(self):
|
|
|
|
mset = self.dict2set(self.mdict)
|
|
|
|
tset = self.dict2set(self.tdict)
|
2011-08-05 21:04:14 +08:00
|
|
|
nottested = mset - tset
|
|
|
|
out = set()
|
|
|
|
|
|
|
|
for name in nottested:
|
|
|
|
out.add(name + " " + self.mwhere[name])
|
|
|
|
|
|
|
|
return out
|
2011-07-25 20:13:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
def parse(self, path):
|
|
|
|
if ".svn" in path:
|
|
|
|
return
|
|
|
|
if os.path.isfile(path):
|
2011-08-05 21:04:14 +08:00
|
|
|
if path.endswith("FeatureDetector.java"):
|
|
|
|
for prefix1 in ("", "Grid", "Pyramid", "Dynamic"):
|
|
|
|
for prefix2 in ("FAST", "STAR", "MSER", "ORB", "SIFT", "SURF", "GFTT", "HARRIS"):
|
|
|
|
parser.parse_file(path,prefix1+prefix2)
|
|
|
|
elif path.endswith("DescriptorExtractor.java"):
|
|
|
|
for prefix1 in ("", "Opponent"):
|
|
|
|
for prefix2 in ("BRIEF", "ORB", "SIFT", "SURF"):
|
|
|
|
parser.parse_file(path,prefix1+prefix2)
|
|
|
|
elif path.endswith("GenericDescriptorMatcher.java"):
|
|
|
|
for prefix in ("OneWay", "Fern"):
|
|
|
|
parser.parse_file(path,prefix)
|
|
|
|
elif path.endswith("DescriptorMatcher.java"):
|
2011-08-09 20:52:47 +08:00
|
|
|
for prefix in ("BruteForce", "BruteForceHamming", "BruteForceHammingLUT", "BruteForceL1", "FlannBased", "BruteForceSL2"):
|
2011-08-05 21:04:14 +08:00
|
|
|
parser.parse_file(path,prefix)
|
|
|
|
else:
|
|
|
|
parser.parse_file(path)
|
2011-07-25 20:13:37 +08:00
|
|
|
elif os.path.isdir(path):
|
|
|
|
for x in os.listdir(path):
|
|
|
|
self.parse(path + "/" + x)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2011-08-05 21:04:14 +08:00
|
|
|
def parse_file(self, fname, prefix = ""):
|
|
|
|
istest = fname.endswith("Test.java")
|
2011-07-25 20:13:37 +08:00
|
|
|
clsname = os.path.basename(fname).replace("Test", "").replace(".java", "")
|
2011-08-05 21:04:14 +08:00
|
|
|
clsname = prefix + clsname[0].upper() + clsname[1:]
|
2011-07-26 21:40:26 +08:00
|
|
|
for cls in classes_ignore_list:
|
|
|
|
if re.match(cls, clsname):
|
|
|
|
return
|
2011-07-25 20:13:37 +08:00
|
|
|
f = open(fname, "rt")
|
2011-08-05 21:04:14 +08:00
|
|
|
linenum = 0
|
2011-07-25 20:13:37 +08:00
|
|
|
for line in f:
|
2011-08-05 21:04:14 +08:00
|
|
|
linenum += 1
|
2011-07-25 20:13:37 +08:00
|
|
|
m1 = self.r1.match(line)
|
|
|
|
m2 = self.r2.match(line)
|
2011-07-26 15:50:44 +08:00
|
|
|
m3 = self.r3.match(line)
|
2011-07-25 20:13:37 +08:00
|
|
|
func = ''
|
|
|
|
args_str = ''
|
|
|
|
if m1:
|
|
|
|
func = m1.group(1)
|
|
|
|
args_str = m1.group(2)
|
|
|
|
elif m2:
|
2011-07-29 22:06:02 +08:00
|
|
|
if "public" not in line:
|
|
|
|
continue
|
2011-07-25 20:13:37 +08:00
|
|
|
func = m2.group(1)
|
|
|
|
args_str = m2.group(2)
|
2011-07-26 15:50:44 +08:00
|
|
|
elif m3:
|
|
|
|
self.empty_stubs_cnt += 1
|
|
|
|
continue
|
2011-07-25 20:13:37 +08:00
|
|
|
else:
|
2011-07-29 22:06:02 +08:00
|
|
|
#if "public" in line:
|
|
|
|
#print "UNRECOGNIZED: " + line
|
2011-07-25 20:13:37 +08:00
|
|
|
continue
|
2011-08-05 21:04:14 +08:00
|
|
|
d = (self.mdict, self.tdict)[istest]
|
|
|
|
w = (self.mwhere, self.twhere)[istest]
|
2011-07-25 20:13:37 +08:00
|
|
|
func = re.sub(r"^test", "", func)
|
|
|
|
func = clsname + "--" + func[0].upper() + func[1:]
|
|
|
|
args_str = args_str.replace("[]", "Array").replace("...", "Array ")
|
|
|
|
args_str = re.sub(r"List<(\w+)>", "ListOf\g<1>", args_str)
|
2011-08-05 21:04:14 +08:00
|
|
|
args_str = re.sub(r"List<(\w+)>", "ListOf\g<1>", args_str)
|
2011-07-25 20:13:37 +08:00
|
|
|
args = [a.split()[0] for a in args_str.split(",") if a]
|
|
|
|
func_ex = func + "".join([a[0].upper() + a[1:] for a in args])
|
2011-08-05 21:04:14 +08:00
|
|
|
func_loc = fname + " (line: " + str(linenum) + ")"
|
2011-07-26 21:40:26 +08:00
|
|
|
skip = False
|
|
|
|
for fi in funcs_ignore_list:
|
|
|
|
if re.match(fi, func_ex):
|
|
|
|
skip = True
|
|
|
|
break
|
|
|
|
if skip:
|
|
|
|
continue
|
2011-07-25 20:13:37 +08:00
|
|
|
if func in d:
|
|
|
|
d[func].append(func_ex)
|
|
|
|
else:
|
|
|
|
d[func] = [func_ex]
|
2011-08-05 21:04:14 +08:00
|
|
|
w[func_ex] = func_loc
|
|
|
|
w[func] = func_loc
|
|
|
|
|
2011-07-25 20:13:37 +08:00
|
|
|
f.close()
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print "Usage:\n", \
|
|
|
|
os.path.basename(sys.argv[0]), \
|
2011-07-26 15:50:44 +08:00
|
|
|
"<Classes/Tests dir1/file1> [<Classes/Tests dir2/file2> ...]\n", "Not tested methods are loggedto stdout."
|
2011-07-25 20:13:37 +08:00
|
|
|
exit(0)
|
|
|
|
parser = JavaParser()
|
|
|
|
for x in sys.argv[1:]:
|
|
|
|
parser.parse(x)
|
|
|
|
funcs = parser.get_not_tested()
|
|
|
|
if funcs:
|
2011-07-26 15:50:44 +08:00
|
|
|
print "NOT TESTED methods:\n\t", "\n\t".join(sorted(funcs))
|
|
|
|
print "Total methods found: %i (%i)" % parser.get_funcs_count()
|
|
|
|
print "Not tested methods found:", len(funcs)
|
|
|
|
print "Total tests found:", parser.get_tests_count()
|
|
|
|
print "Empty test stubs found:", parser.get_empty_stubs_count()
|
2011-07-25 20:13:37 +08:00
|
|
|
|