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