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