From c659f9b9aa7bb924bcb3b722d853f86224959aa0 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 17:18:35 +0100 Subject: [PATCH] implement unit tests for the function storeEmployeeData() and fixed a bug in the unit tests of the function chooseOption. --- build-project.sh | 4 ++++ src/createEmployeeAccount.c | 24 +++++++++++++++++++++++- src/createEmployeeAccount.h | 10 ++++++++++ src/employeesCredentialsList.txt | 5 +++++ src/employeesData.txt | 30 ++++++++++++++++-------------- src/mainMenu.c | 2 +- tests/test_createEmployeeAccount.c | 28 ++++++++++++++++++++++++++++ tests/test_mainMenu.c | 6 +++--- 8 files changed, 90 insertions(+), 19 deletions(-) diff --git a/build-project.sh b/build-project.sh index ab820fc..0f7c75e 100755 --- a/build-project.sh +++ b/build-project.sh @@ -16,6 +16,10 @@ cd src/ sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt mv temp.txt employeesCredentialsList.txt + +sed '/Name : John/,$d' employeesData.txt > temp.txt +mv temp.txt employeesData.txt + # backup files for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do cp "$file" "$file.bak" diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index bb283e0..07877db 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -61,6 +61,23 @@ int StringLengthCounter(char* string) 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) { return !(strcmp(enteredPassword,Confirmation)); @@ -89,12 +106,16 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - + employeedata *data; + data = (employeedata*)malloc(sizeof(employeedata)); const int maxLength = 21; char employeeId[maxLength]; + const int minPasswordLength = 5; + char employeePassword[maxLength]; char passwordVerfication[maxLength]; + 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*/ @@ -115,6 +136,7 @@ void getNewEmployeeCredentials() passwordVerfication[strlen(employeePassword)] = '\0'; + if(verifyPassword(passwordVerfication,employeePassword)) { diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index c4fc698..181228c 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -7,10 +7,20 @@ #include #include +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 isValidPassword( char* password, int minimumLength); bool createNewEmployee(char* employeeId, char* employeePassword); bool verifyPassword(char* enteredPassword,char* passwordConfirmation); +bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber); int StringLengthCounter(char* string); diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index ed5a12d..d44964d 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,3 +9,8 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + + + + + diff --git a/src/employeesData.txt b/src/employeesData.txt index 8b48973..55e1cc0 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -1,36 +1,38 @@ -Employee 1 -Username : Atharva Name : Atharva -last name : Naik +Last name : Naik Adress : Fulda,leipzigerstrasse,1 Phone number : +4964169865172 -Employee 2 + Name : Can -last name : Hacioglu +Last name : Hacioglu Adress : Fulda,leipzigerstrasse,2 Phone number : +4915973325487 -Employee 3 + Name : Haytham -last name : Daoula +Last name : Daoula Adress : Fulda,leipzigerstrasse,3 Phone number : +4995435870169 -Employee 4 + Name : Julius -last name : Engel +Last name : Engel Adress : Fulda,leipzigerstrasse,4 Phone number : +4939172972187 -Employee 5 + Name : Mohamed -last name : Dahi +Last name : Dahi Adress : Fulda,leipzigerstrasse,5 Phone number : +4921865106647 -Employee 6 + Name : Shivam -last name : Chaudhary +Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 -Phone number : +4918756871384 \ No newline at end of file +Phone number : +4918756871384 + + + + diff --git a/src/mainMenu.c b/src/mainMenu.c index b7a8594..fdc2f21 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -27,7 +27,7 @@ bool checkIfInteger(char* userInput) bool chooseOption(int choiceInput) { - return !(choiceInput < 1 || choiceInput > 4); + return !(choiceInput < 1 || choiceInput > 5); } diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 1f4d3b2..df336c1 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -142,6 +142,34 @@ void test_verifyPasswordFailure() 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) diff --git a/tests/test_mainMenu.c b/tests/test_mainMenu.c index 4883180..97cc069 100644 --- a/tests/test_mainMenu.c +++ b/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; } /*Act and Asssert*/ - for(int i = 0; i < 4; i++) + for(int i = 0; i < 5; i++) { bool validInputResult = chooseOption(validInput[i]); @@ -197,7 +197,7 @@ void test_invalidChoiceInput_secondCase(void) for(int i = 0; i < 100; i++) { - invalidInput[i] = i + 5; + invalidInput[i] = i + 6; } /*Act and Assert*/