blob: 4c6aa6329f9340f03501c6e2bc43d83aacd3aef4 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_CLI_Test
//
// Purpose:
// This module contains the implementation of generic EPTF_CLL_CLI tests.
//
// Module depends on:
// -
//
// Current Owner:
// ethbaat
//
// Last Review Date:
// -
//
// Detailed Comments:
// This module contains the tests for testing EPTF_CLL_CLI
// It can be useful for testing components extension of EPTF_CLL_CLI_CT and/or EPTF_CLL_CLI_client_CT
//
///////////////////////////////////////////////////////////////
module EPTF_CLI_Test {
import from EPTF_CLL_CLI_Definitions all;
import from EPTF_CLL_CLI_Functions all;
import from EPTF_CLL_Base_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Common_Definitions all;
//import from TELNETasp_PortType all;
import from EPTF_CLL_Semaphore_Functions all;
import from EPTF_CLI_Test_Definitions all;
import from EPTF_CLI_Test_Functions all;
modulepar charstring tsp_EPTF_CLI_Test_prompt :="TTCN> "
type component EPTF_CLI_Test_CT extends EPTF_CLI_CT, EPTF_CLI_Client_CT {
}
group HelpTextManual {
// this is manual test!
testcase tc_EPTF_CLI_Test_helpText() runs on EPTF_CLI_Test_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
log("Help: ", f_EPTF_CLI_getHelpTxt());
log("Help help: ", f_EPTF_CLI_getHelpTxt("help"));
log("Help stop: ", f_EPTF_CLI_getHelpTxt("stop"));
log("Help xxx: ", f_EPTF_CLI_getHelpTxt("xxx"));
f_EPTF_Base_stop(pass);
}
// this is manual test!
testcase tc_EPTF_CLI_Test_executeHelpCommand() runs on EPTF_CLI_Test_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
log(">help: ", f_EPTF_CLI_executeCommand("help"));
log("> help help: ", f_EPTF_CLI_executeCommand("help help"));
log("> help xxx: ", f_EPTF_CLI_executeCommand("help xxx"));
f_EPTF_Base_stop(pass);
}
} //~group HelpTextManual
group RegisterAndExecuteCommand {
testcase tc_EPTF_CLI_Test_registerCommand() runs on EPTF_CLI_Test_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
// this should be successful
if(not registerOK==f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: Command echo cannot be registered!");
}
// this should fail because help is a CLI built in command
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"help",
"help description",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: Reserved Command help cann be registered!");
}
// this should fail because echo is already registered
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"echo",
"echo description",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with same name cannot be registered!");
}
// this should fail because command name is missing
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"",
"echo desctription",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with empty name cannot be registered!");
}
// this should fail because help is missing
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"xxx",
"",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with empty help cannot be registered!");
}
// this should fail because handler is missing
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"yyy",
"yyy help",
null
)) {
setverdict(fail,"Test FAILED: command with null handler cannot be registered!");
}
// this should fail because echo is already registered as case insensitive command
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"ECHO",
"ECHO help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with case insensitive - case insensitive collision can be registered!");
}
// this should fail because echo is already registered as case insensitive command
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"ECHO",
"ECHO help",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
)) {
setverdict(fail,"Test FAILED: command with case sensitive - case insensitive collision can be registered!");
}
// this should be OK because ECHO2 is a new command
if(registerOK!=f_EPTF_CLI_Client_registerCommand(
"ECHO2",
"ECHO2 help",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
)) {
setverdict(fail,"Test FAILED: command with case sensitive name cannot be registered!");
}
// this should fail because ECHO2 is already registered and the new command case insensitively matches with it
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"echo2",
"echo2 help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with case insensitive - case sensitive collision can be registered!");
}
// this should fail because ECHO2 is already registered as a case sensitive command
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"ECHO2",
"ECHO2 help",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
)) {
setverdict(fail,"Test FAILED: command with case sensitive - case sensitive collision can be registered!");
}
// this should be OK because echo2 is a new command
if(registerOK!=f_EPTF_CLI_Client_registerCommand(
"echo2",
"echo2 help",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
)) {
setverdict(fail,"Test FAILED: command with different case sensitive name cannot be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
" echoXX1",
"echo XXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with space in front can be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"echoXX2 ",
"echoXXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with trailing space can be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
" echoXX3 ",
"echoXXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with front/trailing spaces can be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"echo XX4",
"echo XXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with space in the middle can be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
"echo XX5",
"echo XXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with spaces in the middle can be registered!");
}
// this should fail because command name contains space
if(registerOK==f_EPTF_CLI_Client_registerCommand(
" echo XX6 ",
"echo XXX help",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: command with front/trailing/middle spaces can be registered!");
}
f_EPTF_Base_stop(pass);
}
//============================================
// f_EPTF_CLI_Client_doNothingHandler
//============================================
function f_EPTF_CLI_Client_doNothingHandler(in charstring pl_commandArgs, inout charstring pl_result) runs on EPTF_CLI_Client_CT return integer {
if (pl_commandArgs=="help") {
pl_result := pl_result&" - does nothing\n"&
" If called with ""ERROR!"" argument it exits with code 1\n"&
" If called with -t <duration> as the first argument\n"&
" it exits after that time has passed (in seconds).";
return 0; // OK
}
if (pl_commandArgs=="ERROR!") {
return 1; // set nonzero exit code
}
if (regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,0)=="-t") {
// -t option is given as the first argument
// extract the duration value:
var float vl_duration:=str2float(regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,1));
// delay response:
timer t_wait := vl_duration;
t_wait.start; t_wait.timeout;
return 0; //OK
}
return 0; // OK
}
testcase tc_EPTF_CLI_Test_executeCustomCommand() runs on EPTF_CLI_Test_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
f_EPTF_CLI_Client_registerCommand(
"EcHo2",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
);
f_EPTF_CLI_Client_registerCommand(
"doNothing",
"does nothing",
refers(f_EPTF_CLI_Client_doNothingHandler)
);
log(">help: ", f_EPTF_CLI_executeCommand("help"));
log("> help help: ", f_EPTF_CLI_executeCommand("help help"));
log("> help stop: ", f_EPTF_CLI_executeCommand("help stop"));
log("> help echo: ", f_EPTF_CLI_executeCommand("help echo"));
log("> help EcHo2: ", f_EPTF_CLI_executeCommand("help EcHo2"));
log("> help ECHO2: ", f_EPTF_CLI_executeCommand("help ECHO2"));
log("> help xxx: ", f_EPTF_CLI_executeCommand("help xxx"));
log(">echo AAA: ", f_EPTF_CLI_executeCommand("echo AAA"));
log(">xxx BBB: ", f_EPTF_CLI_executeCommand("xxx BBB"));
log(">echo help: ", f_EPTF_CLI_executeCommand("echo help"));
log(">echo ERROR!: ", f_EPTF_CLI_executeCommand("echo ERROR!"));
log(">echo: ", f_EPTF_CLI_executeCommand("echo"));
log(">doNothing help: ", f_EPTF_CLI_executeCommand("doNothing help"));
log(">doNothing ERROR!: ", f_EPTF_CLI_executeCommand("doNothing ERROR!"));
log(">doNothing: ", f_EPTF_CLI_executeCommand("doNothing"));
if (f_EPTF_CLI_executeCommand("echo BBB") != "BBB") {
setverdict(fail,"Test FAILED: echo returned unexpected message");
}
if (f_EPTF_CLI_executeCommand("EcHo CCC") != "CCC") {
setverdict(fail,"Test FAILED: EcHo returned unexpected message");
}
if (f_EPTF_CLI_executeCommand("EcHo2 DDD") != "DDD") {
setverdict(fail,"Test FAILED: EcHo2 returned unexpected message");
}
if (f_EPTF_CLI_executeCommand("eCHo2 EEE") != "eCHo2: Command not found.") {
setverdict(fail,"Test FAILED: echo2 is not defined!");
}
f_EPTF_Base_stop(pass);
}
} //~group RegisterAndExecuteCommand
group ExecuteCommandSet {
function f_EPTF_CLI_Client_echoHandler_CommandSet(in charstring pl_commandArgs, inout charstring pl_result) runs on EPTF_CLI_Client_CT return integer {
var charstring vl_commandSetName := pl_result;
if (pl_commandArgs=="help") {
pl_result := vl_commandSetName&" echo - prints out its parameters\n"&
"This is the detailed help message of the echo command\n"&
"If called with ""ERROR!"" argument it exits with code 1\n"&
"Belongs to a command set: "&vl_commandSetName;
return 0; // OK
}
if (pl_commandArgs=="ERROR!") {
pl_result := "Syntax error!"
return 1; // set nonzero exit code
}
pl_result := pl_commandArgs;
return 0; // OK
}
function f_EPTF_CLI_Client_aboutHandler_CommandSet(in charstring pl_commandArgs, inout charstring pl_result) runs on EPTF_CLI_Client_CT return integer {
var charstring vl_commandSetName := pl_result;
if (pl_commandArgs=="help") {
pl_result := vl_commandSetName&" about - prints out version information\n"&
"Belongs to a command set: "&vl_commandSetName;
return 0; // OK
}
if (pl_commandArgs!="") {
pl_result := "about: Invalid arguments"
return 1; // error
}
pl_result := "This is the 1.0 version of the command set"
return 0; // OK
}
function f_EPTF_CLI_Client_commandHandler_CommandSet(in charstring pl_commandArgs, inout charstring pl_result) runs on EPTF_CLI_Client_CT return integer {
var charstring vl_commandName := regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,0); // trim down the command name from pl_commandArgs
var charstring vl_commandArgs := regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,1); // trim down the command name from pl_commandArgs
var charstring vl_commandSetName := pl_result;
if (pl_commandArgs=="help") {
pl_result := "list of basic commands:\n"&
"echo, about\n"&
"For more help try: "&vl_commandSetName& " <command> help";
return 0; // OK
}
if (vl_commandName=="echo") {
return f_EPTF_CLI_Client_echoHandler_CommandSet(vl_commandArgs,pl_result);
}
if (vl_commandName=="about") {
return f_EPTF_CLI_Client_aboutHandler_CommandSet(vl_commandArgs,pl_result);
}
pl_result := pl_commandArgs&": Unsupported command."
return 1; // error
}
testcase tc_EPTF_CLI_Test_executeCommandSetCommands() runs on EPTF_CLI_Test_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_CLI_Client_registerCommand(
"basicCommandSet",
"list of basic commands",
refers(f_EPTF_CLI_Client_commandHandler_CommandSet)
);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
f_EPTF_CLI_Client_registerCommand(
"about",
"prints version information",
refers(f_EPTF_CLI_Client_aboutHandler_CommandSet)
);
if (registerOK==f_EPTF_CLI_Client_registerCommand(
"basicCommandSet",
"prints version information",
refers(f_EPTF_CLI_Client_aboutHandler_CommandSet)
)) {
setverdict(fail,"Test FAILED: same command accepted");
}
if (registerOK==f_EPTF_CLI_Client_registerCommand(
"about",
"prints version information",
refers(f_EPTF_CLI_Client_aboutHandler_CommandSet)
)) {
setverdict(fail,"Test FAILED: same command accepted for no command set");
}
log(">help: ", f_EPTF_CLI_executeCommand("help"));
log("> help help: ", f_EPTF_CLI_executeCommand("help help"));
log("> help stop: ", f_EPTF_CLI_executeCommand("help stop"));
log("> help echo: ", f_EPTF_CLI_executeCommand("help echo"));
log("> help about: ", f_EPTF_CLI_executeCommand("help about"));
log("> help xxx: ", f_EPTF_CLI_executeCommand("help xxx"));
log(">xxx BBB: ", f_EPTF_CLI_executeCommand("xxx BBB"));
log(">echo AAA: ", f_EPTF_CLI_executeCommand("echo AAA"));
log(">echo help: ", f_EPTF_CLI_executeCommand("echo help"));
log(">echo ERROR!: ", f_EPTF_CLI_executeCommand("echo ERROR!"));
log(">echo: ", f_EPTF_CLI_executeCommand("echo"));
log(">about: ", f_EPTF_CLI_executeCommand("about"));
log(">about help: ", f_EPTF_CLI_executeCommand("about help"));
log(">about XXX: ", f_EPTF_CLI_executeCommand("about XXX"));
log(">basicCommandSet help: ", f_EPTF_CLI_executeCommand("basicCommandSet help"));
log(">basicCommandSet echo AAA BBB : ", f_EPTF_CLI_executeCommand("basicCommandSet echo AAA BBB "));
log(">basicCommandSet echo help: ", f_EPTF_CLI_executeCommand("basicCommandSet echo help"));
log(">basicCommandSet echo ERROR!: ", f_EPTF_CLI_executeCommand("basicCommandSet echo ERROR!"));
log(">basicCommandSet echo: ", f_EPTF_CLI_executeCommand("basicCommandSet echo "));
log(">basicCommandSet about: ", f_EPTF_CLI_executeCommand("basicCommandSet about"));
log(">basicCommandSet about help: ", f_EPTF_CLI_executeCommand("basicCommandSet about help"));
log(">basicCommandSet about XXX: ", f_EPTF_CLI_executeCommand("basicCommandSet about XXX"));
log(">basicCommandSet XXX: ", f_EPTF_CLI_executeCommand("basicCommandSet XXX"));
if (f_EPTF_CLI_executeCommand("basicCommandSet echo BBB ") != "BBB ") {
setverdict(fail,"Test FAILED: basicCommandSet echo returned unexpected message");
}
f_EPTF_Base_stop(pass);
}
} //~group ExecuteCommandSet
group ExecuteParallelCommands {
type component EPTF_CLI_Test_Parallel_CT extends EPTF_CLI_Test_CT {
timer t1 := 0.0;
timer t2 := 0.0;
timer t3 := 0.0;
}
altstep as_EPTF_CLI_Test_executeCommand(timer pl_t, in charstring pl_command) runs on EPTF_CLI_Test_Parallel_CT {
[] pl_t.timeout {
var charstring vl_result := f_EPTF_CLI_executeCommand(pl_command);
log(">",pl_command, ": ",vl_result);
var charstring vl_expectedResult := regexp(pl_command,c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,1);
if (vl_expectedResult!=vl_result) {
setverdict(fail, "The echo command returned unexpected result.");
}
repeat;
}
}
testcase tc_EPTF_CLI_Test_executeParallelCommands() runs on EPTF_CLI_Test_Parallel_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
activate(as_EPTF_CLI_Test_executeCommand(t1,"echo AAA"));
activate(as_EPTF_CLI_Test_executeCommand(t2,"echo BBB"));
activate(as_EPTF_CLI_Test_executeCommand(t3,"echo CCC"));
t1.start;
t2.start;
t3.start;
log(">echo DDD: ", f_EPTF_CLI_executeCommand("echo DDD"));
// safety timer (in case there is an error in the code)
// normally nothing should happen during the timeout:
timer t_wait := 1.0;
t_wait.start; t_wait.timeout;
f_EPTF_Base_stop(pass);
}
} //~group ExecuteParallelCommands
group ExecuteCommand_During_Semaphore_Timeout {
// Wait for a semaphore, but response does not unlock the semaphore in time => waitForUnlock returns with timeout
// After the semaphore timeouts, execute CLI command (with slow response).
// (In case of bug: it gets the same semaphore ID as timedOut.)
// Before the CLI command resonse arrives, the response for the original semaphore arrives which deletes the semaphore
// (In case of bug, this semaphore ID will be the same as for the CLI command)
// After that, the response of the CLI command arrives, but the semaphore it uses is deleted by the semaphore handler
// (In case of bug: DTE happens: "Dynamic test case error: Index overflow in a value of type @PreGenRecordOf.PREGEN_RECORD_OF_CHARSTRING: The index is 0, but the value has only 0 elements.")
type component EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT extends EPTF_CLI_Test_CT {
timer t_trigger_cli_command := 0.0;
timer t_trigger_semaphore_response := 0.5;
var integer v_semaphoreId := -1;
}
altstep as_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout() runs on EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT {
// triggers the CLI command execution
[] t_trigger_cli_command.timeout {
// start the echo command with 2 sec timeout
log(">echo -t 1 AAA: ", f_EPTF_CLI_executeCommand("echo -t 2 AAA"));
repeat;
}
[] t_trigger_semaphore_response.timeout {
// the response arrives:
f_EPTF_Semaphore_delete(v_semaphoreId);
log("Answer arrived late, semaphore deleted: ", v_semaphoreId);
repeat;
}
}
testcase tc_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout() runs on EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_Semaphore_init_CT("CLI_Test");
activate(as_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout());
// this should be successful
if(not registerOK==f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
)) {
setverdict(fail,"Test FAILED: Command echo cannot be registered!");
}
v_semaphoreId := f_EPTF_Semaphore_new();
// wait for the semaphore with timeout
if (f_EPTF_Semaphore_waitForUnlock(v_semaphoreId, 0.10)) {
// max wait time expired before response received:
log(log2str(%definitionId&": Semaphore timed out before answer received: ",v_semaphoreId));
}
// trigger the echo command instantly with 2 sec timeout
t_trigger_cli_command.start;
// trigger semaphore response after 0.5 sec:
t_trigger_semaphore_response.start(0.5);
timer t_wait_for_CLI := 2.5;
t_wait_for_CLI.start; t_wait_for_CLI.timeout;
// DTE should not happen, so this line should be reached:
f_EPTF_Base_stop(pass);
}
} //~group ExecuteCommand_During_Semaphore_Timeout
testcase tc_EPTF_CLI_Test_stopCommand() runs on EPTF_CLI_Test_Parallel_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
setverdict(pass);
log(">stop: ", f_EPTF_CLI_executeCommand("stop"));
timer t_wait := 1.0;
t_wait.stop;
alt {
[] t_wait.timeout {
log("Test FAILED: Stop command did not terminate the application in time!");
f_EPTF_Base_stop(fail);
}
}
f_EPTF_Base_stop(inconc);
}
group DisplayTest {
type component EPTF_CLI_Client_Test_Display_ShowTime_CT extends EPTF_CLI_Test_CT {
timer t1 := 1.0;
var float v_period := 1.0;
var boolean displayIsOn := false;
}
function f_EPTF_CLI_Client_Test_Display_ShowTime_init_CT() runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
f_EPTF_CLI_init_CT("ShowTime_Test");
f_EPTF_CLI_Client_init_CT("ShowTime_Test", self);
t1.start(1.0);
activate(as_EPTF_CLI_Client_Test_updateTime());
f_EPTF_CLI_Client_registerCommand(
"showTime",
"displays seconds elapsed",
refers(f_EPTF_CLI_Client_showTimeHandler)
);
}
function f_EPTF_CLI_Client_showTimeHandler(in charstring pl_commandArgs, inout charstring pl_result) runs on EPTF_CLI_Client_Test_Display_ShowTime_CT return integer {
if (pl_commandArgs=="help") {
pl_result := " showTime - displays time periodically\n"&
"Displays elapsed time periodically on the display terminal\n"&
"Usage: showTime [stop|period <lenght>]\n"&
" stop: stops time display\n"&
" period <lenght>: sets the period of the display, <lenght> is the period in seconds (float number)\n"&
"If called without arguments the time display is started";
return 0; // OK
}
if (pl_commandArgs=="stop") {
displayIsOn := false;
pl_result := "showTime: Displaying of time is stopped"
f_EPTF_CLI_Client_sendCommandDisplay("showTime","showTime stopped.");
return 0; // set nonzero exit code
}
var charstring vl_argument := regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_everything,0);
if (vl_argument=="period") {
var charstring periodString := regexp(pl_commandArgs,c_EPTF_CLI_anyWord&c_EPTF_CLI_anyWord,1);
if (periodString=="") {
pl_result := "showTime: syntax error\n"&
" period should have a float argument: showTime period 1.0\n"&
"For help try: showTime help";
return 2; // syntax error for setting period
}
v_period := str2float(periodString);
pl_result := "showTime: Display period is set to "&periodString&" seconds."
f_EPTF_CLI_Client_sendCommandDisplay("showTime","Period is changed to "&periodString&" seconds.");
// start the timer with the remaining seconds:
var float vl_remaining := v_period-t1.read;
if (vl_remaining<0.0) {
vl_remaining:=0.0;
}
t1.stop; t1.start(vl_remaining);
return 0; // set nonzero exit code
}
if (pl_commandArgs=="") {
pl_result := "Display of elapsed time is started on the Display terminal.\n"&
"Period of display: "&float2str(v_period);
f_EPTF_CLI_Client_sendCommandDisplay("showTime","showTime started with period "&float2str(v_period)&" seconds.");
displayIsOn := true;
return 0; // OK
} else {
pl_result := "showTime: syntax error: Unknown argument: "&vl_argument&"\n"&
"For help try: showTime help";
return 1; // syntax error
}
pl_result := "Display of elapsed time is started on the Display terminal.\n"&
"Period of display: "&float2str(v_period);
return 0; // OK
}
altstep as_EPTF_CLI_Client_Test_updateTime() runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
[displayIsOn] t1.timeout {
f_EPTF_CLI_Client_sendCommandDisplay("showTime","Elapsed time: "&float2str(f_EPTF_Base_getRelTimeInSecs()));
t1.start(v_period);
repeat;
}
}
// this is manual test!
testcase tc_EPTF_CLI_Test_displayManual() runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
f_EPTF_CLI_Client_Test_Display_ShowTime_init_CT();
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
// case sensitive:
f_EPTF_CLI_Client_registerCommand(
"EcHo2",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
);
f_EPTF_CLI_Client_registerCommand(
"doNothing",
"does nothing",
refers(f_EPTF_CLI_Client_doNothingHandler)
);
setverdict(pass);
f_EPTF_Base_wait4Shutdown();
f_EPTF_Base_stop(inconc);
}
} //~group DisplayTest
// this is manual test!
testcase tc_EPTF_CLI_Test_terminalManual() runs on EPTF_CLI_Test_Parallel_CT {
f_EPTF_CLI_init_CT("CLI_Test");
f_EPTF_CLI_Client_init_CT("CLI_Test", self);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
// case sensitive:
f_EPTF_CLI_Client_registerCommand(
"EcHo2",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler),
-,
false
);
f_EPTF_CLI_Client_registerCommand(
"doNothing",
"does nothing",
refers(f_EPTF_CLI_Client_doNothingHandler)
);
setverdict(pass);
f_EPTF_Base_wait4Shutdown();
f_EPTF_Base_stop(pass);
}
group TestPortParameters {
// this is manual test!
testcase tc_EPTF_CLI_Test_overrideTestPortParametersManual() runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
// modify the terminal port from code:
f_EPTF_CLI_init_CT("ShowTime_Test",
pl_telnetTestPortParameters := {
ctrl_hostname := omit,
ctrl_portnum := 18100,
ctrl_username := "ttcn",
ctrl_password := "ttcn",
ctrl_domain := omit,
ctrl_readmode := omit,
ctrl_login_skipped := true,
ctrl_detect_server_disconnected:= omit,
prompts := omit,
ctrl_terminal_type := omit,
ctrl_echo := omit,
ctrl_CRLF := omit,
ctrl_window_size := omit
}
);
f_EPTF_CLI_Client_Test_Display_ShowTime_init_CT();
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler)
);
setverdict(pass);
f_EPTF_Base_wait4Shutdown();
f_EPTF_Base_stop(inconc);
}
// unfortunately this does not work :(
// type component EPTF_CLI_Test_OverrideTestPortName_CT extends EPTF_CLI_Client_Test_Display_ShowTime_CT {
// private port TELNETasp_PT v_custom_CLI_TELNETaspIf;
// private port TELNETasp_PT v_custom_CLI_displayTELNETaspIf;
// }
//
//
// // this is manual test!
// testcase tc_EPTF_CLI_Test_overrideTestPortName() runs on EPTF_CLI_Test_OverrideTestPortName_CT {
//
// // modify the terminal port from code:
// f_EPTF_CLI_init_CT("OverrideTestPortName",
// pl_terminalPort := v_custom_CLI_TELNETaspIf,
// pl_displayTerminalPort := v_custom_CLI_displayTELNETaspIf
// );
//
// f_EPTF_CLI_Client_Test_Display_ShowTime_init_CT();
//
// f_EPTF_CLI_Client_registerCommand(
// "echo",
// "echoes its arguments",
// refers(f_EPTF_CLI_Client_echoHandler)
// );
//
// setverdict(pass);
//
// f_EPTF_Base_wait4Shutdown();
//
// f_EPTF_Base_stop(inconc);
// }
} //~group TestPortParameters
group SplitStringTest {
type component EPTF_String_Test_CT {
}
testcase tc_EPTF_CLI_Test_splitString() runs on EPTF_String_Test_CT {
var charstring vl_testString := " A B C D EEE FFF GGG ";
var EPTF_CharstringList vl_expectedStringList := { "A", "B", "C", "D", "EEE", "FFF", "GGG" };
if (f_EPTF_CLI_splitString(vl_testString) != vl_expectedStringList) {
setverdict(fail, "Splitting of string "&vl_testString&" failed: Expecting: "&log2str(vl_expectedStringList)&" got: "&log2str(f_EPTF_CLI_splitString(vl_testString)));
stop;
}
vl_testString := " ";
vl_expectedStringList := {};
if (f_EPTF_CLI_splitString(vl_testString) != vl_expectedStringList) {
setverdict(fail, "Splitting of string "&vl_testString&" failed: Expecting: "&log2str(vl_expectedStringList)&" got: "&log2str(f_EPTF_CLI_splitString(vl_testString)));
stop;
}
vl_testString := " A ";
vl_expectedStringList := {"A"};
if (f_EPTF_CLI_splitString(vl_testString) != vl_expectedStringList) {
setverdict(fail, "Splitting of string "&vl_testString&" failed: Expecting: "&log2str(vl_expectedStringList)&" got: "&log2str(f_EPTF_CLI_splitString(vl_testString)));
stop;
}
vl_testString := "A";
vl_expectedStringList := {"A"};
if (f_EPTF_CLI_splitString(vl_testString) != vl_expectedStringList) {
setverdict(fail, "Splitting of string "&vl_testString&" failed: Expecting: "&log2str(vl_expectedStringList)&" got: "&log2str(f_EPTF_CLI_splitString(vl_testString)));
stop;
}
setverdict(pass);
}
} //~group SplitStringTest
//***********************************************************************
// Tests with Terminal Emulation
//***********************************************************************
group TerminalEmulation {
//============================================
// Functions
//============================================
//This is almost the same as f_EPTF_CLI_Client_Test_Display_ShowTime_init_CT but CLI is not used
function f_EPTF_CLI_Test_client_ShowTime_init_CT(in charstring pl_selfName, in EPTF_CLI_CT pl_CLI_compRef := null) runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
//f_EPTF_CLI_init_CT("ShowTime_Test");
f_EPTF_CLI_Client_init_CT(pl_selfName, pl_CLI_compRef);
displayIsOn:=true; //dangerous, refine it!!!!
activate(as_EPTF_CLI_Client_Test_updateTime());
t1.start(1.0);
f_EPTF_CLI_Client_registerCommand(
"showTime",
"displays seconds elapsed",
refers(f_EPTF_CLI_Client_showTimeHandler)
);
f_EPTF_CLI_Client_registerCommand(
"echo",
"echoes its arguments",
refers(f_EPTF_CLI_Client_echoHandler));
}
function f_EPTF_CLI_Test_client_behavior_ShowTime(in charstring pl_selfName, in EPTF_CLI_CT pl_CLI_compRef := null) runs on EPTF_CLI_Client_Test_Display_ShowTime_CT {
f_EPTF_CLI_Test_client_ShowTime_init_CT(pl_selfName,pl_CLI_compRef);
f_EPTF_Base_wait4Shutdown();
}
//============================================
// tc_EPTF_CLI_Test_Terminal_help
//============================================
testcase tc_EPTF_CLI_Test_Terminal_help() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
var template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "help", expectedAnswer:= t_help_answer},
{command:= "help help", expectedAnswer:= t_help_help_answer},
{command:= "help exit", expectedAnswer:= t_help_exit_answer},
{command:= "help quit", expectedAnswer:= t_help_quit_answer},
{command:= "help stop", expectedAnswer:= t_help_stop_answer},
{command:= "help stopAll", expectedAnswer:= t_help_stopAll_answer},
{command:= "help echo", expectedAnswer:= t_help_echo_answer },
{command:= "help alias", expectedAnswer:= t_help_alias_answer },
{command:= "help unalias", expectedAnswer:= t_help_unalias_answer },
{command:= "help lsalias", expectedAnswer:= t_help_lsalias_answer },
{command:= "help allalias", expectedAnswer:= t_help_allalias_answer }};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_exit
//============================================
testcase tc_EPTF_CLI_Test_Terminal_exit() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create alive;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{ command:="exit help", expectedAnswer:=t_help_exit_answer},
{ command:= "exit", expectedAnswer:= ""}
};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
if( vc_EPTF_CLI_Test_CLI_terminal.alive and vc_EPTF_CLI_Test_CLI_client.running and vc_EPTF_CLI_Test_CLI_server.running) {
setverdict(pass);
//Can it connect and work again? :
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
} else {
setverdict(fail);
}
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_quit
//============================================
testcase tc_EPTF_CLI_Test_Terminal_quit() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create alive;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "quit help", expectedAnswer:= t_help_quit_answer},
{command:= "quit", expectedAnswer:= ""}
};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
if( vc_EPTF_CLI_Test_CLI_terminal.alive and vc_EPTF_CLI_Test_CLI_client.running and vc_EPTF_CLI_Test_CLI_server.running) {
setverdict(pass);
//Can it connect and work again? :
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
} else {
setverdict(fail);
}
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_stop
//============================================
testcase tc_EPTF_CLI_Test_Terminal_stop() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "stop help", expectedAnswer:=t_help_stop_answer},
{command:= "stop", expectedAnswer:= ""} };
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
all component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_stopAll
//============================================
testcase tc_EPTF_CLI_Test_Terminal_stopAll() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := { {command:= "stopAll", expectedAnswer:= ""} };
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
all component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_echo
//============================================
testcase tc_EPTF_CLI_Test_Terminal_echo() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "echo haho haliho", expectedAnswer:= "haho haliho"},
{command:="echo help",expectedAnswer:=t_help_echo_answer2}};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_echo2
//============================================
testcase tc_EPTF_CLI_Test_Terminal_echo2() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client1 := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client2 := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client1.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client1",vc_EPTF_CLI_Test_CLI_server));
vc_EPTF_CLI_Test_CLI_client2.start(
f_EPTF_CLI_Test_CLI_client2_behavior(
"CLI_client2",
vc_EPTF_CLI_Test_CLI_server
//"ECHO2",
//"ECHO2 help",
//refers(f_EPTF_CLI_Client_echoHandler
));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:="echo haho haliho", expectedAnswer:= "haho haliho"},
{command:="echo help",expectedAnswer:=t_help_echo_answer2},
{command:="ECHO2 see You later", expectedAnswer:= "see You later"},
{command:="ECHO2 help",expectedAnswer:=t_help_ECHO2_answer},
{command:="stop", expectedAnswer:= ""}};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_echo2PlusNotExistingCmd
//============================================
testcase tc_EPTF_CLI_Test_Terminal_echo2PlusNotExistingCmd() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client1 := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client2 := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client1.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client1",vc_EPTF_CLI_Test_CLI_server));
vc_EPTF_CLI_Test_CLI_client2.start(
f_EPTF_CLI_Test_CLI_client2_behavior(
"CLI_client2",
vc_EPTF_CLI_Test_CLI_server
//"ECHO2",
//"ECHO2 help",
//refers(f_EPTF_CLI_Client_echoHandler
));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:="echo haho haliho", expectedAnswer:= "haho haliho"},
{command:="echo help",expectedAnswer:=t_help_echo_answer2},
{command:="ECHO2 see You later", expectedAnswer:= "see You later"},
{command:="ECHO2 help",expectedAnswer:=t_help_ECHO2_answer},
{command:="NotExistingCmd Wake Up And Run",expectedAnswer:="NotExistingCmd: Command not found."},
{command:="stop", expectedAnswer:= ""}};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_comment
//============================================
testcase tc_EPTF_CLI_Test_Terminal_comment() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "#this is just a comment", expectedAnswer:= ""},
{command:="//this is another kind of command",expectedAnswer:=""}};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
//terminal exits itself...
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_display
//============================================
testcase tc_EPTF_CLI_Test_Terminal_display() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_Test_Display_ShowTime_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_Test_Display_ShowTime_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
var EPTF_CLI_Test_display vc_EPTF_CLI_Test_CLI_display := EPTF_CLI_Test_display.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(1.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_display.start(f_EPTF_CLI_Test_CLI_display_behavior("CLI display",tsp_EPTF_CLI_Test_prompt));
T1.start(1.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_client_behavior_ShowTime("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(1.0); T1.timeout;
template CmdAndAnswerList vl_cmdAndAnswerList := { {command:= "echo haho haliho", expectedAnswer:= "haho haliho"} };
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt, 10.0));
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
//============================================
// tc_EPTF_CLI_Test_Terminal_alias
//============================================
testcase tc_EPTF_CLI_Test_Terminal_alias() runs on EPTF_CLI_Test_MTC {
f_EPTF_Base_init_CT("MTC");
var EPTF_CLI_CT vc_EPTF_CLI_Test_CLI_server := EPTF_CLI_CT.create;
var EPTF_CLI_Client_CT vc_EPTF_CLI_Test_CLI_client := EPTF_CLI_Client_CT.create;
var EPTF_CLI_Test_terminal vc_EPTF_CLI_Test_CLI_terminal := EPTF_CLI_Test_terminal.create;
timer T1;
vc_EPTF_CLI_Test_CLI_server.start(f_EPTF_CLI_Test_CLI_server_behavior("CLI_server"));
T1.start(2.0); T1.timeout;
vc_EPTF_CLI_Test_CLI_client.start(f_EPTF_CLI_Test_CLI_client_behavior("CLI_client",vc_EPTF_CLI_Test_CLI_server));
T1.start(2.0); T1.timeout;
var template CmdAndAnswerList vl_cmdAndAnswerList := {
{command:= "allalias", expectedAnswer:= t_allalias_none},
{command:= "alias help", expectedAnswer:= t_alias_illegalArg},
{command:= "alias help h", expectedAnswer:= t_alias_ok},
{command:= "alias stop h", expectedAnswer:= t_alias_used},
{command:= "h alias", expectedAnswer:= t_help_alias_answer},
{command:= "lsalias h", expectedAnswer:= t_lsalias},
{command:= "lsalias ntrg", expectedAnswer:= t_aliasNotReg},
{command:= "allalias", expectedAnswer:= t_allalias},
{command:= "unalias h", expectedAnswer:= t_unalias},
{command:= "allalias", expectedAnswer:= t_allalias_none},
{command:= "alias help h", expectedAnswer:= t_alias_ok},
{command:= "alias stop s", expectedAnswer:= t_alias_ok},
{command:= "h $s$", expectedAnswer:= t_help_stop_answer}};
vc_EPTF_CLI_Test_CLI_terminal.start(f_EPTF_CLI_Test_CLI_terminal_behavior("CLI_terminal",vl_cmdAndAnswerList,tsp_EPTF_CLI_Test_prompt));
any component.done;
setverdict(pass);
f_EPTF_Base_cleanup_CT();
}//tc_
}
control {
execute(tc_EPTF_CLI_Test_registerCommand());
execute(tc_EPTF_CLI_Test_executeCustomCommand());
execute(tc_EPTF_CLI_Test_executeCommandSetCommands());
execute(tc_EPTF_CLI_Test_executeParallelCommands());
execute(tc_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout());
execute(tc_EPTF_CLI_Test_splitString());
execute(tc_EPTF_CLI_Test_stopCommand());
execute(tc_EPTF_CLI_Test_Terminal_help());
execute(tc_EPTF_CLI_Test_Terminal_exit());
execute(tc_EPTF_CLI_Test_Terminal_quit());
execute(tc_EPTF_CLI_Test_Terminal_stop());
execute(tc_EPTF_CLI_Test_Terminal_stopAll());
execute(tc_EPTF_CLI_Test_Terminal_echo());
execute(tc_EPTF_CLI_Test_Terminal_echo2());
execute(tc_EPTF_CLI_Test_Terminal_comment());
execute(tc_EPTF_CLI_Test_Terminal_display());
execute(tc_EPTF_CLI_Test_Terminal_echo2PlusNotExistingCmd());
execute(tc_EPTF_CLI_Test_Terminal_alias());
}
} //~module EPTF_CLI_Test