diff --git a/build-project.sh b/build-project.sh index 0f7c75e..98b90d6 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,15 +1,6 @@ -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 +rm -r build/ cd src/ @@ -20,36 +11,8 @@ 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" -done - -# replace .c with .h in respective files -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 - -# 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 +gcc mainMenu.c error.c createEmployeeAccount.c showGeneralInfoEmployee.c employeeLogin.c createCustomer.c helperFunctions.c loginCustomer.c customerMenu.c main.c -o main ./main rm main -# 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/project.yml b/project.yml index 640cb8f..b32843f 100644 --- a/project.yml +++ b/project.yml @@ -34,7 +34,14 @@ - +:tests/** - -:tests/support :source: - - src/** + - src/createCustomer.* + - src/customerLogin.* + - src/helperFunctions.* + - src/error.* + - src/createEmployeeAccount.* + - src/employeeLogin.* + - src/mainMenu.* + - src/showGeneralInfoEmployee.* :support: - tests/support :libraries: [] diff --git a/src/createCustomer.c b/src/createCustomer.c new file mode 100644 index 0000000..9d3a93a --- /dev/null +++ b/src/createCustomer.c @@ -0,0 +1,129 @@ +#include "createCustomer.h" +/*Code written by Julius Philipp Engel, fdai7057*/ +int generateID() +{ + srand(clock()); + const int MIN = 1000000, MAX = 9000001; + int pseudoRandomIDForCustomer = (rand() % MAX) + MIN; + return pseudoRandomIDForCustomer; +} + +void collectCustomerProperties() +{ + customer_t instance; + instance.forename = calloc(15+1,sizeof(char)); + instance.surname = calloc(15+1,sizeof(char)); + instance.password = calloc(20+1,sizeof(char)); + instance.ID = generateID(); + int letterCounter = 0; + int letterMaximum = 15; + int errorResult = 0; + char userInput=' '; + bool inputTooLong = false, foundComma = false; + printf("To create a new user, enter the information required below.\n"); + printf("Enter forename (max. 15 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-7); + if(errorResult==-7) exit(-1); + } + else{ + *(instance.forename+letterCounter) = '\0'; + letterCounter = 0; + } + if(!isLetterOfAlphabet(instance.forename)){ + errorResult = errorMessage(-10); + exit(-1); + } + printf("Enter surname (max. 15 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-8); + if(errorResult==-8) exit(-1); + }else{ + *(instance.surname+letterCounter) = '\0'; + letterCounter = 0; + } + if(!isLetterOfAlphabet(instance.surname)){ + errorResult = errorMessage(-11); + if(errorResult==-11) exit(-1); + } + printf("Enter password (max. 20 letters):\n"); + letterMaximum = 20; + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult=errorMessage(-9); + if(errorResult==-9) exit(-1); + }else{ + *(instance.password+letterCounter) = '\0'; + } + + letterCounter = 0; + printf("Enter balance (max. 10 digits):\n"); + char *balanceCharacters = calloc(10+1+1+1,sizeof(char)); + letterMaximum = 10; + while(letterCounter<=letterMaximum && (userInput=getchar())!='\n'){ + *(balanceCharacters+letterCounter) = userInput; + ++letterCounter; + if(letterCounter>letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-12); + if(errorResult==-12) exit(-1); + }else{ + if(!foundComma){ + *(balanceCharacters+letterCounter) = '.'; + ++letterCounter; + *(balanceCharacters+letterCounter) = '0'; + ++letterCounter; + } + *(balanceCharacters+letterCounter) = '\0'; + } + if(!everyCharacterIsDigit(balanceCharacters)){ + puts("You have entered a character that is not a number. This is not allowed. Aborting!"); + exit(-1); + } + instance.balance = balanceToDouble(balanceCharacters); + printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); + customer_t *referenceToCustomerInstance = &instance; + writeCustomerPropertiesToFile(referenceToCustomerInstance); +} + +void writeCustomerPropertiesToFile(customer_t *referenceToCustomerInstance) +{ + FILE *customerData = fopen("CustomerData.txt","a"); + int errorResult = 0; + if(customerData!=NULL){ +fprintf(customerData,"%s\nID=%d\nForename=%s\nSurname=%s\nPassword=%s\nBalance=%.4f€\n\n", +generateCheckString(referenceToCustomerInstance->ID, referenceToCustomerInstance->password),referenceToCustomerInstance->ID,referenceToCustomerInstance->forename,referenceToCustomerInstance->surname,referenceToCustomerInstance->password, referenceToCustomerInstance->balance); + fclose(customerData); + } + else{ + errorResult = errorMessage(-6); + if(errorResult==-6) exit(-1); + } +} diff --git a/src/createCustomer.h b/src/createCustomer.h new file mode 100644 index 0000000..1b87870 --- /dev/null +++ b/src/createCustomer.h @@ -0,0 +1,13 @@ +#ifndef CREATE_CUSTOMER_H +#define CREATE_CUSTOMER_H +#include +#include +#include +#include +#include "customerProperties.h" +#include "helperFunctions.h" +#include "error.h" +int generateID(); +void collectCustomerProperties(); +void writeCustomerPropertiesToFile(customer_t *); +#endif diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 10b8339..ac429e6 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -1,4 +1,3 @@ -#include "employeeLogin.c" #include "createEmployeeAccount.h" diff --git a/src/customerMenu.c b/src/customerMenu.c new file mode 100644 index 0000000..b3bb522 --- /dev/null +++ b/src/customerMenu.c @@ -0,0 +1,72 @@ +#include "customerMenu.h" + +int customerChoiceForMenuItem(int numberOfMenuItem) +{ + int returnStatus = 0; + switch(numberOfMenuItem){ + case 1: + puts("You have chosen to send money.\n"); + returnStatus = 1; + //call sendMoney(); + break; + case 2: + puts("You have chosen to withdraw money.\n"); + returnStatus = 2; + //call withDrawMoney(); + break; + case 3: + puts("You have chosen to deposit money.\n"); + returnStatus = 3; + //call depositMoney(); + break; + case 4: + puts("You have chosen to request a loan.\n"); + returnStatus = 4; + //call requestLoan(); + break; + default: + puts("Invalid input."); + returnStatus = -1; + } + return returnStatus; +} + +void showAllMenuEntries() +{ + + int userDecision = 0; + + puts("\n\n"); + puts("CUSTOMER MENU"); + + puts("\n"); + puts("Select between (1-4):"); + puts("\n\n\n"); + + puts("->->->1. send money<-<-<-"); + puts("\n\n\n"); + + puts("->->->2. withdraw money<-<-<-"); + puts("\n\n\n"); + + puts("->->->3. deposit money<-<-<-"); + puts("\n\n\n"); + + puts("->->->4. request loan<-<-<-"); + puts("\n\n\n"); + + puts("Your decision: "); + scanf("%d",&userDecision); + customerChoiceForMenuItem(userDecision); +} + +void menu(customer_t *c) +{ + if(c==NULL){ + puts("Invalid pointer. Aborting!"); + exit(-1); + }else{ + puts("Welcome!"); + showAllMenuEntries(); + } +} diff --git a/src/customerMenu.h b/src/customerMenu.h new file mode 100644 index 0000000..4b51d22 --- /dev/null +++ b/src/customerMenu.h @@ -0,0 +1,6 @@ +#include +#include +#include "customerProperties.h" +int customerChoiceForMenuItem(int); +void showAllMenuEntries(); +void menu(customer_t *); diff --git a/src/customerProperties.h b/src/customerProperties.h new file mode 100644 index 0000000..39661d1 --- /dev/null +++ b/src/customerProperties.h @@ -0,0 +1,11 @@ +#ifndef CUSTOMER_PROPERTIES_H +#define CUSTOMER_PROPERTIES_H +typedef struct Customer +{ + unsigned int ID; + char *IDAsString; + char *password; + char *forename, *surname; + double balance; +}customer_t; +#endif diff --git a/src/docs.txt b/src/docs.txt new file mode 100644 index 0000000..c76de12 --- /dev/null +++ b/src/docs.txt @@ -0,0 +1,14 @@ +char *stringConcatenation(char string_1*, char string_2*): + +This function takes two char pointers. In this function a new string is created. This new string is the concatenation of string_1 and string_2. The size of the new string is the length of string_1 plus the length of string_2 plus one for '\0'. This function is needed when creating an unique check string for a customer. + +char *to_string(int number): + +This function takes an integer variable as its argument. It returns an string that contains the digits of number. For example to_string(176) would return "176\0". This function is needed to write data in form of characters into the customer file. + + +char *generateCheckString(int customerID, char *password): + +The purpose of this function is to generate a string that is needed when a user wants to login. This string is searched for in the customer-data file and if it is found, the login is successful. This function is needed when a new user is created because then it is written in the file for the first time. +The format of the returned string is [ID]=[PASSWORD]. +For example generateCheckString(177,"tree") would return "177=tree\0". diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 5bcded0..7c58fcf 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,6 +1,6 @@ -#include "mainMenu.h" #include "employeeLogin.h" -#include "showGeneralInfoEmployee.c" +//#include "createEmployeeAccount.h" +#include "showGeneralInfoEmployee.h" bool employeesAccess(char* employeesAccessCode) @@ -16,7 +16,7 @@ int checkEmployeeCredentials(char *inputUsername, char *inputPassword) char* listUsername = malloc(credentialLength * sizeof(char*)); char* listPassword = malloc(credentialLength * sizeof(char*)); - FILE* employeeList = fopen("src/employeesCredentialsList.txt","r"); + FILE* employeeList = fopen("employeesCredentialsList.txt","r"); if(employeeList == NULL ) { diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index ed5a12d..3f2c0bf 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,3 +9,33 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/employeesData.txt b/src/employeesData.txt index 16f8e9a..cf51135 100644 --- a/src/employeesData.txt +++ b/src/employeesData.txt @@ -32,3 +32,63 @@ Name : Shivam Last name : Chaudhary Adress : Fulda,leipzigerstrasse,6 Phone number : +4918756871384 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..481d268 --- /dev/null +++ b/src/error.c @@ -0,0 +1,59 @@ +#include "error.h" + +int errorMessage(int errorCode) +{ + int returnValue=0; + switch(errorCode){ + case -1: + puts("Login not successful."); + returnValue = -1; + break; + case -2: + puts("Maximum number of attempts reached."); + returnValue = -2; + break; + case -3: + puts("No menu entry available for this number."); + returnValue = -3; + break; + case -4: + puts("CustomerData.* not found. Make sure that you've created an user account before logging in for the first time. Without users there is no file. Aborting!"); + returnValue = -4; + break; + case -5: + puts("You should be at least 18 years old to create a bank account!"); + returnValue = -5; + break; + case -6: + puts("Error when trying to open a file to create a customer account."); + returnValue = -6; + break; + case -7: + puts("Forename too long. (length > 15 characters) Aborting!"); + returnValue = -7; + break; + case -8: + puts("Surname too long. (length > 15 characters) Aborting!"); + returnValue = -8; + break; + case -9: + puts("Password too long. (length > 20 characters) Aboring!"); + returnValue = -9; + break; + case -10: + puts("You have entered an invalid character [ä,ö,ü, special characters] for your forename. This is not allowed. Aborting!"); + returnValue = -10; + break; + case -11: + puts("You have entered an invalid character [ä,ö,ü, special characters] for your surname. This is not allowed. Aborting!"); + returnValue = -11; + break; + case -12: + puts("You entered too many digits."); + returnValue = -12; + break; + default: + puts("Error code unknown."); + } + return returnValue; +} diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000..867964a --- /dev/null +++ b/src/error.h @@ -0,0 +1,3 @@ +#include +#include +int errorMessage(int); diff --git a/src/helperFunctions.c b/src/helperFunctions.c new file mode 100644 index 0000000..2f61921 --- /dev/null +++ b/src/helperFunctions.c @@ -0,0 +1,151 @@ +#include "helperFunctions.h" +/*Code written by Julius Philipp Engel, fdai7057*/ + +char *stringConcatenation(char *string_1, char *string_2) +{ + int lengthStringOne = strlen(string_1); + int lengthStringTwo = strlen(string_2); + + if(lengthStringOne==0||lengthStringTwo==0){ + printf("Empty strings are not allowed. Aborting.\n"); + exit(-1); + //call error(); + } + + const int totalLength = lengthStringOne + lengthStringTwo + 1; + char *result = calloc(totalLength, sizeof(char)); + int i,j; + for(i=0,j=0;i0){ + ++len; + number /= 10; + } + char *str = calloc(len+1, sizeof(char)); + for(int i=0,j=len-1;i=1&&exponent==0) return 1; + else{ + unsigned int result = 1, counter = 0; + while(counter='0'&&*(string+i)<='9') && *(string+i)!='.'){ + onlyDigits = false; + break; + } + } + return onlyDigits; +} + +bool isLetterOfAlphabet(char *string){ + bool everyCharIsInAlphabet = true; + for(int i=0;*(string+i)!='\0';++i){ + if(!(*(string+i)>='A'&&*(string+i)<='Z') && !(*(string+i)>='a'&&*(string+i)<='z')){ + everyCharIsInAlphabet = false; + break; + } + } + return everyCharIsInAlphabet; +} + +unsigned int toUnsignedInteger(char *ID) +{ + if(everyCharacterIsDigit(ID)){ + unsigned int result = 0; + int IDLength = strlen(ID); + for(int i=0, j = IDLength - 1;i='0'&&digitCharacterFromUser<='9'){ + *(c.IDAsString+IDLengthCounter) = digitCharacterFromUser; + } + else{ + printf("Character entered is not a digit. Aborting.\n"); + exit(-1); + } + ++IDLengthCounter; + } + *(c.IDAsString+IDLengthCounter) = '\0'; + if(IDLengthCounter>=IDMaxLength){ + printf("ID entered is too long. Aborting.\n"); + exit(-1); + } + printf("Enter password:\n"); + while((passwordCharacterFromUser=getchar())!='\n'&&passwordLengthCounter=passwordMaxLength){ + printf("Password entered is too long. Aborting.\n"); + exit(-1); + } + bool loginSuccessful = loginCustomer(&c); + free(c.IDAsString); + free(c.password); + if(loginSuccessful) { + //call menu(); + menu(&c); + }else if(!loginSuccessful && attempts < MAX_LOGIN_ATTEMPTS){ + printf("You have %d attempts left.\n", MAX_LOGIN_ATTEMPTS - attempts); + collectCustomerDataForLogin(++attempts); + }else{ + errorResult = errorMessage(-2); + if(errorResult==-2) exit(-1); + } +} + +bool loginCustomer(customer_t *c) +{ + bool foundCustomerEntryInFile = false; + unsigned int IDAsNumber = toUnsignedInteger(c->IDAsString); + char *searchForThisString = generateCheckString(IDAsNumber,c->password); + char *lineFromCustomerFile = calloc(40,sizeof(char)); + int errorResult = 0; + FILE *readCustomerFile = fopen("CustomerData.txt", "r"); + if(readCustomerFile==NULL){ + errorResult = errorMessage(-4); + if(errorResult==-4) exit(-1); + } + while((fscanf(readCustomerFile,"%s",lineFromCustomerFile)!=EOF)){ + if(strcmp(searchForThisString,lineFromCustomerFile)==0){ + foundCustomerEntryInFile = true; + break; + } + } + free(lineFromCustomerFile); + if(checkLogin(foundCustomerEntryInFile)){ + printf("Login successful.\n"); + fclose(readCustomerFile); + return foundCustomerEntryInFile; + }else{ + errorResult = errorMessage(-1); + } + fclose(readCustomerFile); + return foundCustomerEntryInFile; +} diff --git a/src/loginCustomer.h b/src/loginCustomer.h new file mode 100644 index 0000000..e126f86 --- /dev/null +++ b/src/loginCustomer.h @@ -0,0 +1,14 @@ +#ifndef LOGIN_CUSTOMER_H +#define LOGIN_CUSTOMER_H +#include +#include +#include +#include +#include "createCustomer.h" +#include "customerMenu.h" +#include "error.h" +#define MAX_LOGIN_ATTEMPTS 3 +bool checkLogin(bool); +void collectCustomerDataForLogin(int); +bool loginCustomer(customer_t *); +#endif diff --git a/src/main b/src/main new file mode 100755 index 0000000..dae05f4 Binary files /dev/null and b/src/main differ diff --git a/src/main.c b/src/main.c index 48041ae..f13161e 100644 --- a/src/main.c +++ b/src/main.c @@ -2,10 +2,12 @@ #include "employeeLogin.h" #include"showGeneralInfoEmployee.h" -int main() +void runBankManagementSystem() { - - ageInput(); - - return 0; + ageInput(); } + +int main() +{ + runBankManagementSystem(); +} \ No newline at end of file diff --git a/src/mainMenu.c b/src/mainMenu.c index 8fcb882..e1a16f8 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,6 +1,9 @@ #include "mainMenu.h" #include "employeeLogin.h" -#include "createEmployeeAccount.c" +#include "createEmployeeAccount.h" +#include "createCustomer.h" +#include "error.h" +#include "showGeneralInfoEmployee.h" @@ -36,13 +39,14 @@ void ageInput() char* userInput = malloc(20*sizeof(char*)); char* userInputPointer; - + int input, ctr=0; long age; - printf("\nPlease specify your age : "); - scanf("%s",userInput); - - + while((input=getchar())!='\n'){ + *(userInput+ctr) = input; + ++ctr; + } + *(userInput+ctr) = '\0'; while (true) { /*the userInput string is changed to a number with the strtol function*/ @@ -50,7 +54,7 @@ void ageInput() age = strtol(userInput,&userInputPointer,10); if((checkIfInteger(userInput))&& (agePermission(age))) - { + { printf("Access granted!\n\n\n\n"); @@ -64,9 +68,7 @@ void ageInput() else if((checkIfInteger(userInput)) && !(agePermission(age))) { - - printf("You should be at least 18 years old to create a bank account!\n"); - + errorMessage(-5); break; } @@ -87,32 +89,40 @@ void menuInput() { char choiceInput[20]; char* choiceInputPointer; - int selection; + int selection, input, ctr = 0; - scanf("%s", choiceInput); - selection = strtol(choiceInput, &choiceInputPointer, 10); + while((input=getchar())!='\n'){ + choiceInput[ctr] = input; + ++ctr; + } + choiceInput[ctr] = '\0'; + + selection = strtol(choiceInput, &choiceInputPointer, 10); while (!checkIfInteger(choiceInput) || !chooseOption(selection)) { printf("Input invalid! try again!\n"); - - scanf("%s", choiceInput); - - selection = strtol(choiceInput, &choiceInputPointer, 10); + ctr = 0; + while((input=getchar())!='\n'){ + choiceInput[ctr] = input; + ++ctr; + } + choiceInput[ctr] = '\0'; + selection = strtol(choiceInput, &choiceInputPointer, 10); } - switch(selection) { - case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n"); + case 1 : collectCustomerDataForLogin(0); break; - case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); + case 2 : collectCustomerProperties(); break; case 3 : getEmployeeAccessCode(); break; - case 4 : getNewEmployeeCredentials(); + case 4 : getNewEmployeeCredentials(); + printf("\nsee you next time !\n\n"); break; case 5 : printf("\e[1;1H\e[2J"); @@ -137,6 +147,3 @@ void showMenu() } - - - diff --git a/src/mainMenu.h b/src/mainMenu.h index 17d81bc..1fd5011 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -5,6 +5,7 @@ #include #include #include +#include "loginCustomer.h" #define credentialLength 20 @@ -13,6 +14,7 @@ bool checkIfInteger(char* userInput); bool chooseOption(int choiceInput); void ageInput(); +void menuInput(); void showMenu(); void menuInput(); diff --git a/tests/test_CreateCustomer.c b/tests/test_CreateCustomer.c new file mode 100644 index 0000000..4b48a74 --- /dev/null +++ b/tests/test_CreateCustomer.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "../src/helperFunctions.c" +#include "../src/error.c" +#include "../src/createCustomer.c" + +void setUp(){} +void tearDown(){} + +void test_generateID(){ + + const int test_values = USHRT_MAX; + + /*initialize blocks by calling generateID()*/ + int *numbers = calloc(test_values, sizeof(int)); + for(int i=0;i +#include "../src/customerMenu.c" + +void test_customerChoiceForMenuEntry() +{ + int decision = 1; + /*customer choses to send money, return 1*/ + TEST_ASSERT_EQUAL_INT(1, customerChoiceForMenuItem(decision)); + /*customer choses to withdraw money, return 2*/ + decision = 2; + TEST_ASSERT_EQUAL_INT(2, customerChoiceForMenuItem(decision)); + /*customer choses to deposit money, return 3*/ + decision = 3; + TEST_ASSERT_EQUAL_INT(3, customerChoiceForMenuItem(decision)); + /*customer choses to request a loan, return 4*/ + decision = 4; + TEST_ASSERT_EQUAL_INT(4, customerChoiceForMenuItem(decision)); + /*invalid input values, the return value should always be -1*/ + int arrayOfInvalidValues[] = {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,0, 123,3247,6839,38593,3033,55055}; + int length = sizeof(arrayOfInvalidValues)/sizeof(int); + for(int i=0;i +#include +#include +#include "../src/error.c" + +void setUp(){} +void tearDown(){} + + +void test_error() +{ + /*arrange*/ + srand(time(0)); + int bound = 1000; + int invalidErrorCodes_1[bound]; + int invalidErrorCodesLarge_2[bound]; + int invalidErrorCodesLargest_3[bound]; + + int validErrorCodeUnsuccessfulLogin[bound]; + int validErrorCodeMaximumNumberOfAttempts[bound]; + int validErrorCodeNoMenuEntryForNumber[bound]; + /*new test cases*/ + int validErrorCodeNoCustomerDataFile[bound]; + int validErrorCodeTooYoung[bound]; + int validErrorCodeCreatingFile[bound]; + int validErrorCodeForenameTooLong[bound]; + int validErrorCodeSurnameTooLong[bound]; + int validErrorCodePasswordTooLong[bound]; + + int validErrorCodeInvalidCharacterForename[bound]; + int validErrorCodeInvalidCharacterSurname[bound]; + int validErrorCodeTooManyDigits[bound]; + + + for(int i=0;i +#include "../src/loginCustomer.c" +#include "../src/customerMenu.c" +#include "../src/helperFunctions.c" +#include "../src/error.c" +void setUp(){}; +void tearDown(){}; +void test_checkLogin() +{ + /*arrange*/ + bool expected_test_values_compute_to_true[] = {4==4,true==true, 1==1, false==false, 'z'=='z', '='=='=',0x1A==0x1A}; + int length_1 = sizeof(expected_test_values_compute_to_true)/sizeof(bool); + + bool expected_test_values_compute_to_false[] = {4!=4,true==false,1==0,false==true,'z'=='x','!'==')',0x1A==0x2B}; + int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof(bool); + + /*act and assertions*/ + for(int i=0;i<7;++i) { + TEST_ASSERT_TRUE(checkLogin(expected_test_values_compute_to_true[i])); + } + for(int i=0;i<7;++i){ + TEST_ASSERT_FALSE(checkLogin(expected_test_values_compute_to_false[i])); + } +} diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index ad3ab81..b42ac75 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "createEmployeeAccount.h" +#include "../src/createEmployeeAccount.c" void setUp(void) { diff --git a/tests/test_employeeLogin.c b/tests/test_employeeLogin.c index 87b9f27..6626a37 100644 --- a/tests/test_employeeLogin.c +++ b/tests/test_employeeLogin.c @@ -2,8 +2,8 @@ #include "unity.h" -#include "employeeLogin.h" - +#include "../src/employeeLogin.c" +#include "../src/showGeneralInfoEmployee.c" void setUp(void) { } diff --git a/tests/test_helperFunctions.c b/tests/test_helperFunctions.c new file mode 100644 index 0000000..0b42d1a --- /dev/null +++ b/tests/test_helperFunctions.c @@ -0,0 +1,213 @@ +#include +#include +#include +#include +#include "../src/helperFunctions.c" + +void test_calculateStringLength() +{ + char *testStrings[] = {"linux","table","book","men","woman","boy","girl","computer","old","new","water","fire","bright","dark","black","white"}; int expectedResults[] = {5,5,4,3,5,3,4,8,3,3,5,4,6,4,5,5}; + int numberOfValues= sizeof(expectedResults) / sizeof(int); + for(int i=0;i