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.

319 lines
9.7 KiB

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