TestUnit TestScript.lsl

///////////////////////////////////////////////////////////////////////////////////
///////
///////
///////
/////// TestUnit_TestScript
/////// 
/////// 
///////
/////// This is the test script that should include the code you want to test. 
/////// 
/////// 
////////////////////////////////////////////////////////////////////////////////////// 
//TestUnit_TestScript .1 -> initial framework 6.23.2007
//TestUnit_TestScript .2 -> tested with minor bug fixes 7.2.2007
//////////////////////////////////////////////////////////////////////////////////////
//
// Command Protocol
//
//////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////
// CHAT commands
//////////////////////////////////////////////
//
// Chat commands will be on the specified broadcastChannel
//
//////// OUTPUT ///////////
//
// AddUnitReport - send Report update to Coordinator on the chat broadcastChannel
// format example -> AddUnitReport::unitKey::00000-0000-0000-00000::Report::Successful Completion of Test
//
//////////////////////////////////////////////
// LINK MESSAGE commands
//////////////////////////////////////////////
//
// link message commands will be sent out on the toAllChannel, and received on the passFailChannel
//
//////// INPUT ///////////
//
// RunTest - activation command to start test
// format example -> RunTest
//
// Report - channel and report type
// format example -> Report::controlChannel::0::reportType::NORMAL
//
// Reset - rest the scripts 
// format example -> Reset
//
//////// OUTPUT ///////////
//
// passFail - status of test sent on passFailChannel
// format example -> PASS
//
//////////////////////////////////////////////////////////////////////////////////////////
// Global Variables
integer toAllChannel = -255; // general channel - linked message
integer passFailChannel = -355; // test scripts channel for communicating pass/fail - linked message
integer debug = 0; // level of debug message
integer debugChannel = DEBUG_CHANNEL; // output channel for debug messages
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////
////////// Function: ParseCommand
//////////
////////// Input: string message - command to be parsed
////////// 
////////// Output: no return value
////////// 
////////// Purpose: This function calls various other functions or sets globals
////////// depending on message string. Allows external command calls.
////////// 
////////// Issues: no known issues 
////////// 
////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////
ParseCommand(string message)
{
 if(debug > 1)llSay(debugChannel, llGetScriptName()+ "->ParseCommand: " + message);
 
 //reset all scripts 
 if(message == "Reset")
 {
 //reset this script 
 llResetScript(); 
 }
 
 //RunTest()
 else if(message == "RunTest")
 {
 RunTest();
 }
 //Report()
 //Example format -> Report::broadcastChannel::0::reportType::NORMAL
 else if( llSubStringIndex(message, "Report") != -1 )
 {
 //parse the string command into a list
 list reportParameters = llParseString2List( message, ["::"], [""] );
 
 //find the broadcastChannel label and increment by one
 integer tempIndex = llListFindList( reportParameters, ["controlChannel"] ) + 1;
 //pull the broadcastChannel from the list with the index just calculated
 integer controlChannel = llList2Integer( reportParameters , tempIndex);
 
 //find the reportType label and increment by one
 tempIndex = llListFindList( reportParameters, ["reportType"] ) + 1;
 //pull the reportType from the list with the index just calculated
 string reportType = llList2String( reportParameters , tempIndex);
 
 //call the Report function with new parameters
 Report( controlChannel, reportType );
 }
 
 
 
} //end ParseCommand
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////
////////// Function: RunTest
//////////
////////// Input: no input parameters
////////// 
////////// Output: link message on passFailChannel test status
////////// 
////////// Purpose: This function is where you put the scripts that you want to test
////////// with this unit.
////////// 
////////// Issues: no known issues 
////////// 
////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////
RunTest()
{
 
 //
 //
 // Put the scripts that you want to test here !!!!!!!!!
 //
 //
 
 
 //One of the following messages needs to be sent at the end of this function
 //each time that it is run
 //
 // llMessageLinked(LINK_SET, passFailChannel, "PASS", NULL_KEY);
 // llMessageLinked(LINK_SET, passFailChannel, "FAIL", NULL_KEY);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////
////////// Function: Report
//////////
////////// Input: broadcastChannel - chat channel to send report
////////// reportType - determines length and content of report type
////////// -> NORMAL - failures and summary information
////////// -> QUITE - summary information only
////////// -> VERBOSE - everything
////////// 
////////// Output: llSay on broadcastChannel 
////////// 
////////// Purpose: This function is where you design the three level of reports
////////// available upon request by the Coordinator
////////// 
////////// Issues: no known issues 
////////// 
////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////
Report( integer broadcastChannel, string reportType )
{
 string reportString;
 
 //Normal - moderate level of reporting
 if( reportType == "NORMAL" )
 {
 reportString = ""; //add what you would like to report here !!!!!!
 }
 
 //QUITE - shortest level of reporting
 if( reportType == "QUIET" )
 {
 reportString = ""; //add what you would like to report here !!!!!!
 }
 
 //VERBOSE - highest level of reporting
 if( reportType == "VERBOSE" )
 {
 reportString = ""; //add what you would like to report here !!!!!!
 }
 
 //AddUnitReport()
 //send to Coordinator on the broadcastChannel the selected report
 //format example -> AddUnitReport::unitKey::00000-0000-0000-00000::Report::Successful Completion of Test
 llSay( broadcastChannel, "AddUnitReport::unitKey::" + (string)llGetKey() + "::Report::" + reportString);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////
////////// Function: Initialize
//////////
////////// Input: no input parameters
////////// 
////////// Output: no return value
////////// 
////////// Purpose: This function initializes any variables or functions necessary
////////// to get us started
////////// 
////////// Issues: no known issues 
////////// 
////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////
Initialize()
{
}
///////////////////////////////////////////////////////////////////////////////////////
//STATE STATE STATE STATE STATE STATE STATE STATE STATE STATE STATE STATE STATE STATE//
///////////////////////////////////////////////////////////////////////////////////////
// //
// //
// DEFAULT STATE //
// //
// //
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
default
{
///////////////////////////////////////////////////////
// State Entry of default state //
///////////////////////////////////////////////////////
 state_entry()
 {
 Initialize();
 }
////////////////////////////////////////////////////////
// On Rez of default state //
//////////////////////////////////////////////////////// 
 on_rez(integer start_param)
 {
 Initialize();
 }
 
///////////////////////////////////////////////////////
// Link Message of default state //
/////////////////////////////////////////////////////// 
 link_message(integer sender_number, integer number, string message, key id)
 {
 //if link message is on the correct channel
 if(number == toAllChannel)
 {
 //treat as command input
 ParseCommand(message);
 }
 
 } //end of link message
 
} // end default