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
module test_LibItsDenm_TypesAndValues /*language "TTCN-3:2009 Advanced Parameterization"*/ {
import from test_CommonCodec all;
import from DENM_PDU_Descriptions language "ASN.1:1997" all
with {
encode "LibItsDenm_asn1"
}
// LibIts
import from CAM_PDU_Descriptions language "ASN.1:1997"all;
import from DENM_PDU_Descriptions language "ASN.1:1997" all;
// LibItsCommon
import from LibItsCommon_TypesAndValues all;
// AtsCam
import from LibItsDenm_TestSystem all;
import from LibItsDenm_Templates all;
import from LibItsDenm_TypesAndValues all;
import from LibItsCommon_TypesAndValues all;
import from LibItsDenm_Functions all;
import from LibItsCommon_Functions all;
group testUtEvent {
testcase tc_UtDenmInitialize() runs on TCType system TCType {
test_PDU<UtInitialize>(m_denmInitialize, false);
}
testcase tc_eventSituation() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEvent(m_situation(c_causeVehicleProblem, c_subCauseUnknown)), false);
}
testcase tc_eventCancellation() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventCancellation(m_situation(c_causeSlowVehicle, c_subCauseUnknown), { f_getTsStationId(), 170 }), false);
}
testcase tc_eventNegation() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventNegation(m_situation(c_causeWrongWayDriving, c_subCauseUnknown), { f_getTsStationId(), 170 }), false);
}
testcase tc_eventTrafficFlowEffect() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventTrafficFlowEffect(m_situation(c_causeExtremWeatherCondition, c_subCauseUnknown), c_tfeFreeTrafficFlow), false);
}
testcase tc_eventLinkedCause() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventLinkedCause(m_situation(c_causeAccident, c_subCauseUnknown), m_situation(c_causeExtremWeatherCondition, c_subCauseUnknown)), false);
}
testcase tc_eventExpirationTime() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventExpirationTime(m_situation(c_causeVehicleProblem, c_subCauseUnknown), 281474976710655), false);
}
testcase tc_eventExpirationTimeFrequency() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventExpirationTimeFrequency(m_situation(c_causeVehicleProblem, c_subCauseUnknown), 281474976710655, 255), false);
}
testcase tc_eventCharact() runs on TCType system TCType {
test_PDU<UtEvent>(m_utEventCharact(m_situation(c_causeVehicleProblem, c_subCauseUnknown), m_eventCharact), false);
}
testcase tc_checkDenmEvent() runs on TCType system TCType {
var template (value) UtCheck v_utMsg := { m_utEvent(m_situation(c_causeVehicleProblem, c_subCauseUnknown)) };
test_PDU<UtCheck>(v_utMsg, false);
}
testcase tc_checkDenmEventNegation() runs on TCType system TCType {
var template (value) UtCheck v_utMsg := { m_utEventNegation(m_situation(c_causeWrongWayDriving, c_subCauseUnknown), { f_getTsStationId(), 170 }) };
test_PDU<UtCheck>(v_utMsg, false);
}
testcase tc_checkDenmEventCancellation() runs on TCType system TCType {
var template (value) UtCheck v_utMsg := { m_utEventCancellation(m_situation(c_causeVehicleProblem, c_subCauseBrakeDownVehicle), { f_getTsStationId(), 170 }) };
test_PDU<UtCheck>(v_utMsg, false);
}
} // End of group testUtEvent
group testDenmPrimitiveMessages {
template (value) DenmInd m_denmInd(template (value) DenmPdu p_denMsg) := {
msgIn := p_denMsg,
receptionTime := 1234587
}
testcase tc_DenmReq() runs on TCType system TCType {
test_PDU<DenmReq>(
m_denmReq(
m_denmPdu(
f_getCurrentTime(),
m_denmWithCause(
0,
m_situation(c_causeVehicleProblem, c_subCauseUnknown),
m_eventPosition(m_tsPosition),
f_getTsStationId()))),
false);
}
testcase tc_DenmReqOutdated() runs on TCType system TCType {
test_PDU<DenmReq>(
m_denmReq(
m_denmPdu(
f_getCurrentTime(),
m_denmWithCause(
0,
m_situation(c_causeSlowVehicle, c_subCauseUnknown),
m_eventPosition(m_tsPosition),
f_getTsStationId()))),
false);
}
testcase tc_DenmInd() runs on TCType system TCType {
test_PDU<DenmInd>(
m_denmInd(
m_denmPdu(
f_getCurrentTime(),
m_denmWithCause(
0,
m_situation(c_causeSlowVehicle, c_subCauseUnknown),
m_eventPosition(m_tsPosition),
f_getTsStationId()))),
false);
}
import from test_CommonCodec all;
group LibItsDenm_testCases {
testcase tc_test() runs on TCType system TCType {
var DenmPdu v_decMsg;
var integer v_res := 0;
v_res := decvalue(oct2bit('00010133a6bf49d07302172f800000002674d823d200391f20000000001ff01000400010802317d1109404000884400400000000000004000000007ffd7fe0000001f81abe34a1eade9e30026e100008ebbb265cda7765c8000000002008c00046bc387a'O), v_decMsg);
select (v_res) {
case (0) {
log(v_decMsg);
setverdict(pass);
group testUtEvent {
testcase tc_UtDenmInitialize() runs on TCType system TCType {
test_PDU<UtInitialize>(m_denmInitialize, false);
}
case (1) {
setverdict(fail, "Decoding failed.");
testcase tc_eventSituation() runs on TCType system TCType {
var template (value) SituationContainer v_situation := m_situation(c_causeVehicleBreakdown, c_subCauseCode_Unavailable);
test_PDU<UtDenmTrigger>(
m_utTriggerEvent(
v_situation,
m_denmLocation_zeroDelta
),
false
);
}
case (2) {
setverdict(fail, "Not enough bits.");
} // End of group testUtEvent
group testDenmPrimitiveMessages {
testcase tc_DenmReq() runs on TCType system TCType {
var template (value) SituationContainer v_situation := m_situation(c_causeVehicleBreakdown, c_subCauseCode_Unavailable);
test_PDU<DenmReq>(
m_denmReq(
m_denmPdu(
m_denm(
m_denmMgmtCon(
m_tsActionId
),
v_situation,
m_denmLocation_zeroDelta
)
)
),
true,
oct2bit('01010001B207C0000D903800000000006072000000188593E91B2B9BDF918C000400400061A80000B6000037FFFDFFFF63390100'O)
);
}
}
// var DenmPdu bla := { header := { protocolVersion := 0, messageID := 1, generationTime := 1321352514000 }, denm := { management := { actionID := { stationID := 2551232892, sequenceNo := 0 }, dataVersion := 0, expiryTime := 1321352634000, frequency := 1, reliability := 100, isNegation := false }, situation := { trafficFlowEffect := 1, situation := { cause := 0, subCause := 0 }, linkedCause := { cause := 0, subCause := 0 }, severity := informative, eventCharact := { eventmobility := false, causeType := itsStation, relevance := physicallyRelevant, timeCriticality := false }, vehicleCommonParameters := { vehicleType := 1, stationLength := 1, stationLengthConfidence := 0, stationWidth := 1, stationWidthConfidence := 0, vehicleSpeed := 38, vehicleSpeedConfidence := 1, longAcceleration := 1, longAccelerationConfidence := 1, accelerationControl := '010000000'B, yawRate := { yawDirection := right, yawRateValue := 1 }, yawRateConfidence := 1, exteriorLights := '10000000'B, turnAdvice := { direction := '00000000'B, distance := 0 }, distanceToStopLine := 0, occupancy := 0, doorOpen := '00000000'B, posConfidenceEllipse := { semiMajorConfidence := 0, semiMinorConfidence := 0, semiMajorOrientation := 0 }, curvature := 0, curvatureChange := 0, curvatureConfidence := 0, crashStatus := false, headingConfidence := 0, dangerousGoods := 0 }, profile := {basicVehicle := { }} }, location := { eventPosition := {eventPositionCurrentDefinition := { refPosition := { longitude := { hemisphere := east, degree := 56084116 }, latitude := { hemisphere := north, degree := 514714083 }, elevation := -47, heading := 0, streetName := "undefined", positionConfidence := 0, elevationConfidence := 0, roadSegmentID := 0 }, eventSpeed := 38 }}, locationRef := {trace := { traceID := 0, waypoints := {} }}, relevanceArea := omit } } };
}
} // End of group testDenmPrimitiveMessages
} // End of group testDenmPrimitiveMessages
} // End of group LibItsDenm_testCases
}
\ No newline at end of file
This diff is collapsed.
......@@ -16,4 +16,6 @@ module test_all /*language "TTCN-3:2009 Advanced Parameterization"*/ {
import from test_LibItsExternalFunctions all;
import from test_LibItsSecurity_TypesAndValues all;
} // End of module test_all
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment