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..4247c59 --- /dev/null +++ b/build-project.sh @@ -0,0 +1,6 @@ +clear +ceedling test:all +cd src/ +gcc main.c mainMenu.c +./a.out +rm a.out diff --git a/build/test/cache/defines_dependency.yml b/build/test/cache/defines_dependency.yml new file mode 100644 index 0000000..64f9ba3 --- /dev/null +++ b/build/test/cache/defines_dependency.yml @@ -0,0 +1,3 @@ +--- +src/mainMenu.c: +- TEST diff --git a/tests/build/test/cache/input.yml b/build/test/cache/input.yml similarity index 90% rename from tests/build/test/cache/input.yml rename to build/test/cache/input.yml index fb9e794..e0eb2fd 100644 --- a/tests/build/test/cache/input.yml +++ b/build/test/cache/input.yml @@ -23,12 +23,12 @@ :artifacts: [] :paths: :test: - - "+:test/**" - - "-:test/support" + - "+:tests/**" + - "-:tests/support" :source: - - "/home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/**" + - src/** :support: - - test/support + - tests/support :include: [] :libraries: [] :test_toolchain_include: [] @@ -77,10 +77,10 @@ :testfail: ".fail" :dependencies: ".d" :unity: - :vendor_path: "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor" + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" :defines: [] :cmock: - :vendor_path: "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor" + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" :defines: [] :includes: [] :mock_prefix: mock_ @@ -99,7 +99,7 @@ :verbosity: 3 :unity_helper: false :cexception: - :vendor_path: "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor" + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" :defines: [] :test_runner: :includes: [] @@ -223,13 +223,13 @@ :arguments: [] :plugins: :load_paths: - - "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins" + - "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins" :enabled: - stdout_pretty_tests_report - module_generator :display_raw_test_results: false - :stdout_pretty_tests_report_path: "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report" - :module_generator_path: "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins/module_generator" + :stdout_pretty_tests_report_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report" + :module_generator_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/module_generator" :gcov: :reports: - HtmlDetailed diff --git a/build/test/cache/test_mainMenu.c b/build/test/cache/test_mainMenu.c new file mode 100644 index 0000000..c8bdf9f --- /dev/null +++ b/build/test/cache/test_mainMenu.c @@ -0,0 +1,299 @@ +#include "src/mainMenu.h" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_agePermissionValidAge(void) + +{ + + + + + + + + + + int validAge[83]; + + + + + + _Bool + + validAgeResult[83]; + + + + int j=0; + + + + for(int i =18;i<101;i++){ + + + + validAge[j]= i; + + j++; + + } + + + + + + + + for(int i=0;i<83;i++){ + + + + validAgeResult[i] = agePermission(validAge[i]); + + } + + + + + + + + for(int i=0;i<83;i++){ + + + + do {if ((validAgeResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(44)));}} while(0); + + + + } + + + +} + + + +void test_agePermissionInvalidAge(void) + +{ + + + + + + + + + + + + int invalidAge[117]; + + + + + + _Bool + + invalidAgeResult[117]; + + + + int j=0; + + + + for(int i =-100;i<18;i++){ + + + + invalidAge[j]= i; + + j++; + + } + + + + + + + + for(int i=0;i<117;i++){ + + + + invalidAgeResult[i] = agePermission(invalidAge[i]); + + + + } + + + + + + + + for(int i=0;i<117;i++){ + + + + do {if (!(invalidAgeResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0); + + + + } + + + +} + + + +void test_IsInteger(void) + +{ + + + + + + + + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + + + + + _Bool + + inputIsIntegerResult[19]; + + + + + + + + for(int i=0;i<19;i++) + + { + + + + inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); + + + + } + + + + + + + + for(int i=0;i<19;i++) + + { + + + + do {if ((inputIsIntegerResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(110)));}} while(0); + + + + } + + + +} + + + +void test_IsNotInteger(void) + +{ + + + + + + + + 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]; + + + + + + + + for(int i=0;i<19;i++) + + { + + + + inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); + + + + } + + + + + + + + for(int i=0;i<19;i++) + + { + + + + do {if (!(inputIsNotIntegerResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(139)));}} while(0); + + + + } + + + +} diff --git a/build/test/dependencies/cmock.d b/build/test/dependencies/cmock.d new file mode 100644 index 0000000..7d1cf5d --- /dev/null +++ b/build/test/dependencies/cmock.d @@ -0,0 +1,6 @@ +build/test/out/c/cmock.o: \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/tests/test/support/.gitkeep b/build/test/dependencies/force_build similarity index 100% rename from tests/test/support/.gitkeep rename to build/test/dependencies/force_build diff --git a/build/test/dependencies/mainMenu.d b/build/test/dependencies/mainMenu.d new file mode 100644 index 0000000..fbd8a70 --- /dev/null +++ b/build/test/dependencies/mainMenu.d @@ -0,0 +1 @@ +build/test/out/c/mainMenu.o: src/mainMenu.c src/mainMenu.h diff --git a/build/test/dependencies/test_mainMenu.d b/build/test/dependencies/test_mainMenu.d new file mode 100644 index 0000000..5ee8500 --- /dev/null +++ b/build/test/dependencies/test_mainMenu.d @@ -0,0 +1,4 @@ +build/test/out/c/test_mainMenu.o: tests/test_mainMenu.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/mainMenu.h diff --git a/build/test/dependencies/test_mainMenu_runner.d b/build/test/dependencies/test_mainMenu_runner.d new file mode 100644 index 0000000..0ac0cdd --- /dev/null +++ b/build/test/dependencies/test_mainMenu_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_mainMenu_runner.o: \ + build/test/runners/test_mainMenu_runner.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/unity.d b/build/test/dependencies/unity.d new file mode 100644 index 0000000..e42504d --- /dev/null +++ b/build/test/dependencies/unity.d @@ -0,0 +1,4 @@ +build/test/out/c/unity.o: \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/out/c/cmock.o b/build/test/out/c/cmock.o new file mode 100644 index 0000000..76192ce Binary files /dev/null and b/build/test/out/c/cmock.o differ diff --git a/build/test/out/c/mainMenu.o b/build/test/out/c/mainMenu.o new file mode 100644 index 0000000..5666f15 Binary files /dev/null and b/build/test/out/c/mainMenu.o differ diff --git a/build/test/out/c/test_mainMenu.o b/build/test/out/c/test_mainMenu.o new file mode 100644 index 0000000..c7879b1 Binary files /dev/null and b/build/test/out/c/test_mainMenu.o differ diff --git a/build/test/out/c/test_mainMenu_runner.o b/build/test/out/c/test_mainMenu_runner.o new file mode 100644 index 0000000..1666f41 Binary files /dev/null and b/build/test/out/c/test_mainMenu_runner.o differ diff --git a/build/test/out/c/unity.o b/build/test/out/c/unity.o new file mode 100644 index 0000000..ca4de30 Binary files /dev/null and b/build/test/out/c/unity.o differ diff --git a/build/test/out/test_mainMenu.out b/build/test/out/test_mainMenu.out new file mode 100755 index 0000000..b4dffd7 Binary files /dev/null and b/build/test/out/test_mainMenu.out differ diff --git a/build/test/preprocess/files/test_mainMenu.c b/build/test/preprocess/files/test_mainMenu.c new file mode 100644 index 0000000..c8bdf9f --- /dev/null +++ b/build/test/preprocess/files/test_mainMenu.c @@ -0,0 +1,299 @@ +#include "src/mainMenu.h" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_agePermissionValidAge(void) + +{ + + + + + + + + + + int validAge[83]; + + + + + + _Bool + + validAgeResult[83]; + + + + int j=0; + + + + for(int i =18;i<101;i++){ + + + + validAge[j]= i; + + j++; + + } + + + + + + + + for(int i=0;i<83;i++){ + + + + validAgeResult[i] = agePermission(validAge[i]); + + } + + + + + + + + for(int i=0;i<83;i++){ + + + + do {if ((validAgeResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(44)));}} while(0); + + + + } + + + +} + + + +void test_agePermissionInvalidAge(void) + +{ + + + + + + + + + + + + int invalidAge[117]; + + + + + + _Bool + + invalidAgeResult[117]; + + + + int j=0; + + + + for(int i =-100;i<18;i++){ + + + + invalidAge[j]= i; + + j++; + + } + + + + + + + + for(int i=0;i<117;i++){ + + + + invalidAgeResult[i] = agePermission(invalidAge[i]); + + + + } + + + + + + + + for(int i=0;i<117;i++){ + + + + do {if (!(invalidAgeResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0); + + + + } + + + +} + + + +void test_IsInteger(void) + +{ + + + + + + + + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + + + + + _Bool + + inputIsIntegerResult[19]; + + + + + + + + for(int i=0;i<19;i++) + + { + + + + inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); + + + + } + + + + + + + + for(int i=0;i<19;i++) + + { + + + + do {if ((inputIsIntegerResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(110)));}} while(0); + + + + } + + + +} + + + +void test_IsNotInteger(void) + +{ + + + + + + + + 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]; + + + + + + + + for(int i=0;i<19;i++) + + { + + + + inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); + + + + } + + + + + + + + for(int i=0;i<19;i++) + + { + + + + do {if (!(inputIsNotIntegerResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(139)));}} while(0); + + + + } + + + +} diff --git a/build/test/preprocess/includes/test_mainMenu.c b/build/test/preprocess/includes/test_mainMenu.c new file mode 100644 index 0000000..fb4dc93 --- /dev/null +++ b/build/test/preprocess/includes/test_mainMenu.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/mainMenu.h diff --git a/build/test/results/test_mainMenu.pass b/build/test/results/test_mainMenu.pass new file mode 100644 index 0000000..d5c35cb --- /dev/null +++ b/build/test/results/test_mainMenu.pass @@ -0,0 +1,30 @@ +--- +:source: + :path: tests + :file: test_mainMenu.c +:successes: +- :test: test_agePermissionValidAge + :line: 15 + :message: '' + :unity_test_time: 0 +- :test: test_agePermissionInvalidAge + :line: 50 + :message: '' + :unity_test_time: 0 +- :test: test_IsInteger + :line: 87 + :message: '' + :unity_test_time: 0 +- :test: test_IsNotInteger + :line: 116 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 4 + :passed: 4 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0009556771256029606 diff --git a/tests/build/test/runners/test_LoginCustomer_runner.c b/build/test/runners/test_mainMenu_runner.c similarity index 75% rename from tests/build/test/runners/test_LoginCustomer_runner.c rename to build/test/runners/test_mainMenu_runner.c index f061ca9..129fa89 100644 --- a/tests/build/test/runners/test_LoginCustomer_runner.c +++ b/build/test/runners/test_mainMenu_runner.c @@ -10,7 +10,10 @@ char* GlobalOrderError; /*=======External Functions This Runner Calls=====*/ extern void setUp(void); extern void tearDown(void); -extern void test_checkLogin(); +extern void test_agePermissionValidAge(void); +extern void test_agePermissionInvalidAge(void); +extern void test_IsInteger(void); +extern void test_IsNotInteger(void); /*=======Mock Management=====*/ @@ -74,8 +77,11 @@ static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE l /*=======MAIN=====*/ int main(void) { - UnityBegin("test_LoginCustomer.c"); - run_test(test_checkLogin, "test_checkLogin", 5); + UnityBegin("test_mainMenu.c"); + run_test(test_agePermissionValidAge, "test_agePermissionValidAge", 15); + run_test(test_agePermissionInvalidAge, "test_agePermissionInvalidAge", 50); + run_test(test_IsInteger, "test_IsInteger", 87); + run_test(test_IsNotInteger, "test_IsNotInteger", 116); return UnityEnd(); } diff --git a/tests/project.yml b/project.yml similarity index 93% rename from tests/project.yml rename to project.yml index 7245e5e..640cb8f 100644 --- a/tests/project.yml +++ b/project.yml @@ -31,12 +31,12 @@ :paths: :test: - - +:test/** - - -:test/support + - +:tests/** + - -:tests/support :source: - - /home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/** + - src/** :support: - - test/support + - tests/support :libraries: [] :defines: diff --git a/src/CustomerData.txt b/src/CustomerData.txt index 3ac070f..f847b08 100644 --- a/src/CustomerData.txt +++ b/src/CustomerData.txt @@ -3,4 +3,18 @@ ID=1234 forename=Max Surname=Mustermann password=example -balance=0 +balance=2000 + +1327=example +ID=1327 +forename=Max +Surname=Mustermann +password=example +balance=1500 + +1666=example +ID=1666 +forename=Max +Surname=Mustermann +password=example +balance=240 \ No newline at end of file diff --git a/src/a.exe b/src/a.exe index 91bc69c..cdc9794 100644 Binary files a/src/a.exe and b/src/a.exe differ diff --git a/src/currentCustomerAccountBalance.c b/src/currentCustomerAccountBalance.c new file mode 100644 index 0000000..1f87d76 --- /dev/null +++ b/src/currentCustomerAccountBalance.c @@ -0,0 +1,50 @@ +#include "currentCustomerAccountBalance.h" + +float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) { + float balance = 0; + char *token = strtok(balance_String, "="); // separates string to two parts + while (token != NULL) { + if (atoi(token) != 0) { + balance = atof(token); // converts string to float + break; + } + token = strtok(NULL, "="); + } + return balance; +} + +float getAvailableAccountBalance(int user_id) { + bool keep_reading = true; + float availableBalance = 0; + + char buffer[MAX_LENGTH]; + char stringID[MAX_LENGTH] = "ID="; + char user_id_as_string[MAX_LENGTH]; + char balance_String[MAX_LENGTH]; + + sprintf(user_id_as_string, "%d", user_id); // converts user_id to string + strcat(stringID, user_id_as_string); + + FILE *file = fopen("CustomerData.txt", "r"); + + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + if (feof(file)) { + keep_reading = false; + } + else if(strstr(buffer, stringID)) { + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + strcpy(balance_String, buffer); + availableBalance = fetchBalanceFromBalanceString(balance_String); + keep_reading = false; + } + + } + fclose(file); + + return availableBalance; + +} \ No newline at end of file diff --git a/src/currentCustomerAccountBalance.h b/src/currentCustomerAccountBalance.h new file mode 100644 index 0000000..76725fe --- /dev/null +++ b/src/currentCustomerAccountBalance.h @@ -0,0 +1,7 @@ +#include +#include +#include +#include + +#define MAX_LENGTH 100 +float getAvailableAccountBalance(int user_id); \ No newline at end of file diff --git a/src/lineReplacer.h b/src/lineReplacer.h new file mode 100644 index 0000000..999855c --- /dev/null +++ b/src/lineReplacer.h @@ -0,0 +1,6 @@ +#include +#include +#include +#include + +void replaceLineInFile(const char* file_name, int line, const char* new_line); //replaces the line at "line" on the file "file_name", with the new line "new_line". \ No newline at end of file diff --git a/src/mainMenu.c b/src/mainMenu.c new file mode 100644 index 0000000..9bdfccb --- /dev/null +++ b/src/mainMenu.c @@ -0,0 +1,93 @@ + +#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; + + } +} + +void ageInput(){ + + char input[20]; + char* input_pointer; + + long age; + + printf("\nPlease specify your age : "); + scanf("%s",input); + + if (checkIfInteger(input) == true ) + { + age = strtol(input,&input_pointer,10); + + if(agePermission(age)== true) + { + printf("Access granted!\n\n\n\n"); + + showMenu(); + + } + else if(agePermission(age)== false) + { + + printf("You should be at least 18 years old to create a bank account!\n"); + + } + } + + else + { + + printf("input invalid! try again!\n"); + + } + +} + + +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 new file mode 100644 index 0000000..f62dda9 --- /dev/null +++ b/src/mainMenu.h @@ -0,0 +1,15 @@ +#ifndef MAINMENU_H_ +#define MAINMENU_H_ + +#include +#include +#include +#include + +void showMenu(); +void ageInput(); + +bool agePermission(int age); +bool checkIfInteger(char* input); + +#endif diff --git a/src/updateCustomerAccountBalance.c b/src/updateCustomerAccountBalance.c new file mode 100644 index 0000000..9c868b2 --- /dev/null +++ b/src/updateCustomerAccountBalance.c @@ -0,0 +1,83 @@ +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.c" +#include "lineReplacer.h" + +void replaceLineInFile(const char* file_name, int line, const char* new_line){ + FILE* file = fopen(file_name, "r"); + if (file == NULL) { + printf("Error opening file!\n"); + return; + } + char current_string[1024]; + int current_line = 1; + char *temp_file_name = "temp.txt"; + FILE* temp_file = fopen(temp_file_name, "w"); + if (temp_file == NULL) { + printf("Error creating temp file!\n"); + fclose(file); + return; + } + while (fgets(current_string, sizeof(current_string), file) != NULL) { + if (current_line == line) { + fprintf(temp_file, "%s", new_line); + } else { + fprintf(temp_file, "%s", current_string); + } + current_line++; + } + fclose(file); + fclose(temp_file); + if(remove(file_name)!=0){ + printf("could not remove the original file!"); + } // Remove the original file + if(rename(temp_file_name, file_name)!=0){ + printf("could not rename!"); + } // Rename the temp file to the original file +} + +void replaceBalanceInString(float replacementBalance, int currentLine) { + char newBalanceLine[MAX_LENGTH] = "balance="; + char balance_as_string[MAX_LENGTH]; + sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string + strcat(newBalanceLine, balance_as_string); + replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); +} + +bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive){ + + bool keep_reading = true; + float availableBalance = 0; + + char buffer[MAX_LENGTH]; + char stringID[MAX_LENGTH] = "ID="; + char user_id_as_string[MAX_LENGTH]; + char balance_String[MAX_LENGTH]; + int currentLine=0; + + sprintf(user_id_as_string, "%d", user_id); // converts user_id to string + strcat(stringID, user_id_as_string); + + FILE *file = fopen("CustomerData.txt", "r+"); + printf(stringID); + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + currentLine++; + if (feof(file)) { + keep_reading = false; + } + else if(strstr(buffer, stringID)) { //found the customer + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + fgets(buffer, MAX_LENGTH, file); + strcpy(balance_String, buffer); + currentLine+=4; + availableBalance = fetchBalanceFromBalanceString(balance_String); + keep_reading = false; + } + + } + fclose(file); + float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance; + replaceBalanceInString(newBalance,currentLine); +} diff --git a/src/updateCustomerAccountBalance.h b/src/updateCustomerAccountBalance.h new file mode 100644 index 0000000..4af3f89 --- /dev/null +++ b/src/updateCustomerAccountBalance.h @@ -0,0 +1,11 @@ +#include +#include +#include +#include + +#define MAX_LENGTH 100 + + +bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive); + +void replaceBalanceInString(float replacementBalance, int currentLine); \ No newline at end of file diff --git a/tests/build/test/cache/defines_dependency.yml b/tests/build/test/cache/defines_dependency.yml deleted file mode 100644 index 9f4fffc..0000000 --- a/tests/build/test/cache/defines_dependency.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -"/home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.c": -- TEST diff --git a/tests/build/test/cache/test_LoginCustomer.c b/tests/build/test/cache/test_LoginCustomer.c deleted file mode 100644 index 28f8ec8..0000000 --- a/tests/build/test/cache/test_LoginCustomer.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h" -#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" -void setUp(){}; - -void tearDown(){}; - -void test_checkLogin() - -{ - - - - - -_Bool - - expected_test_values_compute_to_true[] = {4==4, - - 1 - - == - - 1 - - , 1==1, - - 0 - - == - - 0 - - , '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, - - 1 - - == - - 0 - - ,1==0, - - 0 - - == - - 1 - - ,'z'=='x','!'==')',0x1A==0x2B}; - - int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof( - - _Bool - - ); - - - - - - for(int i=0;i<7;++i) { - - do {if ((checkLogin(expected_test_values_compute_to_true[i]))) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0); - - } - - for(int i=0;i<7;++i){ - - do {if (!(checkLogin(expected_test_values_compute_to_false[i]))) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(19)));}} while(0); - - } - -} diff --git a/tests/build/test/dependencies/LoginCustomer.d b/tests/build/test/dependencies/LoginCustomer.d deleted file mode 100644 index 45e2415..0000000 --- a/tests/build/test/dependencies/LoginCustomer.d +++ /dev/null @@ -1,3 +0,0 @@ -build/test/out/c/LoginCustomer.o: \ - /home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.c \ - /home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h diff --git a/tests/build/test/dependencies/cmock.d b/tests/build/test/dependencies/cmock.d deleted file mode 100644 index 82b64c9..0000000 --- a/tests/build/test/dependencies/cmock.d +++ /dev/null @@ -1,6 +0,0 @@ -build/test/out/c/cmock.o: \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/tests/build/test/dependencies/test_LoginCustomer.d b/tests/build/test/dependencies/test_LoginCustomer.d deleted file mode 100644 index 1a634fe..0000000 --- a/tests/build/test/dependencies/test_LoginCustomer.d +++ /dev/null @@ -1,4 +0,0 @@ -build/test/out/c/test_LoginCustomer.o: test/test_LoginCustomer.c \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ - /home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h diff --git a/tests/build/test/dependencies/test_LoginCustomer_runner.d b/tests/build/test/dependencies/test_LoginCustomer_runner.d deleted file mode 100644 index 1649170..0000000 --- a/tests/build/test/dependencies/test_LoginCustomer_runner.d +++ /dev/null @@ -1,4 +0,0 @@ -build/test/out/c/test_LoginCustomer_runner.o: \ - build/test/runners/test_LoginCustomer_runner.c \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/tests/build/test/dependencies/unity.d b/tests/build/test/dependencies/unity.d deleted file mode 100644 index 02f2997..0000000 --- a/tests/build/test/dependencies/unity.d +++ /dev/null @@ -1,4 +0,0 @@ -build/test/out/c/unity.o: \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/tests/build/test/out/c/LoginCustomer.o b/tests/build/test/out/c/LoginCustomer.o deleted file mode 100644 index 82cb77b..0000000 Binary files a/tests/build/test/out/c/LoginCustomer.o and /dev/null differ diff --git a/tests/build/test/out/c/cmock.o b/tests/build/test/out/c/cmock.o deleted file mode 100644 index 162be59..0000000 Binary files a/tests/build/test/out/c/cmock.o and /dev/null differ diff --git a/tests/build/test/out/c/test_LoginCustomer.o b/tests/build/test/out/c/test_LoginCustomer.o deleted file mode 100644 index 6c5aeaa..0000000 Binary files a/tests/build/test/out/c/test_LoginCustomer.o and /dev/null differ diff --git a/tests/build/test/out/c/test_LoginCustomer_runner.o b/tests/build/test/out/c/test_LoginCustomer_runner.o deleted file mode 100644 index f839ac1..0000000 Binary files a/tests/build/test/out/c/test_LoginCustomer_runner.o and /dev/null differ diff --git a/tests/build/test/out/c/unity.o b/tests/build/test/out/c/unity.o deleted file mode 100644 index ba42096..0000000 Binary files a/tests/build/test/out/c/unity.o and /dev/null differ diff --git a/tests/build/test/out/test_LoginCustomer.out b/tests/build/test/out/test_LoginCustomer.out deleted file mode 100755 index 3c7dca5..0000000 Binary files a/tests/build/test/out/test_LoginCustomer.out and /dev/null differ diff --git a/tests/build/test/preprocess/files/test_LoginCustomer.c b/tests/build/test/preprocess/files/test_LoginCustomer.c deleted file mode 100644 index 28f8ec8..0000000 --- a/tests/build/test/preprocess/files/test_LoginCustomer.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h" -#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" -void setUp(){}; - -void tearDown(){}; - -void test_checkLogin() - -{ - - - - - -_Bool - - expected_test_values_compute_to_true[] = {4==4, - - 1 - - == - - 1 - - , 1==1, - - 0 - - == - - 0 - - , '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, - - 1 - - == - - 0 - - ,1==0, - - 0 - - == - - 1 - - ,'z'=='x','!'==')',0x1A==0x2B}; - - int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof( - - _Bool - - ); - - - - - - for(int i=0;i<7;++i) { - - do {if ((checkLogin(expected_test_values_compute_to_true[i]))) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0); - - } - - for(int i=0;i<7;++i){ - - do {if (!(checkLogin(expected_test_values_compute_to_false[i]))) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(19)));}} while(0); - - } - -} diff --git a/tests/build/test/preprocess/includes/test_LoginCustomer.c b/tests/build/test/preprocess/includes/test_LoginCustomer.c deleted file mode 100644 index 8d24aa9..0000000 --- a/tests/build/test/preprocess/includes/test_LoginCustomer.c +++ /dev/null @@ -1,3 +0,0 @@ ---- -- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" -- Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h diff --git a/tests/build/test/results/test_LoginCustomer.pass b/tests/build/test/results/test_LoginCustomer.pass deleted file mode 100644 index 730ed0b..0000000 --- a/tests/build/test/results/test_LoginCustomer.pass +++ /dev/null @@ -1,18 +0,0 @@ ---- -:source: - :path: test - :file: test_LoginCustomer.c -:successes: -- :test: test_checkLogin - :line: 5 - :message: '' - :unity_test_time: 0 -:failures: [] -:ignores: [] -:counts: - :total: 1 - :passed: 1 - :failed: 0 - :ignored: 0 -:stdout: [] -:time: 0.001912861000164412 diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test/test_LoginCustomer.c b/tests/test_LoginCustomer.c similarity index 100% rename from tests/test/test_LoginCustomer.c rename to tests/test_LoginCustomer.c diff --git a/tests/test_mainMenu.c b/tests/test_mainMenu.c new file mode 100644 index 0000000..be1fb40 --- /dev/null +++ b/tests/test_mainMenu.c @@ -0,0 +1,145 @@ +#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