You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
8.6 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "createEmployeeAccount.h"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. void test_isValidEmployeeID(void)
  11. {
  12. //test case 0
  13. /*Arrange*/
  14. char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"};
  15. int validStringLengths = 20;
  16. bool validEmployeeIdExpected = true;
  17. /*Act and Assert*/
  18. for(int i=0; i<15; i++)
  19. {
  20. bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths);
  21. TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult);
  22. }
  23. }
  24. void test_isNotValidEmployeeID(void)
  25. {
  26. //test case 1
  27. /*Arrange*/
  28. char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"};
  29. int invalidStringLengths = 20;
  30. bool invalidEmployeeIdExpected = false;
  31. /*Act and Assert*/
  32. for(int i=0; i<6; i++)
  33. {
  34. bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths);
  35. TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult);
  36. }
  37. }
  38. void test_validEmployeePassword(void)
  39. {
  40. /*Arrange*/
  41. char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"};
  42. int minimalLength = 8;
  43. bool validPasswordexpectation = true;
  44. bool validPasswordResult[6];
  45. /*Act and Assert*/
  46. for(int i=0; i<6; i++)
  47. {
  48. validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength);
  49. TEST_ASSERT_EQUAL(validPasswordexpectation,validPasswordResult[i]);
  50. }
  51. }
  52. void test_invalidEmployeePassword(void)
  53. {
  54. /*Arrange*/
  55. char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"};
  56. int minimalLength = 8;
  57. bool invalidPasswordexpected = false;
  58. bool invalidPasswordResult[6];
  59. /*Act and Assert*/
  60. for(int i=0; i<6; i++)
  61. {
  62. invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength);
  63. TEST_ASSERT_EQUAL(invalidPasswordexpected,invalidPasswordResult[i]);
  64. }
  65. }
  66. void test_verifyPasswordSuccess()
  67. {
  68. /*Arrange*/
  69. char* passwordsAndVerifications[][2] = {
  70. {"Atharva123.","Atharva123."},
  71. {"fdai.7207","fdai.7207"},
  72. {"fizz.buzz132","fizz.buzz132"},
  73. {"23.March.1999","23.March.1999"},
  74. {"John.doe99","John.doe99"},
  75. {"foo/bar2","foo/bar2"},
  76. {"fizz+3buzz","fizz+3buzz"},
  77. {"gitlab2.com","gitlab2.com"},
  78. {"4test:all","4test:all"},
  79. {"WS-2023","WS-2023"}
  80. };
  81. bool expectation = true;
  82. /*Act and Assert*/
  83. for(int i=0; i<10; i++)
  84. {
  85. bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]);
  86. TEST_ASSERT_EQUAL(expectation,result);
  87. }
  88. }
  89. void test_verifyPasswordFailure()
  90. {
  91. /*Arrange*/
  92. char* passwordsAndVerifications[][2] = {
  93. {"Atharva123.","Atharva123"},
  94. {"fdai.7207","fdai.72"},
  95. {"fizz.buzz132","invalidPassword"},
  96. {"23.March.1999","23.May.1999"},
  97. {"John.doe99","Jane.doe99"},
  98. {"foo/bar2","foo*bar3"},
  99. {"fizz+3buzz","fizz-3buzz"},
  100. {"gitlab2.com","github.com"},
  101. {"4test:all","4ceedlingtest:all"},
  102. {"WS-2023","SS-2023"}
  103. };
  104. bool expectation = false;
  105. /*Act and Assert*/
  106. for(int i=0; i<10; i++)
  107. {
  108. bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]);
  109. TEST_ASSERT_EQUAL(expectation,result);
  110. }
  111. }
  112. void test_employeesDataStoringSuccess(void)
  113. {
  114. /*Arrange*/
  115. char* data[][4] ={
  116. {"John","Doe","fulda,leipzigerstr12","+4926428421469"},
  117. {"Jane","Done","fulda,leipzigerstr13","+4932517359874"},
  118. {"Foo","Bar","fulda,leipzigerstr14","+4913598765315"},
  119. {"Mustermann","Mustermanpass","fulda,leipzigerstr16","+4938197853812"}
  120. };
  121. bool creationExpectation = true;
  122. /*Act and Assert*/
  123. for(int i=0;i<4;i++)
  124. {
  125. bool creationResult = storeEmployeeData(data[i][0],data[i][1],data[i][2],data[i][3]);
  126. TEST_ASSERT_EQUAL(creationExpectation,creationResult);
  127. }
  128. }
  129. void test_employeeCreatedSuccessfully(void)
  130. {
  131. /*Arrange*/
  132. char* potentialEmployees[][2] = {
  133. {"John", "Doe"},
  134. {"Fizz", "Buzz"},
  135. {"Jane", "Doe"},
  136. {"Foo", "Bar"},
  137. {"MusterMann", "MusterManPassword"},
  138. {"MusterFrau", "MusterFrauPassword"}
  139. };
  140. bool expected = true;
  141. bool result;
  142. /*Act and Assert*/
  143. for(int i=0; i<6;i++)
  144. {
  145. result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]);
  146. TEST_ASSERT_EQUAL(expected,result);
  147. }
  148. }
  149. void test_validName(void)
  150. {
  151. /*Arrange*/
  152. char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"};
  153. int minimalLength = 4;
  154. bool validNamesExpectation = true;
  155. /*Act and Assert*/
  156. for(int i = 0;i<10;i++)
  157. {
  158. bool validNamesResult = isValidName(validNames[i],minimalLength);
  159. TEST_ASSERT_EQUAL(validNamesExpectation,validNamesResult);
  160. }
  161. }
  162. void test_invalidName(void)
  163. {
  164. /*Arrange*/
  165. char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"};
  166. int minimalLength = 4;
  167. bool invalidNamesExpectation = false;
  168. /*Act and Assert*/
  169. for(int i = 0;i<10;i++)
  170. {
  171. bool invalidNamesResult = isValidName(invalidNames[i],minimalLength);
  172. TEST_ASSERT_EQUAL(invalidNamesExpectation,invalidNamesResult);
  173. }
  174. }
  175. void test_validPhoneNumber(void)
  176. {
  177. /*Arrange*/
  178. char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"};
  179. bool validPhoneNumbersExpectation = true;
  180. /*Act and Assert*/
  181. for(int i =0;i<5;i++)
  182. {
  183. bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]);
  184. TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult);
  185. }
  186. }
  187. void test_isValidAdressSuccess(void)
  188. {
  189. /*Arrange*/
  190. char* validStreet[] = {"LeipzigerStrasse","HannauerLandStra","HenirichStrasse","MAgdeburgerStrasse"};
  191. char* validCity[] = {"Hannover","Frankfurt","Berlin","Fulda"};
  192. int validHouseNumber[4] = {112,365,16,998};
  193. int validPostalCode[4] = {36879,36897,12354,9999};
  194. bool validAdress[4];
  195. /*Act*/
  196. for(int i=0;i<4;i++)
  197. {
  198. validAdress[i] = isValidAdress(validStreet[i],validCity[i],validHouseNumber[i],validPostalCode[i]);
  199. }
  200. /*Assert*/
  201. for(int j=0;j<4;j++)
  202. {
  203. TEST_ASSERT_TRUE(validAdress[j]);
  204. }
  205. }
  206. void test_isValidAdressFailure(void)
  207. {
  208. /*Arrange*/
  209. char* invalidStreet[] = {"LeipzigerStrassehvjhb","HannauerLandStranl","bob",".."};
  210. char* invalidCity[] = {"log","fiz","foo","bar"};
  211. int invalidHouseNumber[4] = {-10,-1,0,99815};
  212. int invalidPostalCode[4] = {-1,10,999,65};
  213. bool invalidAdress[4];
  214. /*Act*/
  215. for(int i=0;i<4;i++)
  216. {
  217. invalidAdress[i] = isValidAdress(invalidStreet[i],invalidCity[i],invalidHouseNumber[i],invalidPostalCode[i]);
  218. }
  219. /*Assert*/
  220. for(int j=0;j<4;j++)
  221. {
  222. TEST_ASSERT_FALSE(invalidAdress[j]);
  223. }
  224. }
  225. void test_invalidPhoneNumber(void)
  226. {
  227. /*Arrange*/
  228. char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"};
  229. bool invalidPhoneNumbersExpectation = false;
  230. /*Act and Assert*/
  231. for(int i =0;i<5;i++)
  232. {
  233. bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]);
  234. TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult);
  235. }
  236. }
  237. #endif // TEST