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