示例#1
0
///*************************************************************************
/// Method:		 CallFunction
/// Description: 
///
/// Parameters:
///	
///
///*************************************************************************
bool FaultsTest::CallFunction(String *funcName, ArrayList *ParamArray, DWORD returnValue, DWORD errorCode){
	//Console::WriteLine("\n---------->CallFunction Begins<------------\n");
	
	Function0 functionPtr0 = NULL;
	Function1 functionPtr1 = NULL;
	Function2 functionPtr2 = NULL;
	Function3 functionPtr3 = NULL;
	Function4 functionPtr4 = NULL;
	Function5 functionPtr5 = NULL;
	Function6 functionPtr6 = NULL;
	Function7 functionPtr7 = NULL;
	Function8 functionPtr8 = NULL;
	Function9 functionPtr9 = NULL;
	Function10 functionPtr10 = NULL;
	Function11 functionPtr11 = NULL;
	Function12 functionPtr12 = NULL;

	int ret=returnValue;
	int err=errorCode;
bool functionfoundFlag=false;
	Console::WriteLine("Function: {0}  ",funcName);
	Console::WriteLine("ReturnValue: {0}    ErrorCode:{1}\n",Convert::ToString(ret),Convert::ToString(err));

	DWORD realError=0;
	DWORD realReturn=0;

	Hashtable *myFunctionTable = new Hashtable();
	myFunctionTable=dynamic_cast<Hashtable *>(functionNavigatorInstance->FunctionTableByName->Clone());
	IDictionaryEnumerator *fEnum=myFunctionTable->GetEnumerator();
	Function *callFunc;

//Search for the functionName in the functions file
	while (fEnum->MoveNext()){
		callFunc=dynamic_cast<Function *>(fEnum->get_Value());
		if(String::Compare(callFunc->get_FunctionName(),funcName)==0){functionfoundFlag=true;break;}
		
		}
if (functionfoundFlag==true){
Console::WriteLine( callFunc->get_FunctionName() );

DWORD *voidParamArray = new DWORD[13];
String *lpFileName = callFunc->get_OriginalDll(); 	
HMODULE hModule = LoadLibrary( convertGCStringToNative( lpFileName ) );

if ( hModule == NULL )
	{
	Console::WriteLine( "Failed to load module.\n" );
	return false;
	}	

TestingFunctionXML::Parameter *paramTemp =new TestingFunctionXML::Parameter();

for ( int paramCount = 0; paramCount < ParamArray->Count; paramCount++ )
	{
	paramTemp = dynamic_cast<TestingFunctionXML::Parameter *>(ParamArray->get_Item( paramCount ));

	Console::WriteLine("Param{0}:{1}",Convert::ToString(paramTemp->get_Index()),paramTemp->get_AssignedValue());


	if ( paramTemp->get_CompareAs() != S"StringType" )
		{
		if( !paramTemp->get_AssignedValue()->Empty){
			voidParamArray[paramCount] = Convert::ToInt32(paramTemp->get_AssignedValue(),10);
			}
		else{
			char *mychar=new char[];
			voidParamArray[paramCount] = DWORD(mychar);}
		}
	else
		{
		//voidParamArray[paramCount]=NULL;
		//voidParamArray[paramCount] = (DWORD)convertGCStringToNative((dynamic_cast<String *>(paramTemp->get_AssignedValue())));
					voidParamArray[paramCount] = Convert::ToInt32(paramTemp->get_AssignedValue(),10);

		}
	}
示例#2
0
///*************************************************************************
/// Method:		TestFault
/// Description: Tests the fault name specified
///
/// Parameters:
///	faultName - The name of the fault in faults.xml to be tested
///
/// Return Value: true if successful, false otherwise
///*************************************************************************
bool FaultsTest::TestFault(char *faultName){
	//OUTPUT PASSFAIL TO A FILE
	FileStream *FileStreamer;
	FileStreamer = new FileStream("FAULTSTEST.TXT", FileMode::Create  , FileAccess::Write);
	StreamWriter * pWriter = new StreamWriter(FileStreamer);

	Console::WriteLine("---------->TestFault Method Begins<----------\n");

	//Load the Faults xml file in memory using FaultsXMLFramework
	LoadFaultsXmlFile("faults.xml");
	//Load the Functions xml file in memory using FunctionsXMLFramework
	LoadFunctionsXmlFile("functions.xml");

	bool bSuccess=true;

	Hashtable *myHT = new Hashtable();
	myHT=dynamic_cast<Hashtable *>(faultNavigatorInstance->FaultTableByName->Clone());
	IDictionaryEnumerator *faultsEnum=myHT->GetEnumerator();
	Console::WriteLine("OUTPUT FILE:FAULTTEST.TXT\n");

	while (faultsEnum->MoveNext()){
		DWORD ReturnValue=0;
		DWORD ErrorCode=0;

		Fault *fault=dynamic_cast<Fault *>(faultsEnum->get_Value());
		ReturnValue=(Convert::ToInt32(fault->get_ReturnValue()));
		ErrorCode=(Convert::ToInt32(fault->get_ErrorCode()));

		if (System::String::Compare(fault->get_Name(),faultName)==0)
			{
			ArrayList *funcList=fault->Function;
			Console::WriteLine(S"{0} Fault has {1} functions",fault->Name,__box(funcList->Count));
			pWriter->WriteLine("\n-------->   {0} Fault has {1} functions    <-------\n", fault->Name,__box(funcList->Count));
			//cycle through all functions 
			for(int ifuncs=0;ifuncs<funcList->Count;ifuncs++)
				{
				FaultFunction *thisfunc=dynamic_cast<FaultFunction *>(funcList->get_Item(ifuncs));
					{
					//****Search for a specific function--->TEST
					//if (System::String::Compare(thisfunc->get_Name(),"WSARecv")==0)
					//	{
					if(thisfunc->get_OverrideErrorCode()!=NULL){
						ErrorCode=(Convert::ToInt32(thisfunc->get_OverrideErrorCode()));
						}
				if(thisfunc->get_OverrideReturnValue()!=NULL){
					ReturnValue=(Convert::ToInt32(thisfunc->get_OverrideReturnValue()));
					}

			ArrayList *matchArray=thisfunc->get_MatchParams();

			ArrayList *paramsToSendToCallFunction = FillParamArray(convertGCStringToNative(thisfunc->Name),matchArray);

			if (CallFunction(thisfunc->get_Name(),paramsToSendToCallFunction,ReturnValue,ErrorCode) == true)
				{
				//Console::WriteLine("The function {0} has Passed.",thisfunc->Name);
				pWriter->WriteLine("{0} has Passed!",thisfunc->Name);
				bSuccess=true;
				}
			else 
				{	
				//Console::WriteLine("The function {0} has Failed.",thisfunc->Name);
				pWriter->WriteLine("{0} has Failed!",thisfunc->Name);
				bSuccess=false;
				}

					}
				//}
			}
			}
		}

Console::WriteLine("\n---------->TestFault Method Ends<------------\n");
pWriter->Close();
return bSuccess;	
	}