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.

307 lines
9.3 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* validCityAndStreet[][2] = {
  191. {"LeipzigerStrasse","Hannover"},
  192. {"HannauerLandStra","Frankfurt"},
  193. {"HenirichStrasse","Berlin"},
  194. {"MAgdeburgerStrasse","Fulda"}};
  195. int validHouseNumberAndPostalCode[][2] = {
  196. {112,36879},
  197. {365,36897},
  198. {16,12354},
  199. {998,9999}};
  200. bool expectation = true;
  201. /*Act and Assert*/
  202. for(int i=0;i<4;i++)
  203. {
  204. bool validAdress = isValidAdress(validCityAndStreet[i][0],validCityAndStreet[i][1],validHouseNumberAndPostalCode[i][0],validHouseNumberAndPostalCode[i][1]);
  205. TEST_ASSERT_EQUAL(expectation,validAdress);
  206. }
  207. }
  208. void test_isValidAdressFailure(void)
  209. {
  210. /*Arrange*/
  211. char* invalidCityAndStreet[][2] = {
  212. {"LeipzigerStrassehvjhb","log"},
  213. {"HannauerLandStranl","fiz"},
  214. {"bob","foo"},
  215. {"..","bar"}};
  216. int invalidHouseNumberAndPostalCode[][2] = {
  217. {-10,-1},
  218. {-1,10},
  219. {0,999},
  220. {99815,65}};
  221. bool expectation = false;
  222. /*Act and Assert*/
  223. for(int i=0;i<4;i++)
  224. {
  225. bool invalidAdress = isValidAdress(invalidCityAndStreet[i][0],invalidCityAndStreet[i][1],invalidHouseNumberAndPostalCode[i][0],invalidHouseNumberAndPostalCode[i][1]);
  226. TEST_ASSERT_EQUAL(expectation,invalidAdress);
  227. }
  228. }
  229. void test_invalidPhoneNumber(void)
  230. {
  231. /*Arrange*/
  232. char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"};
  233. bool invalidPhoneNumbersExpectation = false;
  234. /*Act and Assert*/
  235. for(int i =0;i<5;i++)
  236. {
  237. bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]);
  238. TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult);
  239. }
  240. }
  241. #endif // TEST