Browse Source

implement unit tests for the function isValidEmployeeID()

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
906ee12708
  1. 20
      build-project.sh
  2. 20
      src/createEmployeeAccount.c
  3. 10
      src/createEmployeeAccount.h
  4. 1
      src/employeeList.txt
  5. 17
      src/employeeLogin.c
  6. 7
      src/employeeLogin.h
  7. 2
      src/main.c
  8. 9
      src/mainMenu.c
  9. 47
      src/showGeneralInfoEmployee.c
  10. 3
      src/showGeneralInfoEmployee.h
  11. 62
      tests/test_createEmployeeAccount.c
  12. 26
      tests/test_showGeneralInfoEmployee.c

20
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/

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

10
src/createEmployeeAccount.h

@ -0,0 +1,10 @@
#ifndef CREATEEMPLOYEEACCOUNT_H_
#define CREATEEMPLOYEEACCOUNT_H_
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
bool isValidEmployeeID(char* employee);
#endif

1
src/employeeList.txt

@ -10,3 +10,4 @@ Mohamed MDfdai6618
Shivam Schivam007fdlt3781

17
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);
}

7
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<stdbool.h>
bool employeesAccess(char* employeesAccessCode);
int checkEmployeeCredentials(char* username , char* password);
void getEmployeeAccessCode();
void getEmployeeCredentials(char* username, char* password);
void loginAsEmployee();
#endif

2
src/main.c

@ -1,4 +1,6 @@
#include "mainMenu.h"
#include "employeeLogin.h"
#include"showGeneralInfoEmployee.h"
int main()
{

9
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()
}

47
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");
}
}

3
src/showGeneralInfoEmployee.h

@ -5,7 +5,8 @@
#include <stdlib.h>
#include <string.h>
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

62
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

26
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
}

Loading…
Cancel
Save