diff --git a/build/test/cache/defines_dependency.yml b/build/test/cache/defines_dependency.yml index 217b8d2..64f9ba3 100644 --- a/build/test/cache/defines_dependency.yml +++ b/build/test/cache/defines_dependency.yml @@ -1,3 +1,3 @@ --- -src/updateCustomerAccountBalance.c: +src/mainMenu.c: - TEST diff --git a/build/test/cache/input.yml b/build/test/cache/input.yml index bc8023f..e0eb2fd 100644 --- a/build/test/cache/input.yml +++ b/build/test/cache/input.yml @@ -77,10 +77,10 @@ :testfail: ".fail" :dependencies: ".d" :unity: - :vendor_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/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: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/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: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/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: - - "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/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: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report" - :module_generator_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/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/cache/test_updateCustomerAccountBalance.c b/build/test/cache/test_updateCustomerAccountBalance.c deleted file mode 100644 index 5b6d44a..0000000 --- a/build/test/cache/test_updateCustomerAccountBalance.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "src/updateCustomerAccountBalance.h" -#include "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" - - - - - - - - -void setUp(void) - -{ - -} - - - -void tearDown(void) - -{ - -} - - - -void test_updateAvailableAccountBalanceSuccess(void){ - - - - int id1 = 1234; - - int id2 = 1327; - - int id3 = 1666; - - - - int newBalance1=500; - - int newBalance2=800; - - int newBalance3=700; - - - - _Bool results1=updateAvailableAccountBalance(id1,newBalance1); - - _Bool results2=updateAvailableAccountBalance(id2,newBalance2); - - _Bool results3=updateAvailableAccountBalance(id3,newBalance3); - - - - do {if ((results1)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(29)));}} while(0); - - do {if ((results2)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(30)));}} while(0); - - do {if ((results3)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(31)));}} while(0); - - - -} diff --git a/build/test/dependencies/cmock.d b/build/test/dependencies/cmock.d index 58d1e9e..7d1cf5d 100644 --- a/build/test/dependencies/cmock.d +++ b/build/test/dependencies/cmock.d @@ -1,6 +1,6 @@ build/test/out/c/cmock.o: \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h + /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/build/test/dependencies/force_build b/build/test/dependencies/force_build new file mode 100644 index 0000000..e69de29 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/test_updateCustomerAccountBalance.d b/build/test/dependencies/test_updateCustomerAccountBalance.d deleted file mode 100644 index 506a323..0000000 --- a/build/test/dependencies/test_updateCustomerAccountBalance.d +++ /dev/null @@ -1,5 +0,0 @@ -build/test/out/c/test_updateCustomerAccountBalance.o: \ - tests/test_updateCustomerAccountBalance.c \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ - src/updateCustomerAccountBalance.h diff --git a/build/test/dependencies/test_updateCustomerAccountBalance_runner.d b/build/test/dependencies/test_updateCustomerAccountBalance_runner.d deleted file mode 100644 index e38698a..0000000 --- a/build/test/dependencies/test_updateCustomerAccountBalance_runner.d +++ /dev/null @@ -1,4 +0,0 @@ -build/test/out/c/test_updateCustomerAccountBalance_runner.o: \ - build/test/runners/test_updateCustomerAccountBalance_runner.c \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.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 index 931f713..e42504d 100644 --- a/build/test/dependencies/unity.d +++ b/build/test/dependencies/unity.d @@ -1,4 +1,4 @@ build/test/out/c/unity.o: \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ - /Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h + /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/dependencies/updateCustomerAccountBalance.d b/build/test/dependencies/updateCustomerAccountBalance.d deleted file mode 100644 index 5f06f3b..0000000 --- a/build/test/dependencies/updateCustomerAccountBalance.d +++ /dev/null @@ -1,5 +0,0 @@ -build/test/out/c/updateCustomerAccountBalance.o: \ - src/updateCustomerAccountBalance.c src/updateCustomerAccountBalance.h \ - src/currentCustomerAccountBalance.c \ - src/currentCustomerAccountBalance.h src/_file_information.h \ - src/lineReplacer.h diff --git a/build/test/out/c/cmock.o b/build/test/out/c/cmock.o index 7a4b511..76192ce 100644 Binary files a/build/test/out/c/cmock.o 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/test_updateCustomerAccountBalance.o b/build/test/out/c/test_updateCustomerAccountBalance.o deleted file mode 100644 index fda3468..0000000 Binary files a/build/test/out/c/test_updateCustomerAccountBalance.o and /dev/null differ diff --git a/build/test/out/c/test_updateCustomerAccountBalance_runner.o b/build/test/out/c/test_updateCustomerAccountBalance_runner.o deleted file mode 100644 index 35fab4e..0000000 Binary files a/build/test/out/c/test_updateCustomerAccountBalance_runner.o and /dev/null differ diff --git a/build/test/out/c/unity.o b/build/test/out/c/unity.o index cf2d7fe..ca4de30 100644 Binary files a/build/test/out/c/unity.o and b/build/test/out/c/unity.o differ diff --git a/build/test/out/c/updateCustomerAccountBalance.o b/build/test/out/c/updateCustomerAccountBalance.o deleted file mode 100644 index 3e002d0..0000000 Binary files a/build/test/out/c/updateCustomerAccountBalance.o and /dev/null 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/out/test_updateCustomerAccountBalance.out b/build/test/out/test_updateCustomerAccountBalance.out deleted file mode 100755 index 42268fb..0000000 Binary files a/build/test/out/test_updateCustomerAccountBalance.out and /dev/null 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/files/test_updateCustomerAccountBalance.c b/build/test/preprocess/files/test_updateCustomerAccountBalance.c deleted file mode 100644 index 5b6d44a..0000000 --- a/build/test/preprocess/files/test_updateCustomerAccountBalance.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "src/updateCustomerAccountBalance.h" -#include "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" - - - - - - - - -void setUp(void) - -{ - -} - - - -void tearDown(void) - -{ - -} - - - -void test_updateAvailableAccountBalanceSuccess(void){ - - - - int id1 = 1234; - - int id2 = 1327; - - int id3 = 1666; - - - - int newBalance1=500; - - int newBalance2=800; - - int newBalance3=700; - - - - _Bool results1=updateAvailableAccountBalance(id1,newBalance1); - - _Bool results2=updateAvailableAccountBalance(id2,newBalance2); - - _Bool results3=updateAvailableAccountBalance(id3,newBalance3); - - - - do {if ((results1)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(29)));}} while(0); - - do {if ((results2)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(30)));}} while(0); - - do {if ((results3)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(31)));}} 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/preprocess/includes/test_updateCustomerAccountBalance.c b/build/test/preprocess/includes/test_updateCustomerAccountBalance.c deleted file mode 100644 index 2b0ad02..0000000 --- a/build/test/preprocess/includes/test_updateCustomerAccountBalance.c +++ /dev/null @@ -1,3 +0,0 @@ ---- -- "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" -- src/updateCustomerAccountBalance.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/build/test/runners/test_updateCustomerAccountBalance_runner.c b/build/test/runners/test_mainMenu_runner.c similarity index 75% rename from build/test/runners/test_updateCustomerAccountBalance_runner.c rename to build/test/runners/test_mainMenu_runner.c index 887be8b..129fa89 100644 --- a/build/test/runners/test_updateCustomerAccountBalance_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_updateAvailableAccountBalanceSuccess(void); +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_updateCustomerAccountBalance.c"); - run_test(test_updateAvailableAccountBalanceSuccess, "test_updateAvailableAccountBalanceSuccess", 15); + 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/src/updateCustomerAccountBalance.c b/src/updateCustomerAccountBalance.c index 6986e08..2040a6d 100644 --- a/src/updateCustomerAccountBalance.c +++ b/src/updateCustomerAccountBalance.c @@ -8,20 +8,19 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){ printf("Error opening file!\n"); return; } - char current_string[100]; + char current_string[1024]; int current_line = 1; - char *temp_file_name = calloc(8+1, sizeof(char)); - temp_file_name = "temp.txt"; + 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) { + while (fgets(current_string, sizeof(current_string), file) != NULL) { if (current_line == line) { - fprintf(temp_file, "%s\n", new_line); - //fputs("\n", temp_file); + fprintf(temp_file, "%s", new_line); + fputs("\n", temp_file); } else { fprintf(temp_file, "%s", current_string); } @@ -40,7 +39,7 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){ void replaceBalanceInString(float replacementBalance, int currentLine) { char newBalanceLine[MAX_LENGTH] = "balance="; char balance_as_string[MAX_LENGTH]; - sprintf(balance_as_string, "%f", replacementBalance); //converts replacement balance to string + sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string strcat(newBalanceLine, balance_as_string); replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); } @@ -49,18 +48,17 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){ bool keep_reading = true; - char *buffer = malloc(MAX_LENGTH * sizeof(char)); - char *stringID = malloc(MAX_LENGTH * sizeof(char)); - stringID = "ID="; - char *user_id_as_string =malloc(MAX_LENGTH * sizeof(char)); - char *balance_String = malloc(MAX_LENGTH * sizeof(char)); + 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); + FILE *file = fopen("CustomerData.txt", "r+"); + printf(stringID); while(keep_reading) { fgets(buffer, MAX_LENGTH, file); currentLine++; @@ -80,5 +78,4 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){ } fclose(file);; replaceBalanceInString(newBalance,currentLine); - return true; } diff --git a/tests/test_LoginCustomer.c b/tests/test_LoginCustomer.c new file mode 100644 index 0000000..610a847 --- /dev/null +++ b/tests/test_LoginCustomer.c @@ -0,0 +1,21 @@ +#include +#include "LoginCustomer.h" +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_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 diff --git a/tests/test_updateCustomerAccountBalance.c b/tests/test_updateCustomerAccountBalance.c deleted file mode 100644 index add1299..0000000 --- a/tests/test_updateCustomerAccountBalance.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef TEST - -#include "unity.h" - -#include "updateCustomerAccountBalance.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_updateAvailableAccountBalanceSuccess(void){ - - int id1 = 1234; - int id2 = 1327; - int id3 = 1666; - - int newBalance1=500; - int newBalance2=800; - int newBalance3=700; - - bool results1=updateAvailableAccountBalance(id1,newBalance1); - bool results2=updateAvailableAccountBalance(id2,newBalance2); - bool results3=updateAvailableAccountBalance(id3,newBalance3); - - TEST_ASSERT_TRUE(results1); - TEST_ASSERT_TRUE(results2); - TEST_ASSERT_TRUE(results3); - -} -#endif