I am new to CPPUnit testing and have written test for login authentication function with various test cases. But it only accepts return value zero.
The first test case should return 1 if expected and actual are the same but it only works when I change to zero. Any advice is appreciated. Thanks.
void POSUnitTest::testAuthenticate()
{
CPPUNIT_ASSERT_EQUAL (console.Authenticate("testuser","password"),1); // valid username and password
CPPUNIT_ASSERT_EQUAL (console.Authenticate("testuser1","password"),0); //invalid username, valid password
CPPUNIT_ASSERT_EQUAL (console.Authenticate("testuser","password1"),0); //valid username, invalid password
CPPUNIT_ASSERT_EQUAL (console.Authenticate("testuser1","password1"),0); // invalid username and password
CPPUNIT_ASSERT_EQUAL (console.Authenticate(" ","password"),0); // Empty username, valid password
CPPUNIT_ASSERT_EQUAL (console.Authenticate("testuser",""),0); // Valid username, empty password
CPPUNIT_ASSERT_EQUAL (console.Authenticate("",""),0); // Empty username and password
cout << "Test 3) testAuthenticate successful.\n\n";
}
This is my Authenticate function in class POSConsole.
int POSConsole::Authenticate(string _userID, string _password)
{
bool failedLogin=false;
int returnValue=0;
_password = Encrypt (_password); //Encrypt user enter password to compare with vector
for (int index = 0; index < cashierVector.size(); index++)
{
if ( (_userID == cashierVector[index].getUserID()) &&
(_password == cashierVector[index].getPassword()))
{
returnValue=1;
system("clear");
POSMenu();
break;
}
else
{
returnValue=0;
cout << "Invalid user login information. Please try again.\n";
failCount++;
break;
}
}
return returnValue;
if (failCount == 3)
{
cout << "You have used maximum attempts to login. Your account has been locked." << endl;
exit (0);
}
}