From c394e533c6297c18b6986ddf7db2b9ef90faa11e Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 19:54:26 +0100 Subject: [PATCH 1/5] implement function showGeneralInfoEmployee() --- project.yml | 101 +++++++++++++++++++++++++++ src/showGeneralInfoEmployee.c | 99 ++++++++++++++++++++++++++ src/showGeneralInfoEmployee.h | 11 +++ tests/support/.gitkeep | 0 tests/test_showGeneralInfoEmployee.c | 20 ++++++ 5 files changed, 231 insertions(+) create mode 100644 project.yml create mode 100644 src/showGeneralInfoEmployee.c create mode 100644 src/showGeneralInfoEmployee.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_showGeneralInfoEmployee.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c new file mode 100644 index 0000000..2a9196b --- /dev/null +++ b/src/showGeneralInfoEmployee.c @@ -0,0 +1,99 @@ +#include "showGeneralInfoEmployee.h" +//a = employeeName b = password +int checkUser(char a[length], char b[length]) +{ + if(strcmp(a,"Atharva")==0 && strcmp(b,"Atharva")==0) + { + return 1; + } + else if(strcmp(a,"Can")==0 && strcmp(b,"BlooMask")==0) + { + return 2; + } + else if(strcmp(a,"Haytham")==0 && strcmp(b,"TimoDL")==0) + { + return 3; + } + else if(strcmp(a,"Julius")==0 && strcmp(b,"Insertcat")==0) + { + return 4; + } + else if(strcmp(a,"Mohamed")==0 && strcmp(b,"MD")==0) + { + return 5; + } + else if(strcmp(a,"Shivam")==0 && strcmp(b,"Schivam007")==0) + { + return 6; + } + else + { + return 0; + } +} + + +void showGeneralInfoEmployee(char id[length], char p[length]) +{ + // "If Statements" check, whether the id and the password match + if(checkUser(id, p) == 1) + { + printf(" Welcome Atharva\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + } + if(checkUser(id, p) == 2) + { + printf(" Welcome Can\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + } + if(checkUser(id, p) == 3) + { + printf(" Welcome Haytham\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + if(checkUser(id, p) == 4) + { + printf(" Welcome Julius\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + if(checkUser(id, p) == 5) + { + printf(" Welcome Mohamed\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + if(checkUser(id, p) == 6) + { + printf(" Welcome Shivam\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + else + { + + } +} + + diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h new file mode 100644 index 0000000..984b035 --- /dev/null +++ b/src/showGeneralInfoEmployee.h @@ -0,0 +1,11 @@ +#ifndef SHOWGENERALINFOEMPLOYEE_H +#define SHOWGENERALINFOEMPLOYEE_H + +#include +#include +#include + +const int length = 100; +int checkUser(char a[length], char b[length]); +void showGeneralInfoEmployee(char id[length], char p[length]); +#endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c new file mode 100644 index 0000000..e666269 --- /dev/null +++ b/tests/test_showGeneralInfoEmployee.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "showGeneralInfoEmployee.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_showGeneralInfoEmployee_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement showGeneralInfoEmployee"); +} + +#endif // TEST From 5a78de5396ca73ba800a8f3d4394d313fe0f457d Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 20:08:43 +0100 Subject: [PATCH 2/5] implement unittest for function showGeneralInfoEmployee() --- tests/test_showGeneralInfoEmployee.c | 48 ++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index e666269..468a993 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "showGeneralInfoEmployee.h" +#include "showGeneralInfoEmployee.c" void setUp(void) { @@ -12,9 +12,51 @@ void tearDown(void) { } -void test_showGeneralInfoEmployee_NeedToImplement(void) +//eN : employeeName pwd: password + +void test1_showGeneralInfoEmployee(void) +{ + char eN[] = "Atharva"; + char pwd[] = "Atharva"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(1, erg); +} +void test2_showGeneralInfoEmployee(void) +{ + char eN[] = "Can"; + char pwd[] = "BlooMask"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(2, erg); +} +void test3_showGeneralInfoEmployee(void) +{ + char eN[] = "Haytham"; + char pwd[] = "TimoDL"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(3, erg); +} +void test4_showGeneralInfoEmployee(void) { - TEST_IGNORE_MESSAGE("Need to Implement showGeneralInfoEmployee"); + char eN[] = "Julius"; + char pwd[] = "Insertcat"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(4, erg); } +void test5_showGeneralInfoEmployee(void) +{ + char eN[] = "Mohamed"; + char pwd[] = "MD"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(5, erg); +} +void test6_showGeneralInfoEmployee(void) +{ + char eN[] = "Shivam"; + char pwd[] = "Schivam007"; + int erg = checkUser(eN, pwd); + TEST_ASSERT_EQUAL_INT(6, erg); +} + + #endif // TEST From 0298030b9f3d08e7065e463bb2451e54e918530f Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 20:37:37 +0100 Subject: [PATCH 3/5] refactoring: changed some variable names and implemented if statements in showGeneralInfoEmployee.c --- src/showGeneralInfoEmployee.c | 86 +++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 2a9196b..3bbb353 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -1,31 +1,38 @@ #include "showGeneralInfoEmployee.h" -//a = employeeName b = password -int checkUser(char a[length], char b[length]) + +//int checkUser() is helpful for unittesting showGeneralInfoEmployee() +int checkUser(char username[length], char password[length]) { - if(strcmp(a,"Atharva")==0 && strcmp(b,"Atharva")==0) - { - return 1; - } - else if(strcmp(a,"Can")==0 && strcmp(b,"BlooMask")==0) - { - return 2; - } - else if(strcmp(a,"Haytham")==0 && strcmp(b,"TimoDL")==0) - { - return 3; - } - else if(strcmp(a,"Julius")==0 && strcmp(b,"Insertcat")==0) - { - return 4; - } - else if(strcmp(a,"Mohamed")==0 && strcmp(b,"MD")==0) - { - return 5; - } - else if(strcmp(a,"Shivam")==0 && strcmp(b,"Schivam007")==0) - { - return 6; - } + if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharva")==0) + { + return 1; + } + + if(strcmp(username,"Can")==0 && strcmp(password,"BlooMask")==0) + { + return 2; + } + + if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDL")==0) + { + return 3; + } + + if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcat")==0) + { + return 4; + } + + if(strcmp(username,"Mohamed")==0 && strcmp(password,"MD")==0) + { + return 5; + } + + if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007")==0) + { + return 6; + } + else { return 0; @@ -33,10 +40,11 @@ int checkUser(char a[length], char b[length]) } -void showGeneralInfoEmployee(char id[length], char p[length]) +void showGeneralInfoEmployee(char id[length], char password[length]) { - // "If Statements" check, whether the id and the password match - if(checkUser(id, p) == 1) + // "If Statements" check, whether the username and password match. + + if(checkUser(id, password) == 1) { printf(" Welcome Atharva\n"); printf(" Clearance: 3\n"); @@ -44,7 +52,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf("\n"); printf(" ->Review new customer applications.\n"); } - if(checkUser(id, p) == 2) + + if(checkUser(id, password) == 2) { printf(" Welcome Can\n"); printf(" Clearance: 3\n"); @@ -52,7 +61,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf("\n"); printf(" ->Review new customer applications.\n"); } - if(checkUser(id, p) == 3) + + if(checkUser(id, password) == 3) { printf(" Welcome Haytham\n"); printf(" Clearance: 2\n"); @@ -61,7 +71,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review new customer applications.\n"); printf(" ->Review loan applications.\n"); } - if(checkUser(id, p) == 4) + + if(checkUser(id, password) == 4) { printf(" Welcome Julius\n"); printf(" Clearance: 2\n"); @@ -70,7 +81,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review new customer applications.\n"); printf(" ->Review loan applications.\n"); } - if(checkUser(id, p) == 5) + + if(checkUser(id, password) == 5) { printf(" Welcome Mohamed\n"); printf(" Clearance: 3\n"); @@ -80,7 +92,8 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review loan applications.\n"); printf(" ->Terminate account.\n"); } - if(checkUser(id, p) == 6) + + if(checkUser(id, password) == 6) { printf(" Welcome Shivam\n"); printf(" Clearance: 3\n"); @@ -90,10 +103,5 @@ void showGeneralInfoEmployee(char id[length], char p[length]) printf(" ->Review loan applications.\n"); printf(" ->Terminate account.\n"); } - else - { - } } - - From da40d8b28bfda6da96690bd1f020d8bc8abaf983 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 29 Jan 2023 21:14:08 +0100 Subject: [PATCH 4/5] refactoring: changed some variable names in test_showGeneralInfoEmployee.c --- tests/test_showGeneralInfoEmployee.c | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 468a993..4a58a83 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -12,51 +12,52 @@ void tearDown(void) { } -//eN : employeeName pwd: password void test1_showGeneralInfoEmployee(void) { - char eN[] = "Atharva"; - char pwd[] = "Atharva"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(1, erg); + char employeeName[] = "Atharva"; //Arrange + char password[] = "Atharva"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert } void test2_showGeneralInfoEmployee(void) { - char eN[] = "Can"; - char pwd[] = "BlooMask"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(2, erg); + char employeeName[] = "Can"; //Arrange + char password[] = "BlooMask"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert } void test3_showGeneralInfoEmployee(void) { - char eN[] = "Haytham"; - char pwd[] = "TimoDL"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(3, erg); + char employeeName[] = "Haytham"; //Arrange + char password[] = "TimoDL"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert } void test4_showGeneralInfoEmployee(void) { - char eN[] = "Julius"; - char pwd[] = "Insertcat"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(4, erg); + char employeeName[] = "Julius"; //Arrange + char password[] = "Insertcat"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert } void test5_showGeneralInfoEmployee(void) { - char eN[] = "Mohamed"; - char pwd[] = "MD"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(5, erg); + char employeeName[] = "Mohamed"; //Arrange + char password[] = "MD"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert } void test6_showGeneralInfoEmployee(void) { - char eN[] = "Shivam"; - char pwd[] = "Schivam007"; - int erg = checkUser(eN, pwd); - TEST_ASSERT_EQUAL_INT(6, erg); + char employeeName[] = "Shivam"; //Arrange + char password[] = "Schivam007"; + int ergebnis = checkUser(employeeName, password); //Act + TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert } + + #endif // TEST From f7a2bf74ac0b0b2475427200d8acc25d8b66acaa Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 2 Feb 2023 18:15:41 +0100 Subject: [PATCH 5/5] update with new Passwords in showGeneralInfoEmployee.c and test_showGeneralInfoEmployee.h --- src/showGeneralInfoEmployee.c | 12 ++++++------ src/showGeneralInfoEmployee.h | 4 ++-- tests/test_showGeneralInfoEmployee.c | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c index 3bbb353..25355c9 100644 --- a/src/showGeneralInfoEmployee.c +++ b/src/showGeneralInfoEmployee.c @@ -3,32 +3,32 @@ //int checkUser() is helpful for unittesting showGeneralInfoEmployee() int checkUser(char username[length], char password[length]) { - if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharva")==0) + if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharvafdai7514")==0) { return 1; } - if(strcmp(username,"Can")==0 && strcmp(password,"BlooMask")==0) + if(strcmp(username,"Can")==0 && strcmp(password,"BlooMaskfdlt3817")==0) { return 2; } - if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDL")==0) + if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDLfdai7207")==0) { return 3; } - if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcat")==0) + if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcatfdai7057")==0) { return 4; } - if(strcmp(username,"Mohamed")==0 && strcmp(password,"MD")==0) + if(strcmp(username,"Mohamed")==0 && strcmp(password,"MDfdai6618")==0) { return 5; } - if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007")==0) + if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007fdlt3781")==0) { return 6; } diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h index 984b035..bfedbbe 100644 --- a/src/showGeneralInfoEmployee.h +++ b/src/showGeneralInfoEmployee.h @@ -6,6 +6,6 @@ #include const int length = 100; -int checkUser(char a[length], char b[length]); -void showGeneralInfoEmployee(char id[length], char p[length]); +int checkUser(char username[length], char password[length]); +void showGeneralInfoEmployee(char id[length], char password[length]); #endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/tests/test_showGeneralInfoEmployee.c b/tests/test_showGeneralInfoEmployee.c index 4a58a83..0d1084c 100644 --- a/tests/test_showGeneralInfoEmployee.c +++ b/tests/test_showGeneralInfoEmployee.c @@ -16,42 +16,42 @@ void tearDown(void) void test1_showGeneralInfoEmployee(void) { char employeeName[] = "Atharva"; //Arrange - char password[] = "Atharva"; + char password[] = "Atharvafdai7514"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert } void test2_showGeneralInfoEmployee(void) { char employeeName[] = "Can"; //Arrange - char password[] = "BlooMask"; + char password[] = "BlooMaskfdlt3817"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert } void test3_showGeneralInfoEmployee(void) { char employeeName[] = "Haytham"; //Arrange - char password[] = "TimoDL"; + char password[] = "TimoDLfdai7207"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert } void test4_showGeneralInfoEmployee(void) { char employeeName[] = "Julius"; //Arrange - char password[] = "Insertcat"; + char password[] = "Insertcatfdai7057"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert } void test5_showGeneralInfoEmployee(void) { char employeeName[] = "Mohamed"; //Arrange - char password[] = "MD"; + char password[] = "MDfdai6618"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert } void test6_showGeneralInfoEmployee(void) { char employeeName[] = "Shivam"; //Arrange - char password[] = "Schivam007"; + char password[] = "Schivam007fdlt3781"; int ergebnis = checkUser(employeeName, password); //Act TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert }