/*****************************************************************
 ** @author   STF 487 (updated by STF 521)
 ** @version  0.0.2
 ** @purpose  1:6.2.10, Ensure that extending a component with several other component works properly
 ** @verdict  pass accept, ttcn3verdict:pass
 *****************************************************************/

/* The following requirements are tested:
 * When defining component types by extending more than one parent type,
 * there shall be no name clash between the definitions of the different parent types,
 * i.e. there shall not be a port, variable, constant or timer identifier that is declared
 * in any two of the parent types (directly or by means of extension).
 */

module Sem_060210_ReuseofComponentTypes_002 {

  //MyCompA has a port pt_myPortA
  type component MyCompA {
    port loopbackPort pt_myPortA;
  }

  //MyComp has a port pt_myPortB
  type component MyCompB {
    port loopbackPort pt_myPortB;
  }

//Component GeneralComp has a timer and inherit two ports from MyCompA and MyCompB
  type component GeneralComp extends MyCompA, MyCompB {
    timer t;
  }

  type port loopbackPort message {
    inout integer;
    inout float;
  }

  function loopback() runs on GeneralComp system GeneralComp {
    var integer v_i;
    var float v_f;
    while (true) {
      alt {
        [] pt_myPortA.receive(integer:?) -> value v_i { pt_myPortA.send(v_i); }
        [] pt_myPortA.receive(float:?) -> value v_f { pt_myPortA.send(v_f); }
        [] pt_myPortB.receive(integer:?) -> value v_i { pt_myPortB.send(v_i); }
        [] pt_myPortB.receive(float:?) -> value v_f { pt_myPortB.send(v_f); }
      }
    }
  }

  testcase TC_Sem_060210_ReuseofComponentTypes_002() runs on GeneralComp system GeneralComp {

    var GeneralComp v_server := GeneralComp.create;

    connect(mtc:pt_myPortA, v_server:pt_myPortA);
    connect(mtc:pt_myPortB, v_server:pt_myPortB);

    v_server.start(loopback());

    //Send an integer from pt_myPortA:
    pt_myPortA.send(2);
    alt {
      [] pt_myPortA.receive(2) {
        setverdict(pass,"Receive successful");
      }
      [] pt_myPortA.receive {
        setverdict(fail,"Unexpected result");
      }
    }

    //Send an integer from pt_myPortB:
    pt_myPortB.send(1.0);
    alt {
      [] pt_myPortB.receive(1.0) {
        setverdict(pass,"Receive successful");
      }
      [] pt_myPortB.receive {
        setverdict(fail,"Unexpected result");
      }
    }

  }

  control{
    execute(TC_Sem_060210_ReuseofComponentTypes_002());
  }
}