/* * DataDriver.cpp * TSMFCAPI v1.1 * 15 March 2004 * © Quality Forge, 2004 */ /***************************************************************************** DataDriver.cpp This MFC/C++ test demonstrates how to use data stored in a .csv file. ---------------------------------------------------------------------------- Description of the System on which the script was recorded: Windows 2000, Screen Size: 1024 x 768, Color: High Color (16 bit) *****************************************************************************/ #include //for AfxWinInit & AfxMessageBox #include "DataDriver.h" //DataDriver class definition /** * $param data: data should contain a single int value */ int DataDriver::Run(CString data) { //initialize try { //initialize test //note: the \Reports directory must already exist in the // same directory where this java class file exists int initialized = InitSession("reports\\mfcDataDriver"); //to run without generating any TestSmith reports use: //int initialized = initSession(); if (initialized == FALSE) { //handle error... //use getLastTSError() for errors generated by TSAPI //use getLastCError() for errors generated by CSmith return -1; } } catch (InSessionException e) { //handle error, e.g. printf("[%s]\n", e.reason); return -1; } try { //set environment int envSet = SetEnv("LAUNCH=Notepad.exe"); if (envSet) { envSet = SetEnv("DATA='Data\\smith1.csv'"); } if (envSet) { envSet = SetEnv("DATA='Data\\smith2.csv'"); } //if any of the above calls failed, deal with it here if (!envSet) { //handle error... //use getLastTSError() for errors generated by TSAPI //use getLastCError() for errors generated by CSmith printf("[%s]\n", GetLastTSError()); return -1; } //run test int lasterr = WndInit("wndInit id=1 wtitle~=Notepad wclass=Notepad " "zsync=s6 zinterval=s2"); if (lasterr == NO_ERR) { //the description of the window is the same for all following calls CString windowDescription = "id=1 wnum=1 wcid=15 wclass=Edit wpclass=Notepad "; int count = 1; //default if (data != EMPTY) { //get the "count" value from 'data' count = atoi(data); if (count < 1) count = 1; } CtrlEditSetText(windowDescription + "ctext='MFC Test\n'"); for (int i=1; i<=count; i++) { //increment the data index SetDataIndex(i); //enter some text into Notepad, using replacement vars CtrlEditSetText(windowDescription + "cedit=end ctext='-----\n{_TIMESTAMPNOW1_}\nHello {firstname} {lastname}. You are {age}.\n'"); //enter more text CtrlEditSetText(windowDescription + "cedit=end ctext=' You said: {comment}\n'"); //and more CtrlEditSetText(windowDescription + "cedit=end ctext=' You randomly shout: {x1}... {x2}... !!!\n'"); Sleep(500); } //check that the text contains the name "James Bond", ignoring case //if the loop count is less than 4, this validation will fail lasterr = ValEditText(windowDescription + "vtext~='JAMES BOND'`i"); if (lasterr > NO_ERR) { //handle error, e.g. printf("Error: Unable to find James Bond.\n"); } //uncomment next command to close Notepad //wndClose("id=1"); } //end test int exit_ok = ExitSession(); if (exit_ok == 0) { //handle error... //use getLastTSError() for errors generated by TSAPI //use getLastCError() for errors generated by CSmith } //full test ran without exceptions, so return GetExitCode(); } catch (UninitializedException e) { //handle error, e.g. printf("[%s]\n", e.reason); return -1; } } //============================================================================= //TEST int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { //initialize MFC (and print error on failure) if (!AfxWinInit(::GetModuleHandle(0), 0, ::GetCommandLine(), 0)) { printf("Fatal Error: MFC initialization failed"); return -1; } CString data = "1"; if (argc > 1) data = argv[1]; DataDriver dataDriver; int exitCode = dataDriver.Run(data); CString result; result.Format("DataDriver exit code = %d", exitCode); printf("\n%s\n", result); //print to stdout AfxMessageBox(result, MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL); //show in dialog box MFCSmith::DisplayLastReport(); return exitCode; } //=============================================================================