Commit c86e2332 authored by garciay's avatar garciay
Browse files

Layers ongoing

parent 40f36735
Loading
Loading
Loading
Loading
+197 −0
Original line number Original line Diff line number Diff line
module TestCodec_Btp {

  // LibCommon
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_DataStrings all;

  // LibItsBtp
  import from LibItsBtp_TypesAndValues all;
  import from LibItsBtp_Templates all;
  import from LibItsBtp_TestSystem all;
  import from LibItsBtp_EncdecDeclarations all;

  // TestCodec
  import from TestCodec_TestAndSystem all;

  group LibItsBtp_testCases {

    group LibItsBtp_DummyTemplates {

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

      template BtpPacket m_btpB_With_Payload ( 
					       in template (value) BtpPortId  p_destPort, 
					       in template (value) BtpPortId  p_destinationPortInfo, 
					       in template DecodedBtpPayload p_decodedPayload, 
					       in template (value) octetstring p_rawPayload 
						) := { 
      header := { 
	btpBHeader := {
	  destinationPort := p_destPort, 
	  destinationPortInfo := p_destinationPortInfo
	}
      }, 
      payload := { 
	decodedPayload := p_decodedPayload,
	rawPayload := p_rawPayload
      } 
      }

    } // End of group LibItsBtp_DummyTemplates

    group LibItsBtp_testCases {

      testcase tc_Btp_A() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpA_With_Payload ( 
					   1234,
					   0,
					   omit, 
					   'CAFEDECA'O 
					    ),
		      true,
		      oct2bit('04D20000CAFEDECA'O)
		      );
      }
	
      testcase tc_Btp_B() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpB_With_Payload ( 
					   1234,
					   4567,
					   omit, 
					   'CAFEDECA'O 
					    ),
		      true,
		      oct2bit('04D211D7CAFEDECA'O)
		      );
      }
	
	/*testcase tc_Btp_A() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpA (
			      BtpPayload:{decodedPayload := omit, rawPayload := '0102030405'O } ), 
		      true, 
		      oct2bit('000000000102030405'O));
		      }}*/

    } // End of group LibItsBtp_testCases

  } // End of group LibItsBtp_testCases

  group encdec_functions {

    function TestBtpPacket(
			   in template (value) BtpPacket p_btpPacket,
			   in boolean p_decode := true, 
			   in template (omit) bitstring p_expEncMsg := omit 
			   ) runs on TCType {
      var bitstring v_encMsg;
      var template (omit) TestRecord v_tr := { bs := p_expEncMsg };
      var BtpPacket v_decMsg;
      var integer v_res := 0;

      // Encode template
      log("Encode template ", valueof(p_btpPacket));
    v_encMsg := encvalue(p_btpPacket);
      log("Encoded message:  ", bit2oct(v_encMsg));
      // Check result
      if (not isbound(v_encMsg)) {
	setverdict(fail, "Encoding failed!");
	stop;
      }
      if (ispresent(v_tr.bs)) {
	if (not match(v_encMsg, p_expEncMsg)) {
	  log("Expected message: ", bit2oct(valueof(p_expEncMsg)));
	  setverdict(fail, "Encoding failed, not the expected result!");
	  stop;
	}
      }
      setverdict(pass, "Encoding passed.");

      // Check decoding
      if (p_decode == true) {
      v_res := decvalue(v_encMsg, v_decMsg);
	log("Decoded message: ", v_decMsg);
	select (v_res) {
	case (0) {
	  if(match(v_decMsg, p_btpPacket)) {
	    setverdict(pass);
	  } else {
	    setverdict(fail);
	  }
	}
	case (1) {
	  setverdict(fail, "Decoding failed.");
	}
	case (2) {
	  setverdict(fail, "Not enough bits.");
	}
	}
      }

    } // End of function TestBtpBtpPacket

  } // End of group encdec_functions 

} // End of module TestCodec_Btp
+17 −17

File changed.

Contains only whitespace changes.