135375f98Sopenharmony_ci/* Copyright (c) 2010 James Grenning and Contributed to Unity Project 235375f98Sopenharmony_ci * ========================================== 335375f98Sopenharmony_ci * Unity Project - A Test Framework for C 435375f98Sopenharmony_ci * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 535375f98Sopenharmony_ci * [Released under MIT License. Please refer to license.txt for details] 635375f98Sopenharmony_ci * ========================================== */ 735375f98Sopenharmony_ci 835375f98Sopenharmony_ci#include "unity_fixture.h" 935375f98Sopenharmony_ci#include <stdlib.h> 1035375f98Sopenharmony_ci#include <string.h> 1135375f98Sopenharmony_ci 1235375f98Sopenharmony_ciTEST_GROUP(UnityFixture); 1335375f98Sopenharmony_ci 1435375f98Sopenharmony_ciTEST_SETUP(UnityFixture) 1535375f98Sopenharmony_ci{ 1635375f98Sopenharmony_ci} 1735375f98Sopenharmony_ci 1835375f98Sopenharmony_ciTEST_TEAR_DOWN(UnityFixture) 1935375f98Sopenharmony_ci{ 2035375f98Sopenharmony_ci} 2135375f98Sopenharmony_ci 2235375f98Sopenharmony_cistatic int* pointer1 = 0; 2335375f98Sopenharmony_cistatic int* pointer2 = (int*)2; 2435375f98Sopenharmony_cistatic int* pointer3 = (int*)3; 2535375f98Sopenharmony_cistatic int int1; 2635375f98Sopenharmony_cistatic int int2; 2735375f98Sopenharmony_cistatic int int3; 2835375f98Sopenharmony_cistatic int int4; 2935375f98Sopenharmony_ci 3035375f98Sopenharmony_ciTEST(UnityFixture, PointerSetting) 3135375f98Sopenharmony_ci{ 3235375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); 3335375f98Sopenharmony_ci UT_PTR_SET(pointer1, &int1); 3435375f98Sopenharmony_ci UT_PTR_SET(pointer2, &int2); 3535375f98Sopenharmony_ci UT_PTR_SET(pointer3, &int3); 3635375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer1, &int1); 3735375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer2, &int2); 3835375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer3, &int3); 3935375f98Sopenharmony_ci UT_PTR_SET(pointer1, &int4); 4035375f98Sopenharmony_ci UnityPointer_UndoAllSets(); 4135375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); 4235375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer2, (int*)2); 4335375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(pointer3, (int*)3); 4435375f98Sopenharmony_ci} 4535375f98Sopenharmony_ci 4635375f98Sopenharmony_cistatic char *p1; 4735375f98Sopenharmony_cistatic char *p2; 4835375f98Sopenharmony_ci 4935375f98Sopenharmony_ciTEST(UnityFixture, PointerSet) 5035375f98Sopenharmony_ci{ 5135375f98Sopenharmony_ci char c1; 5235375f98Sopenharmony_ci char c2; 5335375f98Sopenharmony_ci char newC1; 5435375f98Sopenharmony_ci char newC2; 5535375f98Sopenharmony_ci p1 = &c1; 5635375f98Sopenharmony_ci p2 = &c2; 5735375f98Sopenharmony_ci 5835375f98Sopenharmony_ci UnityPointer_Init(); 5935375f98Sopenharmony_ci UT_PTR_SET(p1, &newC1); 6035375f98Sopenharmony_ci UT_PTR_SET(p2, &newC2); 6135375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(&newC1, p1); 6235375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(&newC2, p2); 6335375f98Sopenharmony_ci UnityPointer_UndoAllSets(); 6435375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(&c1, p1); 6535375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(&c2, p2); 6635375f98Sopenharmony_ci} 6735375f98Sopenharmony_ci 6835375f98Sopenharmony_ciTEST(UnityFixture, FreeNULLSafety) 6935375f98Sopenharmony_ci{ 7035375f98Sopenharmony_ci free(NULL); 7135375f98Sopenharmony_ci} 7235375f98Sopenharmony_ci 7335375f98Sopenharmony_ciTEST(UnityFixture, ConcludeTestIncrementsFailCount) 7435375f98Sopenharmony_ci{ 7535375f98Sopenharmony_ci UNITY_UINT savedFails = Unity.TestFailures; 7635375f98Sopenharmony_ci UNITY_UINT savedIgnores = Unity.TestIgnores; 7735375f98Sopenharmony_ci Unity.CurrentTestFailed = 1; 7835375f98Sopenharmony_ci UnityConcludeFixtureTest(); /* Resets TestFailed for this test to pass */ 7935375f98Sopenharmony_ci Unity.CurrentTestIgnored = 1; 8035375f98Sopenharmony_ci UnityConcludeFixtureTest(); /* Resets TestIgnored */ 8135375f98Sopenharmony_ci TEST_ASSERT_EQUAL(savedFails + 1, Unity.TestFailures); 8235375f98Sopenharmony_ci TEST_ASSERT_EQUAL(savedIgnores + 1, Unity.TestIgnores); 8335375f98Sopenharmony_ci Unity.TestFailures = savedFails; 8435375f98Sopenharmony_ci Unity.TestIgnores = savedIgnores; 8535375f98Sopenharmony_ci} 8635375f98Sopenharmony_ci 8735375f98Sopenharmony_ci/*------------------------------------------------------------ */ 8835375f98Sopenharmony_ci 8935375f98Sopenharmony_ciTEST_GROUP(UnityCommandOptions); 9035375f98Sopenharmony_ci 9135375f98Sopenharmony_cistatic int savedVerbose; 9235375f98Sopenharmony_cistatic unsigned int savedRepeat; 9335375f98Sopenharmony_cistatic const char* savedName; 9435375f98Sopenharmony_cistatic const char* savedGroup; 9535375f98Sopenharmony_ci 9635375f98Sopenharmony_ciTEST_SETUP(UnityCommandOptions) 9735375f98Sopenharmony_ci{ 9835375f98Sopenharmony_ci savedVerbose = UnityFixture.Verbose; 9935375f98Sopenharmony_ci savedRepeat = UnityFixture.RepeatCount; 10035375f98Sopenharmony_ci savedName = UnityFixture.NameFilter; 10135375f98Sopenharmony_ci savedGroup = UnityFixture.GroupFilter; 10235375f98Sopenharmony_ci} 10335375f98Sopenharmony_ci 10435375f98Sopenharmony_ciTEST_TEAR_DOWN(UnityCommandOptions) 10535375f98Sopenharmony_ci{ 10635375f98Sopenharmony_ci UnityFixture.Verbose = savedVerbose; 10735375f98Sopenharmony_ci UnityFixture.RepeatCount= savedRepeat; 10835375f98Sopenharmony_ci UnityFixture.NameFilter = savedName; 10935375f98Sopenharmony_ci UnityFixture.GroupFilter = savedGroup; 11035375f98Sopenharmony_ci} 11135375f98Sopenharmony_ci 11235375f98Sopenharmony_ci 11335375f98Sopenharmony_cistatic const char* noOptions[] = { 11435375f98Sopenharmony_ci "testrunner.exe" 11535375f98Sopenharmony_ci}; 11635375f98Sopenharmony_ci 11735375f98Sopenharmony_ciTEST(UnityCommandOptions, DefaultOptions) 11835375f98Sopenharmony_ci{ 11935375f98Sopenharmony_ci UnityGetCommandLineOptions(1, noOptions); 12035375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityFixture.Verbose); 12135375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.GroupFilter); 12235375f98Sopenharmony_ci TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.NameFilter); 12335375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityFixture.RepeatCount); 12435375f98Sopenharmony_ci} 12535375f98Sopenharmony_ci 12635375f98Sopenharmony_cistatic const char* verbose[] = { 12735375f98Sopenharmony_ci "testrunner.exe", 12835375f98Sopenharmony_ci "-v" 12935375f98Sopenharmony_ci}; 13035375f98Sopenharmony_ci 13135375f98Sopenharmony_ciTEST(UnityCommandOptions, OptionVerbose) 13235375f98Sopenharmony_ci{ 13335375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, verbose)); 13435375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); 13535375f98Sopenharmony_ci} 13635375f98Sopenharmony_ci 13735375f98Sopenharmony_cistatic const char* group[] = { 13835375f98Sopenharmony_ci "testrunner.exe", 13935375f98Sopenharmony_ci "-g", "groupname" 14035375f98Sopenharmony_ci}; 14135375f98Sopenharmony_ci 14235375f98Sopenharmony_ciTEST(UnityCommandOptions, OptionSelectTestByGroup) 14335375f98Sopenharmony_ci{ 14435375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, group)); 14535375f98Sopenharmony_ci STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); 14635375f98Sopenharmony_ci} 14735375f98Sopenharmony_ci 14835375f98Sopenharmony_cistatic const char* name[] = { 14935375f98Sopenharmony_ci "testrunner.exe", 15035375f98Sopenharmony_ci "-n", "testname" 15135375f98Sopenharmony_ci}; 15235375f98Sopenharmony_ci 15335375f98Sopenharmony_ciTEST(UnityCommandOptions, OptionSelectTestByName) 15435375f98Sopenharmony_ci{ 15535375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, name)); 15635375f98Sopenharmony_ci STRCMP_EQUAL("testname", UnityFixture.NameFilter); 15735375f98Sopenharmony_ci} 15835375f98Sopenharmony_ci 15935375f98Sopenharmony_cistatic const char* repeat[] = { 16035375f98Sopenharmony_ci "testrunner.exe", 16135375f98Sopenharmony_ci "-r", "99" 16235375f98Sopenharmony_ci}; 16335375f98Sopenharmony_ci 16435375f98Sopenharmony_ciTEST(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount) 16535375f98Sopenharmony_ci{ 16635375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, repeat)); 16735375f98Sopenharmony_ci TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); 16835375f98Sopenharmony_ci} 16935375f98Sopenharmony_ci 17035375f98Sopenharmony_ciTEST(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount) 17135375f98Sopenharmony_ci{ 17235375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, repeat)); 17335375f98Sopenharmony_ci TEST_ASSERT_EQUAL(99, UnityFixture.RepeatCount); 17435375f98Sopenharmony_ci} 17535375f98Sopenharmony_ci 17635375f98Sopenharmony_cistatic const char* multiple[] = { 17735375f98Sopenharmony_ci "testrunner.exe", 17835375f98Sopenharmony_ci "-v", 17935375f98Sopenharmony_ci "-g", "groupname", 18035375f98Sopenharmony_ci "-n", "testname", 18135375f98Sopenharmony_ci "-r", "98" 18235375f98Sopenharmony_ci}; 18335375f98Sopenharmony_ci 18435375f98Sopenharmony_ciTEST(UnityCommandOptions, MultipleOptions) 18535375f98Sopenharmony_ci{ 18635375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(8, multiple)); 18735375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); 18835375f98Sopenharmony_ci STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); 18935375f98Sopenharmony_ci STRCMP_EQUAL("testname", UnityFixture.NameFilter); 19035375f98Sopenharmony_ci TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); 19135375f98Sopenharmony_ci} 19235375f98Sopenharmony_ci 19335375f98Sopenharmony_cistatic const char* dashRNotLast[] = { 19435375f98Sopenharmony_ci "testrunner.exe", 19535375f98Sopenharmony_ci "-v", 19635375f98Sopenharmony_ci "-g", "gggg", 19735375f98Sopenharmony_ci "-r", 19835375f98Sopenharmony_ci "-n", "tttt", 19935375f98Sopenharmony_ci}; 20035375f98Sopenharmony_ci 20135375f98Sopenharmony_ciTEST(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified) 20235375f98Sopenharmony_ci{ 20335375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(7, dashRNotLast)); 20435375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); 20535375f98Sopenharmony_ci STRCMP_EQUAL("gggg", UnityFixture.GroupFilter); 20635375f98Sopenharmony_ci STRCMP_EQUAL("tttt", UnityFixture.NameFilter); 20735375f98Sopenharmony_ci TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); 20835375f98Sopenharmony_ci} 20935375f98Sopenharmony_ci 21035375f98Sopenharmony_cistatic const char* unknownCommand[] = { 21135375f98Sopenharmony_ci "testrunner.exe", 21235375f98Sopenharmony_ci "-v", 21335375f98Sopenharmony_ci "-g", "groupname", 21435375f98Sopenharmony_ci "-n", "testname", 21535375f98Sopenharmony_ci "-r", "98", 21635375f98Sopenharmony_ci "-z" 21735375f98Sopenharmony_ci}; 21835375f98Sopenharmony_ciTEST(UnityCommandOptions, UnknownCommandIsIgnored) 21935375f98Sopenharmony_ci{ 22035375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(9, unknownCommand)); 22135375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); 22235375f98Sopenharmony_ci STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); 22335375f98Sopenharmony_ci STRCMP_EQUAL("testname", UnityFixture.NameFilter); 22435375f98Sopenharmony_ci TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); 22535375f98Sopenharmony_ci} 22635375f98Sopenharmony_ci 22735375f98Sopenharmony_ciTEST(UnityCommandOptions, GroupOrNameFilterWithoutStringFails) 22835375f98Sopenharmony_ci{ 22935375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(3, unknownCommand)); 23035375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(5, unknownCommand)); 23135375f98Sopenharmony_ci TEST_ASSERT_EQUAL(1, UnityMain(3, unknownCommand, NULL)); 23235375f98Sopenharmony_ci} 23335375f98Sopenharmony_ci 23435375f98Sopenharmony_ciTEST(UnityCommandOptions, GroupFilterReallyFilters) 23535375f98Sopenharmony_ci{ 23635375f98Sopenharmony_ci UNITY_UINT saved = Unity.NumberOfTests; 23735375f98Sopenharmony_ci TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(4, unknownCommand)); 23835375f98Sopenharmony_ci UnityIgnoreTest(NULL, "non-matching", NULL); 23935375f98Sopenharmony_ci TEST_ASSERT_EQUAL(saved, Unity.NumberOfTests); 24035375f98Sopenharmony_ci} 24135375f98Sopenharmony_ci 24235375f98Sopenharmony_ciIGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored) 24335375f98Sopenharmony_ci{ 24435375f98Sopenharmony_ci TEST_FAIL_MESSAGE("This test should not run!"); 24535375f98Sopenharmony_ci} 246