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/testRunnerGeneratorWithMocks.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 / testRunnerGeneratorWithMocks.c` 192 lines ยท 5844 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 #include "mockMock.h" 7 8 #ifdef USE_CEXCEPTION 9 #include "CException.h" 10 #endif 11 12 /* Notes about prefixes: 13 test - normal default prefix. these are "always run" tests for this procedure 14 spec - normal default prefix. required to run default setup/teardown calls. 15 should - normal default prefix. 16 qwiktest - custom prefix for when tests skip all setup/teardown calls. 17 custtest - custom prefix for when tests use custom setup/teardown calls. 18 paratest - custom prefix for when we want to verify parameterized tests. 19 extest - custom prefix only used during cexception 20 suitetest- custom prefix for when we want to use custom suite setup/teardown 21 */ 22 23 /* Support for Meta Test Rig */ 24 #define TEST_CASE(a) 25 void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests 26 27 /* Global Variables Used During These Tests */ 28 int CounterSetup = 0; 29 int CounterTeardown = 0; 30 int CounterSuiteSetup = 0; 31 32 void setUp(void) 33 { 34 CounterSetup = 1; 35 } 36 37 void tearDown(void) 38 { 39 CounterTeardown = 1; 40 } 41 42 void custom_setup(void) 43 { 44 CounterSetup = 2; 45 } 46 47 void custom_teardown(void) 48 { 49 CounterTeardown = 2; 50 } 51 52 /* 53 void test_OldSchoolCommentsShouldBeIgnored(void) 54 { 55 TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored"); 56 } 57 */ 58 59 void test_ThisTestAlwaysPasses(void) 60 { 61 TEST_PASS(); 62 } 63 64 void test_ThisTestAlwaysFails(void) 65 { 66 TEST_FAIL_MESSAGE("This Test Should Fail"); 67 } 68 69 void test_ThisTestAlwaysIgnored(void) 70 { 71 TEST_IGNORE_MESSAGE("This Test Should Be Ignored"); 72 } 73 74 void qwiktest_ThisTestPassesWhenNoSetupRan(void) 75 { 76 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run"); 77 } 78 79 void qwiktest_ThisTestPassesWhenNoTeardownRan(void) 80 { 81 TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run"); 82 } 83 84 void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void) 85 { 86 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run"); 87 } 88 89 void spec_ThisTestPassesWhenNormalSetupRan(void) 90 { 91 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run"); 92 } 93 94 void spec_ThisTestPassesWhenNormalTeardownRan(void) 95 { 96 TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run"); 97 } 98 99 void custtest_ThisTestPassesWhenCustomSetupRan(void) 100 { 101 TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run"); 102 } 103 104 void custtest_ThisTestPassesWhenCustomTeardownRan(void) 105 { 106 TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run"); 107 } 108 109 //void test_NewStyleCommentsShouldBeIgnored(void) 110 //{ 111 // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored"); 112 //} 113 114 void test_NotBeConfusedByLongComplicatedStrings(void) 115 { 116 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"; 117 118 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same"); 119 } 120 121 void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void) 122 { 123 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True"); 124 } 125 126 void test_StillNotBeConfusedByLongComplicatedStrings(void) 127 { 128 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"; 129 130 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same"); 131 } 132 133 void should_RunTestsStartingWithShouldByDefault(void) 134 { 135 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True"); 136 } 137 138 TEST_CASE(25) 139 TEST_CASE(125) 140 TEST_CASE(5) 141 void paratest_ShouldHandleParameterizedTests(int Num) 142 { 143 TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5"); 144 } 145 146 TEST_CASE(7) 147 void paratest_ShouldHandleParameterizedTests2(int Num) 148 { 149 TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes"); 150 } 151 152 void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void) 153 { 154 TEST_PASS(); 155 } 156 157 TEST_CASE(17) 158 void paratest_ShouldHandleParameterizedTestsThatFail(int Num) 159 { 160 TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail"); 161 } 162 163 #ifdef USE_CEXCEPTION 164 void extest_ShouldHandleCExceptionInTest(void) 165 { 166 TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException"); 167 } 168 #endif 169 170 #ifdef USE_ANOTHER_MAIN 171 int custom_main(void); 172 173 int main(void) 174 { 175 return custom_main(); 176 } 177 #endif 178 179 void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void) 180 { 181 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run"); 182 } 183 184 void test_ShouldCallMockInitAndVerifyFunctionsForEachTest(void) 185 { 186 int passesOrIgnores = (int)(Unity.NumberOfTests - Unity.TestFailures); 187 TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests, mockMock_Init_Counter, "Mock Init Should Be Called Once Per Test Started"); 188 TEST_ASSERT_EQUAL_MESSAGE(passesOrIgnores, mockMock_Verify_Counter, "Mock Verify Should Be Called Once Per Test Passed"); 189 TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests - 1, mockMock_Destroy_Counter, "Mock Destroy Should Be Called Once Per Test Completed"); 190 TEST_ASSERT_EQUAL_MESSAGE(0, CMockMemFreeFinalCounter, "Mock MemFreeFinal Should Not Be Called Until End"); 191 } 192