Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cJSON/blob/master/tests/unity/test/testdata/testRunnerGenerator.c # cJSON [Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `cJSON / tests / unity / test / testdata / testRunnerGenerator.c` 183 lines ยท 5137 bytes Raw Blame History 1 /* This Test File Is Used To Verify Many Combinations Of Using the Generate Test Runner Script */ 2 3 #include 4 #include "unity.h" 5 #include "Defs.h" 6 7 #ifdef USE_CEXCEPTION 8 #include "CException.h" 9 #endif 10 11 /* Notes about prefixes: 12 test - normal default prefix. these are "always run" tests for this procedure 13 spec - normal default prefix. required to run default setup/teardown calls. 14 should - normal default prefix. 15 qwiktest - custom prefix for when tests skip all setup/teardown calls. 16 custtest - custom prefix for when tests use custom setup/teardown calls. 17 paratest - custom prefix for when we want to verify parameterized tests. 18 extest - custom prefix only used during cexception 19 suitetest- custom prefix for when we want to use custom suite setup/teardown 20 */ 21 22 /* Support for Meta Test Rig */ 23 #define TEST_CASE(a) 24 void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests 25 26 /* Global Variables Used During These Tests */ 27 int CounterSetup = 0; 28 int CounterTeardown = 0; 29 int CounterSuiteSetup = 0; 30 31 void setUp(void) 32 { 33 CounterSetup = 1; 34 } 35 36 void tearDown(void) 37 { 38 CounterTeardown = 1; 39 } 40 41 void custom_setup(void) 42 { 43 CounterSetup = 2; 44 } 45 46 void custom_teardown(void) 47 { 48 CounterTeardown = 2; 49 } 50 51 /* 52 void test_OldSchoolCommentsShouldBeIgnored(void) 53 { 54 TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored"); 55 } 56 */ 57 58 void test_ThisTestAlwaysPasses(void) 59 { 60 TEST_PASS(); 61 } 62 63 void test_ThisTestAlwaysFails(void) 64 { 65 TEST_FAIL_MESSAGE("This Test Should Fail"); 66 } 67 68 void test_ThisTestAlwaysIgnored(void) 69 { 70 TEST_IGNORE_MESSAGE("This Test Should Be Ignored"); 71 } 72 73 void qwiktest_ThisTestPassesWhenNoSetupRan(void) 74 { 75 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run"); 76 } 77 78 void qwiktest_ThisTestPassesWhenNoTeardownRan(void) 79 { 80 TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run"); 81 } 82 83 void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void) 84 { 85 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run"); 86 } 87 88 void spec_ThisTestPassesWhenNormalSetupRan(void) 89 { 90 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run"); 91 } 92 93 void spec_ThisTestPassesWhenNormalTeardownRan(void) 94 { 95 TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run"); 96 } 97 98 void custtest_ThisTestPassesWhenCustomSetupRan(void) 99 { 100 TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run"); 101 } 102 103 void custtest_ThisTestPassesWhenCustomTeardownRan(void) 104 { 105 TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run"); 106 } 107 108 //void test_NewStyleCommentsShouldBeIgnored(void) 109 //{ 110 // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored"); 111 //} 112 113 void test_NotBeConfusedByLongComplicatedStrings(void) 114 { 115 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"; 116 117 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same"); 118 } 119 120 void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void) 121 { 122 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True"); 123 } 124 125 void test_StillNotBeConfusedByLongComplicatedStrings(void) 126 { 127 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"; 128 129 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same"); 130 } 131 132 void should_RunTestsStartingWithShouldByDefault(void) 133 { 134 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True"); 135 } 136 137 TEST_CASE(25) 138 TEST_CASE(125) 139 TEST_CASE(5) 140 void paratest_ShouldHandleParameterizedTests(int Num) 141 { 142 TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5"); 143 } 144 145 TEST_CASE(7) 146 void paratest_ShouldHandleParameterizedTests2(int Num) 147 { 148 TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes"); 149 } 150 151 void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void) 152 { 153 TEST_PASS(); 154 } 155 156 TEST_CASE(17) 157 void paratest_ShouldHandleParameterizedTestsThatFail(int Num) 158 { 159 TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail"); 160 } 161 162 #ifdef USE_CEXCEPTION 163 void extest_ShouldHandleCExceptionInTest(void) 164 { 165 TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException"); 166 } 167 #endif 168 169 #ifdef USE_ANOTHER_MAIN 170 int custom_main(void); 171 172 int main(void) 173 { 174 return custom_main(); 175 } 176 #endif 177 178 void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void) 179 { 180 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run"); 181 } 182 183