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.

200 lines
5.7 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* firstNames[5] = {"John","Jane","Foo","Fizz","Mustermann"};
  116. char* lastNames[5] = {"Doe","Done","Bar","Buzz","Mustermanpass"};
  117. char* adress[5] = {"fulda,leipzigerstr12","fulda,leipzigerstr13","fulda,leipzigerstr14","fulda,leipzigerstr15","fulda,leipzigerstr16"};
  118. char* phoneNumber[5] = {"+4926428421469","+4932517359874","+4913598765315","+4968145725873","+4938197853812"};
  119. bool creationResult[5];
  120. /*Act*/
  121. for(int i=0;i<5;i++)
  122. {
  123. creationResult[i] = storeEmployeeData(firstNames[i],lastNames[i],adress[i],phoneNumber[i]);
  124. }
  125. /*Assert*/
  126. for(int i=0;i<5;i++)
  127. {
  128. TEST_ASSERT_TRUE(creationResult[i]);
  129. }
  130. }
  131. void test_employeeCreatedSuccessfully(void)
  132. {
  133. /*Arrange*/
  134. char* potentialEmployees[][2] = {
  135. {"John", "Doe"},
  136. {"Fizz", "Buzz"},
  137. {"Jane", "Doe"},
  138. {"Foo", "Bar"},
  139. {"MusterMann", "MusterManPassword"},
  140. {"MusterFrau", "MusterFrauPassword"}
  141. };
  142. bool expected = true;
  143. bool result;
  144. /*Act and Assert*/
  145. for(int i=0; i<6;i++)
  146. {
  147. result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]);
  148. TEST_ASSERT_EQUAL(expected,result);
  149. }
  150. }
  151. #endif // TEST