From 14d97220d07505bae9a4919ec24d25d20c4cb124 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 01:25:05 +0100 Subject: [PATCH] implement unit tests for the checkEmployeeCredentials() function. --- build-project.sh | 2 +- src/employeeList.txt | 12 ++++ src/employeeLogin.c | 22 ++++++ src/employeeLogin.h | 16 +++++ src/main | Bin 0 -> 16408 bytes test/test_employeeLogin.c | 146 ++++++++++++++++++++++++++++++++++++++ test/test_mainMenu.c | 2 +- 7 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 src/employeeList.txt create mode 100644 src/employeeLogin.c create mode 100644 src/employeeLogin.h create mode 100755 src/main create mode 100644 test/test_employeeLogin.c 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 0000000000000000000000000000000000000000..fad988bb3623d9069264d63cdfeaecddd9fa83f8 GIT binary patch literal 16408 zcmeHOdvH|M89y5cga{-cAP<#`LI>((Ng{**0(lVFAOQ-fSi$Sf?%iZ%vp4SEg~So1 z1zR&TmOh<2j>YM8WcnI)9EaLh5R2F<6FSxMhtsC5w3|U~och3uY=7T5=iA)9Ce!L4 z{iCxdv-dmS?|Yo@eCOVqbMHOpzNU@qiUI+_WsF!Yh&x=akUA~cQL8H;b)r^G!f~#+ zT8slfR$@wCrwF8~oGr?yB^n*wVJdV#$gY?~n)lN) z+9^|(=h`#K7{!ps96hM*n0oCfH~ke#zkgLeZP$6})RgUrCA$G_H=ylulma5Trkqa- zgMPI-pMGjUM#YdvA^dhbw4I->)%r}S4JzBtxsgxP-WF|l>>B0APj@O2Rq8k ze_ME%x9avr8;44rf2KOEVsSjyTC-$vJW>&lCDL6LU9~k8HA{jiCs-{*ptz_FI;Yle zx=9r67kz}WJ=Le-M`N7sOfBEA7n#1R7jss3F4_< ziXZ8y{(k{Ag%LetpY9+!TA>)Gjv(9v%oqWuc1F@)Itu=E;0AvFLa~nIXVNJ64WrUL!6zjD z1LA3_Hh4txp9dd33|^M1H=BFT+#c%rOX$GsLtC~tRrOW980uYh8p7=KGN`^24VKM4 zD0L|w$nF9f>Mg#L$np#Bbadyfpz6+q>_FMv{iJ+CQ|Q-A{iQ32EV>lx844YLYfb3* zg)yPP$kPN{t0OSZG?4Ee`0g$K6CO3toC>#;+w3_B(STPpmqfiS84AQ3 z=HEY(u7+f&2zvqgf3VM80)7b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