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.

172 lines
5.0 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_employeeCreatedSuccessfully(void)
  113. {
  114. /*Arrange*/
  115. char* potentialEmployees[][2] = {
  116. {"John", "Doe"},
  117. {"Fizz", "Buzz"},
  118. {"Jane", "Doe"},
  119. {"Foo", "Bar"},
  120. {"MusterMann", "MusterManPassword"},
  121. {"MusterFrau", "MusterFrauPassword"}
  122. };
  123. bool expected = true;
  124. bool result;
  125. /*Act and Assert*/
  126. for(int i=0; i<6;i++)
  127. {
  128. result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]);
  129. TEST_ASSERT_EQUAL(expected,result);
  130. }
  131. }
  132. #endif // TEST