| 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 */ |
| 26 |
void putcharSpy(int c) { (void)putchar(c);} |
| 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 |
|
| 34 |
void setUp(void) |
| 35 |
{ |
| 36 |
CounterSetup = 1; |
| 37 |
} |
| 38 |
|
| 39 |
void tearDown(void) |
| 40 |
{ |
| 41 |
CounterTeardown = 1; |
| 42 |
} |
| 43 |
|
| 44 |
void custom_setup(void) |
| 45 |
{ |
| 46 |
CounterSetup = 2; |
| 47 |
} |
| 48 |
|
| 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 |
|
| 61 |
void test_ThisTestAlwaysPasses(void) |
| 62 |
{ |
| 63 |
TEST_PASS(); |
| 64 |
} |
| 65 |
|
| 66 |
void test_ThisTestAlwaysFails(void) |
| 67 |
{ |
| 68 |
TEST_FAIL_MESSAGE("This Test Should Fail"); |
| 69 |
} |
| 70 |
|
| 71 |
void test_ThisTestAlwaysIgnored(void) |
| 72 |
{ |
| 73 |
TEST_IGNORE_MESSAGE("This Test Should Be Ignored"); |
| 74 |
} |
| 75 |
|
| 76 |
void qwiktest_ThisTestPassesWhenNoSetupRan(void) |
| 77 |
{ |
| 78 |
TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run"); |
| 79 |
} |
| 80 |
|
| 81 |
void qwiktest_ThisTestPassesWhenNoTeardownRan(void) |
| 82 |
{ |
| 83 |
TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run"); |
| 84 |
} |
| 85 |
|
| 86 |
void spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void) |
| 87 |
{ |
| 88 |
TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run"); |
| 89 |
} |
| 90 |
|
| 91 |
void spec_ThisTestPassesWhenNormalSetupRan(void) |
| 92 |
{ |
| 93 |
TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run"); |
| 94 |
} |
| 95 |
|
| 96 |
void spec_ThisTestPassesWhenNormalTeardownRan(void) |
| 97 |
{ |
| 98 |
TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run"); |
| 99 |
} |
| 100 |
|
| 101 |
void custtest_ThisTestPassesWhenCustomSetupRan(void) |
| 102 |
{ |
| 103 |
TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run"); |
| 104 |
} |
| 105 |
|
| 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 |
|
| 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 */ |
| 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 |
|
| 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 |
|
| 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) |
| 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) |
| 154 |
void paratest_ShouldHandleParameterizedTests2(int Num) |
| 155 |
{ |
| 156 |
TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes"); |
| 157 |
} |
| 158 |
|
| 159 |
void paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void) |
| 160 |
{ |
| 161 |
TEST_PASS(); |
| 162 |
} |
| 163 |
|
| 164 |
TEST_CASE(17) |
| 165 |
void paratest_ShouldHandleParameterizedTestsThatFail(int Num) |
| 166 |
{ |
| 167 |
TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail"); |
| 168 |
} |
| 169 |
|
| 170 |
#ifdef USE_CEXCEPTION |
| 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 |
|
| 180 |
int main(void) |
| 181 |
{ |
| 182 |
return custom_main(); |
| 183 |
} |
| 184 |
#endif |
| 185 |
|
| 186 |
void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void) |
| 187 |
{ |
| 188 |
TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run"); |
| 189 |
} |