Browse Source
implement unit tests for the checkEmployeeCredentials() function.
remotes/origin/feature/the-main-menu
implement unit tests for the checkEmployeeCredentials() function.
remotes/origin/feature/the-main-menu
fdai7207
2 years ago
7 changed files with 198 additions and 2 deletions
-
2build-project.sh
-
12src/employeeList.txt
-
22src/employeeLogin.c
-
16src/employeeLogin.h
-
BINsrc/main
-
146test/test_employeeLogin.c
-
2test/test_mainMenu.c
@ -1,6 +1,6 @@ |
|||||
clear |
clear |
||||
ceedling test:all |
ceedling test:all |
||||
cd src/ |
cd src/ |
||||
gcc -o main main.c mainMenu.c |
|
||||
|
gcc main.c mainMenu.c -o main |
||||
./main |
./main |
||||
rm main |
rm main |
@ -0,0 +1,12 @@ |
|||||
|
Atharva Atharvafdai7514 |
||||
|
|
||||
|
Can BlooMaskfdlt3817 |
||||
|
|
||||
|
Haytham TimoDLfdai7207 |
||||
|
|
||||
|
Julius Insertcatfdai7057 |
||||
|
|
||||
|
Mohamed MDfdai6618 |
||||
|
|
||||
|
Shivam Schivam007fdlt3781 |
||||
|
|
@ -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; |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#ifndef EMPLOYEELOGIN_H_ |
||||
|
#define EMPLOYEELOGIN_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
|
||||
|
#define credentialLength 20 |
||||
|
|
||||
|
|
||||
|
|
||||
|
int checkEmployeeCredentials(char* inputUsername , char* inputPassword); |
||||
|
|
||||
|
#endif |
||||
|
|
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue