testparameterized.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* ==========================================
  2. Unity Project - A Test Framework for C
  3. Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
  4. [Released under MIT License. Please refer to license.txt for details]
  5. ========================================== */
  6. #include <setjmp.h>
  7. #include <stdio.h>
  8. #include "unity.h"
  9. void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests
  10. #define TEST_CASE(...)
  11. #define EXPECT_ABORT_BEGIN \
  12. if (TEST_PROTECT()) \
  13. {
  14. #define VERIFY_FAILS_END \
  15. } \
  16. Unity.CurrentTestFailed = (Unity.CurrentTestFailed != 0) ? 0 : 1; \
  17. if (Unity.CurrentTestFailed == 1) { \
  18. SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
  19. UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
  20. UNITY_OUTPUT_CHAR(':'); \
  21. UnityPrint(Unity.CurrentTestName); \
  22. UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \
  23. UNITY_OUTPUT_CHAR('\n'); \
  24. }
  25. #define VERIFY_IGNORES_END \
  26. } \
  27. Unity.CurrentTestFailed = (Unity.CurrentTestIgnored != 0) ? 0 : 1; \
  28. Unity.CurrentTestIgnored = 0; \
  29. if (Unity.CurrentTestFailed == 1) { \
  30. SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
  31. UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
  32. UNITY_OUTPUT_CHAR(':'); \
  33. UnityPrint(Unity.CurrentTestName); \
  34. UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \
  35. UNITY_OUTPUT_CHAR('\n'); \
  36. }
  37. int SetToOneToFailInTearDown;
  38. int SetToOneMeanWeAlreadyCheckedThisGuy;
  39. void setUp(void)
  40. {
  41. SetToOneToFailInTearDown = 0;
  42. SetToOneMeanWeAlreadyCheckedThisGuy = 0;
  43. }
  44. void tearDown(void)
  45. {
  46. if (SetToOneToFailInTearDown == 1)
  47. TEST_FAIL_MESSAGE("<= Failed in tearDown");
  48. if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
  49. {
  50. UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
  51. UNITY_OUTPUT_CHAR('\n');
  52. }
  53. }
  54. TEST_CASE(0)
  55. TEST_CASE(44)
  56. TEST_CASE((90)+9)
  57. void test_TheseShouldAllPass(int Num)
  58. {
  59. TEST_ASSERT_TRUE(Num < 100);
  60. }
  61. TEST_CASE(3)
  62. TEST_CASE(77)
  63. TEST_CASE( (99) + 1 - (1))
  64. void test_TheseShouldAllFail(int Num)
  65. {
  66. EXPECT_ABORT_BEGIN
  67. TEST_ASSERT_TRUE(Num > 100);
  68. VERIFY_FAILS_END
  69. }
  70. TEST_CASE(1)
  71. TEST_CASE(44)
  72. TEST_CASE(99)
  73. TEST_CASE(98)
  74. void test_TheseAreEveryOther(int Num)
  75. {
  76. if (Num & 1)
  77. {
  78. EXPECT_ABORT_BEGIN
  79. TEST_ASSERT_TRUE(Num > 100);
  80. VERIFY_FAILS_END
  81. }
  82. else
  83. {
  84. TEST_ASSERT_TRUE(Num < 100);
  85. }
  86. }
  87. void test_NormalPassesStillWork(void)
  88. {
  89. TEST_ASSERT_TRUE(1);
  90. }
  91. void test_NormalFailsStillWork(void)
  92. {
  93. EXPECT_ABORT_BEGIN
  94. TEST_ASSERT_TRUE(0);
  95. VERIFY_FAILS_END
  96. }