From 46223938440dbb9a27703f4a496c38d8405b1445 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 23:28:17 +0100 Subject: [PATCH] implement unit tests for the function employeesAccess(). --- src/employeeLogin.c | 15 ++++++++++++ src/employeeLogin.h | 7 +++++- test/.test_employeeLogin.c.swp | Bin 16384 -> 0 bytes test/test_employeeLogin.c | 41 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) delete mode 100644 test/.test_employeeLogin.c.swp diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 0d44ddf..dfcac61 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,6 +1,21 @@ #include "mainMenu.h" #include "employeeLogin.h" +bool employeesAccess(char* employeesAccessCode) +{ + + if(strcmp(employeesAccessCode,accessKey) == 0) + { + return true; + } + + else + { + return false; + } + +} + extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { diff --git a/src/employeeLogin.h b/src/employeeLogin.h index 485955f..dd77acc 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,10 +1,15 @@ #ifndef LOGINEMPLOYEE_H_ #define LOGINEMPLOYEE_H_ - +#define accessKey "DF9E9A8B5E" #define credentialLength 20 +#include + +bool employeesAccess(char* employeesAccessCode); + int checkEmployeeCredentials(char* username , char* password); + void employeeCredentials(char* username, char* password); void loginAsEmployee(); diff --git a/test/.test_employeeLogin.c.swp b/test/.test_employeeLogin.c.swp deleted file mode 100644 index 77752368280750880b47ea9f9ce5e66997e1bc68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3TZ|J`7{`xzfmIh#qVhNv5*H}j3$nYq+zMU8E?X7al_+kSVP?7=ww>9`Oc!@+ z4old(g(`pRrIh)^1 zr{_E0IrGi`oar|VyQ23Gr-VCuqXcCUA?EQj(x+<)`C}O&d2zUfMz^`)WPgvB?F1#8Q#cm#L^cm#L^cm#L^cm#L^cm#L^ z{u2?frsk2o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+7x%jo%2k#>9eg{;*BVZbofCY8~UU&p}1b75^1b75^ z1b75^1b754>j>oVc!mAcu71F9kzoW+Otbd$Px`#ldlbrCP&d8=wLt&FY{GOi(H`~y z$E;=>S+`=Y6g8-Ar`c-tG}zOqYR(#t`LfoC|G{Z{IctktwJ!6VBS)>XXvj_L>g#e+ zR!gr(du6U%l)74~Xfl1UcZrKa&D0uUIS)JLe$Wwh)YIoY&u+B(pSkm$uJ0g&1k|3T PbwT>~S~ZTGDwX^R=7EM0 diff --git a/test/test_employeeLogin.c b/test/test_employeeLogin.c index 8e2d8de..e29bf5d 100644 --- a/test/test_employeeLogin.c +++ b/test/test_employeeLogin.c @@ -108,4 +108,45 @@ void test_MissingLoginEmployee(void) } +void test_validEmployeeAccessCode(void) +{ + //test case 0 + + /*Arrange*/ + + char validAccesscode[11] = "DF9E9A8B5E"; + + /*Act*/ + bool validAccessCodeResult = employeesAccess(validAccesscode); + + /*Assert*/ + + TEST_ASSERT_TRUE(validAccessCodeResult); + +} + +void test_invalidEmployeeAccessCode(void) +{ + //test case 1 + + /*Arrange*/ + + char* invalidAccessCode[] = {"15","foo","fizz","buzz","fizzbuzz","test","bankmanagement"}; + bool invalidCodeResults[7]; + + /*Act*/ + + for(int i=0;i<7;i++) + { + invalidCodeResults[i] = employeesAccess(invalidAccessCode[i]); + } + + /*Assert*/ + + for(int i=0;i<7;i++) + { + TEST_ASSERT_FALSE(invalidCodeResults[i]); + } +} + #endif // TEST