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