/* * * * * $RCSfile: EmployeeTest.cpp,v $ * * * * $Source: /u/l/lbaker/www/cosc2325/employeeTest.cpp,v $ * $Revision: 1.1 $ * $Date: 2004/01/21 05:54:14 $ * * * * The following source code is protected under all standard copyright * laws. * * * */ #include #include "employee.h" /* * This error format make emacs error stepping work to help navigate * to failed test cases. */ #define REPORT_ERROR(X) \ cout << __FILE__ << ":" << __LINE__ << ": " << (X) << endl; /**********************************************************************/ int testConstructors() { int error_count = 0; // Test default arguments Employee e1; if (( e1.getId() != 0 ) || ( e1.getName() != "" )) { REPORT_ERROR( "no arg constructor has bad defaults." ); error_count++; } Employee e2("Joe Smith", -43); if (( e2.getName() != "JOE SMITH") || ( e2.getId() != 0 )) { REPORT_ERROR( "two argument constructor has bad values." ); error_count++; } Employee e3("Ann Ryan", 208); if (( e3.getName() != "ANN RYAN")) { REPORT_ERROR( "two argument constructor has bad value in string." ); error_count++; } if( (e3.getId() != 208 )) { REPORT_ERROR( "two argument constructor has bad value in id." ); error_count++; } return error_count; } /**********************************************************************/ int testMutators() { int error_count = 0; Employee e1; //**************************************** // setPoint() tests e1.setId(405); if ( ! (e1.getId()==405)) { REPORT_ERROR( "setId() not working with given id." ); error_count++; } e1.setName("Phil Michelson"); if( !(e1.getName()=="PHIL MICHELSON")) { REPORT_ERROR( "setName() mutator failed." ); error_count++; } e1.setId(-33); /* try invalid id, should stay the same */ if (!(e1.getId() == 405)) { REPORT_ERROR( "setId() failed to test for invalid argument." ); error_count++; } Employee e2; e1.setId(-109); /* try invalid id, should stay the same default arg */ if (!(e2.getId() == 0)) { REPORT_ERROR( "setId() failed to test for invalid argument." ); error_count++; } return error_count; } /**********************************************************************/ /* testing readData and printToStream */ int testRead_Print() { int error_count=0; Employee e1; Employee e2; cout <<"Enter data name id use 'Kim Adam' 444 "< 983 "<> e1; if(e1.getName() != "BILL JONES") { REPORT_ERROR ("input operator, >> , failed on good input for name"); error_count ++; } if(e1.getId() != 983) { REPORT_ERROR ("readData failed on good input for id"); error_count ++; } cout << "enter data in form 'Barb Wilson' -245 "<> e1; if(e1.getName() != "BARB WILSON") { REPORT_ERROR ("input operator, >> , failed on good input for name"); error_count ++; } if(e1.getId() != 983) /* id should still remain same as it was, 983 */ { REPORT_ERROR ("input operator >> failed on invalid input for id"); error_count ++; } cout <<"now printing e1, should be BARB WILSON 983 " <