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
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 /* Include Passthroughs for Linking Tests */
putcharSpy(int c)23 void putcharSpy(int c) { (void)putchar(c);}
flushSpy(void)24 void flushSpy(void) {}
25
26 /* Global Variables Used During These Tests */
27 int CounterSetup = 0;
28 int CounterTeardown = 0;
29 int CounterSuiteSetup = 0;
30
setUp(void)31 void setUp(void)
32 {
33 CounterSetup = 1;
34 }
35
tearDown(void)36 void tearDown(void)
37 {
38 CounterTeardown = 1;
39 }
40
custom_setup(void)41 void custom_setup(void)
42 {
43 CounterSetup = 2;
44 }
45
custom_teardown(void)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
test_ThisTestAlwaysPasses(void)58 void test_ThisTestAlwaysPasses(void)
59 {
60 TEST_PASS();
61 }
62
test_ThisTestAlwaysFails(void)63 void test_ThisTestAlwaysFails(void)
64 {
65 TEST_FAIL_MESSAGE("This Test Should Fail");
66 }
67
test_ThisTestAlwaysIgnored(void)68 void test_ThisTestAlwaysIgnored(void)
69 {
70 TEST_IGNORE_MESSAGE("This Test Should Be Ignored");
71 }
72
qwiktest_ThisTestPassesWhenNoSetupRan(void)73 void qwiktest_ThisTestPassesWhenNoSetupRan(void)
74 {
75 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run");
76 }
77
qwiktest_ThisTestPassesWhenNoTeardownRan(void)78 void qwiktest_ThisTestPassesWhenNoTeardownRan(void)
79 {
80 TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run");
81 }
82
spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)83 void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)
84 {
85 TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run");
86 }
87
spec_ThisTestPassesWhenNormalSetupRan(void)88 void spec_ThisTestPassesWhenNormalSetupRan(void)
89 {
90 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run");
91 }
92
spec_ThisTestPassesWhenNormalTeardownRan(void)93 void spec_ThisTestPassesWhenNormalTeardownRan(void)
94 {
95 TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run");
96 }
97
custtest_ThisTestPassesWhenCustomSetupRan(void)98 void custtest_ThisTestPassesWhenCustomSetupRan(void)
99 {
100 TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run");
101 }
102
custtest_ThisTestPassesWhenCustomTeardownRan(void)103 void custtest_ThisTestPassesWhenCustomTeardownRan(void)
104 {
105 TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run");
106 }
107
108 #ifndef UNITY_EXCLUDE_TESTING_NEW_COMMENTS
109 //void test_NewStyleCommentsShouldBeIgnored(void)
110 //{
111 // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored");
112 //}
113 #endif
114
test_NotBeConfusedByLongComplicatedStrings(void)115 void test_NotBeConfusedByLongComplicatedStrings(void)
116 {
117 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";
118
119 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same");
120 }
121
122 /* The next test should still appear even though we have this confusing nested comment thing going on http://looks_like_comments.com */
test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)123 void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
124 {
125 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
126 /* still should not break anything */
127 }
128 /* nor should this */
129
test_StillNotBeConfusedByLongComplicatedStrings(void)130 void test_StillNotBeConfusedByLongComplicatedStrings(void)
131 {
132 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";
133
134 TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same");
135 }
136
should_RunTestsStartingWithShouldByDefault(void)137 void should_RunTestsStartingWithShouldByDefault(void)
138 {
139 TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
140 }
141
142 TEST_CASE(25)
143 TEST_CASE(125)
144 TEST_CASE(5)
paratest_ShouldHandleParameterizedTests(int Num)145 void paratest_ShouldHandleParameterizedTests(int Num)
146 {
147 TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5");
148 }
149
150 TEST_CASE(7)
paratest_ShouldHandleParameterizedTests2(int Num)151 void paratest_ShouldHandleParameterizedTests2(int Num)
152 {
153 TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes");
154 }
155
paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)156 void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)
157 {
158 TEST_PASS();
159 }
160
161 TEST_CASE(17)
paratest_ShouldHandleParameterizedTestsThatFail(int Num)162 void paratest_ShouldHandleParameterizedTestsThatFail(int Num)
163 {
164 TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail");
165 }
166
isArgumentOne(int i)167 int isArgumentOne(int i)
168 {
169 return i == 1;
170 }
171
TEST_CASE(isArgumentOne)172 TEST_CASE(isArgumentOne)
173 void paratest_WorksWithFunctionPointers(int function(int))
174 {
175 TEST_ASSERT_TRUE_MESSAGE(function(1), "Function should return True");
176 }
177
178 #ifdef USE_CEXCEPTION
extest_ShouldHandleCExceptionInTest(void)179 void extest_ShouldHandleCExceptionInTest(void)
180 {
181 TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException");
182 }
183 #endif
184
185 #ifdef USE_ANOTHER_MAIN
186 int custom_main(void);
187
main(void)188 int main(void)
189 {
190 return custom_main();
191 }
192 #endif
193
suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)194 void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
195 {
196 TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
197 }
198