test_CommonCodec.ttcn3 2.41 KB
Newer Older
1
module test_CommonCodec /*language "TTCN-3:2009 Advanced Parameterization"*/ {
2 3 4 5
    
    import from LibItsSecurity_TestSystem all;
    
    type component TCType extends ItsSecurityBaseComponent { }
6

7 8 9
    type record TestRecord {
        bitstring bs optional
    }
10

11 12 13 14
    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;
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
        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>
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    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>
76
}