Commit 8211f688 authored by berge's avatar berge

Merged branches/Security/unittests (r1488-1820) to trunk.

parent d8021f75
module test_CommonCodec /*language "TTCN-3:2009 Advanced Parameterization"*/ {
import from LibItsSecurity_TestSystem all;
type component TCType extends ItsSecurityBaseComponent { }
type component TCType { }
type record TestRecord {
bitstring bs optional
}
type record TestRecord {
bitstring bs optional
}
function test_decodePDU<PDUType>(in template PDUType p_pdu, in template (present) octetstring p_expEncMsg) runs on TCType {
var PDUType v_decMsg;
var bitstring v_encMsg;
var integer v_res := 0;
function test_decodePDU<PDUType>(in template PDUType p_pdu, in template (present) octetstring p_expEncMsg) runs on TCType {
var PDUType v_decMsg;
var bitstring v_encMsg;
var integer v_res := 0;
v_res := decvalue(oct2bit(valueof(p_expEncMsg)), v_decMsg);
select (v_res) {
case (0) {
if(match(v_decMsg, p_pdu)) {
setverdict(pass);
} else {
setverdict(fail);
}
}
case (1) {
setverdict(fail, "Decoding failed.");
}
case (2) {
setverdict(fail, "Not enough bits.");
}
} // End of 'select' statement
} // End of function test_decodePDU<PDUType>
v_res := decvalue(oct2bit(p_expEncMsg), v_decMsg);
select (v_res) {
case (0) {
if(match(v_decMsg, p_pdu)) {
setverdict(pass);
} else {
setverdict(fail);
}
}
case (1) {
setverdict(fail, "Decoding failed.");
}
case (2) {
setverdict(fail, "Not enough bits.");
}
} // End of 'select' statement
} // End of function test_decodePDU<PDUType>
function test_PDU<PDUType>(in PDUType p_pdu, in boolean p_decode:=true, in template (omit) bitstring p_expEncMsg:=omit) runs on TCType {
var PDUType v_decMsg;
var bitstring v_encMsg;
var integer v_res := 0;
var TestRecord v_tr := { bs := p_expEncMsg }
v_encMsg := encvalue(p_pdu);
log("Encoded message: ", v_encMsg);
if (v_encMsg == null) {
setverdict(fail, "Encoding failed!");
stop;
}
if (ispresent(v_tr.bs)) {
if (not match(v_encMsg, p_expEncMsg)) {
setverdict(fail, "Encoding failed, not the expected result!");
stop;
}
}
setverdict(pass, "Encoding passed.");
if (p_decode == true) {
v_res := decvalue(v_encMsg, v_decMsg);
select (v_res) {
case (0) {
if(match(v_decMsg, p_pdu)) {
setverdict(pass);
} else {
setverdict(fail);
}
}
case (1) {
setverdict(fail, "Decoding failed.");
}
case (2) {
setverdict(fail, "Not enough bits.");
}
}
}
} // End of function test_PDU<PDUType>
function test_PDU<PDUType>(in PDUType p_pdu, in boolean p_decode:=true, in template (omit) bitstring p_expEncMsg:=omit) runs on TCType {
var PDUType v_decMsg;
var bitstring v_encMsg;
var integer v_res := 0;
var TestRecord v_tr := { bs := p_expEncMsg }
v_encMsg := encvalue(p_pdu);
log("Encoded message: ", bit2oct(v_encMsg));
if (not isbound(v_encMsg)) {
setverdict(fail, "Encoding failed!");
stop;
}
if (ispresent(v_tr.bs)) {
if (not match(v_encMsg, p_expEncMsg)) {
setverdict(fail, "Encoding failed, not the expected result!");
stop;
}
}
setverdict(pass, "Encoding passed.");
if (p_decode == true) {
v_res := decvalue(v_encMsg, v_decMsg);
select (v_res) {
case (0) {
if(match(v_decMsg, p_pdu)) {
setverdict(pass);
} else {
setverdict(fail);
}
}
case (1) {
setverdict(fail, "Decoding failed.");
}
case (2) {
setverdict(fail, "Not enough bits.");
}
}
}
} // End of function test_PDU<PDUType>
}
\ No newline at end of file
......@@ -5,535 +5,341 @@ module test_LibItsBtp_TypesAndValues /*language "TTCN-3:2009 Advanced Parameteri
import from LibItsBtp_Templates all;
import from LibItsBtp_TypesAndValues all;
group LibItsBtp_DummyTemplates {
template (value) UtEvent m_utEventBtpA := {
utBtpEvent := {
btpA := {
destinationPort := 1234,
sourcePort := 5678
group LibItsBtp_testCases {
group LibItsBtp_DummyTemplates {
template (value) UtEvent m_utEventBtpA := {
utBtpEvent := {
btpA := {
destinationPort := 1234,
sourcePort := 5678
}
}
}
}
template (value) UtEvent m_utEventBtpB := {
utBtpEvent := {
btpB := {
destinationPort := 123,
destinationPortInfo := 432
template (value) UtEvent m_utEventBtpB := {
utBtpEvent := {
btpB := {
destinationPort := 123,
destinationPortInfo := 432
}
}
}
}
template (value) UtEvent m_utEventBtpPayload := {
utBtpEvent := {
template (value) UtEvent m_utEventBtpPayload := {
utBtpEvent := {
payload := {
decodedPayload := omit,
rawPayload := 'f005ba11'O
} // End of 'payload' field
}
}
template BtpInd m_btpInd(template (present) BtpPacket p_btpPkt) := {
msgIn := p_btpPkt
}
template (value) BtpPacket m_btpA_Without_Payload (
template (value) BtpPortId p_destPort,
template (value) BtpPortId p_sourcePort
):= {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := omit
}
template BtpPacket m_btpA_With_Payload (
in template (value) BtpPortId p_destPort,
in template (value) BtpPortId p_sourcePort,
in template DecodedBtpPayload p_decodedPayload,
in template (value) octetstring p_rawPayload
) := {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := omit,
rawPayload := 'f005ba11'O
} // End of 'payload' field
decodedPayload := p_decodedPayload,
rawPayload := p_rawPayload
}
}
}
template BtpInd m_btpInd(template (present) BtpPacket p_btpPkt) := {
msgIn := p_btpPkt
}
template (value) BtpPacket m_btpA_Without_Payload (
template (value) BtpPortId p_destPort,
template (value) BtpPortId p_sourcePort
):= {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := omit
}
template BtpPacket m_btpA_With_Payload (
in template (value) BtpPortId p_destPort,
in template (value) BtpPortId p_sourcePort,
in template DecodedBtpPayload p_decodedPayload,
in template (value) octetstring p_rawPayload
) := {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := p_decodedPayload,
rawPayload := p_rawPayload
}
}
template (value) BtpPacket m_btpB_Without_Payload (
template (value) BtpPortId p_destPort,
template (value) BtpPortId p_destinationPortInfo
):= {
header := {
btpBHeader := {
destinationPort := p_destPort,
destinationPortInfo := p_destinationPortInfo
}
},
payload := omit
}
template BtpPacket mw_btpA_With_Payload (
in template (present) BtpPortId p_destPort,
in template (present) BtpPortId p_sourcePort,
in template DecodedBtpPayload p_decodedPayload,
in template (present) octetstring p_rawPayload
) := {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := p_decodedPayload,
rawPayload := p_rawPayload
}
}
template BtpPacket mw_btpA_With_CamPayload (
template (present) BtpPortId p_destPort,
template (present) BtpPortId p_sourcePort
):= {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := {
camPacket := {
header := {
protocolVersion := 0,
messageID := 0,
generationTime := 1319182818078
},
cam := {
stationID := 2339,
stationCharacteristics := {
mobileItsStation := true,
privateItsStation := false,
physicalRelevantItsStation := true
},
referencePosition := {
longitude := { hemisphere := east, degree := 0 },
latitude := { hemisphere := north, degree := 0 },
elevation := 0,
heading := 0,
streetName := omit,
positionConfidence := 0,
elevationConfidence := 0,
roadSegmentID := omit
},
camParameters := {
vehicleCommonParameters := {
vehicleType := 1,
stationLength := 0,
stationLengthConfidence := omit,
stationWidth := 0,
stationWidthConfidence := omit,
vehicleSpeed := 0,
vehicleSpeedConfidence := 0,
longAcceleration := 0,
longAccelerationConfidence := 0,
accelerationControl := ''B,
yawRate := { yawDirection := right, yawRateValue := 0 },
yawRateConfidence := 0,
exteriorLights := ''B,
turnAdvice := omit,
distanceToStopLine := omit,
occupancy := omit,
doorOpen := ''B,
posConfidenceEllipse := { semiMajorConfidence := 0, semiMinorConfidence := 0, semiMajorOrientation := 0 },
curvature := 0,
curvatureChange := 0,
curvatureConfidence := 15,
crashStatus := omit,
headingConfidence := 0,
dangerousGoods := omit
},
profileDependent := {
basicVehicle := { }
}
}
} // End of 'cam' field
} // End of 'camPacket' field
}, // End of 'decodedPayload' field
rawPayload := ?
} // End of 'payload' field
} // End of template mw_btpA_With_CamPayload
template BtpPacket mw_btpA_With_DenmPayload (
template (present) BtpPortId p_destPort,
template (present) BtpPortId p_sourcePort
):= {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := {
denmPacket := {
header := {
protocolVersion := 0,
messageID := 1,
generationTime := 1319187879132
},
denm := {
management := {
actionID := {
stationID := 2339,
sequenceNo := 29
},
dataVersion := 0,
expiryTime := 1319187938835,
frequency := omit,
reliability := 0,
isNegation := false
},
situation := {
trafficFlowEffect := omit,
situation := { cause := 103, subCause := 0 },
linkedCause := omit,
severity := informative,
eventCharact := omit,
vehicleCommonParameters := omit,
profile := omit
},
location := {
eventPosition := {
eventPositionCurrentDefinition := {
refPosition := {
longitude := { hemisphere := east, degree := 0 },
latitude := { hemisphere := north, degree := 0 },
elevation := 0,
heading := 0,
streetName := omit,
positionConfidence := 0,
elevationConfidence := 0,
roadSegmentID := omit
},
eventSpeed := 0
}
},
locationRef := {
trace := {
traceID := 0,
waypoints := {
{ ptLat := { hemisphere := south, degree := 0 },
ptLong := { hemisphere := west, degree := 0 },
ptAlt := 0
}
}
}
},
relevanceArea := {
geoAreaCenterLatitude := { hemisphere := south, degree := 0 },
geoAreaCenterLongitude := { hemisphere := west, degree := 0 },
shape := {circle := { radius := 0 } },
directionalityFilter := noFilter,
disseminationAreaSize := omit
}
}
} // End of 'denm' field
} // End of 'denmPacket' field
}, // End of 'decodedPayload' field
rawPayload := ?
} // End of 'payload' field
} // End of template mw_btpA_With_DenmPayload
template BtpPacket mw_btpA_Without_Payload (
template (present) BtpPortId p_destPort,
template (present) BtpPortId p_sourcePort
):= {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
template BtpPacket mw_btpA_With_Payload (
in template (present) BtpPortId p_destPort,
in template (present) BtpPortId p_sourcePort,
in template DecodedBtpPayload p_decodedPayload,
in template (present) octetstring p_rawPayload
) := {
header := {
btpAHeader := {
destinationPort := p_destPort,
sourcePort := p_sourcePort
}
},
payload := {
decodedPayload := p_decodedPayload,
rawPayload := p_rawPayload
}
}
template (value) BtpPacket m_btpB_Without_Payload (
template (value) BtpPortId p_destPort,
template (value) BtpPortId p_destinationPortInfo
):= {
header := {
btpBHeader := {
destinationPort := p_destPort,
destinationPortInfo := p_destinationPortInfo
}
},
payload := omit
}
} // End of group LibItsBtp_DummyTemplates
group testAcPrimitives {
} // End of group testAcPrimitives
group testBtpPrimitiveMessages {
// /**
// * @desc validate BtpReq/BTP type A
// * @verdict Pass on success, Fail otherwise
// */
// testcase tc_BtpReq_A() runs on TCType system TCType {
// test_PDU<BtpReq>(
// m_btpReq( m_btpA_Without_Payload (1234, 5678)),
// true,
// oct2bit('4b000a34000732000404d2162e'O));
// }
//
// /**
// * @desc validate BtpReq/BTP type A with payload
// * @verdict Pass on success, Fail otherwise
// */
// testcase tc_BtpReq_A_With_Payload() runs on TCType system TCType {
// test_PDU<BtpReq>(
// m_btpReq(
// m_btpAWithPorts (
// 1234,
// 5678,
// {
// decodedPayload := omit,
// rawPayload := 'ca5caded'O
// } // End of 'payload' field
// )),
// true,
// oct2bit('4b000e34000b32000404d2162eca5caded'O));
// }
//
// /**
// * @desc validate BtpReq/BTP type A with payload
// * @verdict Pass on success, Fail otherwise
// */
// testcase tc_BtpReq_A_With_DenmPayload() runs on TCType system TCType {
// test_PDU<BtpReq>(
// m_btpReq(
// m_btpAWithPorts (
// 1234,
// 5678,
// {
// decodedPayload := {
// denmPacket := {
// header := {
// protocolVersion := 0,
// messageID := 1,
// generationTime := 1319187879132
// },
// denm := {
// management := {
// actionID := {
// stationID := 2339,
// sequenceNo := 29
// },
// dataVersion := 0,
// expiryTime := 1319187938835,
// frequency := omit,
// reliability := 0,
// isNegation := false
// },
// situation := {
// trafficFlowEffect := omit,
// situation := { cause := 103, subCause := 0 },
// linkedCause := omit,
// severity := informative,
// eventCharact := omit,
// vehicleCommonParameters := omit,
// profile := omit
// },
// location := {
// eventPosition := {
// eventPositionCurrentDefinition := {
// refPosition := {
// longitude := { hemisphere := east, degree := 0 },
// latitude := { hemisphere := north, degree := 0 },
// elevation := 0,
// heading := 0,
// streetName := omit,
// positionConfidence := 0,
// elevationConfidence := 0,
// roadSegmentID := omit
// },
// eventSpeed := 0
// }
// },
// locationRef := {
// trace := {
// traceID := 0,
// waypoints := {
// { ptLat := { hemisphere := south, degree := 0 },
// ptLong := { hemisphere := west, degree := 0 },
// ptAlt := 0
// }
// }
// }
// },
// relevanceArea := {
// geoAreaCenterLatitude := { hemisphere := south, degree := 0 },
// geoAreaCenterLongitude := { hemisphere := west, degree := 0 },
// shape := {circle := { radius := 0 } },
// directionalityFilter := noFilter,
// disseminationAreaSize := omit
// }
// }
// } // End of 'denm' field
// } // End of 'denmPacket' field
// }, // End of 'decodedPayload' field
// rawPayload := '0001013325b994dc400001246003a0002664b74fc2600067002d80000000000000000013880000007ffd00a0000000400000000013880085a80000001000000000000000'O
// } // End of 'payload' field
// )),
// true,
// oct2bit('4b004e34004b32000404d2162e0001013325b994dc400001246003a0002664b74fc2600067002d80000000000000000013880000007ffd00a0000000400000000013880085a80000001000000000000000'O));
// }
//
/**
* @desc validate BtpReq/BTP type B
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpReq_B() runs on TCType system TCType {
test_PDU<BtpReq>(
m_btpReq( m_btpB_Without_Payload (4321, 8765)),
true,
oct2bit('10E1223D'O));
}
/**
* @desc validate BtpReq/BTP type B with payload
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpReq_B_With_Payload() runs on TCType system TCType {
test_PDU<BtpReq>(
m_btpReq(
m_btpBWithPorts (
4321,
8765,
{
decodedPayload := omit,
rawPayload := 'F1A7F007ED'O
} // End of 'payload' field
)),
true,
oct2bit('10E1223DF1A7F007ED'O));
}
/**
* @desc validate BtpInd/BTP type A
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpInd_A() runs on TCType system TCType {
test_PDU<BtpInd>(
m_btpInd( m_btpA_Without_Payload (4321, 8765)),
true,
oct2bit('10E1223D'O));
}
/**
* @desc validate BtpInd/BTP type A with payload
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpInd_A_With_Payload() runs on TCType system TCType {
test_PDU<BtpInd>(
m_btpInd(
m_btpAWithPorts (
4321,
8765,
{
decodedPayload := omit,
rawPayload := 'F1A7F007ED'O
} // End of 'payload' field
)),
true,
oct2bit('10E1223DF1A7F007ED'O));
}
testcase tc_BtpInd_A_With_CamPayload() runs on TCType system TCType {
test_decodePDU<BtpInd>(
{ msgIn := mw_btpA_With_Payload(4321, 8765, ?, ?) },
'10E1223D01020001B20788B80059F48D95CDEFC8C5E0020020002461A83C000004805A100C4528399D4C387FFF80'O
);
}
testcase tc_BtpInd_A_With_TrunkatedCamPayload() runs on TCType system TCType {
test_decodePDU<BtpInd>(
{ msgIn := mw_btpA_With_Payload(4321, 8765, ?, ?) },
'10E1223D000c32000410e1223d00000133256c5b1e40000248d6c0000000000000000009c4080000003ffe83e80004000000000000007ffd7ffe00'O
);
if (getverdict() == fail) {
setverdict(pass);
} else {
setverdict(fail);
}
},
payload := omit
}
} // End of group LibItsBtp_DummyTemplates
group testAcPrimitives {
} // End of group testAcPrimitives
group testBtpPrimitiveMessages {
/**
* @desc validate BtpReq/BTP type A
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpReq_A() runs on TCType system TCType {
test_PDU<BtpReq>(
m_btpReq( m_btpA_Without_Payload (1234, 5678)),
true,
oct2bit('4b000a34000732000404d2162e'O));
}
/**
* @desc validate BtpReq/BTP type A with payload
* @verdict Pass on success, Fail otherwise
*/
testcase tc_BtpReq_A_With_Payload() runs on TCType system TCType {
test_PDU<BtpReq>(
m_btpReq(