testRunnerGenerator.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* This Test File Is Used To Verify Many Combinations Of Using the Generate Test Runner Script */
  2. #include <stdio.h>
  3. #include "unity.h"
  4. #include "Defs.h"
  5. #ifdef USE_CEXCEPTION
  6. #include "CException.h"
  7. #endif
  8. /* Notes about prefixes:
  9. test - normal default prefix. these are "always run" tests for this procedure
  10. spec - normal default prefix. required to run default setup/teardown calls.
  11. should - normal default prefix.
  12. qwiktest - custom prefix for when tests skip all setup/teardown calls.
  13. custtest - custom prefix for when tests use custom setup/teardown calls.
  14. paratest - custom prefix for when we want to verify parameterized tests.
  15. extest - custom prefix only used during cexception
  16. suitetest- custom prefix for when we want to use custom suite setup/teardown
  17. */
  18. /* Support for Meta Test Rig */
  19. #define TEST_CASE(a)
  20. void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests
  21. /* Global Variables Used During These Tests */
  22. int CounterSetup = 0;
  23. int CounterTeardown = 0;
  24. int CounterSuiteSetup = 0;
  25. void setUp(void)
  26. {
  27. CounterSetup = 1;
  28. }
  29. void tearDown(void)
  30. {
  31. CounterTeardown = 1;
  32. }
  33. void custom_setup(void)
  34. {
  35. CounterSetup = 2;
  36. }
  37. void custom_teardown(void)
  38. {
  39. CounterTeardown = 2;
  40. }
  41. /*
  42. void test_OldSchoolCommentsShouldBeIgnored(void)
  43. {
  44. TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored");
  45. }
  46. */
  47. void test_ThisTestAlwaysPasses(void)
  48. {
  49. TEST_PASS();
  50. }
  51. void test_ThisTestAlwaysFails(void)
  52. {
  53. TEST_FAIL_MESSAGE("This Test Should Fail");
  54. }
  55. void test_ThisTestAlwaysIgnored(void)
  56. {
  57. TEST_IGNORE_MESSAGE("This Test Should Be Ignored");
  58. }
  59. void qwiktest_ThisTestPassesWhenNoSetupRan(void)
  60. {
  61. TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run");
  62. }
  63. void qwiktest_ThisTestPassesWhenNoTeardownRan(void)
  64. {
  65. TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run");
  66. }
  67. void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)
  68. {
  69. TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run");
  70. }
  71. void spec_ThisTestPassesWhenNormalSetupRan(void)
  72. {
  73. TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run");
  74. }
  75. void spec_ThisTestPassesWhenNormalTeardownRan(void)
  76. {
  77. TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run");
  78. }
  79. void custtest_ThisTestPassesWhenCustomSetupRan(void)
  80. {
  81. TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run");
  82. }
  83. void custtest_ThisTestPassesWhenCustomTeardownRan(void)
  84. {
  85. TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run");
  86. }
  87. //void test_NewStyleCommentsShouldBeIgnored(void)
  88. //{
  89. // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored");
  90. //}
  91. void test_NotBeConfusedByLongComplicatedStrings(void)
  92. {
  93. const char* crazyString = "GET / HTTP/1.1\r\nHost: 127.0.0.1:8081\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36\r\nPostman-Token: 768c7149-c3fb-f704-71a2-63918d9195b2\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\n\r\n";
  94. TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same");
  95. }
  96. void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
  97. {
  98. TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
  99. }
  100. void test_StillNotBeConfusedByLongComplicatedStrings(void)
  101. {
  102. const char* crazyString = "GET / HTTP/1.1\r\nHost: 127.0.0.1:8081\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36\r\nPostman-Token: 768c7149-c3fb-f704-71a2-63918d9195b2\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\n\r\n";
  103. TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same");
  104. }
  105. void should_RunTestsStartingWithShouldByDefault(void)
  106. {
  107. TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
  108. }
  109. TEST_CASE(25)
  110. TEST_CASE(125)
  111. TEST_CASE(5)
  112. void paratest_ShouldHandleParameterizedTests(int Num)
  113. {
  114. TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5");
  115. }
  116. TEST_CASE(7)
  117. void paratest_ShouldHandleParameterizedTests2(int Num)
  118. {
  119. TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes");
  120. }
  121. void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)
  122. {
  123. TEST_PASS();
  124. }
  125. TEST_CASE(17)
  126. void paratest_ShouldHandleParameterizedTestsThatFail(int Num)
  127. {
  128. TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail");
  129. }
  130. #ifdef USE_CEXCEPTION
  131. void extest_ShouldHandleCExceptionInTest(void)
  132. {
  133. TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException");
  134. }
  135. #endif
  136. #ifdef USE_ANOTHER_MAIN
  137. int custom_main(void);
  138. int main(void)
  139. {
  140. return custom_main();
  141. }
  142. #endif
  143. void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
  144. {
  145. TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
  146. }