Browse Source

implement unit tests for the function storeEmployeeData() and fixed a bug in the unit tests of the function chooseOption.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
c659f9b9aa
  1. 4
      build-project.sh
  2. 24
      src/createEmployeeAccount.c
  3. 10
      src/createEmployeeAccount.h
  4. 5
      src/employeesCredentialsList.txt
  5. 30
      src/employeesData.txt
  6. 2
      src/mainMenu.c
  7. 28
      tests/test_createEmployeeAccount.c
  8. 6
      tests/test_mainMenu.c

4
build-project.sh

@ -16,6 +16,10 @@ cd src/
sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt
mv temp.txt employeesCredentialsList.txt mv temp.txt employeesCredentialsList.txt
sed '/Name : John/,$d' employeesData.txt > temp.txt
mv temp.txt employeesData.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"

24
src/createEmployeeAccount.c

@ -61,6 +61,23 @@ int StringLengthCounter(char* string)
return characterCounter; return characterCounter;
} }
bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber)
{
FILE* employeesDatalist;
employeesDatalist = fopen("src/employeesData.txt","a");
if(employeesDatalist == NULL)
{
printf("Error : could not find file");
return false;
}
else
{
fprintf(employeesDatalist,"\n\nName : %s\nLast name : %s\nAdress : %s\nPhone number : %s",name,lastName,adress,phoneNumber);
fclose(employeesDatalist);
return true;
}
}
bool verifyPassword(char* enteredPassword,char* Confirmation) bool verifyPassword(char* enteredPassword,char* Confirmation)
{ {
return !(strcmp(enteredPassword,Confirmation)); return !(strcmp(enteredPassword,Confirmation));
@ -89,12 +106,16 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials() void getNewEmployeeCredentials()
{ {
employeedata *data;
data = (employeedata*)malloc(sizeof(employeedata));
const int maxLength = 21; const int maxLength = 21;
char employeeId[maxLength]; char employeeId[maxLength];
const int minPasswordLength = 5; const int minPasswordLength = 5;
char employeePassword[maxLength]; char employeePassword[maxLength];
char passwordVerfication[maxLength]; char passwordVerfication[maxLength];
printf("please enter your wished Id :\n"); printf("please enter your wished Id :\n");
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/
@ -115,6 +136,7 @@ void getNewEmployeeCredentials()
passwordVerfication[strlen(employeePassword)] = '\0'; passwordVerfication[strlen(employeePassword)] = '\0';
if(verifyPassword(passwordVerfication,employeePassword)) if(verifyPassword(passwordVerfication,employeePassword))
{ {

10
src/createEmployeeAccount.h

@ -7,10 +7,20 @@
#include<string.h> #include<string.h>
#include<ctype.h> #include<ctype.h>
struct employeesInformations
{
char firstName[15];
char lastName[15];
char adress[20];
char phoneNumber[15];
};
typedef struct employeesInformations employeedata;
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); bool verifyPassword(char* enteredPassword,char* passwordConfirmation);
bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

5
src/employeesCredentialsList.txt

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

30
src/employeesData.txt

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

2
src/mainMenu.c

@ -27,7 +27,7 @@ bool checkIfInteger(char* userInput)
bool chooseOption(int choiceInput) bool chooseOption(int choiceInput)
{ {
return !(choiceInput < 1 || choiceInput > 4);
return !(choiceInput < 1 || choiceInput > 5);
} }

28
tests/test_createEmployeeAccount.c

@ -142,6 +142,34 @@ void test_verifyPasswordFailure()
TEST_ASSERT_EQUAL(expectation,result); TEST_ASSERT_EQUAL(expectation,result);
} }
}
void test_employeesDataStoringSuccess(void)
{
/*Arrange*/
char* firstNames[5] = {"John","Jane","Foo","Fizz","Mustermann"};
char* lastNames[5] = {"Doe","Done","Bar","Buzz","Mustermanpass"};
char* adress[5] = {"fulda,leipzigerstr12","fulda,leipzigerstr13","fulda,leipzigerstr14","fulda,leipzigerstr15","fulda,leipzigerstr16"};
char* phoneNumber[5] = {"+4926428421469","+4932517359874","+4913598765315","+4968145725873","+4938197853812"};
bool creationResult[5];
/*Act*/
for(int i=0;i<5;i++)
{
creationResult[i] = storeEmployeeData(firstNames[i],lastNames[i],adress[i],phoneNumber[i]);
}
/*Assert*/
for(int i=0;i<5;i++)
{
TEST_ASSERT_TRUE(creationResult[i]);
}
} }
void test_employeeCreatedSuccessfully(void) void test_employeeCreatedSuccessfully(void)

6
tests/test_mainMenu.c

@ -138,14 +138,14 @@ void test_validChoiceInput(void)
for(int i = 0; i < 4; i++)
for(int i = 0; i < 5; i++)
{ {
validInput[i] = i + 1; validInput[i] = i + 1;
} }
/*Act and Asssert*/ /*Act and Asssert*/
for(int i = 0; i < 4; i++)
for(int i = 0; i < 5; i++)
{ {
bool validInputResult = chooseOption(validInput[i]); bool validInputResult = chooseOption(validInput[i]);
@ -197,7 +197,7 @@ void test_invalidChoiceInput_secondCase(void)
for(int i = 0; i < 100; i++) for(int i = 0; i < 100; i++)
{ {
invalidInput[i] = i + 5;
invalidInput[i] = i + 6;
} }
/*Act and Assert*/ /*Act and Assert*/

Loading…
Cancel
Save