| 1 |
% Regression tests for automotive scanner test_case |
| 2 |
|
| 3 |
+ Load general modules |
| 4 |
|
| 5 |
= Load contribution layer |
| 6 |
|
| 7 |
from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase |
| 8 |
from scapy.contrib.automotive.ecu import EcuState |
| 9 |
|
| 10 |
+ Basic checks |
| 11 |
|
| 12 |
= Definition of Test class |
| 13 |
|
| 14 |
class MyTestCase(AutomotiveTestCase): |
| 15 |
_description = "MyTestCase" |
| 16 |
_supported_kwargs = {"testarg": (int, None)} |
| 17 |
def supported_responses(self): |
| 18 |
return [] |
| 19 |
|
| 20 |
= Check supported kwargs |
| 21 |
|
| 22 |
try: |
| 23 |
MyTestCase.check_kwargs({"testarg": 5}) |
| 24 |
except Scapy_Exception as e: |
| 25 |
assert False |
| 26 |
|
| 27 |
try: |
| 28 |
MyTestCase.check_kwargs({"test": 5}) |
| 29 |
assert False |
| 30 |
except Scapy_Exception as e: |
| 31 |
assert "Keyword-Argument test not supported" in str(e) |
| 32 |
|
| 33 |
try: |
| 34 |
MyTestCase.check_kwargs({"testarg": 5.5}) |
| 35 |
assert False |
| 36 |
except Scapy_Exception as e: |
| 37 |
assert "Keyword-Value" in str(e) |
| 38 |
assert "is not instance of type <class 'int'>" in str(e) or \ |
| 39 |
"is not instance of type <type 'int'>" in str(e) |
| 40 |
|
| 41 |
= Create instance of test class |
| 42 |
|
| 43 |
mt = MyTestCase() |
| 44 |
|
| 45 |
mt._state_completed[EcuState(session=1)] = True |
| 46 |
mt._state_completed[EcuState(session=2)] = True |
| 47 |
mt._state_completed[EcuState(session=3)] = False |
| 48 |
|
| 49 |
= Tests of has_completed |
| 50 |
|
| 51 |
assert mt.completed is False |
| 52 |
assert mt.has_completed(EcuState(session=1)) |
| 53 |
assert mt.has_completed(EcuState(session=3)) is False |
| 54 |
|
| 55 |
assert len(mt.scanned_states) == 3 |
| 56 |
|
| 57 |
= Tests of has_completed with new state |
| 58 |
|
| 59 |
assert mt.completed is False |
| 60 |
assert mt.has_completed(EcuState(session=4)) is False |
| 61 |
assert mt.has_completed(EcuState(session=3)) is False |
| 62 |
|
| 63 |
assert len(mt.scanned_states) == 4 |
| 64 |
|
| 65 |
= Tests of completed |
| 66 |
|
| 67 |
mt._state_completed[EcuState(session=3)] = True |
| 68 |
mt._state_completed[EcuState(session=4)] = True |
| 69 |
|
| 70 |
assert mt.completed |
| 71 |
|
| 72 |
= Test of show |
| 73 |
|
| 74 |
header = mt._show_header(dump=True) |
| 75 |
|
| 76 |
assert "MyTestCase" in header |
| 77 |
|
| 78 |
state_info = mt._show_state_information(dump=True) |
| 79 |
|
| 80 |
assert "session" in state_info |
| 81 |
assert "False" not in state_info |
| 82 |
assert "True" in state_info |
| 83 |
|
| 84 |
mt._state_completed[EcuState(session=3)] = False |
| 85 |
state_info = mt._show_state_information(dump=True) |
| 86 |
|
| 87 |
assert "session" in state_info |
| 88 |
assert "False" in state_info |
| 89 |
assert "True" in state_info |
| 90 |
|
| 91 |
dump = mt.show(dump=True, verbose=True) |
| 92 |
|
| 93 |
assert "session" in dump |
| 94 |
assert "MyTestCase" in dump |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|