1 /* This Test File Is Used To Verify Many Combinations Of Using the Generate Test Runner Script */
2
3 #include <stdio.h>
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
26 /* Include Passthroughs for Linking Tests */
putcharSpy(int c)27 void putcharSpy(int c) { (void)putchar(c);}
flushSpy(void)28 void flushSpy(void) {}
29
30 /* Global Variables Used During These Tests */
31 int CounterSetup = 0;
32 int CounterTeardown = 0;
33 int CounterSuiteSetup = 0;
34
setUp(void)35 void setUp(void)
36 {
37 CounterSetup = 1;
38 }
39
tearDown(void)40 void tearDown(void)
41 {
42 CounterTeardown = 1;
43 }
44
custom_setup(void)45 void custom_setup(void)
46 {
47 CounterSetup = 2;
48 }
49
custom_teardown(void)50 void custom_teardown(void)
51 {
52 CounterTeardown = 2;
53 }
54
55 /*
56 void test_OldSchoolCommentsShouldBeIgnored(void)
57 {
58 TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored");
59 }
60 */
61
test_ThisTestAlwaysPasses(void)62 void test_ThisTestAlwaysPasses(void)
63 {
64 TEST_PASS();
65 }
66
test_ThisTestAlwaysFails(void)67 void test_ThisTestAlwaysFails(void)
68 {
69 TEST_FAIL_MESSAGE("This Test Should Fail");
70 }
71
test_ThisTestAlwaysIgnored(void)72 void test_ThisTestAlwaysIgnored(void)
73 {
74 TEST_IGNORE_MESSAGE("This Test Should Be Ignored");
75 }
76
qwiktest_ThisTestPassesWhenNoSetupRan(void)77 void qwiktest_ThisTestPassesWhenNoSetupRan(void)
78 {
79 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run");
80 }
81
qwiktest_ThisTestPassesWhenNoTeardownRan(void)82 void qwiktest_ThisTestPassesWhenNoTeardownRan(void)
83 {
84 TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run");
85 }
86
spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)87 void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)
88 {
89 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run");
90 }
91
spec_ThisTestPassesWhenNormalSetupRan(void)92 void spec_ThisTestPassesWhenNormalSetupRan(void)
93 {
94 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run");
95 }
96
spec_ThisTestPassesWhenNormalTeardownRan(void)97 void spec_ThisTestPassesWhenNormalTeardownRan(void)
98 {
99 TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run");
100 }
101
custtest_ThisTestPassesWhenCustomSetupRan(void)102 void custtest_ThisTestPassesWhenCustomSetupRan(void)
103 {
104 TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run");
105 }
106
custtest_ThisTestPassesWhenCustomTeardownRan(void)107 void custtest_ThisTestPassesWhenCustomTeardownRan(void)
108 {
109 TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run");
110 }
111
112 #ifndef UNITY_EXCLUDE_TESTING_NEW_COMMENTS
113 //void test_NewStyleCommentsShouldBeIgnored(void)
114 //{
115 // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored");
116 //}
117 #endif
118
test_NotBeConfusedByLongComplicatedStrings(void)119 void test_NotBeConfusedByLongComplicatedStrings(void)
120 {
121 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";
122
123 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same");
124 }
125
test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)126 void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
127 {
128 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
129 }
130
test_StillNotBeConfusedByLongComplicatedStrings(void)131 void test_StillNotBeConfusedByLongComplicatedStrings(void)
132 {
133 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";
134
135 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same");
136 }
137
should_RunTestsStartingWithShouldByDefault(void)138 void should_RunTestsStartingWithShouldByDefault(void)
139 {
140 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
141 }
142
143 TEST_CASE(25)
144 TEST_CASE(125)
145 TEST_CASE(5)
paratest_ShouldHandleParameterizedTests(int Num)146 void paratest_ShouldHandleParameterizedTests(int Num)
147 {
148 TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5");
149 }
150
151 TEST_CASE(7)
paratest_ShouldHandleParameterizedTests2(int Num)152 void paratest_ShouldHandleParameterizedTests2(int Num)
153 {
154 TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes");
155 }
156
paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)157 void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)
158 {
159 TEST_PASS();
160 }
161
162 TEST_CASE(17)
paratest_ShouldHandleParameterizedTestsThatFail(int Num)163 void paratest_ShouldHandleParameterizedTestsThatFail(int Num)
164 {
165 TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail");
166 }
167
168 #ifdef USE_CEXCEPTION
extest_ShouldHandleCExceptionInTest(void)169 void extest_ShouldHandleCExceptionInTest(void)
170 {
171 TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException");
172 }
173 #endif
174
175 #ifdef USE_ANOTHER_MAIN
176 int custom_main(void);
177
main(void)178 int main(void)
179 {
180 return custom_main();
181 }
182 #endif
183
suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)184 void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
185 {
186 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
187 }
188
test_ShouldCallMockInitAndVerifyFunctionsForEachTest(void)189 void test_ShouldCallMockInitAndVerifyFunctionsForEachTest(void)
190 {
191 int passesOrIgnores = (int)(Unity.NumberOfTests - Unity.TestFailures);
192 TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests, mockMock_Init_Counter, "Mock Init Should Be Called Once Per Test Started");
193 TEST_ASSERT_EQUAL_MESSAGE(passesOrIgnores, mockMock_Verify_Counter, "Mock Verify Should Be Called Once Per Test Passed");
194 TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests - 1, mockMock_Destroy_Counter, "Mock Destroy Should Be Called Once Per Test Completed");
195 TEST_ASSERT_EQUAL_MESSAGE(0, CMockMemFreeFinalCounter, "Mock MemFreeFinal Should Not Be Called Until End");
196 }
197
198