Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions osi_object.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions osi_sensorviewconfiguration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ message GenericSensorViewConfiguration
optional double field_of_view_vertical = 5;

// TBD: Generic sensor specific configuration.
//
}

//
Expand Down Expand Up @@ -677,6 +678,7 @@ message CameraSensorViewConfiguration
}

// TBD: Optical (and other) effects to apply to image, etc.
//
}

//
Expand Down Expand Up @@ -746,4 +748,5 @@ message UltrasonicSensorViewConfiguration
optional double field_of_view_vertical = 5;

// TBD: Ultrasonic Sensor specific configuration.
//
}
171 changes: 161 additions & 10 deletions test_cases.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,174 @@
import sys
import unicodedata
import re
from glob import *

state = 0

for file in glob("*.*"):
if(file != "test_cases.py"):
with open(file, "rt") as fin:
i = 0
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")
with open(file, "rt") as fin:
i = 0
isEnum = False
enumName = ""
noMessage = 0
noComment = 0

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

# Test case 2 is checking if there are more than the two allowed '/'
if file.find(".proto") != -1:
# --------------------------------------------------------------
# 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 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 other type of comment
if line.find("*/") != -1:
print(file + " in line " + str(i) + ": not permitted use of '*/' ")
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-8 camelcase for enums and check enum name?

# .
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:
# 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.
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()

# --------------------------------------------------------------
# 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

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 -
# 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 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:
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 message type wrong. Check: '"+checkType+"'")
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)