diff --git a/build-project.sh b/build-project.sh index ea712c3..420b964 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,6 @@ clear ceedling test:all cd src/ -gcc -o main main.c mainMenu.c +gcc main.c mainMenu.c -o main ./main rm main diff --git a/src/employeeList.txt b/src/employeeList.txt new file mode 100644 index 0000000..94986be --- /dev/null +++ b/src/employeeList.txt @@ -0,0 +1,12 @@ +Atharva Atharvafdai7514 + +Can BlooMaskfdlt3817 + +Haytham TimoDLfdai7207 + +Julius Insertcatfdai7057 + +Mohamed MDfdai6618 + +Shivam Schivam007fdlt3781 + diff --git a/src/employeeLogin.c b/src/employeeLogin.c new file mode 100644 index 0000000..542526f --- /dev/null +++ b/src/employeeLogin.c @@ -0,0 +1,22 @@ +#include "employeeLogin.h" + +int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +{ + + char listUsername[credentialLength]; + char listPassword[credentialLength]; + + FILE *employeeList = fopen("src/employeeList.txt", "r"); + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) { + if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) { + fclose(employeeList); + return 1; + } + else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0){ + fclose(employeeList); + return 2; + } + } + fclose(employeeList); + return 0; +} diff --git a/src/employeeLogin.h b/src/employeeLogin.h new file mode 100644 index 0000000..6e4cb65 --- /dev/null +++ b/src/employeeLogin.h @@ -0,0 +1,16 @@ +#ifndef EMPLOYEELOGIN_H_ +#define EMPLOYEELOGIN_H_ + +#include +#include +#include +#include + +#define credentialLength 20 + + + +int checkEmployeeCredentials(char* inputUsername , char* inputPassword); + +#endif + diff --git a/src/main b/src/main new file mode 100755 index 0000000..fad988b Binary files /dev/null and b/src/main differ diff --git a/test/test_employeeLogin.c b/test/test_employeeLogin.c new file mode 100644 index 0000000..5cfdfdf --- /dev/null +++ b/test/test_employeeLogin.c @@ -0,0 +1,146 @@ +#ifdef TEST + +#include "unity.h" + +#include "employeeLogin.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_SuccessfulLoginEmployee_(void) +{ + + //test case : 0 + + //Arrange + char* ExistingEmployee1 = "Atharva"; + char* ExistingPassword1 = "Atharvafdai7514"; + + char* ExistingEmployee2 = "Can"; + char* ExistingPassword2 = "BlooMaskfdlt3817"; + + char* ExistingEmployee3 = "Haytham"; + char* ExistingPassword3 = "TimoDLfdai7207"; + + char* ExistingEmployee4 = "Julius"; + char* ExistingPassword4 = "Insertcatfdai7057"; + + char* ExistingEmployee5 = "Mohamed"; + char* ExistingPassword5 = "MDfdai6618"; + + char* ExistingEmployee6 = "Shivam"; + char* ExistingPassword6 = "Schivam007fdlt3781"; + + //Act + + int result1 = checkEmployeeCredentials(ExistingEmployee1,ExistingPassword1); + int result2 = checkEmployeeCredentials(ExistingEmployee2,ExistingPassword2); + int result3 = checkEmployeeCredentials(ExistingEmployee3,ExistingPassword3); + int result4 = checkEmployeeCredentials(ExistingEmployee4,ExistingPassword4); + int result5 = checkEmployeeCredentials(ExistingEmployee5,ExistingPassword5); + int result6 = checkEmployeeCredentials(ExistingEmployee6,ExistingPassword6); + + //Assert + + TEST_ASSERT_EQUAL_INT(1,result1); + TEST_ASSERT_EQUAL_INT(1,result2); + TEST_ASSERT_EQUAL_INT(1,result3); + TEST_ASSERT_EQUAL_INT(1,result4); + TEST_ASSERT_EQUAL_INT(1,result5); + TEST_ASSERT_EQUAL_INT(1,result6); + +} + +void test_WrongInfosLoginEmployee(void) +{ + //test case : 1 + + //Arrange + char* wrongInfoEmployee1 = "Atharva"; + char* wrongInfoPassword1 = "doe"; + + char* wrongInfoEmployee2 = "Can"; + char* wrongInfoPassword2 = "Bar"; + + char* wrongInfoEmployee3 = "Haytham"; + char* wrongInfoPassword3 = "buzz"; + + char* wrongInfoEmployee4 = "Julius"; + char* wrongInfoPassword4 = "Musterpass"; + + char* wrongInfoEmployee5 = "Mohamed"; + char* wrongInfoPassword5 = "Irgendwas"; + + char* wrongInfoEmployee6 = "Shivam"; + char* wrongInfoPassword6 = "John"; + + //Act + + int result1 = checkEmployeeCredentials(wrongInfoEmployee1,wrongInfoPassword1); + int result2 = checkEmployeeCredentials(wrongInfoEmployee2,wrongInfoPassword2); + int result3 = checkEmployeeCredentials(wrongInfoEmployee3,wrongInfoPassword3); + int result4 = checkEmployeeCredentials(wrongInfoEmployee4,wrongInfoPassword4); + int result5 = checkEmployeeCredentials(wrongInfoEmployee5,wrongInfoPassword5); + int result6 = checkEmployeeCredentials(wrongInfoEmployee6,wrongInfoPassword6); + + //Assert + + TEST_ASSERT_EQUAL_INT(2,result1); + TEST_ASSERT_EQUAL_INT(2,result2); + TEST_ASSERT_EQUAL_INT(2,result3); + TEST_ASSERT_EQUAL_INT(2,result4); + TEST_ASSERT_EQUAL_INT(2,result5); + TEST_ASSERT_EQUAL_INT(2,result6); + + +} + +void test_MissingLoginEmployee(void) +{ + + //test case : 2 + + //Arrange + + char* missingEmployee1 = "John"; + char* missingPassword1 = "Doe"; + + char* missingEmployee2 = "Jane"; + char* missingPassword2 = "Doe"; + + char* missingEmployee3 = "Foo"; + char* missingPassword3 = "Bar"; + + char* missingEmployee4 = "Mustermann"; + char* missingPassword4 = "PassMustermann"; + + char* missingEmployee5 = "Musterfrau"; + char* missingPassword5 = "PassMusterfrau"; + + char* missingEmployee6 = "Fizz"; + char* missingPassword6 = "Buzz"; + + //Act + int result1 = checkEmployeeCredentials(missingEmployee1,missingPassword1); + int result2 = checkEmployeeCredentials(missingEmployee2,missingPassword2); + int result3 = checkEmployeeCredentials(missingEmployee3,missingPassword3); + int result4 = checkEmployeeCredentials(missingEmployee4,missingPassword4); + int result5 = checkEmployeeCredentials(missingEmployee5,missingPassword5); + int result6 = checkEmployeeCredentials(missingEmployee6,missingPassword6); + + //Assert + TEST_ASSERT_EQUAL_INT(0,result1); + TEST_ASSERT_EQUAL_INT(0,result2); + TEST_ASSERT_EQUAL_INT(0,result3); + TEST_ASSERT_EQUAL_INT(0,result4); + TEST_ASSERT_EQUAL_INT(0,result5); + TEST_ASSERT_EQUAL_INT(0,result6); + +} + +#endif // TEST diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index af93eaf..4883180 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -28,7 +28,7 @@ void test_agePermissionValidAge(void) for(int i =0; i < 83; i++){ - validAgeResult[i]= Age + i; + validAgeResult[i]= agePermission(Age + i); }