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.

241 lines
6.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","Foo","Atharva","Can","Julius","Haytham","Mohamed","Shivam"};
  153. int minimalLength = 4;
  154. bool validNamesResult[10];
  155. /*Act*/
  156. for(int i = 0;i<10;i++)
  157. {
  158. validNamesResult[i] = isValidName(validNames[i],minimalLength);
  159. }
  160. /*Assert*/
  161. for(int i = 0;i<10;i++)
  162. {
  163. TEST_ASSERT_TRUE(validNames[i]);
  164. }
  165. }
  166. void test_invalidName(void)
  167. {
  168. /*Arrange*/
  169. char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul132ius","123Haytham",".Mohamed"," Shivam"};
  170. int minimalLength = 4;
  171. bool invalidNamesResult[10];
  172. /*Act*/
  173. for(int i = 0;i<10;i++)
  174. {
  175. invalidNamesResult[i] = isValidName(invalidNames[i],minimalLength);
  176. }
  177. /*Assert*/
  178. for(int i = 0;i<10;i++)
  179. {
  180. TEST_ASSERT_FALSE(invalidNamesResult[i]);
  181. }
  182. }
  183. #endif // TEST