From f3373ce6b0a0b32b73e46867a66dda33c7293342 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 13:16:33 +0200 Subject: [PATCH 1/7] Update readme.md Link to online doxygen documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5c98ae70e..8aeaa2150 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ is available [here](https://github.com/OpenSimulationInterface/osi-sensor-model- Documentation ------------- +The actual documentation of the GitHub master branch is [online](https://opensimulationinterface.github.io/open-simulation-interface/) available. + Detailed information about installation and usage of OSI can be found in the [Wiki](https://github.com/OpenSimulationInterface/open-simulation-interface/wiki) In order to generate the doxygen documentation for OSI, please follow the following steps: From d4d820ec2fac9c3b650d8d4c6b705e90ba6dc696 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 17:10:08 +0200 Subject: [PATCH 2/7] Add test cases check enum names --- test_cases.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/test_cases.py b/test_cases.py index ce1bb1a7e..3bde364d7 100644 --- a/test_cases.py +++ b/test_cases.py @@ -1,23 +1,104 @@ import sys +import unicodedata +import re from glob import * state = 0 for file in glob("*.*"): - if(file != "test_cases.py"): + if(file != "test_cases.py") and (file != "setup.py"): with open(file, "rt") as fin: i = 0 + isEnum = False + enumName = "" for line in fin: i = i + 1 + # -------------------------------------------------------------- # Test case 1 is checking if there are illegal tabulators in the code if line.find("\t") != -1: print(file + " in line " + str(i) + ": not permitted tab found") state = 1 + # -------------------------------------------------------------- # Test case 2 is checking if there are more than the two allowed '/' if line.find("///") != -1: print(file + " in line " + str(i) + ": not permitted use of '///' ") state = 1 + # -------------------------------------------------------------- + # Test case 3 is checking if there is an other type of comment + if line.find("/*") != -1: + print(file + " in line " + str(i) + ": not permitted use of '/*' ") + state = 1 + + # -------------------------------------------------------------- + # Test case 4 is checking if there is an other type of comment + if line.find("*/") != -1: + print(file + " in line " + str(i) + ": not permitted use of '*/' ") + state = 1 + + # -------------------------------------------------------------- + # Test case 5 is checking if there is an "Umlaut" etc. + if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): + print(file + " in line " + str(i) + ": a none ASCII char is present") + state = 1 + + # -------------------------------------------------------------- + + # Search for comment ("//") and add one more slash character ("/") to the comment + # block to make Doxygen detect it. + matchComment = re.search("//", line) + if matchComment is not None: + statement = line[:matchComment.start()] + else: + statement = line + + # -------------------------------------------------------------- + # Test case 6/7 camelcase for enums? + + # Search again for semicolon if we have detected an enum, and replace semicolon with comma. + if isEnum is True: + matchName = re.search(r"\b\w[\S:]+\b", statement); + if matchName is not None: + checkName = statement[matchName.start():matchName.end()] + # Test case 6: Check correct name + if checkName.find(enumName) != 0: + print(file + " in line " + str(i) + ": enum type wrong. '"+checkName+"' should start with '"+enumName+"'") + state = 1 + # Test case 7: Check upper case + elif checkName != checkName.upper(): + print(file + " in line " + str(i) + ": enum type wrong. '"+checkName+"' should use upper case") + state = 1 + + + # Search for "enum". + matchEnum = re.search(r"\benum\b", statement) + if matchEnum is not None: + isEnum = True + endOfLine = statement[matchEnum.end():] + matchName = re.search(r"\b\w[\S:]+\b", endOfLine); + if matchName is not None: + enumName = convert(endOfLine[matchName.start():matchName.end()])+"_" + + # Search for a closing brace. + matchClosingBrace = re.search("}", statement) + if isEnum is True and matchClosingBrace is not None: + isEnum = False + enumName = "" + + # -------------------------------------------------------------- + # Test case 8 is checking if there is '__' + if line.find("__") != -1: + print(file + " in line " + str(i) + ": not permitted use of '__' ") + state = 1 + + # -------------------------------------------------------------- + + + def convert(name): + s1 = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name) + return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', s1).upper() + sys.exit(state) + From b94e788891781eaea9536012d3b9e15cfd59500c Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 17:20:43 +0200 Subject: [PATCH 3/7] Python2 Bugfix for test cases --- test_cases.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test_cases.py b/test_cases.py index 3bde364d7..c1532add6 100644 --- a/test_cases.py +++ b/test_cases.py @@ -40,9 +40,14 @@ # -------------------------------------------------------------- # Test case 5 is checking if there is an "Umlaut" etc. - if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): - print(file + " in line " + str(i) + ": a none ASCII char is present") - state = 1 + if (sys.version_info > (3, 0)): + if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): + print(file + " in line " + str(i) + ": a none ASCII char is present") + state = 1 + else: + if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode('ASCII'): + print(file + " in line " + str(i) + ": a none ASCII char is present") + state = 1 # -------------------------------------------------------------- From 94ba6a781689881a612c9b8955b9c1c7a6f46aaf Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 17:26:47 +0200 Subject: [PATCH 4/7] Bugfix for python2 --- test_cases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cases.py b/test_cases.py index c1532add6..4f5896ec7 100644 --- a/test_cases.py +++ b/test_cases.py @@ -45,7 +45,7 @@ print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 else: - if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode('ASCII'): + if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore'): print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 From 44c01c36b685e748ba86bcb62f839fcf220f26cc Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 17:32:08 +0200 Subject: [PATCH 5/7] Bugfix --- test_cases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cases.py b/test_cases.py index 4f5896ec7..31f2b2c89 100644 --- a/test_cases.py +++ b/test_cases.py @@ -45,7 +45,7 @@ print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 else: - if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore'): + if line != unicodedata.normalize('NFKD', unicode(line, 'ISO-8859-1')).encode('ASCII', 'ignore'): print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 From 1b92921f66729cd26ec9c1f6967938e82bab387b Mon Sep 17 00:00:00 2001 From: carsten-kuebler <32508295+carsten-kuebler@users.noreply.github.com> Date: Wed, 25 Apr 2018 08:27:09 +0200 Subject: [PATCH 6/7] Add test cases and correct short comments --- osi_object.proto | 4 + osi_sensorviewconfiguration.proto | 3 + test_cases.py | 131 ++++++++++++++++++++++-------- 3 files changed, 103 insertions(+), 35 deletions(-) diff --git a/osi_object.proto b/osi_object.proto index 3bb84ae92..e11f9c89b 100644 --- a/osi_object.proto +++ b/osi_object.proto @@ -185,15 +185,19 @@ message StationaryObject DENSITY_SOLID = 2; // Perforation max. ]0; 100] [mm] + // DENSITY_SMALL_MESH = 3; // Perforation max. ]100; 500] [mm] + // DENSITY_MEDIAN_MESH = 4; // Perforation max. ]500; 5000] [mm] + // DENSITY_LARGE_MESH = 5; // Perforation max. ]5000; infinity] [mm] + // DENSITY_OPEN = 6; } diff --git a/osi_sensorviewconfiguration.proto b/osi_sensorviewconfiguration.proto index f5ca8890e..83fd3899d 100644 --- a/osi_sensorviewconfiguration.proto +++ b/osi_sensorviewconfiguration.proto @@ -281,6 +281,7 @@ message GenericSensorViewConfiguration optional double field_of_view_vertical = 5; // TBD: Generic sensor specific configuration. + // } // @@ -677,6 +678,7 @@ message CameraSensorViewConfiguration } // TBD: Optical (and other) effects to apply to image, etc. + // } // @@ -746,4 +748,5 @@ message UltrasonicSensorViewConfiguration optional double field_of_view_vertical = 5; // TBD: Ultrasonic Sensor specific configuration. + // } diff --git a/test_cases.py b/test_cases.py index 31f2b2c89..2cc395071 100644 --- a/test_cases.py +++ b/test_cases.py @@ -6,49 +6,52 @@ state = 0 for file in glob("*.*"): - if(file != "test_cases.py") and (file != "setup.py"): - with open(file, "rt") as fin: - i = 0 - isEnum = False - enumName = "" - for line in fin: - i = i + 1 + with open(file, "rt") as fin: + i = 0 + isEnum = False + enumName = "" + noMessage = 0 + noComment = 0 - # -------------------------------------------------------------- - # Test case 1 is checking if there are illegal tabulators in the code - if line.find("\t") != -1: - print(file + " in line " + str(i) + ": not permitted tab found") + for line in fin: + i = i + 1 + + # -------------------------------------------------------------- + # Test case 1 is checking if there are illegal tabulators in the code + if line.find("\t") != -1: + print(file + " in line " + str(i) + ": not permitted tab found") + state = 1 + + # -------------------------------------------------------------- + # Test case 2 is checking if there is an "Umlaut" etc. + if (sys.version_info > (3, 0)): + if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): + print(file + " in line " + str(i) + ": a none ASCII char is present") + state = 1 + else: + if line != unicodedata.normalize('NFKD', unicode(line, 'ISO-8859-1')).encode('ASCII', 'ignore'): + print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 + if file.find(".proto") != -1: # -------------------------------------------------------------- - # Test case 2 is checking if there are more than the two allowed '/' + # Test case 3 is checking if there are more than the two allowed '/' if line.find("///") != -1: print(file + " in line " + str(i) + ": not permitted use of '///' ") state = 1 # -------------------------------------------------------------- - # Test case 3 is checking if there is an other type of comment + # Test case 4 is checking if there is an other type of comment if line.find("/*") != -1: print(file + " in line " + str(i) + ": not permitted use of '/*' ") state = 1 # -------------------------------------------------------------- - # Test case 4 is checking if there is an other type of comment + # Test case 5 is checking if there is an other type of comment if line.find("*/") != -1: print(file + " in line " + str(i) + ": not permitted use of '*/' ") state = 1 - # -------------------------------------------------------------- - # Test case 5 is checking if there is an "Umlaut" etc. - if (sys.version_info > (3, 0)): - if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): - print(file + " in line " + str(i) + ": a none ASCII char is present") - state = 1 - else: - if line != unicodedata.normalize('NFKD', unicode(line, 'ISO-8859-1')).encode('ASCII', 'ignore'): - print(file + " in line " + str(i) + ": a none ASCII char is present") - state = 1 - # -------------------------------------------------------------- # Search for comment ("//") and add one more slash character ("/") to the comment @@ -60,11 +63,11 @@ statement = line # -------------------------------------------------------------- - # Test case 6/7 camelcase for enums? + # Test case 6-8 camelcase for enums and check enum name? - # Search again for semicolon if we have detected an enum, and replace semicolon with comma. + # . if isEnum is True: - matchName = re.search(r"\b\w[\S:]+\b", statement); + matchName = re.search(r"\b\w[\S:]+\b", statement) if matchName is not None: checkName = statement[matchName.start():matchName.end()] # Test case 6: Check correct name @@ -76,14 +79,18 @@ print(file + " in line " + str(i) + ": enum type wrong. '"+checkName+"' should use upper case") state = 1 - # Search for "enum". matchEnum = re.search(r"\benum\b", statement) if matchEnum is not None: isEnum = True endOfLine = statement[matchEnum.end():] - matchName = re.search(r"\b\w[\S:]+\b", endOfLine); + matchName = re.search(r"\b\w[\S]*\b", endOfLine) if matchName is not None: + # Test case 8: Check name - no special char + matchNameConv = re.search(r"\b[A-Z][a-zA-Z0-9]*\b",endOfLine[matchName.start():matchName.end()]) + if matchNameConv is None: + print(file + " in line " + str(i) + ": enum name wrong. '"+endOfLine[matchName.start():matchName.end()]+"'") + state = 1 enumName = convert(endOfLine[matchName.start():matchName.end()])+"_" # Search for a closing brace. @@ -91,19 +98,73 @@ if isEnum is True and matchClosingBrace is not None: isEnum = False enumName = "" + + def convert(name): + s1 = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name) + return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', s1).upper() # -------------------------------------------------------------- - # Test case 8 is checking if there is '__' + # Test case 9 is checking if there is '__' if line.find("__") != -1: print(file + " in line " + str(i) + ": not permitted use of '__' ") state = 1 # -------------------------------------------------------------- - + # Test case 10-12 check message name, field type and field name + # + # Check (nested) messages - def convert(name): - s1 = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', s1).upper() + if isEnum is False: + + # Search for "message". + matchMessage = re.search(r"\bmessage\b", statement) + if matchMessage is not None: + noMessage += 1 + endOfLine = statement[matchMessage.end():] + matchName = re.search(r"\b\w[\S]*\b", endOfLine) + if matchName is not None: + # Test case 10: Check name - no special char + matchNameConv = re.search(r"\b[A-Z][a-zA-Z0-9]*\b",endOfLine[matchName.start():matchName.end()]) + if matchNameConv is None: + print(file + " in line " + str(i) + ": message name wrong. '"+endOfLine[matchName.start():matchName.end()]+"'") + state = 1 + else: + # . + if noMessage > 0: + matchName = re.search(r"\b\w[\S]*\b\s*=", statement) + if matchName is not None: + checkName = statement[matchName.start():matchName.end()-1] + # Test case 11: Check lower case for field names + if checkName != checkName.lower(): + print(file + " in line " + str(i) + ": field name wrong. '"+checkName+"' should use lower case") + state = 1 + type = statement.replace(checkName, "") + matchName = re.search(r"\b\w[\S\.]*\s*=", type) + if matchName is not None: + checkType = " "+type[matchName.start():matchName.end()-1]+" " + # Test case 12: Check nested message type + matchNameConv = re.search(r"[ ][a-zA-Z][a-zA-Z0-9]*([\.][A-Z][a-zA-Z0-9]*)*[ ]",checkType) + if matchNameConv is None: + print(file + " in line " + str(i) + ": field type wrong. '"+checkType+"' not correct") + state = 1 + + # Search for a closing brace. + matchClosingBrace = re.search("}", statement) + if noMessage > 0 and matchClosingBrace is not None: + noMessage -= 1 + + # -------------------------------------------------------------- + # Test case 13 is checking if comment is min 2 lines + if line.find("//") != -1: + noComment += 1; + else: + if noComment == 1: + print(file + " in line " + str(i-1) + ": short comment - min 2 lines.") + state = 1 + noComment = 0 + + # -------------------------------------------------------------- + sys.exit(state) From be2de7552ef25b378f3e853d7ab6c5e228c8def9 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Wed, 25 Apr 2018 09:44:42 +0200 Subject: [PATCH 7/7] Documentation Remove spaces at eol. Bugfix: Python 3 is ">= (3,0)" Improve error messages. --- test_cases.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/test_cases.py b/test_cases.py index 2cc395071..025bd2da4 100644 --- a/test_cases.py +++ b/test_cases.py @@ -24,7 +24,7 @@ # -------------------------------------------------------------- # Test case 2 is checking if there is an "Umlaut" etc. - if (sys.version_info > (3, 0)): + if (sys.version_info >= (3, 0)): if line != unicodedata.normalize('NFKD', line).encode('ASCII', 'ignore').decode(): print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 @@ -33,7 +33,7 @@ print(file + " in line " + str(i) + ": a none ASCII char is present") state = 1 - if file.find(".proto") != -1: + if file.find(".proto") != -1: # -------------------------------------------------------------- # Test case 3 is checking if there are more than the two allowed '/' if line.find("///") != -1: @@ -53,7 +53,7 @@ state = 1 # -------------------------------------------------------------- - + # Search for comment ("//") and add one more slash character ("/") to the comment # block to make Doxygen detect it. matchComment = re.search("//", line) @@ -61,10 +61,10 @@ statement = line[:matchComment.start()] else: statement = line - + # -------------------------------------------------------------- - # Test case 6-8 camelcase for enums and check enum name? - + # Test case 6-8 camelcase for enums and check enum name? + # . if isEnum is True: matchName = re.search(r"\b\w[\S:]+\b", statement) @@ -92,13 +92,13 @@ print(file + " in line " + str(i) + ": enum name wrong. '"+endOfLine[matchName.start():matchName.end()]+"'") state = 1 enumName = convert(endOfLine[matchName.start():matchName.end()])+"_" - + # Search for a closing brace. matchClosingBrace = re.search("}", statement) if isEnum is True and matchClosingBrace is not None: isEnum = False enumName = "" - + def convert(name): s1 = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', s1).upper() @@ -113,31 +113,35 @@ def convert(name): # Test case 10-12 check message name, field type and field name # # Check (nested) messages - + if isEnum is False: - + # Check if not inside an enum. + # Search for "message". matchMessage = re.search(r"\bmessage\b", statement) if matchMessage is not None: + # a new message or a new nested message noMessage += 1 endOfLine = statement[matchMessage.end():] matchName = re.search(r"\b\w[\S]*\b", endOfLine) if matchName is not None: - # Test case 10: Check name - no special char + # Test case 10: Check name - no special char - + # start with a capital letter matchNameConv = re.search(r"\b[A-Z][a-zA-Z0-9]*\b",endOfLine[matchName.start():matchName.end()]) if matchNameConv is None: print(file + " in line " + str(i) + ": message name wrong. '"+endOfLine[matchName.start():matchName.end()]+"'") state = 1 else: - # . + # Check field names if noMessage > 0: matchName = re.search(r"\b\w[\S]*\b\s*=", statement) if matchName is not None: checkName = statement[matchName.start():matchName.end()-1] - # Test case 11: Check lower case for field names + # Test case 11: Check lowercase letters for field names if checkName != checkName.lower(): print(file + " in line " + str(i) + ": field name wrong. '"+checkName+"' should use lower case") state = 1 + # Check field message type (remove field name) type = statement.replace(checkName, "") matchName = re.search(r"\b\w[\S\.]*\s*=", type) if matchName is not None: @@ -145,7 +149,7 @@ def convert(name): # Test case 12: Check nested message type matchNameConv = re.search(r"[ ][a-zA-Z][a-zA-Z0-9]*([\.][A-Z][a-zA-Z0-9]*)*[ ]",checkType) if matchNameConv is None: - print(file + " in line " + str(i) + ": field type wrong. '"+checkType+"' not correct") + print(file + " in line " + str(i) + ": field message type wrong. Check: '"+checkType+"'") state = 1 # Search for a closing brace. @@ -154,12 +158,12 @@ def convert(name): noMessage -= 1 # -------------------------------------------------------------- - # Test case 13 is checking if comment is min 2 lines + # Test case 13 is checking if comment is min. 2 lines if line.find("//") != -1: noComment += 1; else: if noComment == 1: - print(file + " in line " + str(i-1) + ": short comment - min 2 lines.") + print(file + " in line " + str(i-1) + ": short comment - min. 2 lines.") state = 1 noComment = 0