void Program::Run()
	{
		StreamWriter* sw = new StreamWriter(new String("test.txt"));
		sw->WriteLine(new String("Hi! I'm a stream writer"));
		sw->Flush();
		sw->Close();
		StreamReader* sr = new StreamReader(new String("test.txt"));
		String* text = sr->ReadToEnd();
		sr->Close();
		Console::WriteLine(text);
	}
Exemple #2
0
void
SessionImpl::WritePackageHistory ()
{
    if (packageHistoryFile.length() == 0)
    {
        return;
    }
    StreamWriter writer (File::Open(packageHistoryFile,
                                    FileMode::Append,
                                    FileAccess::Write));
    for (vector<FileInfoRecord>::const_iterator
            it = fileInfoRecords.begin();
            it != fileInfoRecords.end();
            ++ it)
    {
        if (it->packageName.length() > 0)
        {
            writer.WriteLine (it->packageName);
        }
    }
    writer.Close ();
}
Exemple #3
0
int	main(int argc, char* argv[])
	{
	//open registry	and	delete all values set by FaultIntercepter (Initilize)
	RegistryKey	*LMachine =	RegistryKey::OpenRemoteBaseKey(RegistryHive::LocalMachine, System::Environment::MachineName);			 
	RegistryKey	*SKey =	LMachine->OpenSubKey("SOFTWARE", true);
	RegistryKey	*HKey =	 SKey->OpenSubKey("HolodeckEE",	true);
	try
		{
		HKey->DeleteSubKey("Outcome");
		HKey->DeleteSubKey("FaultIntercepterReady");
		HKey->DeleteSubKey("FaultReady");
		}catch(System::ArgumentException *ArgumentError){}

	String *path = System::Environment::CurrentDirectory;
	int	index =	path->IndexOf("Debug");

	if (index != -1)
		{
		path = path->Substring(0, index-1);
		}

	path = String::Concat(path,"\\Logs\\");
	Console::WriteLine("Logs in	{0}",path);

	//Begin	a streamwriter to output whether a fault has passed	or failed. 
	FileStream *DefaultFileStreamer;
	String *FaultFileLogName = String::Concat(path,	"DefaultLog.Log");
	DefaultFileStreamer	= new FileStream(FaultFileLogName, FileMode::OpenOrCreate, FileAccess::Write  );
	StreamWriter * DefaultWriter = new StreamWriter(DefaultFileStreamer);

	TestFaults *FaultTester	= new TestFaults();

	//load the functions and faults	xml	files to memory
	FaultTester->LoadFaultsXmlFile();
	FaultTester->LoadFunctionsXmlFile();

	//if no	arguments were entered then	notify user	and	exit
	if (argc ==	1)
		{
		Console::WriteLine("Please enter fault names as arguments!");
		Sleep(8000);
		return 0;
		}

	//initilize	detailed log files to record the return	values and errorcodes for each function
	//in a fault.
	String *DetailLogFile =	String::Concat(path,"LastRun-DetailLog.Log");
	FileStream *DetailLogStreamer;
	DetailLogStreamer =	new	FileStream(DetailLogFile, FileMode::OpenOrCreate , FileAccess::Write  );
	StreamWriter * DetailLogWriter = new StreamWriter(DetailLogStreamer);

	bool FaultOutcome =	false;

	for(int	arg=1;arg<argc;arg++)
		{
		//if just one fault	iss	being run then open	a log with the fault name
		if (argc == 2)
			{
			String *FaultFileLogName = String::Concat(path,argv[arg],".Log");
			FileStream *FileStreamer;
			FileStreamer = new FileStream(FaultFileLogName,	FileMode::OpenOrCreate,	FileAccess::Write );
			StreamWriter * Writer =	new	StreamWriter(FileStreamer);
			Console::WriteLine("Currently running {0} fault...", Convert::ToString(argv[arg]));
			FaultOutcome = FaultTester->TestFault(argv[arg],Writer,DetailLogWriter);
			Writer->Close();
			}

		//if more than one argument	then load the default log to store all the faults that are to be run
		if(argc > 2)
			{
			FaultOutcome = FaultTester->TestFault(argv[arg],DefaultWriter,DetailLogWriter);
			}

		RegistryKey	*PassFail =	HKey->CreateSubKey("Outcome");

		if(FaultOutcome	== true)
			{
			PassFail->SetValue("Outcome",static_cast<String	*>("PASS"));
			}
		else 
			{
			PassFail->SetValue("Outcome",static_cast<String	*>("FAIL"));
			}
		FaultOutcome = false;
		}
	//close	all	open writers
	DefaultWriter->Close();
	DetailLogWriter->Close();
	Console::ReadLine();
	return 0;
	}
Exemple #4
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;	
	}