/* * DataDriver.cpp * TSCAPI v1.1 * 15 March 2004 * © Quality Forge, 2004 */ /***************************************************************************** DataDriver.cpp This 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 "DataDriver.h" /** * $param data: data should contain a single int value */ int DataDriver::Run(LPTSTR 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((LPTSTR)"reports\\cDataDriver"); //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((LPTSTR)"[%s]\n", e.reason); return -1; } try { //set environment int envSet = SetEnv((LPTSTR)"LAUNCH=Notepad.exe"); if (envSet) { envSet = SetEnv((LPTSTR)"DATA='Data\\smith1.csv'"); } if (envSet) { envSet = SetEnv((LPTSTR)"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((LPTSTR)"[%s]\n", GetLastTSError()); return -1; } //run test int lasterr = WndInit((LPTSTR)"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 LPTSTR windowDescription = (LPTSTR)"id=1 wnum=1 wcid=15 wclass=Edit wpclass=Notepad "; int count = 1; //default if (data && data != EMPTY) { //get the "count" value from 'data' count = atoi(data); if (count < 1) count = 1; } LPTSTR params; params = (LPTSTR)malloc(256); sprintf(params, "%s %s", windowDescription, (LPTSTR)"ctext='C++ Test\n'"); CtrlEditSetText(params); for (int i=1; i<=count; i++) { //increment the data index SetDataIndex(i); //enter some text into Notepad, using replacement vars sprintf(params, "%s %s", windowDescription, (LPTSTR)"cedit=end ctext='-----\n{_TIMESTAMPNOW1_}\nHello {firstname} {lastname}. You are {age}.\n'"); CtrlEditSetText(params); //enter more text sprintf(params, "%s %s", windowDescription, (LPTSTR)"cedit=end ctext=' You said: {comment}\n'"); CtrlEditSetText(params); //and more sprintf(params, "%s %s", windowDescription, (LPTSTR)"cedit=end ctext=' You randomly shout: {x1}... {x2}... !!!\n'"); CtrlEditSetText(params); 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 sprintf(params, "%s %s", windowDescription, (LPTSTR)"vtext~='JAMES BOND'`i"); lasterr = ValEditText(params); if (lasterr > NO_ERR) { //handle error, e.g. printf((LPTSTR)"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((LPTSTR)"[%s]\n", e.reason); return -1; } } //============================================================================= //TEST int main(int argc, char* argv[]) { LPTSTR data = "1"; if (argc > 1) data = argv[1]; DataDriver* dataDriver = new DataDriver(); int exitCode = dataDriver->Run(data); printf("exitCode: %d\n\n", exitCode); CSmith::DisplayLastReport(); delete dataDriver; return exitCode; } //=============================================================================