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 */
24void putcharSpy(int c) { (void)putchar(c);}
25void flushSpy(void) {}
26
27/* Global Variables Used During These Tests */
28int CounterSetup = 0;
29int CounterTeardown = 0;
30int CounterSuiteSetup = 0;
31
32void setUp(void)
33{
34    CounterSetup = 1;
35}
36
37void tearDown(void)
38{
39    CounterTeardown = 1;
40}
41
42void custom_setup(void)
43{
44    CounterSetup = 2;
45}
46
47void custom_teardown(void)
48{
49    CounterTeardown = 2;
50}
51
52/*
53void test_OldSchoolCommentsShouldBeIgnored(void)
54{
55    TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored");
56}
57*/
58
59void test_ThisTestAlwaysPasses(void)
60{
61    TEST_PASS();
62}
63
64void test_ThisTestAlwaysFails(void)
65{
66    TEST_FAIL_MESSAGE("This Test Should Fail");
67}
68
69void test_ThisTestAlwaysIgnored(void)
70{
71    TEST_IGNORE_MESSAGE("This Test Should Be Ignored");
72}
73
74void qwiktest_ThisTestPassesWhenNoSetupRan(void)
75{
76    TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run");
77}
78
79void qwiktest_ThisTestPassesWhenNoTeardownRan(void)
80{
81    TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run");
82}
83
84void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)
85{
86    TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run");
87}
88
89void spec_ThisTestPassesWhenNormalSetupRan(void)
90{
91    TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run");
92}
93
94void spec_ThisTestPassesWhenNormalTeardownRan(void)
95{
96    TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run");
97}
98
99void custtest_ThisTestPassesWhenCustomSetupRan(void)
100{
101    TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run");
102}
103
104void 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
116void 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
123void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
124{
125    TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
126}
127
128void 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
135void should_RunTestsStartingWithShouldByDefault(void)
136{
137    TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
138}
139
140TEST_CASE(25)
141TEST_CASE(125)
142TEST_CASE(5)
143void paratest_ShouldHandleParameterizedTests(int Num)
144{
145    TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5");
146}
147
148TEST_CASE(7)
149void paratest_ShouldHandleParameterizedTests2(int Num)
150{
151    TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes");
152}
153
154void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)
155{
156    TEST_PASS();
157}
158
159TEST_CASE(17)
160void paratest_ShouldHandleParameterizedTestsThatFail(int Num)
161{
162    TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail");
163}
164
165#ifdef USE_CEXCEPTION
166void 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
173int custom_main(void);
174
175int main(void)
176{
177    return custom_main();
178}
179#endif
180
181void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
182{
183    TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
184}
185
186void 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