From 7b176305a3fa3cfde26f0efe2c03aec94da68be2 Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Sat, 28 Jan 2023 15:29:19 +0100 Subject: [PATCH 01/58] Initial commit --- .gitignore | 1 + build-project.sh | 5 +++++ src/main.c | 6 ++++++ team.md | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 .gitignore create mode 100644 build-project.sh create mode 100644 src/main.c create mode 100644 team.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/build-project.sh b/build-project.sh new file mode 100644 index 0000000..c75f560 --- /dev/null +++ b/build-project.sh @@ -0,0 +1,5 @@ +clear +cd src/ +gcc main.c +./a.out +rm a.out \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a6b9b24 --- /dev/null +++ b/src/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + + return 0; +} \ No newline at end of file diff --git a/team.md b/team.md new file mode 100644 index 0000000..f0e0a28 --- /dev/null +++ b/team.md @@ -0,0 +1,6 @@ +- Can Hacioglu, fdlt3817 +- Atharva Kishor Naik, fdai7514 +- Julius Philipp Engel, fdai7057 +- Shivam Chaudhary, fdlt3781 +- Mohamed Yahya Dahi, fdai6618 +- Haytham Daoula, fdai7207 \ No newline at end of file From c135603ed0fd1ccdba844b698ec7a3999221769b Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 28 Jan 2023 21:38:46 +0100 Subject: [PATCH 02/58] implement unit tests for the functions agePermission() and checkIfInteger() --- build-project.sh | 5 +- project.yml | 101 +++++++++++++++++++++++++++++ src/main.c | 2 +- src/mainMenu.c | 42 +++++++++++++ src/mainMenu.h | 13 ++++ test/support/.gitkeep | 0 test/test_mainMenu.c | 143 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 303 insertions(+), 3 deletions(-) mode change 100644 => 100755 build-project.sh create mode 100644 project.yml create mode 100644 src/mainMenu.c create mode 100644 src/mainMenu.h create mode 100644 test/support/.gitkeep create mode 100644 test/test_mainMenu.c diff --git a/build-project.sh b/build-project.sh old mode 100644 new mode 100755 index c75f560..4247c59 --- a/build-project.sh +++ b/build-project.sh @@ -1,5 +1,6 @@ clear +ceedling test:all cd src/ -gcc main.c +gcc main.c mainMenu.c ./a.out -rm a.out \ No newline at end of file +rm a.out diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..e253248 --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:test/** + - -:test/support + :source: + - src/** + :support: + - test/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/main.c b/src/main.c index a6b9b24..3f845e6 100644 --- a/src/main.c +++ b/src/main.c @@ -3,4 +3,4 @@ int main() { return 0; -} \ No newline at end of file +} diff --git a/src/mainMenu.c b/src/mainMenu.c new file mode 100644 index 0000000..54d20ad --- /dev/null +++ b/src/mainMenu.c @@ -0,0 +1,42 @@ +#include"mainMenu.h" + + +bool agePermission(int age){ + + if(age >= 18) + { + + return true; + + } + + else + { + + return false; + + } + +} + +bool checkIfInteger(char* input){ + + char *end_pointer; + + strtol(input, &end_pointer, 10); + + if (end_pointer == input || *end_pointer != '\0') + { + + return false; + + } + + else + { + + return true; + + } +} + diff --git a/src/mainMenu.h b/src/mainMenu.h new file mode 100644 index 0000000..61192be --- /dev/null +++ b/src/mainMenu.h @@ -0,0 +1,13 @@ +#ifndef MAINMENU_H_ +#define MAINMENU_H_ + +#include +#include +#include +#include + +bool agePermission(int age); +bool checkIfInteger(char* userInput); + +#endif + diff --git a/test/support/.gitkeep b/test/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c new file mode 100644 index 0000000..515237d --- /dev/null +++ b/test/test_mainMenu.c @@ -0,0 +1,143 @@ +#ifdef TEST + +#include "unity.h" + +#include "mainMenu.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} +void test_agePermissionValidAge(void) +{ + //Test case : 0 + + //Arrange + + int validAge[83]; + + bool validAgeResult[83]; + + int j=0; + + for(int i =18;i<101;i++){ + + validAge[j]= i; + j++; + } + + //Act + + for(int i=0;i<83;i++){ + + validAgeResult[i] = agePermission(validAge[i]); + } + + //Assert + + for(int i=0;i<83;i++){ + + TEST_ASSERT_TRUE(validAgeResult[i]); + + } + +} + +void test_agePermissionInvalidAge(void) +{ + + //Test case : 1 + + //Arrange + + int invalidAge[117]; + + bool invalidAgeResult[117]; + + int j=0; + + for(int i =-100;i<18;i++){ + + invalidAge[j]= i; + j++; + } + + //Act + + for(int i=0;i<117;i++){ + + invalidAgeResult[i] = agePermission(invalidAge[i]); + + } + + //Assert + + for(int i=0;i<117;i++){ + + TEST_ASSERT_FALSE(invalidAgeResult[i]); + + } + +} + +void test_IsInteger(void) +{ + + //Arrange + + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + bool inputIsIntegerResult[19]; + + //Act + + for(int i=0;i<19;i++) + { + + inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); + + } + + //Assert + + for(int i=0;i<19;i++) + { + + TEST_ASSERT_TRUE(inputIsIntegerResult[i]); + + } + +} + +void test_IsNotInteger(void) +{ + + //Arrange + + char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; + + bool inputIsNotIntegerResult[19]; + + //Act + + for(int i=0;i<19;i++) + { + + inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); + + } + + //Assert + + for(int i=0;i<19;i++) + { + + TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]); + + } + +} +#endif // TEST From dcee631e6b743f9d08c96bf0945cc97291f714ff Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 00:00:06 +0100 Subject: [PATCH 03/58] implement the functions ageInput() and showMenu() to execute mainMenu.c . --- build-project.sh | 6 ++--- src/main.c | 4 +++- src/mainMenu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ src/mainMenu.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/build-project.sh b/build-project.sh index 4247c59..ea712c3 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,6 @@ clear ceedling test:all cd src/ -gcc main.c mainMenu.c -./a.out -rm a.out +gcc -o main main.c mainMenu.c +./main +rm main diff --git a/src/main.c b/src/main.c index 3f845e6..b37734e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ -#include +#include "mainMenu.h" int main() { + + ageInput(); return 0; } diff --git a/src/mainMenu.c b/src/mainMenu.c index 54d20ad..9cd19c0 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -39,4 +39,63 @@ bool checkIfInteger(char* input){ } } +void ageInput(){ + char input[20]; + char* input_pointer; + + long age; + + printf("\nPlease specify your age : "); + scanf("%s",input); + + + while (true) + { + age = strtol(input,&input_pointer,10); + + if(checkIfInteger(input) == true && agePermission(age)== true) + { + age = strtol(input,&input_pointer,10); + + printf("Access granted!\n\n\n\n"); + + showMenu(); + + break; + + } + + else if(checkIfInteger(input) == true && agePermission(age)== false) + { + + printf("You should be at least 18 years old to create a bank account!\n"); + + break; + + } + + else + { + printf("input invalid! try again!\n"); + + scanf("%s",input); + + } + + } + +} + + +void showMenu(){ + + printf("\t\t\t\t\t\t\t Welcome to Bank Manager!"); + printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!"); + printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer."); + printf("\n\n\t\t\t\t\t\t ->Register as a new costumer."); + printf("\n\n\t\t\t\t\t\t ->Login as an Employee."); + printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n"); + printf("\n\n\n\n\n Selection :\n"); + +} diff --git a/src/mainMenu.h b/src/mainMenu.h index 61192be..ccc7d9c 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -9,5 +9,8 @@ bool agePermission(int age); bool checkIfInteger(char* userInput); +void ageInput(); +void showMenu(); + #endif From cf756de8b96281c35aa2efb3dd8912357c69c3b2 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 00:25:24 +0100 Subject: [PATCH 04/58] refactoring: changed some variable names, made code more readable and enhanced some functions --- src/mainMenu.c | 59 ++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/mainMenu.c b/src/mainMenu.c index 9cd19c0..dd249fc 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,62 +1,44 @@ #include"mainMenu.h" -bool agePermission(int age){ +bool agePermission(int age) +{ - if(age >= 18) - { - - return true; - - } - - else - { - - return false; - - } + return age >= 18; } -bool checkIfInteger(char* input){ - - char *end_pointer; - - strtol(input, &end_pointer, 10); - - if (end_pointer == input || *end_pointer != '\0') - { +bool checkIfInteger(char* userInput) +{ - return false; + char *endPointer; - } + /*the endPointer points to the first non-integer character signaled to stop conversion*/ - else - { + strtol(userInput, &endPointer, 10); - return true; + return !(endPointer == userInput || *endPointer != '\0'); - } } -void ageInput(){ +void ageInput() +{ - char input[20]; - char* input_pointer; + char* userInput = malloc(20*sizeof(char*)); + char* userInputPointer; long age; printf("\nPlease specify your age : "); - scanf("%s",input); + scanf("%s",userInput); while (true) { - age = strtol(input,&input_pointer,10); + age = strtol(userInput,&userInputPointer,10); - if(checkIfInteger(input) == true && agePermission(age)== true) + if((checkIfInteger(userInput))&& (agePermission(age))) { - age = strtol(input,&input_pointer,10); + //age = strtol(userInput,&userInputPointer,10); printf("Access granted!\n\n\n\n"); @@ -66,7 +48,7 @@ void ageInput(){ } - else if(checkIfInteger(input) == true && agePermission(age)== false) + else if((checkIfInteger(userInput)) && !(agePermission(age))) { printf("You should be at least 18 years old to create a bank account!\n"); @@ -79,7 +61,7 @@ void ageInput(){ { printf("input invalid! try again!\n"); - scanf("%s",input); + scanf("%s",userInput); } @@ -88,7 +70,8 @@ void ageInput(){ } -void showMenu(){ +void showMenu() +{ printf("\t\t\t\t\t\t\t Welcome to Bank Manager!"); printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!"); From 8543ec2ec2705a60a59b5e5b92891ce30602985f Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 01:08:46 +0100 Subject: [PATCH 05/58] refactoring: removed redundant code in the unit tests to improve readability and maintainability. --- test/test_mainMenu.c | 142 +++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 78 deletions(-) diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index 515237d..eb93bb7 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -6,138 +6,124 @@ void setUp(void) { + } void tearDown(void) { + } + void test_agePermissionValidAge(void) { //Test case : 0 - //Arrange - - int validAge[83]; - - bool validAgeResult[83]; + /*Arrange*/ - int j=0; + int Age = 18; - for(int i =18;i<101;i++){ + bool validAgeResult[83]; - validAge[j]= i; - j++; - } - - //Act + /*Act*/ - for(int i=0;i<83;i++){ - - validAgeResult[i] = agePermission(validAge[i]); + for(int i =0;i<83;i++){ + + validAgeResult[i]= Age + i; } - - //Assert + + + /*Assert*/ for(int i=0;i<83;i++){ - - TEST_ASSERT_TRUE(validAgeResult[i]); - - } + TEST_ASSERT_TRUE(validAgeResult[i]); + + } + } void test_agePermissionInvalidAge(void) { //Test case : 1 - - //Arrange - + + /*Arrange*/ + int invalidAge[117]; - + bool invalidAgeResult[117]; - - int j=0; - - for(int i =-100;i<18;i++){ - - invalidAge[j]= i; - j++; + + + for(int i =-100;i<18;i++) + { + + invalidAge[i+100]= i; } - - //Act - - for(int i=0;i<117;i++){ - + + /*Act*/ + + for(int i=0;i<117;i++) + { + invalidAgeResult[i] = agePermission(invalidAge[i]); } - - //Assert - - for(int i=0;i<117;i++){ - + + /*Assert*/ + + for(int i=0;i<117;i++) + { + TEST_ASSERT_FALSE(invalidAgeResult[i]); - - } + + } } void test_IsInteger(void) { - - //Arrange - - char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; - bool inputIsIntegerResult[19]; + //test case 0 - //Act - - for(int i=0;i<19;i++) - { + /*Arrange*/ - inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); - - } + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + bool inputIsIntegerExpected = true; - //Assert + /*Act and Assert*/ for(int i=0;i<19;i++) { + bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); - TEST_ASSERT_TRUE(inputIsIntegerResult[i]); + TEST_ASSERT_EQUAL(inputIsIntegerExpected,inputIsIntegerResult); - } + } } void test_IsNotInteger(void) { + //test case 1 + + /*Arrange*/ - //Arrange - char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; - - bool inputIsNotIntegerResult[19]; - - //Act - - for(int i=0;i<19;i++) - { - - inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); - - } - - //Assert - + + bool inputIsNotIntegerExpected = false; + + /*Act and Assert*/ + + for(int i=0;i<19;i++) { - - TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]); - + bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); + + TEST_ASSERT_EQUAL(inputIsNotIntegerExpected,inputIsNotIntegerResult); + } + } #endif // TEST From c394e533c6297c18b6986ddf7db2b9ef90faa11e Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 19:54:26 +0100 Subject: [PATCH 06/58] implement function showGeneralInfoEmployee() --- project.yml | 101 +++++++++++++++++++++++++++ src/showGeneralInfoEmployee.c | 99 ++++++++++++++++++++++++++ src/showGeneralInfoEmployee.h | 11 +++ tests/support/.gitkeep | 0 tests/test_showGeneralInfoEmployee.c | 20 ++++++ 5 files changed, 231 insertions(+) create mode 100644 project.yml create mode 100644 src/showGeneralInfoEmployee.c create mode 100644 src/showGeneralInfoEmployee.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_showGeneralInfoEmployee.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c new file mode 100644 index 0000000..2a9196b --- /dev/null +++ b/src/showGeneralInfoEmployee.c @@ -0,0 +1,99 @@ +#include "showGeneralInfoEmployee.h" +//a = employeeName b = password +int checkUser(char a[length], char b[length]) +{ + if(strcmp(a,"Atharva")==0 && strcmp(b,"Atharva")==0) + { + return 1; + } + else if(strcmp(a,"Can")==0 && strcmp(b,"BlooMask")==0) + { + return 2; + } + else if(strcmp(a,"Haytham")==0 && strcmp(b,"TimoDL")==0) + { + return 3; + } + else if(strcmp(a,"Julius")==0 && strcmp(b,"Insertcat")==0) + { + return 4; + } + else if(strcmp(a,"Mohamed")==0 && strcmp(b,"MD")==0) + { + return 5; + } + else if(strcmp(a,"Shivam")==0 && strcmp(b,"Schivam007")==0) + { + return 6; + } + else + { + return 0; + } +} + + +void showGeneralInfoEmployee(char id[length], char p[length]) +{ + // "If Statements" check, whether the id and the password match + if(checkUser(id, p) == 1) + { + printf(" Welcome Atharva\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + } + if(checkUser(id, p) == 2) + { + printf(" Welcome Can\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + } + if(checkUser(id, p) == 3) + { + printf(" Welcome Haytham\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + if(checkUser(id, p) == 4) + { + printf(" Welcome Julius\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + if(checkUser(id, p) == 5) + { + printf(" Welcome Mohamed\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + if(checkUser(id, p) == 6) + { + printf(" Welcome Shivam\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + else + { + + } +} + + diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h new file mode 100644 index 0000000..984b035 --- /dev/null +++ b/src/showGeneralInfoEmployee.h @@ -0,0 +1,11 @@ +#ifndef SHOWGENERALINFOEMPLOYEE_H +#define SHOWGENERALINFOEMPLOYEE_H + +#include +#include +#include + +const int length = 100; +int checkUser(char a[length], char b[length]); +void showGeneralInfoEmployee(char id[length], char p[length]); +#endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c new file mode 100644 index 0000000..e666269 --- /dev/null +++ b/tests/test_showGeneralInfoEmployee.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "showGeneralInfoEmployee.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_showGeneralInfoEmployee_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement showGeneralInfoEmployee"); +} + +#endif // TEST From 5a78de5396ca73ba800a8f3d4394d313fe0f457d Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 20:08:43 +0100 Subject: [PATCH 07/58] implement unittest for function showGeneralInfoEmployee() --- tests/test_showGeneralInfoEmployee.c | 48 ++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index e666269..468a993 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "showGeneralInfoEmployee.h" +#include "showGeneralInfoEmployee.c" void setUp(void) { @@ -12,9 +12,51 @@ void tearDown(void) { } -void test_showGeneralInfoEmployee_NeedToImplement(void) +//eN : employeeName pwd: password + +void test1_showGeneralInfoEmployee(void) +{ + char eN[] = "Atharva"; + char pwd[] = "Atharva"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(1, erg); +} +void test2_showGeneralInfoEmployee(void) +{ + char eN[] = "Can"; + char pwd[] = "BlooMask"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(2, erg); +} +void test3_showGeneralInfoEmployee(void) +{ + char eN[] = "Haytham"; + char pwd[] = "TimoDL"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(3, erg); +} +void test4_showGeneralInfoEmployee(void) { - TEST_IGNORE_MESSAGE("Need to Implement showGeneralInfoEmployee"); + char eN[] = "Julius"; + char pwd[] = "Insertcat"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(4, erg); } +void test5_showGeneralInfoEmployee(void) +{ + char eN[] = "Mohamed"; + char pwd[] = "MD"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(5, erg); +} +void test6_showGeneralInfoEmployee(void) +{ + char eN[] = "Shivam"; + char pwd[] = "Schivam007"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(6, erg); +} + + #endif // TEST From 0298030b9f3d08e7065e463bb2451e54e918530f Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 20:37:37 +0100 Subject: [PATCH 08/58] refactoring: changed some variable names and implemented if statements in showGeneralInfoEmployee.c --- src/showGeneralInfoEmployee.c | 86 +++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 2a9196b..3bbb353 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -1,31 +1,38 @@ #include "showGeneralInfoEmployee.h" -//a = employeeName b = password -int checkUser(char a[length], char b[length]) + +//int checkUser() is helpful for unittesting showGeneralInfoEmployee() +int checkUser(char username[length], char password[length]) { - if(strcmp(a,"Atharva")==0 && strcmp(b,"Atharva")==0) - { - return 1; - } - else if(strcmp(a,"Can")==0 && strcmp(b,"BlooMask")==0) - { - return 2; - } - else if(strcmp(a,"Haytham")==0 && strcmp(b,"TimoDL")==0) - { - return 3; - } - else if(strcmp(a,"Julius")==0 && strcmp(b,"Insertcat")==0) - { - return 4; - } - else if(strcmp(a,"Mohamed")==0 && strcmp(b,"MD")==0) - { - return 5; - } - else if(strcmp(a,"Shivam")==0 && strcmp(b,"Schivam007")==0) - { - return 6; - } + if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharva")==0) + { + return 1; + } + + if(strcmp(username,"Can")==0 && strcmp(password,"BlooMask")==0) + { + return 2; + } + + if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDL")==0) + { + return 3; + } + + if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcat")==0) + { + return 4; + } + + if(strcmp(username,"Mohamed")==0 && strcmp(password,"MD")==0) + { + return 5; + } + + if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007")==0) + { + return 6; + } + else { return 0; @@ -33,10 +40,11 @@ int checkUser(char a[length], char b[length]) } -void showGeneralInfoEmployee(char id[length], char p[length]) +void showGeneralInfoEmployee(char id[length], char password[length]) { - // "If Statements" check, whether the id and the password match - if(checkUser(id, p) == 1) + // "If Statements" check, whether the username and password match. + + if(checkUser(id, password) == 1) { printf(" Welcome Atharva\n"); printf(" Clearance: 3\n"); @@ -44,7 +52,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf("\n"); printf(" ->Review new customer applications.\n"); } - if(checkUser(id, p) == 2) + + if(checkUser(id, password) == 2) { printf(" Welcome Can\n"); printf(" Clearance: 3\n"); @@ -52,7 +61,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf("\n"); printf(" ->Review new customer applications.\n"); } - if(checkUser(id, p) == 3) + + if(checkUser(id, password) == 3) { printf(" Welcome Haytham\n"); printf(" Clearance: 2\n"); @@ -61,7 +71,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review new customer applications.\n"); printf(" ->Review loan applications.\n"); } - if(checkUser(id, p) == 4) + + if(checkUser(id, password) == 4) { printf(" Welcome Julius\n"); printf(" Clearance: 2\n"); @@ -70,7 +81,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review new customer applications.\n"); printf(" ->Review loan applications.\n"); } - if(checkUser(id, p) == 5) + + if(checkUser(id, password) == 5) { printf(" Welcome Mohamed\n"); printf(" Clearance: 3\n"); @@ -80,7 +92,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review loan applications.\n"); printf(" ->Terminate account.\n"); } - if(checkUser(id, p) == 6) + + if(checkUser(id, password) == 6) { printf(" Welcome Shivam\n"); printf(" Clearance: 3\n"); @@ -90,10 +103,5 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review loan applications.\n"); printf(" ->Terminate account.\n"); } - else - { - } } - - From da40d8b28bfda6da96690bd1f020d8bc8abaf983 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 21:14:08 +0100 Subject: [PATCH 09/58] refactoring: changed some variable names in test_showGeneralInfoEmployee.c --- tests/test_showGeneralInfoEmployee.c | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 468a993..4a58a83 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -12,51 +12,52 @@ void tearDown(void) { } -//eN : employeeName pwd: password void test1_showGeneralInfoEmployee(void) { - char eN[] = "Atharva"; - char pwd[] = "Atharva"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(1, erg); + char employeeName[] = "Atharva"; //Arrange + char password[] = "Atharva"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert } void test2_showGeneralInfoEmployee(void) { - char eN[] = "Can"; - char pwd[] = "BlooMask"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(2, erg); + char employeeName[] = "Can"; //Arrange + char password[] = "BlooMask"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert } void test3_showGeneralInfoEmployee(void) { - char eN[] = "Haytham"; - char pwd[] = "TimoDL"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(3, erg); + char employeeName[] = "Haytham"; //Arrange + char password[] = "TimoDL"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert } void test4_showGeneralInfoEmployee(void) { - char eN[] = "Julius"; - char pwd[] = "Insertcat"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(4, erg); + char employeeName[] = "Julius"; //Arrange + char password[] = "Insertcat"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert } void test5_showGeneralInfoEmployee(void) { - char eN[] = "Mohamed"; - char pwd[] = "MD"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(5, erg); + char employeeName[] = "Mohamed"; //Arrange + char password[] = "MD"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert } void test6_showGeneralInfoEmployee(void) { - char eN[] = "Shivam"; - char pwd[] = "Schivam007"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(6, erg); + char employeeName[] = "Shivam"; //Arrange + char password[] = "Schivam007"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert } + + #endif // TEST From ceccdd60a9c47576822201d15f245325391a29f0 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 30 Jan 2023 15:13:57 +0100 Subject: [PATCH 10/58] implement unit tests for the function chooseOption(). --- .gitignore | 3 +- src/mainMenu.c | 20 +++++++- src/mainMenu.h | 1 + test/test_mainMenu.c | 111 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 126 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 496ee2c..dce188f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +.swp diff --git a/src/mainMenu.c b/src/mainMenu.c index dd249fc..eca4c34 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,4 +1,4 @@ -#include"mainMenu.h" +#include "mainMenu.h" bool agePermission(int age) @@ -20,6 +20,22 @@ bool checkIfInteger(char* userInput) return !(endPointer == userInput || *endPointer != '\0'); } + +bool chooseOption(int choiceInput) +{ + + if(choiceInput < 1 || choiceInput > 4) + { + return false; + } + + else + { + return true; + } + +} + void ageInput() { @@ -82,3 +98,5 @@ void showMenu() printf("\n\n\n\n\n Selection :\n"); } + + diff --git a/src/mainMenu.h b/src/mainMenu.h index ccc7d9c..6974d21 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -8,6 +8,7 @@ bool agePermission(int age); bool checkIfInteger(char* userInput); +bool chooseOption(int choiceInput); void ageInput(); void showMenu(); diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index eb93bb7..ea65cc2 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -26,7 +26,7 @@ void test_agePermissionValidAge(void) /*Act*/ - for(int i =0;i<83;i++){ + for(int i =0; i < 83; i++){ validAgeResult[i]= Age + i; } @@ -34,7 +34,7 @@ void test_agePermissionValidAge(void) /*Assert*/ - for(int i=0;i<83;i++){ + for(int i=0; i < 83; i++){ TEST_ASSERT_TRUE(validAgeResult[i]); @@ -54,7 +54,7 @@ void test_agePermissionInvalidAge(void) bool invalidAgeResult[117]; - for(int i =-100;i<18;i++) + for(int i =-100; i < 18; i++) { invalidAge[i+100]= i; @@ -62,7 +62,7 @@ void test_agePermissionInvalidAge(void) /*Act*/ - for(int i=0;i<117;i++) + for(int i=0; i < 117; i++) { invalidAgeResult[i] = agePermission(invalidAge[i]); @@ -71,7 +71,7 @@ void test_agePermissionInvalidAge(void) /*Assert*/ - for(int i=0;i<117;i++) + for(int i=0; i < 117; i++) { TEST_ASSERT_FALSE(invalidAgeResult[i]); @@ -93,7 +93,7 @@ void test_IsInteger(void) /*Act and Assert*/ - for(int i=0;i<19;i++) + for(int i=0; i < 19; i++) { bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); @@ -116,7 +116,7 @@ void test_IsNotInteger(void) /*Act and Assert*/ - for(int i=0;i<19;i++) + for(int i=0; i<19; i++) { bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); @@ -126,4 +126,101 @@ void test_IsNotInteger(void) } +void test_validChoiceInput(void) +{ + //test case 0 + + /*Arrange*/ + + int validInput[4]; + + bool validInputResult[4]; + + /*Act*/ + + for(int i = 0; i < 4; i++) + { + validInput[i] = i + 1; + } + + for(int i = 0; i < 4; i++) + { + validInputResult[i] = chooseOption(validInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 4; i++) + { + TEST_ASSERT_TRUE(validInputResult[i]); + } + +} + +void test_invalidChoiceInput_firstCase(void) +{ + // test case 1 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = -100; i < 0; i++) + { + invalidInput[i+100] = i; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + +void test_invalidChoiceInput_secondCase(void) +{ + // test case 2 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = 0; i < 100; i++) + { + invalidInput[i] = i + 5; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + + + + + #endif // TEST From ac4b64166e22e13d84cbcb54ae071125302817b5 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 30 Jan 2023 19:44:01 +0100 Subject: [PATCH 11/58] implement the function menuInput(), in order for the user to choose a banking option. --- src/mainMenu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- src/mainMenu.h | 1 + 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/mainMenu.c b/src/mainMenu.c index eca4c34..fdb0aa8 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -54,12 +54,13 @@ void ageInput() if((checkIfInteger(userInput))&& (agePermission(age))) { - //age = strtol(userInput,&userInputPointer,10); printf("Access granted!\n\n\n\n"); showMenu(); + menuInput(); + break; } @@ -84,6 +85,57 @@ void ageInput() } } +void menuInput() +{ + + char choiceInput[20]; + + char* choiceInputPointer; + + int selection; + + scanf("%s",choiceInput); + + while(true) + { + selection = strtol(choiceInput,&choiceInputPointer,10); + + if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true) + { + switch(selection) + { + + case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n"); + + break; + + case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); + + break; + + case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n"); + + break; + + case 4 : printf("\e[1;1H\e[2J"); + + printf("\nsee you next time !\n\n"); + + break; + + } + break; + } + + else + { + printf("Input invalid! try again!\n"); + + scanf("%s",choiceInput); + } + } + +} void showMenu() diff --git a/src/mainMenu.h b/src/mainMenu.h index 6974d21..0824d42 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -12,6 +12,7 @@ bool chooseOption(int choiceInput); void ageInput(); void showMenu(); +void menuInput(); #endif From 0e8d805605d65c8352f05aefa025ef31386a9a69 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 30 Jan 2023 20:01:49 +0100 Subject: [PATCH 12/58] refactoring: made code more readable and enhanced the menuInput() and chooseOption() functions. --- src/mainMenu.c | 70 +++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/src/mainMenu.c b/src/mainMenu.c index fdb0aa8..7b60ecf 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -24,15 +24,7 @@ bool checkIfInteger(char* userInput) bool chooseOption(int choiceInput) { - if(choiceInput < 1 || choiceInput > 4) - { - return false; - } - - else - { - return true; - } + return !(choiceInput < 1 || choiceInput > 4); } @@ -50,6 +42,8 @@ void ageInput() while (true) { + /*the userInput string is changed to a number with the strtol function*/ + age = strtol(userInput,&userInputPointer,10); if((checkIfInteger(userInput))&& (agePermission(age))) @@ -85,56 +79,40 @@ void ageInput() } } + void menuInput() { - char choiceInput[20]; - char* choiceInputPointer; - int selection; - scanf("%s",choiceInput); + scanf("%s", choiceInput); + selection = strtol(choiceInput, &choiceInputPointer, 10); - while(true) + while (!checkIfInteger(choiceInput) || !chooseOption(selection)) { - selection = strtol(choiceInput,&choiceInputPointer,10); - - if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true) - { - switch(selection) - { + printf("Input invalid! try again!\n"); - case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n"); + scanf("%s", choiceInput); - break; - - case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); - - break; - - case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n"); - - break; - - case 4 : printf("\e[1;1H\e[2J"); - - printf("\nsee you next time !\n\n"); - - break; - - } - break; - } + selection = strtol(choiceInput, &choiceInputPointer, 10); + } + + switch(selection) + { + case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n"); + break; - else - { - printf("Input invalid! try again!\n"); + case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); + break; - scanf("%s",choiceInput); - } - } + case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n"); + break; + case 4 : printf("\e[1;1H\e[2J"); + printf("\nsee you next time !\n\n"); + break; + } } From eee36c1fda7192a609446d0b0e8e9d785544a21d Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Tue, 31 Jan 2023 14:30:31 +0100 Subject: [PATCH 13/58] refactoring: removed redundant code in the unit tests of the chooseOption() function. --- test/test_mainMenu.c | 47 +++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index ea65cc2..af93eaf 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -134,25 +134,23 @@ void test_validChoiceInput(void) int validInput[4]; - bool validInputResult[4]; + bool validInputExpected = true; - /*Act*/ + for(int i = 0; i < 4; i++) { validInput[i] = i + 1; } + /*Act and Asssert*/ + for(int i = 0; i < 4; i++) { - validInputResult[i] = chooseOption(validInput[i]); - } - /*Assert*/ + bool validInputResult = chooseOption(validInput[i]); - for(int i = 0; i < 4; i++) - { - TEST_ASSERT_TRUE(validInputResult[i]); + TEST_ASSERT_EQUAL(validInputExpected,validInputResult); } } @@ -165,25 +163,24 @@ void test_invalidChoiceInput_firstCase(void) int invalidInput[100]; - bool invalidInputResult[100]; + bool invalidInputExpected = false; - /*Act*/ + - for(int i = -100; i < 0; i++) + for(int i = -100; i < 1; i++) { invalidInput[i+100] = i; } + /*Act and Assert*/ + for(int i = 0; i < 100; i++) { - invalidInputResult[i] = chooseOption(invalidInput[i]); - } - /*Assert*/ + bool invalidInputResult = chooseOption(invalidInput[i]); + + TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); - for(int i = 0; i < 100; i++) - { - TEST_ASSERT_FALSE(invalidInputResult[i]); } } @@ -196,27 +193,23 @@ void test_invalidChoiceInput_secondCase(void) int invalidInput[100]; - bool invalidInputResult[100]; - - /*Act*/ + bool invalidInputExpected = false; for(int i = 0; i < 100; i++) { invalidInput[i] = i + 5; } - for(int i = 0; i < 100; i++) - { - invalidInputResult[i] = chooseOption(invalidInput[i]); - } - - /*Assert*/ + /*Act and Assert*/ for(int i = 0; i < 100; i++) { - TEST_ASSERT_FALSE(invalidInputResult[i]); + bool invalidInputResult = chooseOption(invalidInput[i]); + + TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); } + } From 14d97220d07505bae9a4919ec24d25d20c4cb124 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 01:25:05 +0100 Subject: [PATCH 14/58] 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)7bWIK?i2yKgFYnQy^DHTN)jqH1l_rB?RwXS4+$*J>Zn zfjux305Sz`qT06W`2Hy(N;A(_&SY-=&uMG7z4Jg$M6Fn(d zMqYYb&XU;M&+Nr)wx{Xh`6jfuQn&b9V8d>n^tu_6qK~^drrap27c%doHQBZF(L+ra zk*`YbYx*G?Nq3tZ&%1COfQd0ZRc? z>wsqyFdx89Z+4~u1-4Bqz55~Z#EI%HzS*lf2pLrG^kT0l>_IPfTwzanu^%h!v={r1 z!peJta@eLXt&Yrq?3l#W*aLEu^=Vt!(ls>GTM?>!nGswN=y0M%&kt^NVPlZ zc*JP64a+sijcZiZ8r`;)Oc@RYu49Cgw&g-@v|5SXh7}Gw>4ZB^#1i;iXT%bF@EtBP z&v297XcHgk=85J}B`W;VjZRxEQJ-pbQf|7#PA*(zMAM0|8*>uI-dH?N(Zo7B<93Hl z5gYCJIA^3BC!qr`RS~f{`bQCcQZM)ptK(=wTTZuae*zD4ZmU{Z6`FHf^#)OzvTaJa zk+8d5!;N*=#yl111XT><7CRnxfFqd=l*1M)f#FHc)1!$IDOIXGkapY-yM~jn4JT^2 z?Y0qh@HKRAEYX(BRBE0Wwlid@SS>qbSSiCw7M|F3{s|;YAGStDq%#jqo?ng`k!Hzym7ic2IhAb^A~@`vB;d--aJhD)il)O5pCT zBG6SHm@{#F$>G5Ga>B2~ZwK1&et#ZWUx@iy|JWPZ>>a3!$>r-N&)iUU+1`@xEjoX5Nz>@qP{7ynHzYVke#$ov* zkUs+QIk|4`=8@C06E2)lbgf#uK|7?@>0qT`yW#rAPus=h~H`Cc2S;ueolTR z@IN5eJMxgRK=$^$sg7B_+BV^&NCh*B>xpH|3LE`w{GTtPI&#ezu_8v9<0;!W=*4- z?$MO(cwOlF#>N%K!nJm543CLb)xqjuWkuDJMY_t`AE%V3vEuElUqX2gKyr^xl%W+a z2OUZOYT!kpO!WEUBRj%}eE9Vm=j#HjEX_Cu#B5Ppr+6MmT2~to(*>XBN~)f<$Uk3a zj6Wdtr{&h!GX6L!BgOxdQSj0F`%~%vaM0b z6ZkbF;Cq2jEy8~<4uo~Kg_CYo(7`f$t2Ji2R+|8TcY@JqFf4|b1Y%`MX=;(%t zhclt+=Bd)I1H?n5#ZIJAHO+Nf>sy-4rcG;2>!$ja=0?ES31T*dv^2DKt1#DZ z+}u#V(cHXl-L|If=JxuAjZLudZ)&LHT?+qUKLTx#$m!BP2GfpMt|jm`QNDB)vZH!W zM4n=}-EmU(=1zLaD)7>GFLechkh$95048sKP)!pG*t)SR&B56C(w#sPin>W9*<&YVXQi5EOvsXU+#&;A z>x{c1D8me*8f8U_X+a6lUpENZ@Cr>&Gm5GkY%*}a9W(3zcOEg zir3!1FOL6@us+|%nWuS$*PiD!Obu4l)Ng+a@b@rxH49vEQ=!gfr@ z!Pslh^YMk1N}uCoH*ClJL>Lps@$>w%R@?jasV#4rqTAQ%IT72>%^|A7_Fn2cMWx~n y?NF|O2XYmDH1+0q`2I`R2gi Date: Wed, 1 Feb 2023 16:30:01 +0100 Subject: [PATCH 15/58] implement the functions employeeCredentials() and loginAsEmployee() for employees to access their accounts. --- build-project.sh | 6 +++ project.yml | 1 + src/employeeLogin.c | 89 +++++++++++++++++++++++++++++++++++--------- src/employeeLogin.h | 15 +++----- src/main | Bin 16408 -> 0 bytes src/main.c | 3 +- src/mainMenu.c | 7 ++-- src/mainMenu.h | 2 + 8 files changed, 93 insertions(+), 30 deletions(-) delete mode 100755 src/main diff --git a/build-project.sh b/build-project.sh index 420b964..5988d59 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,12 @@ clear ceedling test:all cd src/ +cp employeeLogin.c employeeLogin.c.bak +sed -i 's/src\///g' employeeLogin.c gcc main.c mainMenu.c -o main ./main rm main +cp employeeLogin.c.bak employeeLogin.c +rm employeeLogin.c.bak +cd .. +rm -r build/ diff --git a/project.yml b/project.yml index e253248..51a5a2a 100644 --- a/project.yml +++ b/project.yml @@ -35,6 +35,7 @@ - -:test/support :source: - src/** + - src/ :support: - test/support :libraries: [] diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 542526f..624d0ae 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,22 +1,77 @@ +#include "mainMenu.h" #include "employeeLogin.h" -int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +extern 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; + char listUsername[credentialLength]; + char listPassword[credentialLength]; + + FILE* employeeList = fopen("src/employeeList.txt","r"); + + if(employeeList == NULL ) + { + printf("file does not exist"); + exit(1); + } + else + { + 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; + } +} + +void employeeCredentials(char* username,char* password) +{ + printf("Enter username: "); + scanf("%s", username); + printf("Enter password: "); + scanf("%s", password); +} + +void loginAsEmployee() +{ + int counter=2; + char username[credentialLength]; + char password[credentialLength]; + + employeeCredentials(username, password); + + while(counter>0) + { + if(checkEmployeeCredentials(username, password) == 0) + { + printf("User not found\n"); + employeeCredentials(username, password); + } + else if(checkEmployeeCredentials(username, password)==2) + { + printf("Wrong Informations !\nyou have %d tries left\n",counter); + employeeCredentials(username, password); + --counter; + } + else + { + printf("User Approved\n"); + break; + } + } + if(counter==0) + { + printf("you used up all of the tries! account locked\n"); + } + } diff --git a/src/employeeLogin.h b/src/employeeLogin.h index 6e4cb65..485955f 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,16 +1,13 @@ -#ifndef EMPLOYEELOGIN_H_ -#define EMPLOYEELOGIN_H_ +#ifndef LOGINEMPLOYEE_H_ +#define LOGINEMPLOYEE_H_ -#include -#include -#include -#include #define credentialLength 20 - - -int checkEmployeeCredentials(char* inputUsername , char* inputPassword); +int checkEmployeeCredentials(char* username , char* password); +void employeeCredentials(char* username, char* password); +void loginAsEmployee(); #endif + diff --git a/src/main b/src/main deleted file mode 100755 index fad988bb3623d9069264d63cdfeaecddd9fa83f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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)7bWIK?i2yKgFYnQy^DHTN)jqH1l_rB?RwXS4+$*J>Zn zfjux305Sz`qT06W`2Hy(N;A(_&SY-=&uMG7z4Jg$M6Fn(d zMqYYb&XU;M&+Nr)wx{Xh`6jfuQn&b9V8d>n^tu_6qK~^drrap27c%doHQBZF(L+ra zk*`YbYx*G?Nq3tZ&%1COfQd0ZRc? z>wsqyFdx89Z+4~u1-4Bqz55~Z#EI%HzS*lf2pLrG^kT0l>_IPfTwzanu^%h!v={r1 z!peJta@eLXt&Yrq?3l#W*aLEu^=Vt!(ls>GTM?>!nGswN=y0M%&kt^NVPlZ zc*JP64a+sijcZiZ8r`;)Oc@RYu49Cgw&g-@v|5SXh7}Gw>4ZB^#1i;iXT%bF@EtBP z&v297XcHgk=85J}B`W;VjZRxEQJ-pbQf|7#PA*(zMAM0|8*>uI-dH?N(Zo7B<93Hl z5gYCJIA^3BC!qr`RS~f{`bQCcQZM)ptK(=wTTZuae*zD4ZmU{Z6`FHf^#)OzvTaJa zk+8d5!;N*=#yl111XT><7CRnxfFqd=l*1M)f#FHc)1!$IDOIXGkapY-yM~jn4JT^2 z?Y0qh@HKRAEYX(BRBE0Wwlid@SS>qbSSiCw7M|F3{s|;YAGStDq%#jqo?ng`k!Hzym7ic2IhAb^A~@`vB;d--aJhD)il)O5pCT zBG6SHm@{#F$>G5Ga>B2~ZwK1&et#ZWUx@iy|JWPZ>>a3!$>r-N&)iUU+1`@xEjoX5Nz>@qP{7ynHzYVke#$ov* zkUs+QIk|4`=8@C06E2)lbgf#uK|7?@>0qT`yW#rAPus=h~H`Cc2S;ueolTR z@IN5eJMxgRK=$^$sg7B_+BV^&NCh*B>xpH|3LE`w{GTtPI&#ezu_8v9<0;!W=*4- z?$MO(cwOlF#>N%K!nJm543CLb)xqjuWkuDJMY_t`AE%V3vEuElUqX2gKyr^xl%W+a z2OUZOYT!kpO!WEUBRj%}eE9Vm=j#HjEX_Cu#B5Ppr+6MmT2~to(*>XBN~)f<$Uk3a zj6Wdtr{&h!GX6L!BgOxdQSj0F`%~%vaM0b z6ZkbF;Cq2jEy8~<4uo~Kg_CYo(7`f$t2Ji2R+|8TcY@JqFf4|b1Y%`MX=;(%t zhclt+=Bd)I1H?n5#ZIJAHO+Nf>sy-4rcG;2>!$ja=0?ES31T*dv^2DKt1#DZ z+}u#V(cHXl-L|If=JxuAjZLudZ)&LHT?+qUKLTx#$m!BP2GfpMt|jm`QNDB)vZH!W zM4n=}-EmU(=1zLaD)7>GFLechkh$95048sKP)!pG*t)SR&B56C(w#sPin>W9*<&YVXQi5EOvsXU+#&;A z>x{c1D8me*8f8U_X+a6lUpENZ@Cr>&Gm5GkY%*}a9W(3zcOEg zir3!1FOL6@us+|%nWuS$*PiD!Obu4l)Ng+a@b@rxH49vEQ=!gfr@ z!Pslh^YMk1N}uCoH*ClJL>Lps@$>w%R@?jasV#4rqTAQ%IT72>%^|A7_Fn2cMWx~n y?NF|O2XYmDH1+0q`2I`R2gi #include +#define credentialLength 20 + bool agePermission(int age); bool checkIfInteger(char* userInput); bool chooseOption(int choiceInput); From 509362d0aa60dce0ea5bea5b08b9d1c3a8db68d9 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 19:46:39 +0100 Subject: [PATCH 16/58] refactoring: changed some variable names for readability and used pointers to conserve memory in the functions CheckEmployeeCredentials() and EmployeeCredentials. --- src/.employeeLogin.c.swp | Bin 0 -> 12288 bytes src/employeeLogin.c | 55 ++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 src/.employeeLogin.c.swp diff --git a/src/.employeeLogin.c.swp b/src/.employeeLogin.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..a2975fcb31a1a48c8e9e0e9a4ff11c9c866b60ce GIT binary patch literal 12288 zcmeI2O>Epm6vw9(6_n z=2=m_G;wiuj?RotFti64yYlh(_6JWe_TwmHE?-Yv-c?U-+s-x@&Od))zJ7Lc?wO}% zXZ9R>H8(iE#N~3AOWqM(A(MK%9w(wZ9!K`L=!SldhqkvJsC}0#Y3K#{90!D#5Pyya%?B*fH7Vd`g`2Tb_6>LqTmzfn5_k@bf``FxhZ*|`Tn8KAWv~ofFbynl0z3pB1b2bI zq32)V4e&bH0$0IH;38NAO7kUPno+=Re)UHeyeZ5#j zl6M9A($0LmniEEzOdPAc9`p#q+SCh)`#uE@C9a?(@CfoYMAz%MA|kReD&o=>G; mSw&CM(Tv;SgBDFH5wBY?U?dOwM~{@ z@_&{h!I!gubhma~SzbhZG!uqVu%f)nmMU$qlJH~EH#BUrUe8zG+w2QbAUiZGognJ+ z#0zAs0#Qo2d_~a7b|w$`!b#FqYq`n#WUjt)Hj7r>DQ`%H?FxJO=}5HkDWb>ym>Lb5 zsxUP~wP8PZ#3_S>9PCCv&}`P=LVK(Ml}l=HrnS1m-qTKRvaV+SVdQ|LmQJMFK$bCO zNHv`TyH22i8ESB*%Bt)6LZ`u#Ity%NF@JcFb4FoF7*8e0aW&Dx07Cwwv&o2&qHbU~QnU@1zbRtsT4hUp&xu z^f4~-G!jWKk~C2qCCB!ISXkP#mKP@jN1~XiA{_pudUAVHg+0})+U@PC5m{oXJJs}& z8?oXfvb&)*tO)sVtRGi}PMxB`aayHXI!^zp6h~Dpv8Vf!|J{AhA?x3}K0H#pyWRN; zG39nz2}>w`~j1NQ0Ue&gB)oG+yc>gS|Qyg-49BowfTifodk!P={nu`J20xd9?~vw;h#%PVGKY fiH&;F_IqtX<-Ts|m-KFV;8B-*a!$zJ7<&H!zLM@d literal 0 HcmV?d00001 diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 624d0ae..0d44ddf 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,8 +4,8 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { - char listUsername[credentialLength]; - char listPassword[credentialLength]; + char* listUsername = malloc(credentialLength * sizeof(char*)); + char* listPassword = malloc(credentialLength * sizeof(char*)); FILE* employeeList = fopen("src/employeeList.txt","r"); @@ -15,15 +15,18 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) exit(1); } else - { + { + /*loop that checks if the two strings seperated by space exist in the employee list*/ + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) { - if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) + + if (!(strcmp(inputUsername, listUsername)) && !(strcmp(inputPassword, listPassword))) { fclose(employeeList); return 1; } - else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) + else if(!(strcmp(inputUsername, listUsername)) && strcmp(inputPassword, listPassword)) { fclose(employeeList); return 2; @@ -32,46 +35,56 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) fclose(employeeList); return 0; } + + free(inputUsername); + free(inputPassword); } -void employeeCredentials(char* username,char* password) +void employeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); - scanf("%s", username); + scanf("%s", inputUsername); printf("Enter password: "); - scanf("%s", password); + scanf("%s", inputPassword); } void loginAsEmployee() { - int counter=2; - char username[credentialLength]; - char password[credentialLength]; - - employeeCredentials(username, password); + int counter=3; + char* username = malloc(credentialLength * sizeof(char*)); + char* password = malloc(credentialLength * sizeof(char*)); while(counter>0) { - if(checkEmployeeCredentials(username, password) == 0) + employeeCredentials(username, password); + + int checkCredentials = checkEmployeeCredentials(username,password); + + + if(checkCredentials == 0) { - printf("User not found\n"); - employeeCredentials(username, password); + printf("\n\nUser not found\n\n"); } - else if(checkEmployeeCredentials(username, password)==2) + else if(checkCredentials == 2) { - printf("Wrong Informations !\nyou have %d tries left\n",counter); - employeeCredentials(username, password); + printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); --counter; } else { - printf("User Approved\n"); + printf("\n\nUser Approved\n\n"); break; } } + if(counter==0) { - printf("you used up all of the tries! account locked\n"); + + printf("you used up all of the tries! account locked\nPlease contact an employee of higher clearance !\n\n"); + } + free(username); + free(password); + } From be083578653005756d80ca32cad372f8287c12a7 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 20:12:06 +0100 Subject: [PATCH 17/58] refactoring: removed redundant code from the unit test file test_employeeLogin.c, changed variable names and added som comments . --- .../.test_employeeLogin.c.swp | Bin 12288 -> 16384 bytes test/test_employeeLogin.c | 159 +++++++----------- 2 files changed, 62 insertions(+), 97 deletions(-) rename src/.employeeLogin.c.swp => test/.test_employeeLogin.c.swp (57%) diff --git a/src/.employeeLogin.c.swp b/test/.test_employeeLogin.c.swp similarity index 57% rename from src/.employeeLogin.c.swp rename to test/.test_employeeLogin.c.swp index a2975fcb31a1a48c8e9e0e9a4ff11c9c866b60ce..77752368280750880b47ea9f9ce5e66997e1bc68 100644 GIT binary patch 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?frsk2oIFotK*-Se7E9&-FI>%Qz`^W0)okPCk5#SNv5#SNv5#SNv5#SNv5#SNv z5#SNv5#SNH3?m@QguITVzIY7=hkyTf^Z$!C5OM*04ZZ>&gO9*5a1kKi1b z1v6k2Yz0ZM86?0)umP+G>%bCl3%D5&@KYBdKY;gu1y+L#3kZ1|jDuI^6Y@NG4(tXh z*bY)44#MDea17VzFqj1;paFW_PF_vOo8S$w7mR@n=miVFeDDpf@p14LI15gLQ{V(R zkB2`Wf&*Yb$b$_a2BN@M1Qb=X1Vb@P1QX%>o-b{;Ba2GcB-2}w zOt{_|9S;lkdNa|?BsN~#bD8y@(~Tb5zq&3uD5z`uuvxisxi`MZiiBhdq9zLo(^L#= zMTD?Q+NOGD<5(@r(Qx&zGH4rhu_7Q+gQN?)c1k&vD&b{1BWH-EP*|urni5TOk8a4J zN<04kl5NMM$Gd^v;BnxMJ=}rMyVcoQ>TXjB`$|V1be%a6jn3MSh?+tjBz1*4=rE|| z(1@OAfss8wQeHGxw3P7p&Nx#V>y~YxPQwtj2?esGV~Mc0E(J+672z%+j$bEbGOeq! zK;OvBrr7Oxg1w9B&XFEky__u?6Y3~aZ3X> ziR~`!87wrJ!nRH0JdKB|f9^bOoaFRu5C&T4M_-|n*)Htsawwfwr^O^$WKxS96*(2RuYQaD1}`<(<*MIju-Tqzn>tgreS+ms z0ob=6vzF`p`TP&o{1Io+I7m{21Mb?WL9AKSRou%@(mu)EB( zSWsnma?Ev)X=&hzv*q1|jj2(Yv2gVd8lz)on?`jy+MpKf*5V4GR*GqfsWKYv&&dUA zb^k!DR+hNCc$!QlbF!%R^~DB!y2C0}73Hu-Z+?(gG z3%Z^X%}F-2ftYQ@PN%JnPp^)2S;uQ)chCV+XZEt%{Hj&8%dBgK+hu>_TT-KSOKQ3# zNs4LaN(G;Iv+lB5@uV&qNqvvjP+=<8*p&P2QdN@*C0P+ditokwe25UQuB55fOt1Z2 zPF8YkIuM%wzmL59dqDGlq=T&dhT~tr&raPZ*uMtKU<^b+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 literal 12288 zcmeI2O>Epm6vw9(6_n z=2=m_G;wiuj?RotFti64yYlh(_6JWe_TwmHE?-Yv-c?U-+s-x@&Od))zJ7Lc?wO}% zXZ9R>H8(iE#N~3AOWqM(A(MK%9w(wZ9!K`L=!SldhqkvJsC}0#Y3K#{90!D#5Pyya%?B*fH7Vd`g`2Tb_6>LqTmzfn5_k@bf``FxhZ*|`Tn8KAWv~ofFbynl0z3pB1b2bI zq32)V4e&bH0$0IH;38NAO7kUPno+=Re)UHeyeZ5#j zl6M9A($0LmniEEzOdPAc9`p#q+SCh)`#uE@C9a?(@CfoYMAz%MA|kReD&o=>G; mSw&CM(Tv;SgBDFH5wBY?U?dOwM~{@ z@_&{h!I!gubhma~SzbhZG!uqVu%f)nmMU$qlJH~EH#BUrUe8zG+w2QbAUiZGognJ+ z#0zAs0#Qo2d_~a7b|w$`!b#FqYq`n#WUjt)Hj7r>DQ`%H?FxJO=}5HkDWb>ym>Lb5 zsxUP~wP8PZ#3_S>9PCCv&}`P=LVK(Ml}l=HrnS1m-qTKRvaV+SVdQ|LmQJMFK$bCO zNHv`TyH22i8ESB*%Bt)6LZ`u#Ity%NF@JcFb4FoF7*8e0aW&Dx07Cwwv&o2&qHbU~QnU@1zbRtsT4hUp&xu z^f4~-G!jWKk~C2qCCB!ISXkP#mKP@jN1~XiA{_pudUAVHg+0})+U@PC5m{oXJJs}& z8?oXfvb&)*tO)sVtRGi}PMxB`aayHXI!^zp6h~Dpv8Vf!|J{AhA?x3}K0H#pyWRN; zG39nz2}>w`~j1NQ0Ue&gB)oG+yc>gS|Qyg-49BowfTifodk!P={nu`J20xd9?~vw;h#%PVGKY fiH&;F_IqtX<-Ts|m-KFV;8B-*a!$zJ7<&H!zLM@d diff --git a/test/test_employeeLogin.c b/test/test_employeeLogin.c index 5cfdfdf..8e2d8de 100644 --- a/test/test_employeeLogin.c +++ b/test/test_employeeLogin.c @@ -17,130 +17,95 @@ void test_SuccessfulLoginEmployee_(void) //test case : 0 - //Arrange - char* ExistingEmployee1 = "Atharva"; - char* ExistingPassword1 = "Atharvafdai7514"; - - char* ExistingEmployee2 = "Can"; - char* ExistingPassword2 = "BlooMaskfdlt3817"; + /*Arrange*/ + + char* validEmployeesCredentials[][2] = { + {"Atharva", "Atharvafdai7514"}, + {"Can", "BlooMaskfdlt3817"}, + {"Haytham", "TimoDLfdai7207"}, + {"Julius", "Insertcatfdai7057"}, + {"Mohamed", "MDfdai6618"}, + {"Shivam", "Schivam007fdlt3781"} + }; + /*Act and Assert*/ - char* ExistingEmployee3 = "Haytham"; - char* ExistingPassword3 = "TimoDLfdai7207"; + int expected[] = {1,1,1,1,1,1}; - char* ExistingEmployee4 = "Julius"; - char* ExistingPassword4 = "Insertcatfdai7057"; + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(validEmployeesCredentials[i][0], validEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } - 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* wrongEmployeesCredentials[][2] = { + {"Atharva", "doe"}, + {"Can", "Bar"}, + {"Haytham", "buzz"}, + {"Julius", "fizz"}, + {"Mohamed", "muster"}, + {"Shivam", "TimoDL"} + }; - //Arrange - char* wrongInfoEmployee1 = "Atharva"; - char* wrongInfoPassword1 = "doe"; - - char* wrongInfoEmployee2 = "Can"; - char* wrongInfoPassword2 = "Bar"; + /*Act and Assert*/ - char* wrongInfoEmployee3 = "Haytham"; - char* wrongInfoPassword3 = "buzz"; + int expected[] = {2,2,2,2,2,2}; - char* wrongInfoEmployee4 = "Julius"; - char* wrongInfoPassword4 = "Musterpass"; + for(int i=0; i<6; i++) + { - char* wrongInfoEmployee5 = "Mohamed"; - char* wrongInfoPassword5 = "Irgendwas"; + int result = checkEmployeeCredentials(wrongEmployeesCredentials[i][0], wrongEmployeesCredentials[i][1]); - char* wrongInfoEmployee6 = "Shivam"; - char* wrongInfoPassword6 = "John"; + TEST_ASSERT_EQUAL_INT(expected[i],result); - //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* missingEmployeesCredentials[][2] = { + {"John", "doe"}, + {"Jane", "Doe"}, + {"Foo", "Bar"}, + {"Fizz", "Buzz"}, + {"Musterman", "Mustermanpassword"}, + {"Musterfrau", "Musterfraupassword"} + }; + + int expected[] = {0,0,0,0,0,0}; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(missingEmployeesCredentials[i][0], missingEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } - //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 From 46223938440dbb9a27703f4a496c38d8405b1445 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 23:28:17 +0100 Subject: [PATCH 18/58] 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?frsk2oIFotK*-Se7E9&-FI>%Qz`^W0)okPCk5#SNv5#SNv5#SNv5#SNv5#SNv z5#SNv5#SNH3?m@QguITVzIY7=hkyTf^Z$!C5OM*04ZZ>&gO9*5a1kKi1b z1v6k2Yz0ZM86?0)umP+G>%bCl3%D5&@KYBdKY;gu1y+L#3kZ1|jDuI^6Y@NG4(tXh z*bY)44#MDea17VzFqj1;paFW_PF_vOo8S$w7mR@n=miVFeDDpf@p14LI15gLQ{V(R zkB2`Wf&*Yb$b$_a2BN@M1Qb=X1Vb@P1QX%>o-b{;Ba2GcB-2}w zOt{_|9S;lkdNa|?BsN~#bD8y@(~Tb5zq&3uD5z`uuvxisxi`MZiiBhdq9zLo(^L#= zMTD?Q+NOGD<5(@r(Qx&zGH4rhu_7Q+gQN?)c1k&vD&b{1BWH-EP*|urni5TOk8a4J zN<04kl5NMM$Gd^v;BnxMJ=}rMyVcoQ>TXjB`$|V1be%a6jn3MSh?+tjBz1*4=rE|| z(1@OAfss8wQeHGxw3P7p&Nx#V>y~YxPQwtj2?esGV~Mc0E(J+672z%+j$bEbGOeq! zK;OvBrr7Oxg1w9B&XFEky__u?6Y3~aZ3X> ziR~`!87wrJ!nRH0JdKB|f9^bOoaFRu5C&T4M_-|n*)Htsawwfwr^O^$WKxS96*(2RuYQaD1}`<(<*MIju-Tqzn>tgreS+ms z0ob=6vzF`p`TP&o{1Io+I7m{21Mb?WL9AKSRou%@(mu)EB( zSWsnma?Ev)X=&hzv*q1|jj2(Yv2gVd8lz)on?`jy+MpKf*5V4GR*GqfsWKYv&&dUA zb^k!DR+hNCc$!QlbF!%R^~DB!y2C0}73Hu-Z+?(gG z3%Z^X%}F-2ftYQ@PN%JnPp^)2S;uQ)chCV+XZEt%{Hj&8%dBgK+hu>_TT-KSOKQ3# zNs4LaN(G;Iv+lB5@uV&qNqvvjP+=<8*p&P2QdN@*C0P+ditokwe25UQuB55fOt1Z2 zPF8YkIuM%wzmL59dqDGlq=T&dhT~tr&raPZ*uMtKU<^b+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 From 557709bdd6fbdbabc91846daa6f83d86a675180a Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 00:53:37 +0100 Subject: [PATCH 19/58] implement the function inputEmployeeAccessCode() so that only employees can access the loginAsEmployee() function. --- build-project.sh | 1 + src/employeeLogin.c | 39 ++++++++++++++++++++++++++++++++++++++- src/employeeLogin.h | 2 +- src/mainMenu.c | 2 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/build-project.sh b/build-project.sh index 5988d59..3aac8dc 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,3 +1,4 @@ +trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; rm employeeLogin.c.bak; cd ..; rm -r build/; exit' SIGINT clear ceedling test:all cd src/ diff --git a/src/employeeLogin.c b/src/employeeLogin.c index dfcac61..6ec85db 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,7 +4,7 @@ bool employeesAccess(char* employeesAccessCode) { - if(strcmp(employeesAccessCode,accessKey) == 0) + if(strcmp(employeesAccessCode,employeeAccessKey) == 0) { return true; } @@ -55,6 +55,43 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) free(inputPassword); } +void inputEmployeeAccessCode() +{ + char accessKey[10]; + + int remainingAttempts = 10; + + + printf("\n\nPlease enter the Access key : "); + // scanf("%s",accessKey); + + while(remainingAttempts>0) + { + scanf("%s",accessKey); + + if(employeesAccess(accessKey)==true) + { + printf("\n\nAccess granted!\n\n"); + + loginAsEmployee(); + break; + + } + else + { + --remainingAttempts; + printf("\n\nAccess key didnt match! try again !\n\n"); + + } + if(remainingAttempts == 0) + { + printf("you've reached the maximum number of tries!\nplease contact an employee of a high clearance(2 or higher) \n\n"); + } + } + + +} + void employeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); diff --git a/src/employeeLogin.h b/src/employeeLogin.h index dd77acc..c563e18 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,7 +1,7 @@ #ifndef LOGINEMPLOYEE_H_ #define LOGINEMPLOYEE_H_ -#define accessKey "DF9E9A8B5E" +#define employeeAccessKey "DF9E9A8B5E" #define credentialLength 20 #include diff --git a/src/mainMenu.c b/src/mainMenu.c index f9f48a2..40c553f 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -107,7 +107,7 @@ void menuInput() case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); break; - case 3 : loginAsEmployee(); + case 3 : inputEmployeeAccessCode(); break; case 4 : printf("\e[1;1H\e[2J"); From 098ce77c87a6837bf17269fcecde5ab31a1b4606 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 01:34:36 +0100 Subject: [PATCH 20/58] refactoring: changed some variables and some functions names for a better readability and optimized the employeesAccess() function --- src/employeeLogin.c | 38 ++++++++++++++------------------------ src/employeeLogin.h | 2 +- src/mainMenu.c | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 6ec85db..3182746 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,19 +4,11 @@ bool employeesAccess(char* employeesAccessCode) { - if(strcmp(employeesAccessCode,employeeAccessKey) == 0) - { - return true; - } - - else - { - return false; - } + return !(strcmp(employeesAccessCode,employeeAccessKey)); } -extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { char* listUsername = malloc(credentialLength * sizeof(char*)); @@ -55,44 +47,42 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) free(inputPassword); } -void inputEmployeeAccessCode() +void getEmployeeAccessCode() { - char accessKey[10]; + char accessCode[10]; int remainingAttempts = 10; - printf("\n\nPlease enter the Access key : "); - // scanf("%s",accessKey); - while(remainingAttempts>0) + while(remainingAttempts > 0) { - scanf("%s",accessKey); + scanf("%s",accessCode); - if(employeesAccess(accessKey)==true) + if(employeesAccess(accessCode)) { - printf("\n\nAccess granted!\n\n"); + printf("\n\nAccess granted!\n\n"); loginAsEmployee(); - break; + break; } + else { - --remainingAttempts; printf("\n\nAccess key didnt match! try again !\n\n"); - + --remainingAttempts; } + if(remainingAttempts == 0) { printf("you've reached the maximum number of tries!\nplease contact an employee of a high clearance(2 or higher) \n\n"); } } - } -void employeeCredentials(char* inputUsername,char* inputPassword) +void getEmployeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); scanf("%s", inputUsername); @@ -108,7 +98,7 @@ void loginAsEmployee() while(counter>0) { - employeeCredentials(username, password); + getEmployeeCredentials(username, password); int checkCredentials = checkEmployeeCredentials(username,password); diff --git a/src/employeeLogin.h b/src/employeeLogin.h index c563e18..d6f3314 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -10,7 +10,7 @@ bool employeesAccess(char* employeesAccessCode); int checkEmployeeCredentials(char* username , char* password); -void employeeCredentials(char* username, char* password); +void getEmployeeCredentials(char* username, char* password); void loginAsEmployee(); #endif diff --git a/src/mainMenu.c b/src/mainMenu.c index 40c553f..b2d8243 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -107,7 +107,7 @@ void menuInput() case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); break; - case 3 : inputEmployeeAccessCode(); + case 3 : getEmployeeAccessCode(); break; case 4 : printf("\e[1;1H\e[2J"); From fdf0bcd9cafb8f6678bd5a5b5ca17cc0f5b18588 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 03:01:53 +0100 Subject: [PATCH 21/58] refactoring: removed redundant code from the unit test of the employeeAccess() function. --- test/test_employeeLogin.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/test_employeeLogin.c b/test/test_employeeLogin.c index e29bf5d..8860af5 100644 --- a/test/test_employeeLogin.c +++ b/test/test_employeeLogin.c @@ -132,21 +132,16 @@ void test_invalidEmployeeAccessCode(void) /*Arrange*/ char* invalidAccessCode[] = {"15","foo","fizz","buzz","fizzbuzz","test","bankmanagement"}; - bool invalidCodeResults[7]; + bool invalidCodeExpectation = false; - /*Act*/ + /*Act and assert*/ for(int i=0;i<7;i++) { - invalidCodeResults[i] = employeesAccess(invalidAccessCode[i]); + bool invalidCodeResults = employeesAccess(invalidAccessCode[i]); + TEST_ASSERT_EQUAL(invalidCodeExpectation,invalidCodeResults); } - /*Assert*/ - - for(int i=0;i<7;i++) - { - TEST_ASSERT_FALSE(invalidCodeResults[i]); - } } #endif // TEST From f7a2bf74ac0b0b2475427200d8acc25d8b66acaa Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 2 Feb 2023 18:15:41 +0100 Subject: [PATCH 22/58] update with new Passwords in showGeneralInfoEmployee.c and test_showGeneralInfoEmployee.h --- src/showGeneralInfoEmployee.c | 12 ++++++------ src/showGeneralInfoEmployee.h | 4 ++-- tests/test_showGeneralInfoEmployee.c | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 3bbb353..25355c9 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -3,32 +3,32 @@ //int checkUser() is helpful for unittesting showGeneralInfoEmployee() int checkUser(char username[length], char password[length]) { - if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharva")==0) + if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharvafdai7514")==0) { return 1; } - if(strcmp(username,"Can")==0 && strcmp(password,"BlooMask")==0) + if(strcmp(username,"Can")==0 && strcmp(password,"BlooMaskfdlt3817")==0) { return 2; } - if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDL")==0) + if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDLfdai7207")==0) { return 3; } - if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcat")==0) + if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcatfdai7057")==0) { return 4; } - if(strcmp(username,"Mohamed")==0 && strcmp(password,"MD")==0) + if(strcmp(username,"Mohamed")==0 && strcmp(password,"MDfdai6618")==0) { return 5; } - if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007")==0) + if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007fdlt3781")==0) { return 6; } diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h index 984b035..bfedbbe 100644 --- a/src/showGeneralInfoEmployee.h +++ b/src/showGeneralInfoEmployee.h @@ -6,6 +6,6 @@ #include const int length = 100; -int checkUser(char a[length], char b[length]); -void showGeneralInfoEmployee(char id[length], char p[length]); +int checkUser(char username[length], char password[length]); +void showGeneralInfoEmployee(char id[length], char password[length]); #endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 4a58a83..0d1084c 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -16,42 +16,42 @@ void tearDown(void) void test1_showGeneralInfoEmployee(void) { char employeeName[] = "Atharva"; //Arrange - char password[] = "Atharva"; + char password[] = "Atharvafdai7514"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert } void test2_showGeneralInfoEmployee(void) { char employeeName[] = "Can"; //Arrange - char password[] = "BlooMask"; + char password[] = "BlooMaskfdlt3817"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert } void test3_showGeneralInfoEmployee(void) { char employeeName[] = "Haytham"; //Arrange - char password[] = "TimoDL"; + char password[] = "TimoDLfdai7207"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert } void test4_showGeneralInfoEmployee(void) { char employeeName[] = "Julius"; //Arrange - char password[] = "Insertcat"; + char password[] = "Insertcatfdai7057"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert } void test5_showGeneralInfoEmployee(void) { char employeeName[] = "Mohamed"; //Arrange - char password[] = "MD"; + char password[] = "MDfdai6618"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert } void test6_showGeneralInfoEmployee(void) { char employeeName[] = "Shivam"; //Arrange - char password[] = "Schivam007"; + char password[] = "Schivam007fdlt3781"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert } From cda5d0bdad807f862d37a8ce599df78d7ac08297 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 19:24:58 +0100 Subject: [PATCH 23/58] merge the feature/show-general-info-employee functions with feature/the-main-menu. --- src/employeeLogin.c | 2 ++ test/support/.gitkeep | 0 {test => tests}/test_employeeLogin.c | 0 {test => tests}/test_mainMenu.c | 0 4 files changed, 2 insertions(+) delete mode 100644 test/support/.gitkeep rename {test => tests}/test_employeeLogin.c (100%) rename {test => tests}/test_mainMenu.c (100%) diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 3182746..a27e71d 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,5 +1,6 @@ #include "mainMenu.h" #include "employeeLogin.h" +#include "showGeneralInfoEmployee.c" bool employeesAccess(char* employeesAccessCode) { @@ -115,6 +116,7 @@ void loginAsEmployee() else { printf("\n\nUser Approved\n\n"); + showGeneralInfoEmployee(username, password); break; } } diff --git a/test/support/.gitkeep b/test/support/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_employeeLogin.c b/tests/test_employeeLogin.c similarity index 100% rename from test/test_employeeLogin.c rename to tests/test_employeeLogin.c diff --git a/test/test_mainMenu.c b/tests/test_mainMenu.c similarity index 100% rename from test/test_mainMenu.c rename to tests/test_mainMenu.c From c60c470f088efd4baef33284333ab2f2d80a3f9d Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Fri, 3 Feb 2023 18:57:08 +0100 Subject: [PATCH 24/58] removed unwanted directories and updated new Clearances in showGeneralInfoEmployee.c --- .gitignore | 2 -- src/main.c | 9 ------- src/showGeneralInfoEmployee.c | 50 ++++++++++++++++++----------------- team.md | 6 ----- 4 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 .gitignore delete mode 100644 src/main.c delete mode 100644 team.md diff --git a/.gitignore b/.gitignore deleted file mode 100644 index dce188f..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.DS_Store -.swp diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 7032d5b..0000000 --- a/src/main.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "mainMenu.h" - -int main() -{ - - ageInput(); - - return 0; -} diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 25355c9..1c67c1b 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -46,62 +46,64 @@ 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"); + printf(" ->Review new customer applications.\n"); } 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"); } } + + diff --git a/team.md b/team.md deleted file mode 100644 index f0e0a28..0000000 --- a/team.md +++ /dev/null @@ -1,6 +0,0 @@ -- Can Hacioglu, fdlt3817 -- Atharva Kishor Naik, fdai7514 -- Julius Philipp Engel, fdai7057 -- Shivam Chaudhary, fdlt3781 -- Mohamed Yahya Dahi, fdai6618 -- Haytham Daoula, fdai7207 \ No newline at end of file From 906ee1270839cfaf56846b5980b891b95e646bc9 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 00:23:53 +0100 Subject: [PATCH 25/58] implement unit tests for the function isValidEmployeeID() --- build-project.sh | 20 +++++++-- src/createEmployeeAccount.c | 20 +++++++++ src/createEmployeeAccount.h | 10 +++++ src/employeeList.txt | 1 + src/employeeLogin.c | 17 +++++--- src/employeeLogin.h | 7 ++-- src/main.c | 2 + src/mainMenu.c | 9 +++- src/showGeneralInfoEmployee.c | 47 ++++++++++----------- src/showGeneralInfoEmployee.h | 3 +- tests/test_createEmployeeAccount.c | 62 ++++++++++++++++++++++++++++ tests/test_showGeneralInfoEmployee.c | 26 ++++++------ 12 files changed, 173 insertions(+), 51 deletions(-) create mode 100644 src/createEmployeeAccount.c create mode 100644 src/createEmployeeAccount.h create mode 100644 tests/test_createEmployeeAccount.c diff --git a/build-project.sh b/build-project.sh index 3aac8dc..26458c7 100755 --- a/build-project.sh +++ b/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/ diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c new file mode 100644 index 0000000..22253a3 --- /dev/null +++ b/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; + } +} + diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h new file mode 100644 index 0000000..4bdb783 --- /dev/null +++ b/src/createEmployeeAccount.h @@ -0,0 +1,10 @@ +#ifndef CREATEEMPLOYEEACCOUNT_H_ +#define CREATEEMPLOYEEACCOUNT_H_ + +#include +#include +#include +#include + +bool isValidEmployeeID(char* employee); +#endif \ No newline at end of file diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..c9e8c0b 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -10,3 +10,4 @@ Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + diff --git a/src/employeeLogin.c b/src/employeeLogin.c index a27e71d..e26e910 100644 --- a/src/employeeLogin.c +++ b/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); } + + diff --git a/src/employeeLogin.h b/src/employeeLogin.h index d6f3314..ca918a7 100644 --- a/src/employeeLogin.h +++ b/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 bool employeesAccess(char* employeesAccessCode); - int checkEmployeeCredentials(char* username , char* password); +void getEmployeeAccessCode(); void getEmployeeCredentials(char* username, char* password); void loginAsEmployee(); + #endif diff --git a/src/main.c b/src/main.c index 7032d5b..48041ae 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,6 @@ #include "mainMenu.h" +#include "employeeLogin.h" +#include"showGeneralInfoEmployee.h" int main() { diff --git a/src/mainMenu.c b/src/mainMenu.c index b2d8243..e62e11d 100644 --- a/src/mainMenu.c +++ b/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() } + + + diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 25355c9..8e881f2 100644 --- a/src/showGeneralInfoEmployee.c +++ b/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"); } } + diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h index bfedbbe..65165f1 100644 --- a/src/showGeneralInfoEmployee.h +++ b/src/showGeneralInfoEmployee.h @@ -5,7 +5,8 @@ #include #include -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 diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c new file mode 100644 index 0000000..f53d86c --- /dev/null +++ b/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 diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 0d1084c..c28c306 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/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 } From affa82bc3d067006fe47681913cdf0aa6e7149f7 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 03:19:45 +0100 Subject: [PATCH 26/58] implement unit tests for the function createNewEmployee() --- build-project.sh | 40 ++++++++++++++++++++++++------ src/createEmployeeAccount.c | 20 ++++++++++++++- src/createEmployeeAccount.h | 2 ++ src/employeeList.txt | 2 ++ src/employeeLogin.c | 2 +- tests/test_createEmployeeAccount.c | 31 +++++++++++++++++++++++ tests/test_employeeLogin.c | 12 ++++----- 7 files changed, 93 insertions(+), 16 deletions(-) diff --git a/build-project.sh b/build-project.sh index 26458c7..aca0b67 100755 --- a/build-project.sh +++ b/build-project.sh @@ -2,26 +2,50 @@ trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; cp mainMenu.c.bak mainMenu.c; + cp createEmployeeAccount.c.bak createEmployeeAccount.c; rm employeeLogin.c.bak; rm mainMenu.c.bak; + rm createEmployeeAccount.c.bak; cd ..; rm -r build; exit' SIGINT clear ceedling test:all + cd src/ -cp employeeLogin.c employeeLogin.c.bak -cp mainMenu.c mainMenu.c.bak + +sed '/John Doe/,$d' employeeList.txt > temp.txt +mv temp.txt employeeList.txt +# backup files +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do + cp "$file" "$file.bak" +done + +# replace .c with .h in respective files 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 employeeLogin.c showGeneralInfoEmployee.c -o main +sed -i 's/employeeLogin.c/employeeLogin.h/g' createEmployeeAccount.c + +# remove 'src/' +for file in employeeLogin.c createEmployeeAccount.c; do + sed -i 's/src\///g' "$file" +done + +# compile and run program +gcc main.c mainMenu.c employeeLogin.c showGeneralInfoEmployee.c createEmployeeAccount.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 + +# restore backups +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do + cp "$file.bak" "$file" +done + +# remove backups +for file in employeeLogin.c.bak mainMenu.c.bak createEmployeeAccount.c.bak; do + rm "$file" +done + cd .. rm -r build/ diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 22253a3..b2743ab 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -1,5 +1,5 @@ #include "employeeLogin.c" -#include "employeeLogin.h" + #include "createEmployeeAccount.h" @@ -18,3 +18,21 @@ bool isValidEmployeeID(char* employeeId) } } +bool createNewEmployee(char* employeeId, char* employeePassword) +{ + FILE* employeesList; + employeesList = fopen("src/employeeList.txt","a"); + + if(employeesList == NULL) + { + printf("Error: could not open the list of Employees"); + return false; + } + + fprintf(employeesList,"\n%s %s\n",employeeId,employeePassword); + fclose(employeesList); + + + return checkEmployeeCredentials(employeeId, employeePassword); +} + diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 4bdb783..4bb2df2 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -7,4 +7,6 @@ #include bool isValidEmployeeID(char* employee); +bool createNewEmployee(char* employeeId, char* employeePassword); + #endif \ No newline at end of file diff --git a/src/employeeList.txt b/src/employeeList.txt index c9e8c0b..1e66ce6 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -11,3 +11,5 @@ Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + + diff --git a/src/employeeLogin.c b/src/employeeLogin.c index e26e910..b9cc3da 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,5 +1,5 @@ #include "mainMenu.h" -#include"employeeLogin.h" +#include "employeeLogin.h" #include "showGeneralInfoEmployee.c" diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index f53d86c..fb6f768 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -59,4 +59,35 @@ void test_isNotValidEmployeeID(void) } +void test_employeeCreatedSuccessfully(void) +{ + /*Arrange*/ + char* potentialEmployees[][2] = { + {"John", "Doe"}, + {"Fizz", "Buzz"}, + {"Jane", "Doe"}, + {"Foo", "Bar"}, + {"MusterMann", "MusterManPassword"}, + {"MusterFrau", "MusterFrauPassword"} + }; + + bool expected[6] = {true,true,true,true,true,true}; + bool result[6]; + + /*Act*/ + + for(int i=0; i<6;i++) + { + result[i] = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); + } + + /*Assert*/ + + for(int i=0; i<6;i++) + { + TEST_ASSERT_EQUAL(expected[i],result[i]); + } + +} + #endif // TEST diff --git a/tests/test_employeeLogin.c b/tests/test_employeeLogin.c index 8860af5..87b9f27 100644 --- a/tests/test_employeeLogin.c +++ b/tests/test_employeeLogin.c @@ -84,12 +84,12 @@ void test_MissingLoginEmployee(void) /*Arrange*/ char* missingEmployeesCredentials[][2] = { - {"John", "doe"}, - {"Jane", "Doe"}, - {"Foo", "Bar"}, - {"Fizz", "Buzz"}, - {"Musterman", "Mustermanpassword"}, - {"Musterfrau", "Musterfraupassword"} + {"Germany", "Berlin"}, + {"Italy", "Rome"}, + {"Belgium", "Bruxelle"}, + {"Swizerland", "Geneve"}, + {"Netherlands", "Amsterdam"}, + {"Sweden", "Stockholm"} }; int expected[] = {0,0,0,0,0,0}; From 7cf0febf2878eae51e1b95ce5706ef39a1387a76 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 03:57:16 +0100 Subject: [PATCH 27/58] implement the getNewEmployeeCredentials() function in order for the user to sign up as an employee --- build-project.sh | 2 +- src/createEmployeeAccount.c | 19 +++++++++++++++++++ src/createEmployeeAccount.h | 2 ++ src/employeeList.txt | 3 --- src/mainMenu.c | 10 +++++++--- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/build-project.sh b/build-project.sh index aca0b67..9b064c8 100755 --- a/build-project.sh +++ b/build-project.sh @@ -22,7 +22,7 @@ for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do done # replace .c with .h in respective files -sed -i 's/employeeLogin.c/employeeLogin.h/g' mainMenu.c +sed -i 's/createEmployeeAccount.c/createEmployeeAccount.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/employeeLogin.c/employeeLogin.h/g' createEmployeeAccount.c diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index b2743ab..92f0f90 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -36,3 +36,22 @@ bool createNewEmployee(char* employeeId, char* employeePassword) return checkEmployeeCredentials(employeeId, employeePassword); } +void getNewEmployeeCredentials() +{ + char newEmployeeId[20]; + char newEmployeePassword[20]; + + printf("please enter your wished Id :"); + scanf("%s",newEmployeeId); + printf("please enter your wished Password :"); + scanf("%s",newEmployeePassword); + + if(createNewEmployee(newEmployeeId,newEmployeePassword)) + { + printf("\n\n Account created successfully !\n\n"); + } + else + { + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + } +} diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 4bb2df2..a5b272a 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -9,4 +9,6 @@ bool isValidEmployeeID(char* employee); bool createNewEmployee(char* employeeId, char* employeePassword); +void getNewEmployeeCredentials(); + #endif \ No newline at end of file diff --git a/src/employeeList.txt b/src/employeeList.txt index 1e66ce6..94986be 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -10,6 +10,3 @@ Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - - - diff --git a/src/mainMenu.c b/src/mainMenu.c index e62e11d..b7a8594 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,6 +1,6 @@ #include "mainMenu.h" - -#include "employeeLogin.c" +#include "employeeLogin.h" +#include "createEmployeeAccount.c" @@ -112,7 +112,10 @@ void menuInput() case 3 : getEmployeeAccessCode(); break; - case 4 : printf("\e[1;1H\e[2J"); + case 4 : getNewEmployeeCredentials(); + break; + + case 5 : printf("\e[1;1H\e[2J"); printf("\nsee you next time !\n\n"); break; } @@ -127,6 +130,7 @@ void showMenu() printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer."); printf("\n\n\t\t\t\t\t\t ->Register as a new costumer."); printf("\n\n\t\t\t\t\t\t ->Login as an Employee."); + printf("\n\n\t\t\t\t\t\t ->Register as an Employee."); printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n"); printf("\n\n\n\n\n Selection :\n"); From e570fb9f66b2f7edc9ee8ffe13436bd9e46223a4 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 04:12:39 +0100 Subject: [PATCH 28/58] refactoring: changed some variables names and added some comments for documentation and enhanced the getnewEmployeeCredentials function. --- src/createEmployeeAccount.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 92f0f90..ac1a26a 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -20,18 +20,19 @@ bool isValidEmployeeID(char* employeeId) bool createNewEmployee(char* employeeId, char* employeePassword) { - FILE* employeesList; - employeesList = fopen("src/employeeList.txt","a"); + FILE* employeesFile; + employeesFile = fopen("src/employeeList.txt","a"); - if(employeesList == NULL) + if(employeesFile == NULL) { - printf("Error: could not open the list of Employees"); + printf("Error: could not find the list of Employees"); return false; } - fprintf(employeesList,"\n%s %s\n",employeeId,employeePassword); - fclose(employeesList); + fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); + fclose(employeesFile); +/*used the checkEmployeeCredentials to check if the new id and password are created successfully*/ return checkEmployeeCredentials(employeeId, employeePassword); } @@ -46,12 +47,6 @@ void getNewEmployeeCredentials() printf("please enter your wished Password :"); scanf("%s",newEmployeePassword); - if(createNewEmployee(newEmployeeId,newEmployeePassword)) - { - printf("\n\n Account created successfully !\n\n"); - } - else - { - printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - } + createNewEmployee(newEmployeeId,newEmployeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + } From b7d38fac5eb9a381524dc9b653fdb19899bfa6d5 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 04:38:01 +0100 Subject: [PATCH 29/58] refactoring: clean up duplicated code for the createEmployeeAccount.c unit tests. --- src/employeeList.txt | 1 - tests/test_createEmployeeAccount.c | 46 +++++++++--------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..ed5a12d 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -9,4 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index fb6f768..7ce99aa 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -18,20 +18,14 @@ 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]; + bool validEmployeeIdExpected = true; - /*Act*/ + /*Act and Assert*/ 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]); + bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i]); + TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); } } @@ -41,22 +35,16 @@ void test_isNotValidEmployeeID(void) /*Arrange*/ char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; - bool invalidEmployeeIdResult[6]; + bool invalidEmployeeIdExpected = false; - /*Act*/ + /*Act and Assert*/ 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]); + bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i]); + TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); } - + } void test_employeeCreatedSuccessfully(void) @@ -71,21 +59,15 @@ void test_employeeCreatedSuccessfully(void) {"MusterFrau", "MusterFrauPassword"} }; - bool expected[6] = {true,true,true,true,true,true}; - bool result[6]; + bool expected = true; + bool result; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<6;i++) { - result[i] = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); - } - - /*Assert*/ - - for(int i=0; i<6;i++) - { - TEST_ASSERT_EQUAL(expected[i],result[i]); + result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); + TEST_ASSERT_EQUAL(expected,result); } } From 5e72e1f6524cfcfe17b9aec48b43717bf98ff0e8 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 05:51:16 +0100 Subject: [PATCH 30/58] optimised the isValidEmployeeID() function and its unit tests --- src/createEmployeeAccount.c | 31 ++++++++++++++++++++++-------- src/createEmployeeAccount.h | 4 +++- tests/test_createEmployeeAccount.c | 15 +++++++++++++-- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index ac1a26a..7abfb02 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -3,19 +3,32 @@ #include "createEmployeeAccount.h" -bool isValidEmployeeID(char* employeeId) +int StringLengthCounter(char* string) { - int characterLimit = 20; - - if(strlen(employeeId)>characterLimit || strchr(employeeId,' ')) + int characterCounter = 0; + int i = 0; + while(string[i] !='\0') { - return false; + characterCounter++; + ++i; } + string[characterCounter] = '\0'; + return characterCounter; +} + - else +bool isValidEmployeeID(char* employeeId, int maximumLength) +{ + int employeeIdLength = strlen(employeeId); + int i; + for(i=0;i #include -bool isValidEmployeeID(char* employee); +bool isValidEmployeeID(char* employee, int maximumLength); bool createNewEmployee(char* employeeId, char* employeePassword); +int StringLengthCounter(char* string); + void getNewEmployeeCredentials(); #endif \ No newline at end of file diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 7ce99aa..dbd971d 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -18,13 +18,19 @@ void test_isValidEmployeeID(void) /*Arrange*/ char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; + int validStringLengths[15]; bool validEmployeeIdExpected = true; + for(int i =0;i<15;i++) + { + validStringLengths[i] = 20; + } + /*Act and Assert*/ for(int i=0; i<15; i++) { - bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i]); + bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths[i]); TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); } } @@ -35,13 +41,18 @@ void test_isNotValidEmployeeID(void) /*Arrange*/ char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; + int invalidStringLengths[6]; bool invalidEmployeeIdExpected = false; + for(int i =0;i<6;i++) + { + invalidStringLengths[i] = 20; + } /*Act and Assert*/ for(int i=0; i<6; i++) { - bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i]); + bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths[i]); TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); } From fed4a0a3ad1f5496be75669d905135ade1b24b54 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 06:31:08 +0100 Subject: [PATCH 31/58] implement the isValidEmployeeID() in the getNewEmployeeCredentials to check Id's validity --- src/createEmployeeAccount.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 7abfb02..8532456 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -53,15 +53,32 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - char newEmployeeId[20]; - char newEmployeePassword[20]; + + int newEmployeeIdlength = 21; + char newEmployeeId[newEmployeeIdlength]; + char newEmployeePassword[newEmployeeIdlength]; + + printf("please enter your wished Id :\n"); + + scanf(" %[^\n]s",newEmployeeId); + + newEmployeeId[newEmployeeIdlength] = '\0'; + + printf("\nplease enter your wished Password :\n"); - printf("please enter your wished Id :"); - scanf("%s",newEmployeeId); - printf("please enter your wished Password :"); scanf("%s",newEmployeePassword); - createNewEmployee(newEmployeeId,newEmployeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + newEmployeePassword[newEmployeeIdlength] = '\0'; + + if(isValidEmployeeID(newEmployeeId,newEmployeeIdlength)) + { + createNewEmployee(newEmployeeId,newEmployeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + } + + else + { + printf("Error : the entered ID either contains space or exceeds the maximum of 20 characters!"); + } } From 25b42cd0c06a5d25a91576fb4b64d5f7cc387c94 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 06:52:53 +0100 Subject: [PATCH 32/58] refactoring: changed some variabales names in createEmployeeAccount.c for better readability. --- src/createEmployeeAccount.c | 28 +++++++++++++++------------- src/createEmployeeAccount.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 8532456..ab4f38a 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -17,18 +17,18 @@ int StringLengthCounter(char* string) } -bool isValidEmployeeID(char* employeeId, int maximumLength) +bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { int employeeIdLength = strlen(employeeId); - int i; - for(i=0;i #include -bool isValidEmployeeID(char* employee, int maximumLength); +bool isValidEmployeeID(const char* employee, int maximumLength); bool createNewEmployee(char* employeeId, char* employeePassword); int StringLengthCounter(char* string); From 7f0db86eb125159fa7baf761c3d6b759f4b3e29e Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 07:03:12 +0100 Subject: [PATCH 33/58] refactoring : removed redundant code from the unit tests of the isValidEmployee() function. --- src/employeeList.txt | 1 + tests/test_createEmployeeAccount.c | 21 ++++++--------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/employeeList.txt b/src/employeeList.txt index ed5a12d..94986be 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -9,3 +9,4 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index dbd971d..5ba39aa 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -14,45 +14,36 @@ void tearDown(void) void test_isValidEmployeeID(void) { - + //test case 0 /*Arrange*/ char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; - int validStringLengths[15]; + int validStringLengths = 20; bool validEmployeeIdExpected = true; - for(int i =0;i<15;i++) - { - validStringLengths[i] = 20; - } - /*Act and Assert*/ for(int i=0; i<15; i++) { - bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths[i]); + bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths); TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); } } void test_isNotValidEmployeeID(void) { - + //test case 1 /*Arrange*/ char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; - int invalidStringLengths[6]; + int invalidStringLengths = 20; bool invalidEmployeeIdExpected = false; - for(int i =0;i<6;i++) - { - invalidStringLengths[i] = 20; - } /*Act and Assert*/ for(int i=0; i<6; i++) { - bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths[i]); + bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths); TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); } From 17327b8e43b7010196a80e884b5d321d87253484 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 18:42:32 +0100 Subject: [PATCH 34/58] implement unit tests for the function isValidPassword(). --- src/createEmployeeAccount.c | 45 ++++++++++++++++++++++++---- src/createEmployeeAccount.h | 2 ++ src/employeeList.txt | 1 - tests/test_createEmployeeAccount.c | 48 ++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index ab4f38a..3951a63 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -16,6 +16,38 @@ int StringLengthCounter(char* string) return characterCounter; } +bool isValidPassword(char* employeePassword, int minimumStringLength) +{ + char* stringpointer = employeePassword; + int employeePasswordLength = 0; + bool letterFound = false, punctuationFound = false, numberFound = false; + + while(*stringpointer!='\0') + { + if(isalpha(* stringpointer)) + { + letterFound = true; + } + else if(isdigit(* stringpointer)) + { + numberFound = true; + } + else if(ispunct(* stringpointer)) + { + punctuationFound = true; + } + if( employeePasswordLength >= minimumStringLength && letterFound && numberFound && punctuationFound) + { + return true; + } + ++stringpointer; + ++employeePasswordLength; + } + + return false; + +} + bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { @@ -54,9 +86,10 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - const int employeeIdlength = 21; - char employeeId[employeeIdlength]; - char employeePassword[employeeIdlength]; + const int employeeIdLength = 21; + char employeeId[employeeIdLength]; + const int minimumPasswordLength = 5; + char employeePassword[minimumPasswordLength]; printf("please enter your wished Id :\n"); @@ -64,15 +97,15 @@ void getNewEmployeeCredentials() scanf(" %[^\n]s",employeeId); - employeeId[employeeIdlength] = '\0'; + employeeId[employeeIdLength] = '\0'; printf("\nplease enter your wished Password :\n"); scanf("%s",employeePassword); - employeePassword[employeeIdlength] = '\0'; + employeePassword[strlen(employeePassword)] = '\0'; - if(isValidEmployeeID(employeeId,employeeIdlength)) + if(isValidEmployeeID(employeeId,employeeIdLength)) { createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); } diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 22cf4d7..7940693 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -5,8 +5,10 @@ #include #include #include +#include bool isValidEmployeeID(const char* employee, int maximumLength); +bool isValidPassword(char* employeePassword, int minimumStringLength); bool createNewEmployee(char* employeeId, char* employeePassword); int StringLengthCounter(char* string); diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..ed5a12d 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -9,4 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 5ba39aa..7cfdb5d 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -49,6 +49,54 @@ void test_isNotValidEmployeeID(void) } +void test_validEmployeePassword(void) +{ + /*Arrange*/ + + char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"}; + int minimalLength = 8; + bool validPasswordResult[6]; + + /*Act*/ + + for(int i=0; i<6; i++) + { + validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); + } + + /*Assert*/ + + for(int i=0; i<6; i++) + { + TEST_ASSERT_TRUE(validPasswordResult[i]); + } + +} + +void test_invalidEmployeePassword(void) +{ + /*Arrange*/ + + char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; + int minimalLength = 8; + bool invalidPasswordResult[6]; + + /*Act*/ + + for(int i=0; i<6; i++) + { + invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); + } + + /*Assert*/ + + for(int i=0; i<6; i++) + { + TEST_ASSERT_FALSE(invalidPasswordResult[i]); + } + +} + void test_employeeCreatedSuccessfully(void) { /*Arrange*/ From 39fce8d4369e0e368f65838a898bb64b59996b87 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 19:29:54 +0100 Subject: [PATCH 35/58] implement the isValidPassword() function in the getNewEmployeeCredentials() function in order to check the validity of the entered password. --- src/createEmployeeAccount.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 3951a63..37b8452 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -105,14 +105,19 @@ void getNewEmployeeCredentials() employeePassword[strlen(employeePassword)] = '\0'; - if(isValidEmployeeID(employeeId,employeeIdLength)) + if(isValidEmployeeID(employeeId,employeeIdLength) && isValidPassword(employeePassword,minimumPasswordLength)) { createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); } + else if(isValidEmployeeID(employeeId,employeeIdLength) && !isValidPassword(employeePassword,minimumPasswordLength)) + { + printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 punctuation character!"); + } + else { - printf("Error : the entered ID either contains space or exceeds the maximum of 20 characters!"); + printf("Error : the entered ID should contain a maximum of 20 letters"); } } From 0ec4eadc9753a8ddde1ea8c855a9ad26dc2e6bbb Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 21:09:21 +0100 Subject: [PATCH 36/58] refactoring: made code more readable by changing some variable name in the isValidPassword() function and added some documentation. --- src/createEmployeeAccount.c | 15 +++++++-------- src/createEmployeeAccount.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 37b8452..f2dcd1a 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -16,11 +16,11 @@ int StringLengthCounter(char* string) return characterCounter; } -bool isValidPassword(char* employeePassword, int minimumStringLength) +bool isValidPassword( char *password, int minimumLength) { - char* stringpointer = employeePassword; - int employeePasswordLength = 0; - bool letterFound = false, punctuationFound = false, numberFound = false; + /*created a pointer(*stringpointer) which helps loop through characters of the string password*/ + char *stringpointer = password; + bool letterFound = false, symbolFound = false, numberFound = false; while(*stringpointer!='\0') { @@ -34,14 +34,13 @@ bool isValidPassword(char* employeePassword, int minimumStringLength) } else if(ispunct(* stringpointer)) { - punctuationFound = true; + symbolFound = true; } - if( employeePasswordLength >= minimumStringLength && letterFound && numberFound && punctuationFound) + if( strlen(password) >= minimumLength && letterFound && numberFound && symbolFound) { return true; } ++stringpointer; - ++employeePasswordLength; } return false; @@ -112,7 +111,7 @@ void getNewEmployeeCredentials() else if(isValidEmployeeID(employeeId,employeeIdLength) && !isValidPassword(employeePassword,minimumPasswordLength)) { - printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 punctuation character!"); + printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!"); } else diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 7940693..12b38f2 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -8,7 +8,7 @@ #include bool isValidEmployeeID(const char* employee, int maximumLength); -bool isValidPassword(char* employeePassword, int minimumStringLength); +bool isValidPassword( char* password, int minimumLength); bool createNewEmployee(char* employeeId, char* employeePassword); int StringLengthCounter(char* string); From 1dc001b251d7d0632a629fef42dd33effa2ae57d Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 21:31:14 +0100 Subject: [PATCH 37/58] refactoring: removed redundant code from the unit tests of the function isValidPassword(). --- tests/test_createEmployeeAccount.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 7cfdb5d..6d8ad91 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -55,20 +55,15 @@ void test_validEmployeePassword(void) char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"}; int minimalLength = 8; + bool validPasswordexpectation = true; bool validPasswordResult[6]; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<6; i++) { validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); - } - - /*Assert*/ - - for(int i=0; i<6; i++) - { - TEST_ASSERT_TRUE(validPasswordResult[i]); + TEST_ASSERT_EQUAL(validPasswordexpectation,validPasswordResult[i]); } } @@ -79,20 +74,15 @@ void test_invalidEmployeePassword(void) char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; int minimalLength = 8; + bool invalidPasswordexpected = false; bool invalidPasswordResult[6]; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<6; i++) { invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); - } - - /*Assert*/ - - for(int i=0; i<6; i++) - { - TEST_ASSERT_FALSE(invalidPasswordResult[i]); + TEST_ASSERT_EQUAL(invalidPasswordexpected,invalidPasswordResult[i]); } } From 69a25cfa6aaa9f2228154b0656d2cefa03717d89 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 04:51:26 +0100 Subject: [PATCH 38/58] implemented unit tests for the new function verifyPassword() and changed the .txt files name while adding a new .txt file for personal emoyees data. --- build-project.sh | 4 +- src/createEmployeeAccount.c | 50 ++++++++++++------- src/createEmployeeAccount.h | 1 + src/employeeLogin.c | 2 +- ...eList.txt => employeesCredentialsList.txt} | 5 ++ src/employeesData.txt | 36 +++++++++++++ tests/test_createEmployeeAccount.c | 46 +++++++++++++++++ 7 files changed, 122 insertions(+), 22 deletions(-) rename src/{employeeList.txt => employeesCredentialsList.txt} (96%) create mode 100644 src/employeesData.txt diff --git a/build-project.sh b/build-project.sh index 9b064c8..ab820fc 100755 --- a/build-project.sh +++ b/build-project.sh @@ -14,8 +14,8 @@ ceedling test:all cd src/ -sed '/John Doe/,$d' employeeList.txt > temp.txt -mv temp.txt employeeList.txt +sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt +mv temp.txt employeesCredentialsList.txt # backup files for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do cp "$file" "$file.bak" diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index f2dcd1a..4af6f04 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -2,20 +2,21 @@ #include "createEmployeeAccount.h" - -int StringLengthCounter(char* string) +bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { - int characterCounter = 0; - int i = 0; - while(string[i] !='\0') + int employeeIdLength = strlen(employeeId); + + for(int i=0;i Date: Mon, 6 Feb 2023 06:49:08 +0100 Subject: [PATCH 39/58] implement the verifyPassword() function in the getNewEmployeeCredentials() so that the validity of the password can be checked twice. --- src/createEmployeeAccount.c | 42 +++++++++++++++++++++----------- src/employeesCredentialsList.txt | 5 ---- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 4af6f04..633561f 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -97,18 +97,18 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - const int employeeIdLength = 21; - char employeeId[employeeIdLength]; + const int Length = 21; + char employeeId[Length]; const int minimumPasswordLength = 5; - char employeePassword[minimumPasswordLength]; - + char employeePassword[Length]; + char passwordVerfication[Length]; printf("please enter your wished Id :\n"); /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ scanf(" %[^\n]s",employeeId); - employeeId[employeeIdLength] = '\0'; + employeeId[Length] = '\0'; printf("\nplease enter your wished Password :\n"); @@ -116,20 +116,34 @@ void getNewEmployeeCredentials() employeePassword[strlen(employeePassword)] = '\0'; - if(isValidEmployeeID(employeeId,employeeIdLength) && isValidPassword(employeePassword,minimumPasswordLength)) - { - createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - } + printf("\nplease confirm your Password :\n"); + + scanf("%s",passwordVerfication); + + passwordVerfication[strlen(employeePassword)] = '\0'; - else if(isValidEmployeeID(employeeId,employeeIdLength) && !isValidPassword(employeePassword,minimumPasswordLength)) + if(verifyPassword(passwordVerfication,employeePassword)) { - printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!"); - } + + if(isValidEmployeeID(employeeId,Length) && isValidPassword(employeePassword,minimumPasswordLength)) + { + createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + } + + else if(isValidEmployeeID(employeeId,Length) && !isValidPassword(employeePassword,minimumPasswordLength)) + { + printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!"); + } + else + { + printf("Error : the entered ID should contain a maximum of 20 letters"); + } + + } else { - printf("Error : the entered ID should contain a maximum of 20 letters"); + printf("the Verification password and the entered password dont match"); } - } diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index d44964d..ed5a12d 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,8 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - - - - - From c06136470d95f0fe7dc0918606a41160cd688053 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 07:00:49 +0100 Subject: [PATCH 40/58] refactoring: improved code readability by removing redundant lines, renaming variables and adding comments for documentation. --- src/createEmployeeAccount.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 633561f..bb283e0 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -5,7 +5,7 @@ bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { int employeeIdLength = strlen(employeeId); - + /* looping through the employeeId string until a space is found to return false or true otherwise*/ for(int i=0;i Date: Mon, 6 Feb 2023 07:32:32 +0100 Subject: [PATCH 41/58] refactoring: replaced the redundant arrays in the unit tests of verifyPassword() function with a matrix for better readability --- tests/test_createEmployeeAccount.c | 57 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 456655e..1f4d3b2 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -91,22 +91,27 @@ void test_verifyPasswordSuccess() { /*Arrange*/ - char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"}; - char* confirmation[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"}; - bool result[10]; - - /*Act*/ - - for(int i=0; i<10; i++) - { - result[i] = verifyPassword(password[i],confirmation[i]); - } + char* passwordsAndVerifications[][2] = { + {"Atharva123.","Atharva123."}, + {"fdai.7207","fdai.7207"}, + {"fizz.buzz132","fizz.buzz132"}, + {"23.March.1999","23.March.1999"}, + {"John.doe99","John.doe99"}, + {"foo/bar2","foo/bar2"}, + {"fizz+3buzz","fizz+3buzz"}, + {"gitlab2.com","gitlab2.com"}, + {"4test:all","4test:all"}, + {"WS-2023","WS-2023"} + }; + + bool expectation = true; - /*Assert*/ + /*Act and Assert*/ for(int i=0; i<10; i++) { - TEST_ASSERT_TRUE(result[i]); + bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); + TEST_ASSERT_EQUAL(expectation,result); } } @@ -114,23 +119,29 @@ void test_verifyPasswordFailure() { /*Arrange*/ - char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"}; - char* confirmation[10] = {"Atharva123","fdai.72","invalidPassword","23.May.1999","Jane.doe99","foo*bar3","fizz-3buzz","github.com","4ceedlingtest:all","SS-2023"}; - bool result[10]; + char* passwordsAndVerifications[][2] = { + {"Atharva123.","Atharva123"}, + {"fdai.7207","fdai.72"}, + {"fizz.buzz132","invalidPassword"}, + {"23.March.1999","23.May.1999"}, + {"John.doe99","Jane.doe99"}, + {"foo/bar2","foo*bar3"}, + {"fizz+3buzz","fizz-3buzz"}, + {"gitlab2.com","github.com"}, + {"4test:all","4ceedlingtest:all"}, + {"WS-2023","SS-2023"} + }; + + bool expectation = false; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<10; i++) { - result[i] = verifyPassword(password[i],confirmation[i]); + bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); + TEST_ASSERT_EQUAL(expectation,result); } - /*Assert*/ - - for(int i=0; i<10; i++) - { - TEST_ASSERT_FALSE(result[i]); - } } void test_employeeCreatedSuccessfully(void) From c659f9b9aa7bb924bcb3b722d853f86224959aa0 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 17:18:35 +0100 Subject: [PATCH 42/58] implement unit tests for the function storeEmployeeData() and fixed a bug in the unit tests of the function chooseOption. --- build-project.sh | 4 ++++ src/createEmployeeAccount.c | 24 +++++++++++++++++++++++- src/createEmployeeAccount.h | 10 ++++++++++ src/employeesCredentialsList.txt | 5 +++++ src/employeesData.txt | 30 ++++++++++++++++-------------- src/mainMenu.c | 2 +- tests/test_createEmployeeAccount.c | 28 ++++++++++++++++++++++++++++ tests/test_mainMenu.c | 6 +++--- 8 files changed, 90 insertions(+), 19 deletions(-) diff --git a/build-project.sh b/build-project.sh index ab820fc..0f7c75e 100755 --- a/build-project.sh +++ b/build-project.sh @@ -16,6 +16,10 @@ cd src/ sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt mv temp.txt employeesCredentialsList.txt + +sed '/Name : John/,$d' employeesData.txt > temp.txt +mv temp.txt employeesData.txt + # backup files for file in employeeLogin.c mainMenu.c createEmployeeAccount.c; do cp "$file" "$file.bak" diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index bb283e0..07877db 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -61,6 +61,23 @@ int StringLengthCounter(char* string) return characterCounter; } +bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber) +{ + FILE* employeesDatalist; + employeesDatalist = fopen("src/employeesData.txt","a"); + if(employeesDatalist == NULL) + { + printf("Error : could not find file"); + return false; + } + else + { + fprintf(employeesDatalist,"\n\nName : %s\nLast name : %s\nAdress : %s\nPhone number : %s",name,lastName,adress,phoneNumber); + fclose(employeesDatalist); + return true; + } +} + bool verifyPassword(char* enteredPassword,char* Confirmation) { return !(strcmp(enteredPassword,Confirmation)); @@ -89,12 +106,16 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - + employeedata *data; + data = (employeedata*)malloc(sizeof(employeedata)); const int maxLength = 21; char employeeId[maxLength]; + const int minPasswordLength = 5; + char employeePassword[maxLength]; char passwordVerfication[maxLength]; + printf("please enter your wished Id :\n"); /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ @@ -115,6 +136,7 @@ void getNewEmployeeCredentials() passwordVerfication[strlen(employeePassword)] = '\0'; + if(verifyPassword(passwordVerfication,employeePassword)) { diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index c4fc698..181228c 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -7,10 +7,20 @@ #include #include +struct employeesInformations +{ + char firstName[15]; + char lastName[15]; + char adress[20]; + char phoneNumber[15]; +}; +typedef struct employeesInformations employeedata; + bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidPassword( char* password, int minimumLength); bool createNewEmployee(char* employeeId, char* employeePassword); bool verifyPassword(char* enteredPassword,char* passwordConfirmation); +bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber); int StringLengthCounter(char* string); diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index ed5a12d..d44964d 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,3 +9,8 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + + + + + diff --git a/src/employeesData.txt b/src/employeesData.txt index 8b48973..55e1cc0 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -1,36 +1,38 @@ -Employee 1 -Username : Atharva Name : Atharva -last name : Naik +Last name : Naik Adress : Fulda,leipzigerstrasse,1 Phone number : +4964169865172 -Employee 2 + Name : Can -last name : Hacioglu +Last name : Hacioglu Adress : Fulda,leipzigerstrasse,2 Phone number : +4915973325487 -Employee 3 + Name : Haytham -last name : Daoula +Last name : Daoula Adress : Fulda,leipzigerstrasse,3 Phone number : +4995435870169 -Employee 4 + Name : Julius -last name : Engel +Last name : Engel Adress : Fulda,leipzigerstrasse,4 Phone number : +4939172972187 -Employee 5 + Name : Mohamed -last name : Dahi +Last name : Dahi Adress : Fulda,leipzigerstrasse,5 Phone number : +4921865106647 -Employee 6 + Name : Shivam -last name : Chaudhary +Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 -Phone number : +4918756871384 \ No newline at end of file +Phone number : +4918756871384 + + + + diff --git a/src/mainMenu.c b/src/mainMenu.c index b7a8594..fdc2f21 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -27,7 +27,7 @@ bool checkIfInteger(char* userInput) bool chooseOption(int choiceInput) { - return !(choiceInput < 1 || choiceInput > 4); + return !(choiceInput < 1 || choiceInput > 5); } diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 1f4d3b2..df336c1 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -142,6 +142,34 @@ void test_verifyPasswordFailure() TEST_ASSERT_EQUAL(expectation,result); } +} + +void test_employeesDataStoringSuccess(void) +{ + /*Arrange*/ + + char* firstNames[5] = {"John","Jane","Foo","Fizz","Mustermann"}; + char* lastNames[5] = {"Doe","Done","Bar","Buzz","Mustermanpass"}; + char* adress[5] = {"fulda,leipzigerstr12","fulda,leipzigerstr13","fulda,leipzigerstr14","fulda,leipzigerstr15","fulda,leipzigerstr16"}; + char* phoneNumber[5] = {"+4926428421469","+4932517359874","+4913598765315","+4968145725873","+4938197853812"}; + bool creationResult[5]; + + /*Act*/ + + for(int i=0;i<5;i++) + { + creationResult[i] = storeEmployeeData(firstNames[i],lastNames[i],adress[i],phoneNumber[i]); + } + + /*Assert*/ + + for(int i=0;i<5;i++) + { + TEST_ASSERT_TRUE(creationResult[i]); + } + + + } void test_employeeCreatedSuccessfully(void) diff --git a/tests/test_mainMenu.c b/tests/test_mainMenu.c index 4883180..97cc069 100644 --- a/tests/test_mainMenu.c +++ b/tests/test_mainMenu.c @@ -138,14 +138,14 @@ void test_validChoiceInput(void) - for(int i = 0; i < 4; i++) + for(int i = 0; i < 5; i++) { validInput[i] = i + 1; } /*Act and Asssert*/ - for(int i = 0; i < 4; i++) + for(int i = 0; i < 5; i++) { bool validInputResult = chooseOption(validInput[i]); @@ -197,7 +197,7 @@ void test_invalidChoiceInput_secondCase(void) for(int i = 0; i < 100; i++) { - invalidInput[i] = i + 5; + invalidInput[i] = i + 6; } /*Act and Assert*/ From b5a764b566af457ecf361f6b80b5a2efbc7c3d52 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 19:17:07 +0100 Subject: [PATCH 43/58] implemented the storeEmployeeData() function in the getnewEmployeeCredentials() function in order for the new employee to enter his personal data. --- src/createEmployeeAccount.c | 35 +++++++++++++++++++------------- src/employeesCredentialsList.txt | 5 ----- src/employeesData.txt | 4 ---- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 07877db..791a92a 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -137,28 +137,35 @@ void getNewEmployeeCredentials() passwordVerfication[strlen(employeePassword)] = '\0'; - if(verifyPassword(passwordVerfication,employeePassword)) + if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) { + printf("\n\nplease enter your first name\n"); + + scanf("%s",data->firstName); + + printf("\n\nplease enter your last name\n"); + + scanf("%s",data->lastName); + + printf("\n\nplease enter your adress\n"); + + scanf("%s",data->adress); + + printf("\n\nplease enter your Phone number\n"); + + scanf("%s",data->phoneNumber); - if(isValidEmployeeID(employeeId,maxLength) && isValidPassword(employeePassword,minPasswordLength)) - { createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - } - else if(isValidEmployeeID(employeeId,maxLength) && !isValidPassword(employeePassword,minPasswordLength)) - { - printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!"); - } - - else - { - printf("Error : the entered ID should contain a maximum of 20 letters"); - } + storeEmployeeData(data->firstName,data->lastName,data->adress,data->phoneNumber); } else { - printf("the Verification password and the entered password dont match"); + printf("\n\nError! one of these conditions is not met in your input\n\n"); + printf("\n-the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!\n"); + printf("\n-the entered ID should contain a maximum of 20 letters!\n"); + printf("\n-the verification password should match with the entered password.\n"); } } diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index d44964d..ed5a12d 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,8 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - - - - - diff --git a/src/employeesData.txt b/src/employeesData.txt index 55e1cc0..16f8e9a 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -32,7 +32,3 @@ Name : Shivam Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 Phone number : +4918756871384 - - - - From 6ad040483c1bed1f321aab03230b9ded91020fb8 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 19:35:59 +0100 Subject: [PATCH 44/58] refactoring: removed unnecessary lines and changed variables to constants in the storeEmployeeData() given that the function doesnt modify them. --- src/createEmployeeAccount.c | 36 +++++++++++++----------------------- src/createEmployeeAccount.h | 4 ++-- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 791a92a..47c6eb9 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -61,7 +61,9 @@ int StringLengthCounter(char* string) return characterCounter; } -bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber) +/*changed the string parameters to constants as an indicator that the function doesnt modify them*/ + +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber) { FILE* employeesDatalist; employeesDatalist = fopen("src/employeesData.txt","a"); @@ -106,66 +108,54 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - employeedata *data; - data = (employeedata*)malloc(sizeof(employeedata)); + employeedata *data = (employeedata*)malloc(sizeof(employeedata)); const int maxLength = 21; char employeeId[maxLength]; - const int minPasswordLength = 5; - char employeePassword[maxLength]; char passwordVerfication[maxLength]; printf("please enter your wished Id :\n"); - /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ - scanf(" %[^\n]s",employeeId); - employeeId[maxLength] = '\0'; printf("\nplease enter your wished Password :\n"); - scanf("%s",employeePassword); - employeePassword[strlen(employeePassword)] = '\0'; printf("\nplease confirm your Password :\n"); - scanf("%s",passwordVerfication); - passwordVerfication[strlen(employeePassword)] = '\0'; if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) { printf("\n\nplease enter your first name\n"); - scanf("%s",data->firstName); printf("\n\nplease enter your last name\n"); - scanf("%s",data->lastName); printf("\n\nplease enter your adress\n"); - - scanf("%s",data->adress); + scanf("%s",data->address); printf("\n\nplease enter your Phone number\n"); - scanf("%s",data->phoneNumber); - createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + createNewEmployee(employeeId,employeePassword) ? + printf("\n\n Account created successfully !\n\n") : + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - storeEmployeeData(data->firstName,data->lastName,data->adress,data->phoneNumber); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); } else { - printf("\n\nError! one of these conditions is not met in your input\n\n"); - printf("\n-the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!\n"); - printf("\n-the entered ID should contain a maximum of 20 letters!\n"); - printf("\n-the verification password should match with the entered password.\n"); + printf("\nError! one of these conditions is not met in your input.\n"); + printf("\n-The entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol.\n"); + printf("\n-The entered ID should contain a maximum of 20 letters.\n"); + printf("\n-The verification password should match with the entered password.\n"); } } diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 181228c..ca94af0 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -11,7 +11,7 @@ struct employeesInformations { char firstName[15]; char lastName[15]; - char adress[20]; + char address[20]; char phoneNumber[15]; }; typedef struct employeesInformations employeedata; @@ -20,7 +20,7 @@ bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidPassword( char* password, int minimumLength); bool createNewEmployee(char* employeeId, char* employeePassword); bool verifyPassword(char* enteredPassword,char* passwordConfirmation); -bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber); +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); int StringLengthCounter(char* string); From 6a1e132e53d6ca1d147f8499663f59341826aac1 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 20:19:42 +0100 Subject: [PATCH 45/58] refactoring: replaced 4 arrays in the unit tests of the function storeEmployeeData() with one matrix to avoid repeated code and removed unnecessary lines. --- tests/test_createEmployeeAccount.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index df336c1..4db4ca1 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -147,29 +147,22 @@ void test_verifyPasswordFailure() void test_employeesDataStoringSuccess(void) { /*Arrange*/ + char*data[][4] ={ + {"John","Doe","fulda,leipzigerstr12","+4926428421469"}, + {"Jane","Done","fulda,leipzigerstr13","+4932517359874"}, + {"Foo","Bar","fulda,leipzigerstr14","+4913598765315"}, + {"Mustermann","Mustermanpass","fulda,leipzigerstr16","+4938197853812"} + }; + bool creationExpectation = true; - char* firstNames[5] = {"John","Jane","Foo","Fizz","Mustermann"}; - char* lastNames[5] = {"Doe","Done","Bar","Buzz","Mustermanpass"}; - char* adress[5] = {"fulda,leipzigerstr12","fulda,leipzigerstr13","fulda,leipzigerstr14","fulda,leipzigerstr15","fulda,leipzigerstr16"}; - char* phoneNumber[5] = {"+4926428421469","+4932517359874","+4913598765315","+4968145725873","+4938197853812"}; - bool creationResult[5]; - - /*Act*/ - - for(int i=0;i<5;i++) - { - creationResult[i] = storeEmployeeData(firstNames[i],lastNames[i],adress[i],phoneNumber[i]); - } - - /*Assert*/ + /*Act and Assert*/ - for(int i=0;i<5;i++) + for(int i=0;i<4;i++) { - TEST_ASSERT_TRUE(creationResult[i]); + bool creationResult = storeEmployeeData(data[i][0],data[i][1],data[i][2],data[i][3]); + TEST_ASSERT_EQUAL(creationExpectation,creationResult); } - - } void test_employeeCreatedSuccessfully(void) From 80b26f2a6dba01794228bf6653ae191eaf111683 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Tue, 7 Feb 2023 23:09:08 +0100 Subject: [PATCH 46/58] implement unit tests for the new function isvalidName(). --- src/createEmployeeAccount.c | 19 ++++++++++++ src/createEmployeeAccount.h | 1 + tests/test_createEmployeeAccount.c | 50 +++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 47c6eb9..b298929 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -48,6 +48,24 @@ bool isValidPassword( char *password, int minimumLength) } +bool isValidName(char* name, int minimalLength) +{ + if(strlen(name) < minimalLength) + { + return false; + } + + for(int i = 0;i Date: Wed, 8 Feb 2023 00:15:54 +0100 Subject: [PATCH 47/58] implement the isValidName() in the getNewEmployeeCredentials() and fixed a bug in the createNewEmployee() function. --- src/createEmployeeAccount.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index b298929..db149f8 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -88,6 +88,7 @@ bool storeEmployeeData(const char *name,const char *lastName,const char *adress, if(employeesDatalist == NULL) { printf("Error : could not find file"); + fclose(employeesDatalist); return false; } else @@ -112,6 +113,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword) if(employeesFile == NULL) { printf("Error: could not find the list of Employees"); + fclose(employeesFile); return false; } @@ -120,7 +122,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword) /*used the checkEmployeeCredentials to check if the new id and password are created successfully*/ - return checkEmployeeCredentials(employeeId, employeePassword); + return true; } @@ -140,33 +142,39 @@ void getNewEmployeeCredentials() employeeId[maxLength] = '\0'; printf("\nplease enter your wished Password :\n"); - scanf("%s",employeePassword); + scanf(" %[^\n]s",employeePassword); employeePassword[strlen(employeePassword)] = '\0'; printf("\nplease confirm your Password :\n"); - scanf("%s",passwordVerfication); + scanf(" %[^\n]s",passwordVerfication); passwordVerfication[strlen(employeePassword)] = '\0'; if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) { printf("\n\nplease enter your first name\n"); - scanf("%s",data->firstName); + scanf(" %[^\n]s",data->firstName); printf("\n\nplease enter your last name\n"); - scanf("%s",data->lastName); + scanf(" %[^\n]s",data->lastName); - printf("\n\nplease enter your adress\n"); - scanf("%s",data->address); - - printf("\n\nplease enter your Phone number\n"); - scanf("%s",data->phoneNumber); + if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) + { + printf("\n\nplease enter your adress\n"); + scanf(" %[^\n]s",data->address); - createNewEmployee(employeeId,employeePassword) ? - printf("\n\n Account created successfully !\n\n") : - printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + printf("\n\nplease enter your Phone number\n"); + scanf(" %[^\n]s",data->phoneNumber); - storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + createNewEmployee(employeeId,employeePassword) ? + printf("\n\n Account created successfully !\n\n") : + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + } + else + { + printf("the given name contains unwanted characters(spaces, symbols,numbers)"); + } } else From d5952a55bf49536e07548add3f74b03e71fc1de2 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 00:37:00 +0100 Subject: [PATCH 48/58] refactoring: removed some constants from the .c file and added them to the header file and made the isValidName() function more readable. --- src/createEmployeeAccount.c | 21 ++++++++------------- src/createEmployeeAccount.h | 4 ++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index db149f8..3fb19e5 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -2,7 +2,7 @@ #include "createEmployeeAccount.h" -bool isValidEmployeeID(const char* employeeId, int maximumStringLength) +bool isValidEmployeeID(const char* employeeId,const int maximumStringLength) { int employeeIdLength = strlen(employeeId); /* looping through the employeeId string until a space is found to return false or true otherwise*/ @@ -17,7 +17,7 @@ bool isValidEmployeeID(const char* employeeId, int maximumStringLength) } -bool isValidPassword( char *password, int minimumLength) +bool isValidPassword( char *password,const int minimumLength) { /*created a pointer(*stringpointer) which helps loop through characters of the string password*/ char *stringpointer = password; @@ -48,20 +48,21 @@ bool isValidPassword( char *password, int minimumLength) } -bool isValidName(char* name, int minimalLength) +bool isValidName(char* name,const int minimalLength) { - if(strlen(name) < minimalLength) + int nameLength = strlen(name); + if(nameLength < minimalLength) { return false; } - for(int i = 0;i #include +#define minPasswordLength 5 +#define minimumNameLength 4 +#define maxLength 21 + struct employeesInformations { char firstName[15]; From 5ba7c64f538cf72b2f99ee16a999e8b1a468806e Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 00:59:09 +0100 Subject: [PATCH 49/58] correct some logical mistakes in the test_createEmployeeAccount.c file --- src/employeesData.txt | 8 ++++++++ tests/test_createEmployeeAccount.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/employeesData.txt b/src/employeesData.txt index 16f8e9a..0169bc0 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -32,3 +32,11 @@ Name : Shivam Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 Phone number : +4918756871384 + + + + + + + + diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index f6504b3..d08f64f 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -194,7 +194,7 @@ void test_validName(void) { /*Arrange*/ - char* validNames[] = {"John","Jane","Fizz","Foo","Atharva","Can","Julius","Haytham","Mohamed","Shivam"}; + char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"}; int minimalLength = 4; bool validNamesResult[10]; @@ -209,7 +209,7 @@ void test_validName(void) for(int i = 0;i<10;i++) { - TEST_ASSERT_TRUE(validNames[i]); + TEST_ASSERT_TRUE(validNamesResult[i]); } } @@ -218,7 +218,7 @@ void test_invalidName(void) { /*Arrange*/ - char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul132ius","123Haytham",".Mohamed"," Shivam"}; + char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"}; int minimalLength = 4; bool invalidNamesResult[10]; From 1112a6f36506e8fa16f646fa866b69242622db52 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 01:07:34 +0100 Subject: [PATCH 50/58] refactoring: removed redundant codes from the unit tests of the isValidName() function. --- src/employeesData.txt | 8 -------- tests/test_createEmployeeAccount.c | 28 ++++++++-------------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/employeesData.txt b/src/employeesData.txt index 0169bc0..16f8e9a 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -32,11 +32,3 @@ Name : Shivam Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 Phone number : +4918756871384 - - - - - - - - diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index d08f64f..4b66ccf 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -196,20 +196,14 @@ void test_validName(void) char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"}; int minimalLength = 4; - bool validNamesResult[10]; + bool validNamesExpectation = true; - /*Act*/ - - for(int i = 0;i<10;i++) - { - validNamesResult[i] = isValidName(validNames[i],minimalLength); - } - - /*Assert*/ + /*Act and Assert*/ for(int i = 0;i<10;i++) { - TEST_ASSERT_TRUE(validNamesResult[i]); + bool validNamesResult = isValidName(validNames[i],minimalLength); + TEST_ASSERT_EQUAL(validNamesExpectation,validNamesResult); } } @@ -220,20 +214,14 @@ void test_invalidName(void) char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"}; int minimalLength = 4; - bool invalidNamesResult[10]; + bool invalidNamesExpectation = false; - /*Act*/ - - for(int i = 0;i<10;i++) - { - invalidNamesResult[i] = isValidName(invalidNames[i],minimalLength); - } - - /*Assert*/ + /*Act and Assert*/ for(int i = 0;i<10;i++) { - TEST_ASSERT_FALSE(invalidNamesResult[i]); + bool invalidNamesResult = isValidName(invalidNames[i],minimalLength); + TEST_ASSERT_EQUAL(invalidNamesExpectation,invalidNamesResult); } } From 57292f4b64a1c9e58ce932337fcb4701dd68dedc Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 02:12:04 +0100 Subject: [PATCH 51/58] implement unit tests for the function validPhoneNumber(). --- src/createEmployeeAccount.c | 19 +++++++++++++++ src/createEmployeeAccount.h | 1 + src/mainMenu.c | 34 +++++++++++++------------- tests/test_createEmployeeAccount.c | 38 ++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 3fb19e5..f8668bd 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -67,6 +67,25 @@ bool isValidName(char* name,const int minimalLength) return true; } +bool isValidPhoneNumber(char *phoneNumber) +{ + const int validNumberLength = 14; + int numberLength = strlen(phoneNumber); + + if(numberLength != validNumberLength) + { + return false; + } + + if(phoneNumber[0]!='+' || phoneNumber[1]!='4' || phoneNumber[2]!='9') + { + return false; + } + + return true; + +} + int StringLengthCounter(char* string) { int characterCounter = 0; diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 33b5f97..03cd582 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -26,6 +26,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword); bool verifyPassword(char* enteredPassword,char* passwordConfirmation); bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); bool isValidName(char* name,int minimalLength); +bool isValidPhoneNumber(char *phoneNumber); int StringLengthCounter(char* string); diff --git a/src/mainMenu.c b/src/mainMenu.c index fdc2f21..8fcb882 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -45,42 +45,42 @@ void ageInput() while (true) { - /*the userInput string is changed to a number with the strtol function*/ + /*the userInput string is changed to a number with the strtol function*/ - age = strtol(userInput,&userInputPointer,10); + age = strtol(userInput,&userInputPointer,10); if((checkIfInteger(userInput))&& (agePermission(age))) - { + { - printf("Access granted!\n\n\n\n"); + printf("Access granted!\n\n\n\n"); - showMenu(); + showMenu(); - menuInput(); + menuInput(); - break; + break; - } + } - else if((checkIfInteger(userInput)) && !(agePermission(age))) - { + else if((checkIfInteger(userInput)) && !(agePermission(age))) + { printf("You should be at least 18 years old to create a bank account!\n"); - break; + break; - } + } - else - { - printf("input invalid! try again!\n"); + else + { + printf("input invalid! try again!\n"); scanf("%s",userInput); - } + } -} + } } void menuInput() diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 4b66ccf..d1c369e 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -226,4 +226,42 @@ void test_invalidName(void) } +void test_validPhoneNumber(void) +{ + /*Arrange*/ + char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; + bool validPhoneNumbersResult[5]; + + /*Act*/ + for(int i =0;i<5;i++) + { + validPhoneNumbersResult[i] = isValidPhoneNumber(validPhoneNumbers[i]); + } + + /*Assert*/ + for(int i=0;i<5;i++) + { + TEST_ASSERT_TRUE(validPhoneNumbersResult[i]); + } +} + +void test_invalidPhoneNumber(void) +{ + /*Arrange*/ + char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; + bool invalidPhoneNumbersResult[2]; + + /*Act*/ + for(int i =0;i<5;i++) + { + invalidPhoneNumbersResult[i] = isValidPhoneNumber(invalidPhoneNumbers[i]); + } + + /*Assert*/ + for(int i=0;i<5;i++) + { + TEST_ASSERT_FALSE(invalidPhoneNumbersResult[i]); + } +} + #endif // TEST From 1e047c30b065b78c0a5a7a093f06ebcb8869a1e1 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 02:16:53 +0100 Subject: [PATCH 52/58] implement the function isValidPhoneNumber() in the getNewEmployeeCredentials() function. --- src/createEmployeeAccount.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index f8668bd..308b390 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -179,11 +179,17 @@ void getNewEmployeeCredentials() printf("\n\nplease enter your Phone number\n"); scanf(" %[^\n]s",data->phoneNumber); - - createNewEmployee(employeeId,employeePassword) ? - printf("\n\n Account created successfully !\n\n") : - printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + if(isValidPhoneNumber(data->phoneNumber)) + { + createNewEmployee(employeeId,employeePassword) ? + printf("\n\n Account created successfully !\n\n") : + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + } + else + { + printf("\nInvalid phone number!\n"); + } } else { From fc6033da000058972f55b42b450098c2b6381349 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 02:23:32 +0100 Subject: [PATCH 53/58] refactoring: removed redundant code from the function isValidPhoneNumber() and the constant from the function and added it to the header file. --- src/createEmployeeAccount.c | 10 ++-------- src/createEmployeeAccount.h | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 308b390..9550f40 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -69,21 +69,15 @@ bool isValidName(char* name,const int minimalLength) bool isValidPhoneNumber(char *phoneNumber) { - const int validNumberLength = 14; int numberLength = strlen(phoneNumber); - if(numberLength != validNumberLength) - { - return false; - } - - if(phoneNumber[0]!='+' || phoneNumber[1]!='4' || phoneNumber[2]!='9') + /*this function checks if the 3 first characters a german suffix are*/ + if(phoneNumber[0]!='+' || phoneNumber[1]!='4' || phoneNumber[2]!='9' || numberLength != validNumberLength) { return false; } return true; - } int StringLengthCounter(char* string) diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 03cd582..9c67108 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -10,6 +10,7 @@ #define minPasswordLength 5 #define minimumNameLength 4 #define maxLength 21 +#define validNumberLength 14 struct employeesInformations { From 4c49a78378b0668c1b378d6ed4027f6426958880 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 02:31:37 +0100 Subject: [PATCH 54/58] refactoring : removed code duplicates for better readability in the unit tests of the function isValidPhoneNumber(). --- tests/test_createEmployeeAccount.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index d1c369e..fcd24d3 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -230,18 +230,13 @@ void test_validPhoneNumber(void) { /*Arrange*/ char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; - bool validPhoneNumbersResult[5]; + bool validPhoneNumbersExpectation = true; - /*Act*/ + /*Act and Assert*/ for(int i =0;i<5;i++) { - validPhoneNumbersResult[i] = isValidPhoneNumber(validPhoneNumbers[i]); - } - - /*Assert*/ - for(int i=0;i<5;i++) - { - TEST_ASSERT_TRUE(validPhoneNumbersResult[i]); + bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]); + TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult); } } @@ -249,19 +244,15 @@ void test_invalidPhoneNumber(void) { /*Arrange*/ char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; - bool invalidPhoneNumbersResult[2]; + bool invalidPhoneNumbersExpectation = false; - /*Act*/ + /*Act and Assert*/ for(int i =0;i<5;i++) { - invalidPhoneNumbersResult[i] = isValidPhoneNumber(invalidPhoneNumbers[i]); + bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]); + TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult); } - /*Assert*/ - for(int i=0;i<5;i++) - { - TEST_ASSERT_FALSE(invalidPhoneNumbersResult[i]); - } } #endif // TEST From 9cad95ce803813f66ded574f7ccc4e66a4cc8627 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Fri, 10 Feb 2023 01:57:41 +0100 Subject: [PATCH 55/58] implement the function isValidAdress(). --- src/createEmployeeAccount.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 9550f40..c7fac7c 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -80,6 +80,41 @@ bool isValidPhoneNumber(char *phoneNumber) return true; } +bool isValidAdress(char *street,int houseNumber,char* city,int postalCode) +{ + int maximalLength = 20; + int minimalLength = 3; + bool validStreet = true; + bool validHouseNumber = true; + bool validCity = true; + bool validpostalCode = true; + if(strlen(street)>20 || strlen(street)<3) + { + validStreet = false; + } + + if(strlen(city)>20 || strlen(city)<3) + { + validCity = false; + } + if(houseNumber<1 || houseNumber > 999) + { + validHouseNumber = false; + } + if(postalCode<1000 || postalCode > 99000) + { + validpostalCode = false; + } + if(validStreet && validCity && validHouseNumber && validpostalCode) + { + return true; + } + else + { + return false; + } +} + int StringLengthCounter(char* string) { int characterCounter = 0; From f1948736400453fed59078051298b55e49a7b725 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Fri, 10 Feb 2023 03:16:09 +0100 Subject: [PATCH 56/58] implement unit tests for the isValidAdress() function. --- src/createEmployeeAccount.c | 13 ++++----- src/createEmployeeAccount.h | 7 +++-- tests/test_createEmployeeAccount.c | 47 +++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index c7fac7c..39f2bac 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -80,20 +80,20 @@ bool isValidPhoneNumber(char *phoneNumber) return true; } -bool isValidAdress(char *street,int houseNumber,char* city,int postalCode) +bool isValidAdress(char *street,char* city,int houseNumber,int postalCode) { - int maximalLength = 20; - int minimalLength = 3; + int lengthMax = 20; + int LengthMin = 3; bool validStreet = true; bool validHouseNumber = true; bool validCity = true; bool validpostalCode = true; - if(strlen(street)>20 || strlen(street)<3) + if(strlen(street)>lengthMax || strlen(street)20 || strlen(city)<3) + if(strlen(city)>lengthMax || strlen(city) Date: Fri, 10 Feb 2023 03:34:57 +0100 Subject: [PATCH 57/58] refactoring: removed redundancy in the isValidAdress() function. --- src/createEmployeeAccount.c | 15 +++------------ src/createEmployeeAccount.h | 2 ++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 39f2bac..edd9262 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -82,18 +82,15 @@ bool isValidPhoneNumber(char *phoneNumber) bool isValidAdress(char *street,char* city,int houseNumber,int postalCode) { - int lengthMax = 20; - int LengthMin = 3; bool validStreet = true; bool validHouseNumber = true; bool validCity = true; bool validpostalCode = true; - if(strlen(street)>lengthMax || strlen(street)maximalAdressLength || strlen(street)lengthMax || strlen(city)maximalAdressLength || strlen(city) Date: Fri, 10 Feb 2023 04:24:40 +0100 Subject: [PATCH 58/58] refactoring: made unit test of the function isValidAdress() more readable by removing code duplicates. --- src/createEmployeeAccount.c | 21 ++++++++++- src/createEmployeeAccount.h | 2 +- tests/test_createEmployeeAccount.c | 56 ++++++++++++++++-------------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index edd9262..10b8339 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -2,6 +2,7 @@ #include "createEmployeeAccount.h" + bool isValidEmployeeID(const char* employeeId,const int maximumStringLength) { int employeeIdLength = strlen(employeeId); @@ -169,6 +170,12 @@ void getNewEmployeeCredentials() char employeeId[maxLength]; char employeePassword[maxLength]; char passwordVerfication[maxLength]; + char street[maximalAdressLength]; + char city[maximalAdressLength]; + int houseNumber; + char houseNumberString[10]; + int postalCode; + char postalCodeString[10]; printf("please enter your wished Id :\n"); /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ @@ -194,7 +201,19 @@ void getNewEmployeeCredentials() if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) { printf("\n\nplease enter your adress\n"); - scanf(" %[^\n]s",data->address); + scanf(" %[^\n]s",street); + strcat(data->address,street); + + scanf(" %[^\n]s",city); + strcat(data->address,city); + + scanf("%d",houseNumber); + sprintf(houseNumberString,"%d",houseNumber); + strcat(data->address,houseNumberString); + + scanf("%s",postalCode); + sprintf(postalCodeString,"%d",postalCode); + strcat(data->address,postalCodeString); printf("\n\nplease enter your Phone number\n"); scanf(" %[^\n]s",data->phoneNumber); diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 5b9b6fe..e9321f4 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -18,7 +18,7 @@ struct employeesInformations { char firstName[15]; char lastName[15]; - char address[20]; + char address[100]; char phoneNumber[15]; }; typedef struct employeesInformations employeedata; diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 8fea023..ad3ab81 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -243,44 +243,48 @@ void test_validPhoneNumber(void) void test_isValidAdressSuccess(void) { /*Arrange*/ - char* validStreet[] = {"LeipzigerStrasse","HannauerLandStra","HenirichStrasse","MAgdeburgerStrasse"}; - char* validCity[] = {"Hannover","Frankfurt","Berlin","Fulda"}; - int validHouseNumber[4] = {112,365,16,998}; - int validPostalCode[4] = {36879,36897,12354,9999}; - bool validAdress[4]; + char* validCityAndStreet[][2] = { + {"LeipzigerStrasse","Hannover"}, + {"HannauerLandStra","Frankfurt"}, + {"HenirichStrasse","Berlin"}, + {"MAgdeburgerStrasse","Fulda"}}; - /*Act*/ + int validHouseNumberAndPostalCode[][2] = { + {112,36879}, + {365,36897}, + {16,12354}, + {998,9999}}; + bool expectation = true; + + /*Act and Assert*/ for(int i=0;i<4;i++) { - validAdress[i] = isValidAdress(validStreet[i],validCity[i],validHouseNumber[i],validPostalCode[i]); - } - - /*Assert*/ - for(int j=0;j<4;j++) - { - TEST_ASSERT_TRUE(validAdress[j]); + bool validAdress = isValidAdress(validCityAndStreet[i][0],validCityAndStreet[i][1],validHouseNumberAndPostalCode[i][0],validHouseNumberAndPostalCode[i][1]); + TEST_ASSERT_EQUAL(expectation,validAdress); } } void test_isValidAdressFailure(void) { /*Arrange*/ - char* invalidStreet[] = {"LeipzigerStrassehvjhb","HannauerLandStranl","bob",".."}; - char* invalidCity[] = {"log","fiz","foo","bar"}; - int invalidHouseNumber[4] = {-10,-1,0,99815}; - int invalidPostalCode[4] = {-1,10,999,65}; - bool invalidAdress[4]; + char* invalidCityAndStreet[][2] = { + {"LeipzigerStrassehvjhb","log"}, + {"HannauerLandStranl","fiz"}, + {"bob","foo"}, + {"..","bar"}}; + + int invalidHouseNumberAndPostalCode[][2] = { + {-10,-1}, + {-1,10}, + {0,999}, + {99815,65}}; + bool expectation = false; - /*Act*/ + /*Act and Assert*/ for(int i=0;i<4;i++) { - invalidAdress[i] = isValidAdress(invalidStreet[i],invalidCity[i],invalidHouseNumber[i],invalidPostalCode[i]); - } - - /*Assert*/ - for(int j=0;j<4;j++) - { - TEST_ASSERT_FALSE(invalidAdress[j]); + bool invalidAdress = isValidAdress(invalidCityAndStreet[i][0],invalidCityAndStreet[i][1],invalidHouseNumberAndPostalCode[i][0],invalidHouseNumberAndPostalCode[i][1]); + TEST_ASSERT_EQUAL(expectation,invalidAdress); } }