diff --git a/build-project.sh b/build-project.sh index 26458c7..aca0b67 100755 --- a/build-project.sh +++ b/build-project.sh @@ -2,26 +2,50 @@ trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; cp mainMenu.c.bak mainMenu.c; + cp createEmployeeAccount.c.bak createEmployeeAccount.c; rm employeeLogin.c.bak; rm mainMenu.c.bak; + rm createEmployeeAccount.c.bak; cd ..; rm -r build; exit' SIGINT clear ceedling test:all + cd src/ -cp employeeLogin.c employeeLogin.c.bak -cp mainMenu.c mainMenu.c.bak + +sed '/John Doe/,$d' employeeList.txt > temp.txt +mv temp.txt employeeList.txt +# backup files +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do + cp "$file" "$file.bak" +done + +# replace .c with .h in respective files sed -i 's/employeeLogin.c/employeeLogin.h/g' mainMenu.c sed -i 's/showGeneralInfoEmployee.c/showGeneralInfoEmployee.h/g' employeeLogin.c sed -i 's/mainMenu.c/mainMenu.h/g' employeeLogin.c -sed -i 's/src\///g' employeeLogin.c -gcc main.c mainMenu.c employeeLogin.c showGeneralInfoEmployee.c -o main +sed -i 's/employeeLogin.c/employeeLogin.h/g' createEmployeeAccount.c + +# remove 'src/' +for file in employeeLogin.c createEmployeeAccount.c; do + sed -i 's/src\///g' "$file" +done + +# compile and run program +gcc main.c mainMenu.c employeeLogin.c showGeneralInfoEmployee.c createEmployeeAccount.c -o main ./main rm main -cp employeeLogin.c.bak employeeLogin.c -cp mainMenu.c.bak mainMenu.c -rm employeeLogin.c.bak -rm mainMenu.c.bak + +# restore backups +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do + cp "$file.bak" "$file" +done + +# remove backups +for file in employeeLogin.c.bak mainMenu.c.bak createEmployeeAccount.c.bak; do + rm "$file" +done + cd .. rm -r build/ diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 22253a3..b2743ab 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -1,5 +1,5 @@ #include "employeeLogin.c" -#include "employeeLogin.h" + #include "createEmployeeAccount.h" @@ -18,3 +18,21 @@ bool isValidEmployeeID(char* employeeId) } } +bool createNewEmployee(char* employeeId, char* employeePassword) +{ + FILE* employeesList; + employeesList = fopen("src/employeeList.txt","a"); + + if(employeesList == NULL) + { + printf("Error: could not open the list of Employees"); + return false; + } + + fprintf(employeesList,"\n%s %s\n",employeeId,employeePassword); + fclose(employeesList); + + + return checkEmployeeCredentials(employeeId, employeePassword); +} + diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 4bdb783..4bb2df2 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -7,4 +7,6 @@ #include bool isValidEmployeeID(char* employee); +bool createNewEmployee(char* employeeId, char* employeePassword); + #endif \ No newline at end of file diff --git a/src/employeeList.txt b/src/employeeList.txt index c9e8c0b..1e66ce6 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -11,3 +11,5 @@ Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + + diff --git a/src/employeeLogin.c b/src/employeeLogin.c index e26e910..b9cc3da 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,5 +1,5 @@ #include "mainMenu.h" -#include"employeeLogin.h" +#include "employeeLogin.h" #include "showGeneralInfoEmployee.c" diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index f53d86c..fb6f768 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -59,4 +59,35 @@ void test_isNotValidEmployeeID(void) } +void test_employeeCreatedSuccessfully(void) +{ + /*Arrange*/ + char* potentialEmployees[][2] = { + {"John", "Doe"}, + {"Fizz", "Buzz"}, + {"Jane", "Doe"}, + {"Foo", "Bar"}, + {"MusterMann", "MusterManPassword"}, + {"MusterFrau", "MusterFrauPassword"} + }; + + bool expected[6] = {true,true,true,true,true,true}; + bool result[6]; + + /*Act*/ + + for(int i=0; i<6;i++) + { + result[i] = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); + } + + /*Assert*/ + + for(int i=0; i<6;i++) + { + TEST_ASSERT_EQUAL(expected[i],result[i]); + } + +} + #endif // TEST diff --git a/tests/test_employeeLogin.c b/tests/test_employeeLogin.c index 8860af5..87b9f27 100644 --- a/tests/test_employeeLogin.c +++ b/tests/test_employeeLogin.c @@ -84,12 +84,12 @@ void test_MissingLoginEmployee(void) /*Arrange*/ char* missingEmployeesCredentials[][2] = { - {"John", "doe"}, - {"Jane", "Doe"}, - {"Foo", "Bar"}, - {"Fizz", "Buzz"}, - {"Musterman", "Mustermanpassword"}, - {"Musterfrau", "Musterfraupassword"} + {"Germany", "Berlin"}, + {"Italy", "Rome"}, + {"Belgium", "Bruxelle"}, + {"Swizerland", "Geneve"}, + {"Netherlands", "Amsterdam"}, + {"Sweden", "Stockholm"} }; int expected[] = {0,0,0,0,0,0};