#include "unity.h" #include "../src/createEmployeeAccount.c" 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); } }