Browse Source

implemented unit tests for the new function verifyPassword() and changed the .txt files name while adding a new .txt file for personal emoyees data.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
69a25cfa6a
  1. 4
      build-project.sh
  2. 50
      src/createEmployeeAccount.c
  3. 1
      src/createEmployeeAccount.h
  4. 2
      src/employeeLogin.c
  5. 5
      src/employeesCredentialsList.txt
  6. 36
      src/employeesData.txt
  7. 46
      tests/test_createEmployeeAccount.c

4
build-project.sh

@ -14,8 +14,8 @@ ceedling test:all
cd src/ cd src/
sed '/John Doe/,$d' employeeList.txt > temp.txt
mv temp.txt employeeList.txt
sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt
mv temp.txt employeesCredentialsList.txt
# backup files # backup files
for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do
cp "$file" "$file.bak" cp "$file" "$file.bak"

50
src/createEmployeeAccount.c

@ -2,20 +2,21 @@
#include "createEmployeeAccount.h" #include "createEmployeeAccount.h"
int StringLengthCounter(char* string)
bool isValidEmployeeID(const char* employeeId, int maximumStringLength)
{ {
int characterCounter = 0;
int i = 0;
while(string[i] !='\0')
int employeeIdLength = strlen(employeeId);
for(int i=0;i<employeeIdLength;i++)
{ {
characterCounter++;
++i;
if(employeeId[i]==' ')
{
return false;
}
} }
string[characterCounter] = '\0';
return characterCounter;
return employeeIdLength <= maximumStringLength ;
} }
bool isValidPassword( char *password, int minimumLength) bool isValidPassword( char *password, int minimumLength)
{ {
/*created a pointer(*stringpointer) which helps loop through characters of the string password*/ /*created a pointer(*stringpointer) which helps loop through characters of the string password*/
@ -47,25 +48,36 @@ bool isValidPassword( char *password, int minimumLength)
} }
bool isValidEmployeeID(const char* employeeId, int maximumStringLength)
int StringLengthCounter(char* string)
{ {
int employeeIdLength = strlen(employeeId);
int characterCounter = 0;
int i = 0;
while(string[i] !='\0')
{
characterCounter++;
++i;
}
string[characterCounter] = '\0';
return characterCounter;
}
for(int i=0;i<employeeIdLength;i++)
bool verifyPassword(char* enteredPassword,char* passwordConfirmation)
{
if(strcmp(enteredPassword,passwordConfirmation)==0)
{ {
if(employeeId[i]==' ')
{
return false;
}
return true;
}
else
{
return false;
} }
return employeeIdLength <= maximumStringLength ;
} }
bool createNewEmployee(char* employeeId, char* employeePassword) bool createNewEmployee(char* employeeId, char* employeePassword)
{ {
FILE* employeesFile; FILE* employeesFile;
employeesFile = fopen("src/employeeList.txt","a");
employeesFile = fopen("src/employeesCredentialsList.txt","a");
if(employeesFile == NULL) if(employeesFile == NULL)
{ {

1
src/createEmployeeAccount.h

@ -10,6 +10,7 @@
bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidEmployeeID(const char* employee, int maximumLength);
bool isValidPassword( char* password, int minimumLength); bool isValidPassword( char* password, int minimumLength);
bool createNewEmployee(char* employeeId, char* employeePassword); bool createNewEmployee(char* employeeId, char* employeePassword);
bool verifyPassword(char* enteredPassword,char* passwordConfirmation);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

2
src/employeeLogin.c

@ -16,7 +16,7 @@ int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
char* listUsername = malloc(credentialLength * sizeof(char*)); char* listUsername = malloc(credentialLength * sizeof(char*));
char* listPassword = malloc(credentialLength * sizeof(char*)); char* listPassword = malloc(credentialLength * sizeof(char*));
FILE* employeeList = fopen("src/employeeList.txt","r");
FILE* employeeList = fopen("src/employeesCredentialsList.txt","r");
if(employeeList == NULL ) if(employeeList == NULL )
{ {

5
src/employeeList.txt → src/employeesCredentialsList.txt

@ -9,3 +9,8 @@ Julius Insertcatfdai7057
Mohamed MDfdai6618 Mohamed MDfdai6618
Shivam Schivam007fdlt3781 Shivam Schivam007fdlt3781

36
src/employeesData.txt

@ -0,0 +1,36 @@
Employee 1
Username : Atharva
Name : Atharva
last name : Naik
Adress : Fulda,leipzigerstrasse,1
Phone number : +4964169865172
Employee 2
Name : Can
last name : Hacioglu
Adress : Fulda,leipzigerstrasse,2
Phone number : +4915973325487
Employee 3
Name : Haytham
last name : Daoula
Adress : Fulda,leipzigerstrasse,3
Phone number : +4995435870169
Employee 4
Name : Julius
last name : Engel
Adress : Fulda,leipzigerstrasse,4
Phone number : +4939172972187
Employee 5
Name : Mohamed
last name : Dahi
Adress : Fulda,leipzigerstrasse,5
Phone number : +4921865106647
Employee 6
Name : Shivam
last name : Chaudhary
Adress : Fulda,leipzigerstrasse,6
Phone number : +4918756871384

46
tests/test_createEmployeeAccount.c

@ -87,6 +87,52 @@ void test_invalidEmployeePassword(void)
} }
void test_verifyPasswordSuccess()
{
/*Arrange*/
char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
char* confirmation[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
bool result[10];
/*Act*/
for(int i=0; i<10; i++)
{
result[i] = verifyPassword(password[i],confirmation[i]);
}
/*Assert*/
for(int i=0; i<10; i++)
{
TEST_ASSERT_TRUE(result[i]);
}
}
void test_verifyPasswordFailure()
{
/*Arrange*/
char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
char* confirmation[10] = {"Atharva123","fdai.72","invalidPassword","23.May.1999","Jane.doe99","foo*bar3","fizz-3buzz","github.com","4ceedlingtest:all","SS-2023"};
bool result[10];
/*Act*/
for(int i=0; i<10; i++)
{
result[i] = verifyPassword(password[i],confirmation[i]);
}
/*Assert*/
for(int i=0; i<10; i++)
{
TEST_ASSERT_FALSE(result[i]);
}
}
void test_employeeCreatedSuccessfully(void) void test_employeeCreatedSuccessfully(void)
{ {
/*Arrange*/ /*Arrange*/

Loading…
Cancel
Save