Browse Source

implement unit tests for the checkEmployeeCredentials() function.

remotes/origin/feature/the-main-menu
fdai7207 2 years ago
parent
commit
14d97220d0
  1. 2
      build-project.sh
  2. 12
      src/employeeList.txt
  3. 22
      src/employeeLogin.c
  4. 16
      src/employeeLogin.h
  5. BIN
      src/main
  6. 146
      test/test_employeeLogin.c
  7. 2
      test/test_mainMenu.c

2
build-project.sh

@ -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

12
src/employeeList.txt

@ -0,0 +1,12 @@
Atharva Atharvafdai7514
Can BlooMaskfdlt3817
Haytham TimoDLfdai7207
Julius Insertcatfdai7057
Mohamed MDfdai6618
Shivam Schivam007fdlt3781

22
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;
}

16
src/employeeLogin.h

@ -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

BIN
src/main

146
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

2
test/test_mainMenu.c

@ -28,7 +28,7 @@ void test_agePermissionValidAge(void)
for(int i =0; i < 83; i++){ for(int i =0; i < 83; i++){
validAgeResult[i]= Age + i;
validAgeResult[i]= agePermission(Age + i);
} }

Loading…
Cancel
Save