135375f98Sopenharmony_ci/* This Test File Is Used To Verify Many Combinations Of Using the Generate Test Runner Script */
235375f98Sopenharmony_ci
335375f98Sopenharmony_ci#include <stdio.h>
435375f98Sopenharmony_ci#include "unity.h"
535375f98Sopenharmony_ci#include "Defs.h"
635375f98Sopenharmony_ci#include "mockMock.h"
735375f98Sopenharmony_ci
835375f98Sopenharmony_ci#ifdef USE_CEXCEPTION
935375f98Sopenharmony_ci#include "CException.h"
1035375f98Sopenharmony_ci#endif
1135375f98Sopenharmony_ci
1235375f98Sopenharmony_ci/* Notes about prefixes:
1335375f98Sopenharmony_ci   test     - normal default prefix. these are "always run" tests for this procedure
1435375f98Sopenharmony_ci   spec     - normal default prefix. required to run default setup/teardown calls.
1535375f98Sopenharmony_ci   should   - normal default prefix.
1635375f98Sopenharmony_ci   qwiktest - custom prefix for when tests skip all setup/teardown calls.
1735375f98Sopenharmony_ci   custtest - custom prefix for when tests use custom setup/teardown calls.
1835375f98Sopenharmony_ci   paratest - custom prefix for when we want to verify parameterized tests.
1935375f98Sopenharmony_ci   extest   - custom prefix only used during cexception
2035375f98Sopenharmony_ci   suitetest- custom prefix for when we want to use custom suite setup/teardown
2135375f98Sopenharmony_ci*/
2235375f98Sopenharmony_ci
2335375f98Sopenharmony_ci/* Include Passthroughs for Linking Tests */
2435375f98Sopenharmony_civoid putcharSpy(int c) { (void)putchar(c);}
2535375f98Sopenharmony_civoid flushSpy(void) {}
2635375f98Sopenharmony_ci
2735375f98Sopenharmony_ci/* Global Variables Used During These Tests */
2835375f98Sopenharmony_ciint CounterSetup = 0;
2935375f98Sopenharmony_ciint CounterTeardown = 0;
3035375f98Sopenharmony_ciint CounterSuiteSetup = 0;
3135375f98Sopenharmony_ci
3235375f98Sopenharmony_civoid setUp(void)
3335375f98Sopenharmony_ci{
3435375f98Sopenharmony_ci    CounterSetup = 1;
3535375f98Sopenharmony_ci}
3635375f98Sopenharmony_ci
3735375f98Sopenharmony_civoid tearDown(void)
3835375f98Sopenharmony_ci{
3935375f98Sopenharmony_ci    CounterTeardown = 1;
4035375f98Sopenharmony_ci}
4135375f98Sopenharmony_ci
4235375f98Sopenharmony_civoid custom_setup(void)
4335375f98Sopenharmony_ci{
4435375f98Sopenharmony_ci    CounterSetup = 2;
4535375f98Sopenharmony_ci}
4635375f98Sopenharmony_ci
4735375f98Sopenharmony_civoid custom_teardown(void)
4835375f98Sopenharmony_ci{
4935375f98Sopenharmony_ci    CounterTeardown = 2;
5035375f98Sopenharmony_ci}
5135375f98Sopenharmony_ci
5235375f98Sopenharmony_ci/*
5335375f98Sopenharmony_civoid test_OldSchoolCommentsShouldBeIgnored(void)
5435375f98Sopenharmony_ci{
5535375f98Sopenharmony_ci    TEST_ASSERT_FAIL("Old-School Comments Should Be Ignored");
5635375f98Sopenharmony_ci}
5735375f98Sopenharmony_ci*/
5835375f98Sopenharmony_ci
5935375f98Sopenharmony_civoid test_ThisTestAlwaysPasses(void)
6035375f98Sopenharmony_ci{
6135375f98Sopenharmony_ci    TEST_PASS();
6235375f98Sopenharmony_ci}
6335375f98Sopenharmony_ci
6435375f98Sopenharmony_civoid test_ThisTestAlwaysFails(void)
6535375f98Sopenharmony_ci{
6635375f98Sopenharmony_ci    TEST_FAIL_MESSAGE("This Test Should Fail");
6735375f98Sopenharmony_ci}
6835375f98Sopenharmony_ci
6935375f98Sopenharmony_civoid test_ThisTestAlwaysIgnored(void)
7035375f98Sopenharmony_ci{
7135375f98Sopenharmony_ci    TEST_IGNORE_MESSAGE("This Test Should Be Ignored");
7235375f98Sopenharmony_ci}
7335375f98Sopenharmony_ci
7435375f98Sopenharmony_civoid qwiktest_ThisTestPassesWhenNoSetupRan(void)
7535375f98Sopenharmony_ci{
7635375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(0, CounterSetup, "Setup Was Unexpectedly Run");
7735375f98Sopenharmony_ci}
7835375f98Sopenharmony_ci
7935375f98Sopenharmony_civoid qwiktest_ThisTestPassesWhenNoTeardownRan(void)
8035375f98Sopenharmony_ci{
8135375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(0, CounterTeardown, "Teardown Was Unexpectedly Run");
8235375f98Sopenharmony_ci}
8335375f98Sopenharmony_ci
8435375f98Sopenharmony_civoid spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan(void)
8535375f98Sopenharmony_ci{
8635375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(0, CounterSuiteSetup, "Suite Setup Was Unexpectedly Run");
8735375f98Sopenharmony_ci}
8835375f98Sopenharmony_ci
8935375f98Sopenharmony_civoid spec_ThisTestPassesWhenNormalSetupRan(void)
9035375f98Sopenharmony_ci{
9135375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run");
9235375f98Sopenharmony_ci}
9335375f98Sopenharmony_ci
9435375f98Sopenharmony_civoid spec_ThisTestPassesWhenNormalTeardownRan(void)
9535375f98Sopenharmony_ci{
9635375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run");
9735375f98Sopenharmony_ci}
9835375f98Sopenharmony_ci
9935375f98Sopenharmony_civoid custtest_ThisTestPassesWhenCustomSetupRan(void)
10035375f98Sopenharmony_ci{
10135375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(2, CounterSetup, "Custom Setup Wasn't Run");
10235375f98Sopenharmony_ci}
10335375f98Sopenharmony_ci
10435375f98Sopenharmony_civoid custtest_ThisTestPassesWhenCustomTeardownRan(void)
10535375f98Sopenharmony_ci{
10635375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run");
10735375f98Sopenharmony_ci}
10835375f98Sopenharmony_ci
10935375f98Sopenharmony_ci#ifndef UNITY_EXCLUDE_TESTING_NEW_COMMENTS
11035375f98Sopenharmony_ci//void test_NewStyleCommentsShouldBeIgnored(void)
11135375f98Sopenharmony_ci//{
11235375f98Sopenharmony_ci//    TEST_ASSERT_FAIL("New Style Comments Should Be Ignored");
11335375f98Sopenharmony_ci//}
11435375f98Sopenharmony_ci#endif
11535375f98Sopenharmony_ci
11635375f98Sopenharmony_civoid test_NotBeConfusedByLongComplicatedStrings(void)
11735375f98Sopenharmony_ci{
11835375f98Sopenharmony_ci    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";
11935375f98Sopenharmony_ci
12035375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are The Same");
12135375f98Sopenharmony_ci}
12235375f98Sopenharmony_ci
12335375f98Sopenharmony_civoid test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
12435375f98Sopenharmony_ci{
12535375f98Sopenharmony_ci    TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
12635375f98Sopenharmony_ci}
12735375f98Sopenharmony_ci
12835375f98Sopenharmony_civoid test_StillNotBeConfusedByLongComplicatedStrings(void)
12935375f98Sopenharmony_ci{
13035375f98Sopenharmony_ci    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";
13135375f98Sopenharmony_ci
13235375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_STRING_MESSAGE(crazyString, crazyString, "These Strings Are Still The Same");
13335375f98Sopenharmony_ci}
13435375f98Sopenharmony_ci
13535375f98Sopenharmony_civoid should_RunTestsStartingWithShouldByDefault(void)
13635375f98Sopenharmony_ci{
13735375f98Sopenharmony_ci    TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
13835375f98Sopenharmony_ci}
13935375f98Sopenharmony_ci
14035375f98Sopenharmony_ciTEST_CASE(25)
14135375f98Sopenharmony_ciTEST_CASE(125)
14235375f98Sopenharmony_ciTEST_CASE(5)
14335375f98Sopenharmony_civoid paratest_ShouldHandleParameterizedTests(int Num)
14435375f98Sopenharmony_ci{
14535375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(0, (Num % 5), "All The Values Are Divisible By 5");
14635375f98Sopenharmony_ci}
14735375f98Sopenharmony_ci
14835375f98Sopenharmony_ciTEST_CASE(7)
14935375f98Sopenharmony_civoid paratest_ShouldHandleParameterizedTests2(int Num)
15035375f98Sopenharmony_ci{
15135375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(7, Num, "The Only Call To This Passes");
15235375f98Sopenharmony_ci}
15335375f98Sopenharmony_ci
15435375f98Sopenharmony_civoid paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid(void)
15535375f98Sopenharmony_ci{
15635375f98Sopenharmony_ci    TEST_PASS();
15735375f98Sopenharmony_ci}
15835375f98Sopenharmony_ci
15935375f98Sopenharmony_ciTEST_CASE(17)
16035375f98Sopenharmony_civoid paratest_ShouldHandleParameterizedTestsThatFail(int Num)
16135375f98Sopenharmony_ci{
16235375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(3, Num, "This call should fail");
16335375f98Sopenharmony_ci}
16435375f98Sopenharmony_ci
16535375f98Sopenharmony_ci#ifdef USE_CEXCEPTION
16635375f98Sopenharmony_civoid extest_ShouldHandleCExceptionInTest(void)
16735375f98Sopenharmony_ci{
16835375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(1, CEXCEPTION_BEING_USED, "Should be pulling in CException");
16935375f98Sopenharmony_ci}
17035375f98Sopenharmony_ci#endif
17135375f98Sopenharmony_ci
17235375f98Sopenharmony_ci#ifdef USE_ANOTHER_MAIN
17335375f98Sopenharmony_ciint custom_main(void);
17435375f98Sopenharmony_ci
17535375f98Sopenharmony_ciint main(void)
17635375f98Sopenharmony_ci{
17735375f98Sopenharmony_ci    return custom_main();
17835375f98Sopenharmony_ci}
17935375f98Sopenharmony_ci#endif
18035375f98Sopenharmony_ci
18135375f98Sopenharmony_civoid suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
18235375f98Sopenharmony_ci{
18335375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
18435375f98Sopenharmony_ci}
18535375f98Sopenharmony_ci
18635375f98Sopenharmony_civoid test_ShouldCallMockInitAndVerifyFunctionsForEachTest(void)
18735375f98Sopenharmony_ci{
18835375f98Sopenharmony_ci    int passesOrIgnores = (int)(Unity.NumberOfTests - Unity.TestFailures);
18935375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests,     mockMock_Init_Counter,    "Mock Init Should Be Called Once Per Test Started");
19035375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(passesOrIgnores,         mockMock_Verify_Counter,  "Mock Verify Should Be Called Once Per Test Passed");
19135375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests - 1, mockMock_Destroy_Counter, "Mock Destroy Should Be Called Once Per Test Completed");
19235375f98Sopenharmony_ci    TEST_ASSERT_EQUAL_MESSAGE(0,                       CMockMemFreeFinalCounter, "Mock MemFreeFinal Should Not Be Called Until End");
19335375f98Sopenharmony_ci}
194