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.

161 lines
4.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* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
  70. char* confirmation[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
  71. bool result[10];
  72. /*Act*/
  73. for(int i=0; i<10; i++)
  74. {
  75. result[i] = verifyPassword(password[i],confirmation[i]);
  76. }
  77. /*Assert*/
  78. for(int i=0; i<10; i++)
  79. {
  80. TEST_ASSERT_TRUE(result[i]);
  81. }
  82. }
  83. void test_verifyPasswordFailure()
  84. {
  85. /*Arrange*/
  86. char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
  87. char* confirmation[10] = {"Atharva123","fdai.72","invalidPassword","23.May.1999","Jane.doe99","foo*bar3","fizz-3buzz","github.com","4ceedlingtest:all","SS-2023"};
  88. bool result[10];
  89. /*Act*/
  90. for(int i=0; i<10; i++)
  91. {
  92. result[i] = verifyPassword(password[i],confirmation[i]);
  93. }
  94. /*Assert*/
  95. for(int i=0; i<10; i++)
  96. {
  97. TEST_ASSERT_FALSE(result[i]);
  98. }
  99. }
  100. void test_employeeCreatedSuccessfully(void)
  101. {
  102. /*Arrange*/
  103. char* potentialEmployees[][2] = {
  104. {"John", "Doe"},
  105. {"Fizz", "Buzz"},
  106. {"Jane", "Doe"},
  107. {"Foo", "Bar"},
  108. {"MusterMann", "MusterManPassword"},
  109. {"MusterFrau", "MusterFrauPassword"}
  110. };
  111. bool expected = true;
  112. bool result;
  113. /*Act and Assert*/
  114. for(int i=0; i<6;i++)
  115. {
  116. result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]);
  117. TEST_ASSERT_EQUAL(expected,result);
  118. }
  119. }
  120. #endif // TEST