diff --git a/build-project.sh b/build-project.sh index 3aac8dc..26458c7 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,13 +1,27 @@ -trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; rm employeeLogin.c.bak; cd ..; rm -r build/; exit' SIGINT +trap 'echo "Interrupted"; + rm main; + cp employeeLogin.c.bak employeeLogin.c; + cp mainMenu.c.bak mainMenu.c; + rm employeeLogin.c.bak; + rm mainMenu.c.bak; + cd ..; + rm -r build; exit' SIGINT clear -ceedling test:all +ceedling test:all + cd src/ cp employeeLogin.c employeeLogin.c.bak +cp mainMenu.c mainMenu.c.bak +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 -o main +gcc main.c mainMenu.c employeeLogin.c showGeneralInfoEmployee.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 cd .. rm -r build/ diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c new file mode 100644 index 0000000..22253a3 --- /dev/null +++ b/src/createEmployeeAccount.c @@ -0,0 +1,20 @@ +#include "employeeLogin.c" +#include "employeeLogin.h" +#include "createEmployeeAccount.h" + + +bool isValidEmployeeID(char* employeeId) +{ + int characterLimit = 20; + + if(strlen(employeeId)>characterLimit || strchr(employeeId,' ')) + { + return false; + } + + else + { + return true; + } +} + diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h new file mode 100644 index 0000000..4bdb783 --- /dev/null +++ b/src/createEmployeeAccount.h @@ -0,0 +1,10 @@ +#ifndef CREATEEMPLOYEEACCOUNT_H_ +#define CREATEEMPLOYEEACCOUNT_H_ + +#include +#include +#include +#include + +bool isValidEmployeeID(char* employee); +#endif \ No newline at end of file diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..c9e8c0b 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -10,3 +10,4 @@ Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + diff --git a/src/employeeLogin.c b/src/employeeLogin.c index a27e71d..e26e910 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,7 +1,8 @@ #include "mainMenu.h" -#include "employeeLogin.h" +#include"employeeLogin.h" #include "showGeneralInfoEmployee.c" + bool employeesAccess(char* employeesAccessCode) { @@ -58,7 +59,8 @@ void getEmployeeAccessCode() while(remainingAttempts > 0) { - scanf("%s",accessCode); + scanf("%s",accessCode); + if(employeesAccess(accessCode)) { @@ -68,8 +70,8 @@ void getEmployeeAccessCode() break; } - - else + + else if(!(employeesAccess(accessCode))) { printf("\n\nAccess key didnt match! try again !\n\n"); --remainingAttempts; @@ -87,6 +89,7 @@ void getEmployeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); scanf("%s", inputUsername); + printf("Enter password: "); scanf("%s", inputPassword); } @@ -113,8 +116,8 @@ void loginAsEmployee() printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); --counter; } - else - { + else + { printf("\n\nUser Approved\n\n"); showGeneralInfoEmployee(username, password); break; @@ -132,3 +135,5 @@ void loginAsEmployee() free(password); } + + diff --git a/src/employeeLogin.h b/src/employeeLogin.h index d6f3314..ca918a7 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,5 +1,5 @@ -#ifndef LOGINEMPLOYEE_H_ -#define LOGINEMPLOYEE_H_ +#ifndef EMPLOYEELOGIN_H_ +#define EMPLOYEELOGIN_H_ #define employeeAccessKey "DF9E9A8B5E" #define credentialLength 20 @@ -7,12 +7,13 @@ #include bool employeesAccess(char* employeesAccessCode); - int checkEmployeeCredentials(char* username , char* password); +void getEmployeeAccessCode(); void getEmployeeCredentials(char* username, char* password); void loginAsEmployee(); + #endif diff --git a/src/main.c b/src/main.c index 7032d5b..48041ae 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,6 @@ #include "mainMenu.h" +#include "employeeLogin.h" +#include"showGeneralInfoEmployee.h" int main() { diff --git a/src/mainMenu.c b/src/mainMenu.c index b2d8243..e62e11d 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -2,6 +2,8 @@ #include "employeeLogin.c" + + bool agePermission(int age) { @@ -54,7 +56,7 @@ void ageInput() showMenu(); - menuInput(); + menuInput(); break; @@ -95,7 +97,7 @@ void menuInput() printf("Input invalid! try again!\n"); scanf("%s", choiceInput); - + selection = strtol(choiceInput, &choiceInputPointer, 10); } @@ -131,3 +133,6 @@ void showMenu() } + + + diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 25355c9..8e881f2 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -46,8 +46,8 @@ void showGeneralInfoEmployee(char id[length], char password[length]) if(checkUser(id, password) == 1) { - printf(" Welcome Atharva\n"); - printf(" Clearance: 3\n"); + printf(" Welcome Atharva\n"); + printf(" Clearance: 3\n"); printf("\n"); printf("\n"); printf(" ->Review new customer applications.\n"); @@ -55,53 +55,54 @@ void showGeneralInfoEmployee(char id[length], char password[length]) if(checkUser(id, password) == 2) { - printf(" Welcome Can\n"); - printf(" Clearance: 3\n"); + printf(" Welcome Can\n"); + printf(" Clearance: 3\n"); printf("\n"); printf("\n"); - printf(" ->Review new customer applications.\n"); + printf(" ->Review new customer applications.\n"); } if(checkUser(id, password) == 3) { - printf(" Welcome Haytham\n"); - printf(" Clearance: 2\n"); + printf(" Welcome Haytham\n"); + printf(" Clearance: 2\n"); printf("\n"); printf("\n"); - printf(" ->Review new customer applications.\n"); - printf(" ->Review loan applications.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); } if(checkUser(id, password) == 4) { - printf(" Welcome Julius\n"); - printf(" Clearance: 2\n"); + printf(" Welcome Julius\n"); + printf(" Clearance: 2\n"); printf("\n"); printf("\n"); - printf(" ->Review new customer applications.\n"); - printf(" ->Review loan applications.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); } if(checkUser(id, password) == 5) { - printf(" Welcome Mohamed\n"); - printf(" Clearance: 3\n"); + printf(" Welcome Mohamed\n"); + printf(" Clearance: 1\n"); printf("\n"); printf("\n"); - printf(" ->Review new customer applications.\n"); - printf(" ->Review loan applications.\n"); - printf(" ->Terminate account.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); } if(checkUser(id, password) == 6) { - printf(" Welcome Shivam\n"); - printf(" Clearance: 3\n"); + printf(" Welcome Shivam\n"); + printf(" Clearance: 1\n"); printf("\n"); printf("\n"); - printf(" ->Review new customer applications.\n"); - printf(" ->Review loan applications.\n"); - printf(" ->Terminate account.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); } } + diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h index bfedbbe..65165f1 100644 --- a/src/showGeneralInfoEmployee.h +++ b/src/showGeneralInfoEmployee.h @@ -5,7 +5,8 @@ #include #include -const int length = 100; +#define length 20 + int checkUser(char username[length], char password[length]); void showGeneralInfoEmployee(char id[length], char password[length]); #endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c new file mode 100644 index 0000000..f53d86c --- /dev/null +++ b/tests/test_createEmployeeAccount.c @@ -0,0 +1,62 @@ +#ifdef TEST + +#include "unity.h" + +#include "createEmployeeAccount.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_isValidEmployeeID(void) +{ + + /*Arrange*/ + + char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; + bool validEmployeeIdResult[15]; + + /*Act*/ + + for(int i=0; i<15; i++) + { + validEmployeeIdResult[i] = isValidEmployeeID(validEmployeeId[i]); + } + + /*Assert*/ + + for(int i =0; i<15;i++) + { + TEST_ASSERT_TRUE(validEmployeeIdResult[i]); + } +} + +void test_isNotValidEmployeeID(void) +{ + + /*Arrange*/ + + char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; + bool invalidEmployeeIdResult[6]; + + /*Act*/ + + for(int i=0; i<6; i++) + { + invalidEmployeeIdResult[i] = isValidEmployeeID(invalidEmployeeId[i]); + } + + /*Assert*/ + + for(int i =0; i<6;i++) + { + TEST_ASSERT_FALSE(invalidEmployeeIdResult[i]); + } + +} + +#endif // TEST diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 0d1084c..c28c306 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "showGeneralInfoEmployee.c" +#include "showGeneralInfoEmployee.h" void setUp(void) { @@ -15,43 +15,43 @@ void tearDown(void) void test1_showGeneralInfoEmployee(void) { - char employeeName[] = "Atharva"; //Arrange - char password[] = "Atharvafdai7514"; + char employeeName[20] = "Atharva"; //Arrange + char password[20] = "Atharvafdai7514"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert } void test2_showGeneralInfoEmployee(void) { - char employeeName[] = "Can"; //Arrange - char password[] = "BlooMaskfdlt3817"; + char employeeName[20] = "Can"; //Arrange + char password[20] = "BlooMaskfdlt3817"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert } void test3_showGeneralInfoEmployee(void) { - char employeeName[] = "Haytham"; //Arrange - char password[] = "TimoDLfdai7207"; + char employeeName[20] = "Haytham"; //Arrange + char password[20] = "TimoDLfdai7207"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert } void test4_showGeneralInfoEmployee(void) { - char employeeName[] = "Julius"; //Arrange - char password[] = "Insertcatfdai7057"; + char employeeName[20] = "Julius"; //Arrange + char password[20] = "Insertcatfdai7057"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert } void test5_showGeneralInfoEmployee(void) { - char employeeName[] = "Mohamed"; //Arrange - char password[] = "MDfdai6618"; + char employeeName[20] = "Mohamed"; //Arrange + char password[20] = "MDfdai6618"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert } void test6_showGeneralInfoEmployee(void) { - char employeeName[] = "Shivam"; //Arrange - char password[] = "Schivam007fdlt3781"; + char employeeName[20] = "Shivam"; //Arrange + char password[20] = "Schivam007fdlt3781"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert }