Browse Source
Merge branch 'backup-for-employees-infos-access' into 'Alpha'
Merge branch 'backup-for-employees-infos-access' into 'Alpha'
merge From backup-for-employees-infos-access into Alpha See merge request fdai7057/bankmanagement-system!36remotes/origin/Alpha
fdai7207
2 years ago
18 changed files with 1691 additions and 4 deletions
-
52build-project.sh
-
101project.yml
-
246src/createEmployeeAccount.c
-
39src/createEmployeeAccount.h
-
139src/employeeLogin.c
-
19src/employeeLogin.h
-
11src/employeesCredentialsList.txt
-
34src/employeesData.txt
-
13src/main.c
-
142src/mainMenu.c
-
20src/mainMenu.h
-
131src/showGeneralInfoEmployee.c
-
12src/showGeneralInfoEmployee.h
-
0tests/support/.gitkeep
-
307tests/test_createEmployeeAccount.c
-
147tests/test_employeeLogin.c
-
219tests/test_mainMenu.c
-
63tests/test_showGeneralInfoEmployee.c
@ -1,5 +1,55 @@ |
|||||
|
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 |
clear |
||||
|
ceedling test:all |
||||
|
|
||||
|
|
||||
cd src/ |
cd src/ |
||||
gcc main.c -o main |
|
||||
|
|
||||
|
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" |
||||
|
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 |
||||
./main |
./main |
||||
rm 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/ |
@ -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 |
||||
|
... |
@ -0,0 +1,246 @@ |
|||||
|
#include "employeeLogin.c" |
||||
|
|
||||
|
#include "createEmployeeAccount.h" |
||||
|
|
||||
|
|
||||
|
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*/ |
||||
|
for(int i=0;i<employeeIdLength;i++) |
||||
|
{ |
||||
|
if(employeeId[i]==' ') |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
return employeeIdLength <= maximumStringLength ; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool isValidPassword( char *password,const int minimumLength) |
||||
|
{ |
||||
|
/*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') |
||||
|
{ |
||||
|
if(isalpha(* stringpointer)) |
||||
|
{ |
||||
|
letterFound = true; |
||||
|
} |
||||
|
else if(isdigit(* stringpointer)) |
||||
|
{ |
||||
|
numberFound = true; |
||||
|
} |
||||
|
else if(ispunct(* stringpointer)) |
||||
|
{ |
||||
|
symbolFound = true; |
||||
|
} |
||||
|
if( strlen(password) >= minimumLength && letterFound && numberFound && symbolFound) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
++stringpointer; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool isValidName(char* name,const int minimalLength) |
||||
|
{ |
||||
|
int nameLength = strlen(name); |
||||
|
if(nameLength < minimalLength) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
for(int i = 0;i<nameLength;i++) |
||||
|
{ |
||||
|
int currentCharacter = name[i]; |
||||
|
if(isdigit(currentCharacter)||ispunct(currentCharacter)||isspace(currentCharacter)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool isValidPhoneNumber(char *phoneNumber) |
||||
|
{ |
||||
|
int numberLength = strlen(phoneNumber); |
||||
|
|
||||
|
/*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; |
||||
|
} |
||||
|
|
||||
|
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode) |
||||
|
{ |
||||
|
bool validStreet = true; |
||||
|
bool validHouseNumber = true; |
||||
|
bool validCity = true; |
||||
|
bool validpostalCode = true; |
||||
|
if(strlen(street)>maximalAdressLength || strlen(street)<minimalAdressLength) |
||||
|
{ |
||||
|
validStreet = false; |
||||
|
} |
||||
|
if(strlen(city)>maximalAdressLength || strlen(city)<minimalAdressLength) |
||||
|
{ |
||||
|
validCity = false; |
||||
|
} |
||||
|
if(houseNumber<1 || houseNumber > 999) |
||||
|
{ |
||||
|
validHouseNumber = false; |
||||
|
} |
||||
|
if(postalCode<1000 || postalCode > 99000) |
||||
|
{ |
||||
|
validpostalCode = false; |
||||
|
} |
||||
|
return (validStreet && validCity && validHouseNumber && validpostalCode); |
||||
|
} |
||||
|
|
||||
|
int StringLengthCounter(char* string) |
||||
|
{ |
||||
|
int characterCounter = 0; |
||||
|
int i = 0; |
||||
|
while(string[i] !='\0') |
||||
|
{ |
||||
|
characterCounter++; |
||||
|
++i; |
||||
|
} |
||||
|
string[characterCounter] = '\0'; |
||||
|
return characterCounter; |
||||
|
} |
||||
|
|
||||
|
/*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"); |
||||
|
if(employeesDatalist == NULL) |
||||
|
{ |
||||
|
printf("Error : could not find file"); |
||||
|
fclose(employeesDatalist); |
||||
|
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)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool createNewEmployee(char* employeeId, char* employeePassword) |
||||
|
{ |
||||
|
FILE* employeesFile; |
||||
|
employeesFile = fopen("src/employeesCredentialsList.txt","a"); |
||||
|
|
||||
|
if(employeesFile == NULL) |
||||
|
{ |
||||
|
printf("Error: could not find the list of Employees"); |
||||
|
fclose(employeesFile); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); |
||||
|
fclose(employeesFile); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void getNewEmployeeCredentials() |
||||
|
{ |
||||
|
employeedata *data = (employeedata*)malloc(sizeof(employeedata)); |
||||
|
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*/ |
||||
|
scanf(" %[^\n]s",employeeId); |
||||
|
employeeId[maxLength] = '\0'; |
||||
|
|
||||
|
printf("\nplease enter your wished Password :\n"); |
||||
|
scanf(" %[^\n]s",employeePassword); |
||||
|
employeePassword[strlen(employeePassword)] = '\0'; |
||||
|
|
||||
|
printf("\nplease confirm your Password :\n"); |
||||
|
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(" %[^\n]s",data->firstName); |
||||
|
|
||||
|
printf("\n\nplease enter your last name\n"); |
||||
|
scanf(" %[^\n]s",data->lastName); |
||||
|
|
||||
|
if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) |
||||
|
{ |
||||
|
printf("\n\nplease enter your adress\n"); |
||||
|
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); |
||||
|
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 |
||||
|
{ |
||||
|
printf("the given name contains unwanted characters(spaces, symbols,numbers)"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
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"); |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,39 @@ |
|||||
|
#ifndef CREATEEMPLOYEEACCOUNT_H_ |
||||
|
#define CREATEEMPLOYEEACCOUNT_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
#include<ctype.h> |
||||
|
|
||||
|
#define minPasswordLength 5 |
||||
|
#define minimumNameLength 4 |
||||
|
#define maxLength 21 |
||||
|
#define validNumberLength 14 |
||||
|
#define maximalAdressLength 20 |
||||
|
#define minimalAdressLength 3 |
||||
|
|
||||
|
struct employeesInformations |
||||
|
{ |
||||
|
char firstName[15]; |
||||
|
char lastName[15]; |
||||
|
char address[100]; |
||||
|
char phoneNumber[15]; |
||||
|
}; |
||||
|
typedef struct employeesInformations employeedata; |
||||
|
|
||||
|
bool isValidEmployeeID(const char* employee, int maximumLength); |
||||
|
bool isValidPassword( char* password, int minimumLength); |
||||
|
bool isValidName(char* name,int minimalLength); |
||||
|
bool isValidPhoneNumber(char *phoneNumber); |
||||
|
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode); |
||||
|
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); |
||||
|
bool verifyPassword(char* enteredPassword,char* passwordConfirmation); |
||||
|
bool createNewEmployee(char* employeeId, char* employeePassword); |
||||
|
|
||||
|
int StringLengthCounter(char* string); |
||||
|
|
||||
|
void getNewEmployeeCredentials(); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,139 @@ |
|||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include "showGeneralInfoEmployee.c" |
||||
|
|
||||
|
|
||||
|
bool employeesAccess(char* employeesAccessCode) |
||||
|
{ |
||||
|
|
||||
|
return !(strcmp(employeesAccessCode,employeeAccessKey)); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
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"); |
||||
|
|
||||
|
if(employeeList == NULL ) |
||||
|
{ |
||||
|
printf("file does not exist"); |
||||
|
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)) && !(strcmp(inputPassword, listPassword))) |
||||
|
{ |
||||
|
fclose(employeeList); |
||||
|
return 1; |
||||
|
} |
||||
|
else if(!(strcmp(inputUsername, listUsername)) && strcmp(inputPassword, listPassword)) |
||||
|
{ |
||||
|
fclose(employeeList); |
||||
|
return 2; |
||||
|
} |
||||
|
} |
||||
|
fclose(employeeList); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
free(inputUsername); |
||||
|
free(inputPassword); |
||||
|
} |
||||
|
|
||||
|
void getEmployeeAccessCode() |
||||
|
{ |
||||
|
char accessCode[10]; |
||||
|
|
||||
|
int remainingAttempts = 10; |
||||
|
|
||||
|
printf("\n\nPlease enter the Access key : "); |
||||
|
|
||||
|
while(remainingAttempts > 0) |
||||
|
{ |
||||
|
scanf("%s",accessCode); |
||||
|
|
||||
|
|
||||
|
if(employeesAccess(accessCode)) |
||||
|
{ |
||||
|
printf("\n\nAccess granted!\n\n"); |
||||
|
|
||||
|
loginAsEmployee(); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
else if(!(employeesAccess(accessCode))) |
||||
|
{ |
||||
|
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 getEmployeeCredentials(char* inputUsername,char* inputPassword) |
||||
|
{ |
||||
|
printf("Enter username: "); |
||||
|
scanf("%s", inputUsername); |
||||
|
|
||||
|
printf("Enter password: "); |
||||
|
scanf("%s", inputPassword); |
||||
|
} |
||||
|
|
||||
|
void loginAsEmployee() |
||||
|
{ |
||||
|
int counter=3; |
||||
|
char* username = malloc(credentialLength * sizeof(char*)); |
||||
|
char* password = malloc(credentialLength * sizeof(char*)); |
||||
|
|
||||
|
while(counter>0) |
||||
|
{ |
||||
|
getEmployeeCredentials(username, password); |
||||
|
|
||||
|
int checkCredentials = checkEmployeeCredentials(username,password); |
||||
|
|
||||
|
|
||||
|
if(checkCredentials == 0) |
||||
|
{ |
||||
|
printf("\n\nUser not found\n\n"); |
||||
|
} |
||||
|
else if(checkCredentials == 2) |
||||
|
{ |
||||
|
printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); |
||||
|
--counter; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("\n\nUser Approved\n\n"); |
||||
|
showGeneralInfoEmployee(username, password); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(counter==0) |
||||
|
{ |
||||
|
|
||||
|
printf("you used up all of the tries! account locked\nPlease contact an employee of higher clearance !\n\n"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
free(username); |
||||
|
free(password); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
#ifndef EMPLOYEELOGIN_H_ |
||||
|
#define EMPLOYEELOGIN_H_ |
||||
|
|
||||
|
#define employeeAccessKey "DF9E9A8B5E" |
||||
|
#define credentialLength 20 |
||||
|
|
||||
|
#include<stdbool.h> |
||||
|
|
||||
|
bool employeesAccess(char* employeesAccessCode); |
||||
|
int checkEmployeeCredentials(char* username , char* password); |
||||
|
|
||||
|
void getEmployeeAccessCode(); |
||||
|
void getEmployeeCredentials(char* username, char* password); |
||||
|
void loginAsEmployee(); |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
@ -0,0 +1,11 @@ |
|||||
|
Atharva Atharvafdai7514 |
||||
|
|
||||
|
Can BlooMaskfdlt3817 |
||||
|
|
||||
|
Haytham TimoDLfdai7207 |
||||
|
|
||||
|
Julius Insertcatfdai7057 |
||||
|
|
||||
|
Mohamed MDfdai6618 |
||||
|
|
||||
|
Shivam Schivam007fdlt3781 |
@ -0,0 +1,34 @@ |
|||||
|
Name : Atharva |
||||
|
Last name : Naik |
||||
|
Adress : Fulda,leipzigerstrasse,1 |
||||
|
Phone number : +4964169865172 |
||||
|
|
||||
|
|
||||
|
Name : Can |
||||
|
Last name : Hacioglu |
||||
|
Adress : Fulda,leipzigerstrasse,2 |
||||
|
Phone number : +4915973325487 |
||||
|
|
||||
|
|
||||
|
Name : Haytham |
||||
|
Last name : Daoula |
||||
|
Adress : Fulda,leipzigerstrasse,3 |
||||
|
Phone number : +4995435870169 |
||||
|
|
||||
|
|
||||
|
Name : Julius |
||||
|
Last name : Engel |
||||
|
Adress : Fulda,leipzigerstrasse,4 |
||||
|
Phone number : +4939172972187 |
||||
|
|
||||
|
|
||||
|
Name : Mohamed |
||||
|
Last name : Dahi |
||||
|
Adress : Fulda,leipzigerstrasse,5 |
||||
|
Phone number : +4921865106647 |
||||
|
|
||||
|
|
||||
|
Name : Shivam |
||||
|
Last name : Chaudhary |
||||
|
Adress : Fulda,leipzigerstrasse,6 |
||||
|
Phone number : +4918756871384 |
@ -1,4 +1,11 @@ |
|||||
#include <stdio.h> |
|
||||
int main(){ |
|
||||
return 0; |
|
||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include"showGeneralInfoEmployee.h" |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
|
||||
|
ageInput(); |
||||
|
|
||||
|
return 0; |
||||
} |
} |
@ -0,0 +1,142 @@ |
|||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include "createEmployeeAccount.c" |
||||
|
|
||||
|
|
||||
|
|
||||
|
bool agePermission(int age) |
||||
|
{ |
||||
|
|
||||
|
return age >= 18; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool checkIfInteger(char* userInput) |
||||
|
{ |
||||
|
|
||||
|
char *endPointer; |
||||
|
|
||||
|
/*the endPointer points to the first non-integer character signaled to stop conversion*/ |
||||
|
|
||||
|
strtol(userInput, &endPointer, 10); |
||||
|
|
||||
|
return !(endPointer == userInput || *endPointer != '\0'); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool chooseOption(int choiceInput) |
||||
|
{ |
||||
|
|
||||
|
return !(choiceInput < 1 || choiceInput > 5); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void ageInput() |
||||
|
{ |
||||
|
|
||||
|
char* userInput = malloc(20*sizeof(char*)); |
||||
|
char* userInputPointer; |
||||
|
|
||||
|
long age; |
||||
|
|
||||
|
printf("\nPlease specify your age : "); |
||||
|
scanf("%s",userInput); |
||||
|
|
||||
|
|
||||
|
while (true) |
||||
|
{ |
||||
|
/*the userInput string is changed to a number with the strtol function*/ |
||||
|
|
||||
|
age = strtol(userInput,&userInputPointer,10); |
||||
|
|
||||
|
if((checkIfInteger(userInput))&& (agePermission(age))) |
||||
|
{ |
||||
|
|
||||
|
printf("Access granted!\n\n\n\n"); |
||||
|
|
||||
|
showMenu(); |
||||
|
|
||||
|
menuInput(); |
||||
|
|
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
else if((checkIfInteger(userInput)) && !(agePermission(age))) |
||||
|
{ |
||||
|
|
||||
|
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",userInput); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void menuInput() |
||||
|
{ |
||||
|
char choiceInput[20]; |
||||
|
char* choiceInputPointer; |
||||
|
int selection; |
||||
|
|
||||
|
scanf("%s", choiceInput); |
||||
|
selection = strtol(choiceInput, &choiceInputPointer, 10); |
||||
|
|
||||
|
while (!checkIfInteger(choiceInput) || !chooseOption(selection)) |
||||
|
{ |
||||
|
printf("Input invalid! try again!\n"); |
||||
|
|
||||
|
scanf("%s", choiceInput); |
||||
|
|
||||
|
selection = strtol(choiceInput, &choiceInputPointer, 10); |
||||
|
} |
||||
|
|
||||
|
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 : getEmployeeAccessCode(); |
||||
|
break; |
||||
|
|
||||
|
case 4 : getNewEmployeeCredentials(); |
||||
|
break; |
||||
|
|
||||
|
case 5 : printf("\e[1;1H\e[2J"); |
||||
|
printf("\nsee you next time !\n\n"); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
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 ->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"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,20 @@ |
|||||
|
#ifndef MAINMENU_H_ |
||||
|
#define MAINMENU_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
|
||||
|
#define credentialLength 20 |
||||
|
|
||||
|
bool agePermission(int age); |
||||
|
bool checkIfInteger(char* userInput); |
||||
|
bool chooseOption(int choiceInput); |
||||
|
|
||||
|
void ageInput(); |
||||
|
void showMenu(); |
||||
|
void menuInput(); |
||||
|
|
||||
|
#endif |
||||
|
|
@ -0,0 +1,131 @@ |
|||||
|
#include "showGeneralInfoEmployee.h" |
||||
|
|
||||
|
//int checkUser() is helpful for unittesting showGeneralInfoEmployee() |
||||
|
int checkUser(char username[length], char password[length]) |
||||
|
{ |
||||
|
if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharvafdai7514")==0) |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Can")==0 && strcmp(password,"BlooMaskfdlt3817")==0) |
||||
|
{ |
||||
|
return 2; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDLfdai7207")==0) |
||||
|
{ |
||||
|
return 3; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcatfdai7057")==0) |
||||
|
{ |
||||
|
return 4; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Mohamed")==0 && strcmp(password,"MDfdai6618")==0) |
||||
|
{ |
||||
|
return 5; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007fdlt3781")==0) |
||||
|
{ |
||||
|
return 6; |
||||
|
} |
||||
|
|
||||
|
else |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void showGeneralInfoEmployee(char id[length], char password[length]) |
||||
|
{ |
||||
|
// "If Statements" check, whether the username and password match. |
||||
|
|
||||
|
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"); |
||||
|
} |
||||
|
|
||||
|
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: 1\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: 1\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"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,12 @@ |
|||||
|
#ifndef SHOWGENERALINFOEMPLOYEE_H |
||||
|
#define SHOWGENERALINFOEMPLOYEE_H |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#define length 20 |
||||
|
|
||||
|
int checkUser(char username[length], char password[length]); |
||||
|
void showGeneralInfoEmployee(char id[length], char password[length]); |
||||
|
#endif // SHOWGENERALINFOEMPLOYEE_H |
@ -0,0 +1,307 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "createEmployeeAccount.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
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 = 20; |
||||
|
bool validEmployeeIdExpected = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<15; 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 = 20; |
||||
|
bool invalidEmployeeIdExpected = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths); |
||||
|
TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
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 validPasswordexpectation = true; |
||||
|
bool validPasswordResult[6]; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(validPasswordexpectation,validPasswordResult[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidEmployeePassword(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; |
||||
|
int minimalLength = 8; |
||||
|
bool invalidPasswordexpected = false; |
||||
|
bool invalidPasswordResult[6]; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(invalidPasswordexpected,invalidPasswordResult[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_verifyPasswordSuccess() |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
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; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<10; i++) |
||||
|
{ |
||||
|
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,result); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_verifyPasswordFailure() |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
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 and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<10; i++) |
||||
|
{ |
||||
|
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
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; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0;i<4;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) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* potentialEmployees[][2] = { |
||||
|
{"John", "Doe"}, |
||||
|
{"Fizz", "Buzz"}, |
||||
|
{"Jane", "Doe"}, |
||||
|
{"Foo", "Bar"}, |
||||
|
{"MusterMann", "MusterManPassword"}, |
||||
|
{"MusterFrau", "MusterFrauPassword"} |
||||
|
}; |
||||
|
|
||||
|
bool expected = true; |
||||
|
bool result; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6;i++) |
||||
|
{ |
||||
|
result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expected,result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validName(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"}; |
||||
|
int minimalLength = 4; |
||||
|
bool validNamesExpectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0;i<10;i++) |
||||
|
{ |
||||
|
bool validNamesResult = isValidName(validNames[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(validNamesExpectation,validNamesResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidName(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"}; |
||||
|
int minimalLength = 4; |
||||
|
bool invalidNamesExpectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0;i<10;i++) |
||||
|
{ |
||||
|
bool invalidNamesResult = isValidName(invalidNames[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(invalidNamesExpectation,invalidNamesResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validPhoneNumber(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; |
||||
|
bool validPhoneNumbersExpectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i =0;i<5;i++) |
||||
|
{ |
||||
|
bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]); |
||||
|
TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_isValidAdressSuccess(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* validCityAndStreet[][2] = { |
||||
|
{"LeipzigerStrasse","Hannover"}, |
||||
|
{"HannauerLandStra","Frankfurt"}, |
||||
|
{"HenirichStrasse","Berlin"}, |
||||
|
{"MAgdeburgerStrasse","Fulda"}}; |
||||
|
|
||||
|
int validHouseNumberAndPostalCode[][2] = { |
||||
|
{112,36879}, |
||||
|
{365,36897}, |
||||
|
{16,12354}, |
||||
|
{998,9999}}; |
||||
|
bool expectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i=0;i<4;i++) |
||||
|
{ |
||||
|
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* invalidCityAndStreet[][2] = { |
||||
|
{"LeipzigerStrassehvjhb","log"}, |
||||
|
{"HannauerLandStranl","fiz"}, |
||||
|
{"bob","foo"}, |
||||
|
{"..","bar"}}; |
||||
|
|
||||
|
int invalidHouseNumberAndPostalCode[][2] = { |
||||
|
{-10,-1}, |
||||
|
{-1,10}, |
||||
|
{0,999}, |
||||
|
{99815,65}}; |
||||
|
bool expectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i=0;i<4;i++) |
||||
|
{ |
||||
|
bool invalidAdress = isValidAdress(invalidCityAndStreet[i][0],invalidCityAndStreet[i][1],invalidHouseNumberAndPostalCode[i][0],invalidHouseNumberAndPostalCode[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,invalidAdress); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void test_invalidPhoneNumber(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; |
||||
|
bool invalidPhoneNumbersExpectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i =0;i<5;i++) |
||||
|
{ |
||||
|
bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]); |
||||
|
TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,147 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "employeeLogin.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_SuccessfulLoginEmployee_(void) |
||||
|
{ |
||||
|
|
||||
|
//test case : 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validEmployeesCredentials[][2] = { |
||||
|
{"Atharva", "Atharvafdai7514"}, |
||||
|
{"Can", "BlooMaskfdlt3817"}, |
||||
|
{"Haytham", "TimoDLfdai7207"}, |
||||
|
{"Julius", "Insertcatfdai7057"}, |
||||
|
{"Mohamed", "MDfdai6618"}, |
||||
|
{"Shivam", "Schivam007fdlt3781"} |
||||
|
}; |
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
int expected[] = {1,1,1,1,1,1}; |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
|
||||
|
int result = checkEmployeeCredentials(validEmployeesCredentials[i][0], validEmployeesCredentials[i][1]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(expected[i],result); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_WrongInfosLoginEmployee(void) |
||||
|
{ |
||||
|
//test case : 1 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* wrongEmployeesCredentials[][2] = { |
||||
|
{"Atharva", "doe"}, |
||||
|
{"Can", "Bar"}, |
||||
|
{"Haytham", "buzz"}, |
||||
|
{"Julius", "fizz"}, |
||||
|
{"Mohamed", "muster"}, |
||||
|
{"Shivam", "TimoDL"} |
||||
|
}; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
int expected[] = {2,2,2,2,2,2}; |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
|
||||
|
int result = checkEmployeeCredentials(wrongEmployeesCredentials[i][0], wrongEmployeesCredentials[i][1]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(expected[i],result); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void test_MissingLoginEmployee(void) |
||||
|
{ |
||||
|
|
||||
|
//test case : 2 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* missingEmployeesCredentials[][2] = { |
||||
|
{"Germany", "Berlin"}, |
||||
|
{"Italy", "Rome"}, |
||||
|
{"Belgium", "Bruxelle"}, |
||||
|
{"Swizerland", "Geneve"}, |
||||
|
{"Netherlands", "Amsterdam"}, |
||||
|
{"Sweden", "Stockholm"} |
||||
|
}; |
||||
|
|
||||
|
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); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
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 invalidCodeExpectation = false; |
||||
|
|
||||
|
/*Act and assert*/ |
||||
|
|
||||
|
for(int i=0;i<7;i++) |
||||
|
{ |
||||
|
bool invalidCodeResults = employeesAccess(invalidAccessCode[i]); |
||||
|
TEST_ASSERT_EQUAL(invalidCodeExpectation,invalidCodeResults); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,219 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "mainMenu.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_agePermissionValidAge(void) |
||||
|
{ |
||||
|
//Test case : 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int Age = 18; |
||||
|
|
||||
|
bool validAgeResult[83]; |
||||
|
|
||||
|
/*Act*/ |
||||
|
|
||||
|
for(int i =0; i < 83; i++){ |
||||
|
|
||||
|
validAgeResult[i]= agePermission(Age + 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]; |
||||
|
|
||||
|
|
||||
|
for(int i =-100; i < 18; i++) |
||||
|
{ |
||||
|
|
||||
|
invalidAge[i+100]= i; |
||||
|
} |
||||
|
|
||||
|
/*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) |
||||
|
{ |
||||
|
|
||||
|
//test case 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; |
||||
|
|
||||
|
bool inputIsIntegerExpected = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i < 19; i++) |
||||
|
{ |
||||
|
bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(inputIsIntegerExpected,inputIsIntegerResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_IsNotInteger(void) |
||||
|
{ |
||||
|
//test case 1 |
||||
|
|
||||
|
/*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 inputIsNotIntegerExpected = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
|
||||
|
for(int i=0; i<19; i++) |
||||
|
{ |
||||
|
bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(inputIsNotIntegerExpected,inputIsNotIntegerResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
void test_validChoiceInput(void) |
||||
|
{ |
||||
|
//test case 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int validInput[4]; |
||||
|
|
||||
|
bool validInputExpected = true; |
||||
|
|
||||
|
|
||||
|
|
||||
|
for(int i = 0; i < 5; i++) |
||||
|
{ |
||||
|
validInput[i] = i + 1; |
||||
|
} |
||||
|
|
||||
|
/*Act and Asssert*/ |
||||
|
|
||||
|
for(int i = 0; i < 5; i++) |
||||
|
{ |
||||
|
|
||||
|
bool validInputResult = chooseOption(validInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(validInputExpected,validInputResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidChoiceInput_firstCase(void) |
||||
|
{ |
||||
|
// test case 1 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int invalidInput[100]; |
||||
|
|
||||
|
bool invalidInputExpected = false; |
||||
|
|
||||
|
|
||||
|
|
||||
|
for(int i = -100; i < 1; i++) |
||||
|
{ |
||||
|
invalidInput[i+100] = i; |
||||
|
} |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
|
||||
|
bool invalidInputResult = chooseOption(invalidInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidChoiceInput_secondCase(void) |
||||
|
{ |
||||
|
// test case 2 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int invalidInput[100]; |
||||
|
|
||||
|
bool invalidInputExpected = false; |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
invalidInput[i] = i + 6; |
||||
|
} |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
bool invalidInputResult = chooseOption(invalidInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,63 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "showGeneralInfoEmployee.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test1_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
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[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[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[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[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[20] = "Shivam"; //Arrange |
||||
|
char password[20] = "Schivam007fdlt3781"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue