diff --git a/tests/unittests/embunit/AUTHORS b/tests/unittests/embunit/AUTHORS new file mode 100644 index 0000000000..fa7bbdada4 --- /dev/null +++ b/tests/unittests/embunit/AUTHORS @@ -0,0 +1 @@ +arms22 diff --git a/tests/unittests/embunit/COPYING b/tests/unittests/embunit/COPYING new file mode 100644 index 0000000000..4f8934de8a --- /dev/null +++ b/tests/unittests/embunit/COPYING @@ -0,0 +1,30 @@ +COPYRIGHT AND PERMISSION NOTICE + +Copyright (c) 2003 Embedded Unit Project + +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, and/or sell copies of the Software, and to permit persons +to whom the Software is furnished to do so, provided that the above +copyright notice(s) and this permission notice appear in all copies +of the Software and that both the above copyright notice(s) and this +permission notice appear in supporting documentation. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY +SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF +CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +Except as contained in this notice, the name of a copyright holder +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization of the copyright holder. diff --git a/tests/unittests/embunit/embUnit/AssertImpl.c b/tests/unittests/embunit/embUnit/AssertImpl.c new file mode 100644 index 0000000000..4698d8375c --- /dev/null +++ b/tests/unittests/embunit/embUnit/AssertImpl.c @@ -0,0 +1,100 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: AssertImpl.c,v 1.5 2004/02/10 16:15:25 arms22 Exp $ + */ +#include "config.h" +#include "stdImpl.h" +#include "AssertImpl.h" + +void assertImplementationInt(int expected,int actual, long line, const char *file) +{ + char buffer[32]; /*"exp -2147483647 was -2147483647"*/ + char numbuf[12]; /*32bit int decimal maximum column is 11 (-2147483647~2147483647)*/ + + stdimpl_strcpy(buffer, "exp "); + + { stdimpl_itoa(expected, numbuf, 10); + stdimpl_strncat(buffer, numbuf, 11); } + + stdimpl_strcat(buffer, " was "); + + { stdimpl_itoa(actual, numbuf, 10); + stdimpl_strncat(buffer, numbuf, 11); } + + addFailure(buffer, line, file); +} + +void assertImplementationCStr(const char *expected,const char *actual, long line, const char *file) +{ + char buffer[ASSERT_STRING_BUFFER_MAX]; + #define exp_act_limit ((ASSERT_STRING_BUFFER_MAX-11-1)/2)/* "exp'' was''" = 11 byte */ + int el; + int al; + + if (expected) { + el = stdimpl_strlen(expected); + } else { + el = 4; + expected = "null"; + } + + if (actual) { + al = stdimpl_strlen(actual); + } else { + al = 4; + actual = "null"; + } + if (el > exp_act_limit) { + if (al > exp_act_limit) { + al = exp_act_limit; + el = exp_act_limit; + } else { + int w = exp_act_limit + (exp_act_limit - al); + if (el > w) { + el = w; + } + } + } else { + int w = exp_act_limit + (exp_act_limit - el); + if (al > w) { + al = w; + } + } + stdimpl_strcpy(buffer, "exp \""); + stdimpl_strncat(buffer, expected, el); + stdimpl_strcat(buffer, "\" was \""); + stdimpl_strncat(buffer, actual, al); + stdimpl_strcat(buffer, "\""); + + addFailure(buffer, line, file); +} diff --git a/tests/unittests/embunit/embUnit/AssertImpl.h b/tests/unittests/embunit/embUnit/AssertImpl.h new file mode 100644 index 0000000000..de76b2117e --- /dev/null +++ b/tests/unittests/embunit/embUnit/AssertImpl.h @@ -0,0 +1,72 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: AssertImpl.h,v 1.6 2003/09/16 11:09:53 arms22 Exp $ + */ +#ifndef __ASSERTIMPL_H__ +#define __ASSERTIMPL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void addFailure(const char *msg, long line, const char *file); /*TestCase.c*/ + +void assertImplementationInt(int expected,int actual, long line, const char *file); +void assertImplementationCStr(const char *expected,const char *actual, long line, const char *file); + +#define TEST_ASSERT_EQUAL_STRING(expected,actual)\ + if (expected && actual && (stdimpl_strcmp(expected,actual)==0)) {} else {assertImplementationCStr(expected,actual,__LINE__,__FILE__);return;} + +#define TEST_ASSERT_EQUAL_INT(expected,actual)\ + if (expected == actual) {} else {assertImplementationInt(expected,actual,__LINE__,__FILE__);return;} + +#define TEST_ASSERT_NULL(pointer)\ + TEST_ASSERT_MESSAGE(pointer == NULL,#pointer " was not null.") + +#define TEST_ASSERT_NOT_NULL(pointer)\ + TEST_ASSERT_MESSAGE(pointer != NULL,#pointer " was null.") + +#define TEST_ASSERT_MESSAGE(condition, message)\ + if (condition) {} else {TEST_FAIL(message);} + +#define TEST_ASSERT(condition)\ + if (condition) {} else {TEST_FAIL(#condition);} + +#define TEST_FAIL(message)\ + if (0) {} else {addFailure(message,__LINE__,__FILE__);return;} + +#ifdef __cplusplus +} +#endif + +#endif/*__ASSERTIMPL_H__*/ diff --git a/tests/unittests/embunit/embUnit/HelperMacro.h b/tests/unittests/embunit/embUnit/HelperMacro.h new file mode 100644 index 0000000000..533e1be2a1 --- /dev/null +++ b/tests/unittests/embunit/embUnit/HelperMacro.h @@ -0,0 +1,59 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: HelperMacro.h,v 1.3 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __HELPERMACRO_H__ +#define __HELPERMACRO_H__ + +#define EMB_UNIT_TESTCASE(ca,name,sup,tdw,run) \ + static const TestCase ca = new_TestCase(name,sup,tdw,run) + +#define EMB_UNIT_TESTSUITE(su,name,array) \ + static const TestSuite su = new_TestSuite(name,(Test**)array,sizeof(array)/sizeof(array[0])) + +#define EMB_UNIT_TESTREFS(tests) \ + static Test* const tests[] = + +#define EMB_UNIT_ADD_TESTREF(testref) \ + (Test*) testref + +#define EMB_UNIT_TESTCALLER(caller,name,sup,tdw,fixtures) \ + static const TestCaller caller = new_TestCaller(name,sup,tdw,sizeof(fixtures)/sizeof(fixtures[0]),(TestFixture*)fixtures) + +#define EMB_UNIT_TESTFIXTURES(fixtures) \ + static const TestFixture fixtures[] = + +#define EMB_UNIT_REPEATEDTEST(repeater,test,tmrp) \ + static const RepeatedTest repeater = new_RepeatedTest(test,tmrp) + +#endif/*__HELPERMACRO_H__*/ diff --git a/tests/unittests/embunit/embUnit/RepeatedTest.c b/tests/unittests/embunit/embUnit/RepeatedTest.c new file mode 100644 index 0000000000..d8b09b8395 --- /dev/null +++ b/tests/unittests/embunit/embUnit/RepeatedTest.c @@ -0,0 +1,61 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: RepeatedTest.c,v 1.5 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "Test.h" +#include "RepeatedTest.h" + +char* RepeatedTest_name(RepeatedTest* self) +{ + return Test_name(self->test); +} + +void RepeatedTest_run(RepeatedTest* self,TestResult* result) +{ + int i; + Test* test = self->test; + for (i=0; itimesRepeat; i++) { + Test_run(test, result); + } +} + +int RepeatedTest_countTestCases(RepeatedTest* self) +{ + return Test_countTestCases(self->test) * self->timesRepeat; +} + +const TestImplement RepeatedTestImplement = { + (TestNameFunction) RepeatedTest_name, + (TestRunFunction) RepeatedTest_run, + (TestCountTestCasesFunction)RepeatedTest_countTestCases, +}; diff --git a/tests/unittests/embunit/embUnit/RepeatedTest.h b/tests/unittests/embunit/embUnit/RepeatedTest.h new file mode 100644 index 0000000000..c6b7335e70 --- /dev/null +++ b/tests/unittests/embunit/embUnit/RepeatedTest.h @@ -0,0 +1,56 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: RepeatedTest.h,v 1.7 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __REPEATEDTEST_H__ +#define __REPEATEDTEST_H__ + +typedef struct __RepeatedTest RepeatedTest; +typedef struct __RepeatedTest* RepeatedTestRef; /*downward compatible*/ + +struct __RepeatedTest { + TestImplement* isa; + Test* test; + int timesRepeat; +}; + +extern const TestImplement RepeatedTestImplement; + +#define new_RepeatedTest(test,tmrp)\ + {\ + (TestImplement*)&RepeatedTestImplement,\ + (Test*)test,\ + tmrp,\ + } + +#endif/*__REPEATEDTEST_H__*/ diff --git a/tests/unittests/embunit/embUnit/Test.h b/tests/unittests/embunit/embUnit/Test.h new file mode 100644 index 0000000000..5705a1cb42 --- /dev/null +++ b/tests/unittests/embunit/embUnit/Test.h @@ -0,0 +1,65 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: Test.h,v 1.4 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TEST_H__ +#define __TEST_H__ + +typedef struct __TestResult TestResult; +typedef struct __TestResult* TestResultRef;/*downward compatible*/ + +typedef struct __TestImplement TestImplement; +typedef struct __TestImplement* TestImplementRef;/*downward compatible*/ + +typedef char*(*TestNameFunction)(void*); +typedef void(*TestRunFunction)(void*,TestResult*); +typedef int(*TestCountTestCasesFunction)(void*); + +struct __TestImplement { + TestNameFunction name; + TestRunFunction run; + TestCountTestCasesFunction countTestCases; +}; + +typedef struct __Test Test; +typedef struct __Test* TestRef;/*downward compatible*/ + +struct __Test { + TestImplement* isa; +}; + +#define Test_name(s) ((Test*)s)->isa->name(s) +#define Test_run(s,r) ((Test*)s)->isa->run(s,r) +#define Test_countTestCases(s) ((Test*)s)->isa->countTestCases(s) + +#endif/*__TEST_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestCaller.c b/tests/unittests/embunit/embUnit/TestCaller.c new file mode 100644 index 0000000000..5ecec9fb37 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestCaller.c @@ -0,0 +1,67 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestCaller.c,v 1.6 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "Test.h" +#include "TestCase.h" +#include "TestCaller.h" + +char* TestCaller_name(TestCaller* self) +{ + return self->name; +} + +void TestCaller_run(TestCaller* self,TestResult* result) +{ + TestCase cs = new_TestCase(0,0,0,0); + int i; + cs.setUp= self->setUp; + cs.tearDown = self->tearDown; + for (i=0; inumberOfFixtuers; i++) { + cs.name = self->fixtuers[i].name; + cs.runTest = self->fixtuers[i].test; + /*run test*/ + Test_run(&cs,result); + } +} + +int TestCaller_countTestCases(TestCaller* self) +{ + return self->numberOfFixtuers; +} + +const TestImplement TestCallerImplement = { + (TestNameFunction) TestCaller_name, + (TestRunFunction) TestCaller_run, + (TestCountTestCasesFunction)TestCaller_countTestCases, +}; diff --git a/tests/unittests/embunit/embUnit/TestCaller.h b/tests/unittests/embunit/embUnit/TestCaller.h new file mode 100644 index 0000000000..22166b8387 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestCaller.h @@ -0,0 +1,76 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestCaller.h,v 1.7 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTCALLER_H__ +#define __TESTCALLER_H__ + +typedef struct __TestFixture TestFixture; +typedef struct __TestFixture* TestFixtureRef;/*downward compatible*/ + +struct __TestFixture { + char *name; + void(*test)(void); +}; + +#define new_TestFixture(name,test)\ + {\ + name,\ + test,\ + } + +typedef struct __TestCaller TestCaller; +typedef struct __TestCaller* TestCallerRef;/*downward compatible*/ + +struct __TestCaller { + TestImplement* isa; + char *name; + void(*setUp)(void); + void(*tearDown)(void); + int numberOfFixtuers; + TestFixture *fixtuers; +}; + +extern const TestImplement TestCallerImplement; + +#define new_TestCaller(name,sup,tdw,numberOfFixtuers,fixtuers)\ + {\ + (TestImplement*)&TestCallerImplement,\ + name,\ + sup,\ + tdw,\ + numberOfFixtuers,\ + fixtuers,\ + } + +#endif/*__TESTCALLER_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestCase.c b/tests/unittests/embunit/embUnit/TestCase.c new file mode 100644 index 0000000000..6688ca66be --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestCase.c @@ -0,0 +1,82 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestCase.c,v 1.6 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "Test.h" +#include "TestCase.h" +#include "TestResult.h" + +static TestResult* result_; +static TestCase* self_; + +char* TestCase_name(TestCase* self) +{ + return self->name; +} + +void TestCase_run(TestCase* self,TestResult* result) +{ + TestResult_startTest(result, (Test*)self); + if (self->setUp) { + self->setUp(); + } + if (self->runTest) { + TestResult* wr =result_; /*push*/ + TestCase* ws = self_; /*push*/ + result_ = result; + self_ = self; + self->runTest(); + result_ = wr; /*pop*/ + self_ = ws; /*pop*/ + } + if (self->tearDown) { + self->tearDown(); + } + TestResult_endTest(result, (Test*)self); +} + +int TestCase_countTestCases(TestCase* self) +{ + return 1; +} + +const TestImplement TestCaseImplement = { + (TestNameFunction) TestCase_name, + (TestRunFunction) TestCase_run, + (TestCountTestCasesFunction)TestCase_countTestCases, +}; + +void addFailure(const char *msg, long line, const char *file) +{ + TestResult_addFailure(result_, (Test*)self_, (char*)msg, line, (char*)file); +} diff --git a/tests/unittests/embunit/embUnit/TestCase.h b/tests/unittests/embunit/embUnit/TestCase.h new file mode 100644 index 0000000000..bbbd59fdab --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestCase.h @@ -0,0 +1,60 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestCase.h,v 1.7 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTCASE_H__ +#define __TESTCASE_H__ + +typedef struct __TestCase TestCase; +typedef struct __TestCase* TestCaseRef;/*compatible embUnit1.0*/ + +struct __TestCase { + TestImplement* isa; + char *name; + void(*setUp)(void); + void(*tearDown)(void); + void(*runTest)(void); +}; + +extern const TestImplement TestCaseImplement; + +#define new_TestCase(name,setUp,tearDown,runTest)\ + {\ + (TestImplement*)&TestCaseImplement,\ + name,\ + setUp,\ + tearDown,\ + runTest,\ + } + +#endif/*__TESTCASE_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestListener.h b/tests/unittests/embunit/embUnit/TestListener.h new file mode 100644 index 0000000000..404a971fc4 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestListener.h @@ -0,0 +1,62 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestListener.h,v 1.4 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTLISTENER_H__ +#define __TESTLISTENER_H__ + +typedef struct __TestListnerImplement TestListnerImplement; +typedef struct __TestListnerImplement* TestListnerImplementRef;/*downward compatible*/ + +typedef void(*TestListnerStartTestCallBack)(void*,void*); +typedef void(*TestListnerEndTestCallBack)(void*,void*); +typedef void(*TestListnerAddFailureCallBack)(void*,void*,const char*,int,const char*); + +struct __TestListnerImplement { + TestListnerStartTestCallBack startTest; + TestListnerEndTestCallBack endTest; + TestListnerAddFailureCallBack addFailure; +}; + +/*typedef struct __TestListner TestListner;*/ /*->TestResult.h*/ +/*typedef struct __TestListner* TestListnerRef;*/ /*->TestResult.h*/ + +struct __TestListner { + TestListnerImplement* isa; +}; + +#define TestListner_startTest(s,t) ((TestListner*)s)->isa->startTest(s,t) +#define TestListner_endTest(s,t) ((TestListner*)s)->isa->endTest(s,t) +#define TestListner_addFailure(s,t,m,l,f) ((TestListner*)s)->isa->addFailure(s,t,m,l,f) + +#endif/*__TESTLISTENER_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestResult.c b/tests/unittests/embunit/embUnit/TestResult.c new file mode 100644 index 0000000000..6006df8be5 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestResult.c @@ -0,0 +1,67 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestResult.c,v 1.4 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "Test.h" +#include "TestListener.h" +#include "TestResult.h" + +void TestResult_init(TestResult* self,TestListner* listner) +{ + self->runCount = 0; + self->failureCount = 0; + self->listener = listner; +} + +void TestResult_startTest(TestResult* self,Test* test) +{ + self->runCount++; + if (self->listener) { + TestListner_startTest(self->listener, test); + } +} + +void TestResult_endTest(TestResult* self,Test* test) +{ + if (self->listener) { + TestListner_endTest(self->listener, test); + } +} + +void TestResult_addFailure(TestResult* self,Test* test,const char* msg,int line,const char* file) +{ + self->failureCount++; + if (self->listener) { + TestListner_addFailure(self->listener, test, msg, line, file); + } +} diff --git a/tests/unittests/embunit/embUnit/TestResult.h b/tests/unittests/embunit/embUnit/TestResult.h new file mode 100644 index 0000000000..7ebfb28333 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestResult.h @@ -0,0 +1,70 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestResult.h,v 1.7 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTRESULT_H__ +#define __TESTRESULT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/*typedef struct __TestResult TestResult;*//* -> Test.h*/ +/*typedef struct __TestResult* TestResultRef;*//* -> Test.h*/ + +typedef struct __TestListner TestListner; +typedef struct __TestListner* TestListnerRef;/*downward compatible*/ + +struct __TestResult { + unsigned short runCount; + unsigned short failureCount; + TestListner* listener; +}; + +#define new_TestResult(listener)\ + {\ + 0,\ + 0,\ + (TestListner*)listener,\ + } + +void TestResult_init(TestResult* self,TestListner* listner); +void TestResult_startTest(TestResult* self,Test* test); +void TestResult_endTest(TestResult* self,Test* test); +void TestResult_addFailure(TestResult* self,Test* test,const char* msg,int line,const char* file); + +#ifdef __cplusplus +} +#endif + +#endif/*__TESTRESULT_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestRunner.c b/tests/unittests/embunit/embUnit/TestRunner.c new file mode 100644 index 0000000000..a6388d0e30 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestRunner.c @@ -0,0 +1,111 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestRunner.c,v 1.6 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "config.h" +#include "stdImpl.h" +#include "Test.h" +#include "TestListener.h" +#include "TestResult.h" +#include "TestRunner.h" + +static TestResult result_; +static Test* root_; + +static void TestRunner_startTest(TestListner* self,Test* test) +{ + stdimpl_print("."); +} + +static void TestRunner_endTest(TestListner* self,Test* test) +{ +} + +static void TestRunner_addFailure(TestListner* self,Test* test,char* msg,int line,char* file) +{ + stdimpl_print("\n"); + stdimpl_print(Test_name(root_)); + stdimpl_print("."); + stdimpl_print(Test_name(test)); + { + char buf[16]; + stdimpl_print(" ("); + stdimpl_print(file); + stdimpl_print(" "); + stdimpl_itoa(line, buf, 10); + stdimpl_print(buf); + stdimpl_print(") "); + } + stdimpl_print(msg); + stdimpl_print("\n"); +} + +static const TestListnerImplement TestRunnerImplement = { + (TestListnerStartTestCallBack) TestRunner_startTest, + (TestListnerEndTestCallBack) TestRunner_endTest, + (TestListnerAddFailureCallBack) TestRunner_addFailure, +}; + +static const TestListner testrunner_ = { + (TestListnerImplement*)&TestRunnerImplement, +}; + +void TestRunner_start(void) +{ + TestResult_init(&result_, (TestListner*)&testrunner_); +} + +void TestRunner_runTest(Test* test) +{ + root_ = test; + Test_run(test, &result_); +} + +void TestRunner_end(void) +{ + char buf[16]; + if (result_.failureCount) { + stdimpl_print("\nrun "); + stdimpl_itoa(result_.runCount, buf, 10); + stdimpl_print(buf); + stdimpl_print(" failures "); + stdimpl_itoa(result_.failureCount, buf, 10); + stdimpl_print(buf); + stdimpl_print("\n"); + } else { + stdimpl_print("\nOK ("); + stdimpl_itoa(result_.runCount, buf, 10); + stdimpl_print(buf); + stdimpl_print(" tests)\n"); + } +} diff --git a/tests/unittests/embunit/embUnit/TestRunner.h b/tests/unittests/embunit/embUnit/TestRunner.h new file mode 100644 index 0000000000..f709f7491f --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestRunner.h @@ -0,0 +1,50 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestRunner.h,v 1.6 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTRUNNER_H__ +#define __TESTRUNNER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void TestRunner_start(void); +void TestRunner_runTest(Test* test); +void TestRunner_end(void); + +#ifdef __cplusplus +} +#endif + +#endif/*__TESTRUNNER_H__*/ diff --git a/tests/unittests/embunit/embUnit/TestSuite.c b/tests/unittests/embunit/embUnit/TestSuite.c new file mode 100644 index 0000000000..a8899e2999 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestSuite.c @@ -0,0 +1,73 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestSuite.c,v 1.5 2004/02/10 16:19:29 arms22 Exp $ + */ +#include "Test.h" +#include "TestSuite.h" + +char* TestSuite_name(TestSuite* self) +{ + return self->name; +} + +void TestSuite_run(TestSuite* self,TestResult* result) +{ + int i; + Test* test; + if (self->tests) { + for (i=0; inumberOfTests; i++) { + test = self->tests[i]; + Test_run(test, result); + } + } +} + +int TestSuite_countTestCases(TestSuite* self) +{ + int count = 0; + int i; + Test* test; + if (self->tests) { + for (i=0; inumberOfTests; i++) { + test = self->tests[i]; + count += Test_countTestCases(test); + } + } + return count; +} + +const TestImplement TestSuiteImplement = { + (TestNameFunction) TestSuite_name, + (TestRunFunction) TestSuite_run, + (TestCountTestCasesFunction)TestSuite_countTestCases, +}; diff --git a/tests/unittests/embunit/embUnit/TestSuite.h b/tests/unittests/embunit/embUnit/TestSuite.h new file mode 100644 index 0000000000..ae100ed4f5 --- /dev/null +++ b/tests/unittests/embunit/embUnit/TestSuite.h @@ -0,0 +1,58 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TestSuite.h,v 1.7 2004/02/10 16:19:29 arms22 Exp $ + */ +#ifndef __TESTSUITE_H__ +#define __TESTSUITE_H__ + +typedef struct __TestSuite TestSuite; +typedef struct __TestSuite* TestSuiteRef;/*downward compatible*/ + +struct __TestSuite { + TestImplement* isa; + char *name; + int numberOfTests; + Test** tests; +}; + +extern const TestImplement TestSuiteImplement; + +#define new_TestSuite(name,tests,numberOfTests)\ + {\ + (TestImplement*)&TestSuiteImplement,\ + name,\ + numberOfTests,\ + tests,\ + } + +#endif/*__TESTSUITE_H__*/ diff --git a/tests/unittests/embunit/embUnit/config.h b/tests/unittests/embunit/embUnit/config.h new file mode 100644 index 0000000000..2328d3a14b --- /dev/null +++ b/tests/unittests/embunit/embUnit/config.h @@ -0,0 +1,48 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: config.h,v 1.7 2004/02/10 16:17:07 arms22 Exp $ + */ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +/* #define NO_STDIO_PRINTF*/ + #ifdef NO_STDIO_PRINTF + extern void stdimpl_print(const char *string); + #else + #include + #define stdimpl_print printf + #endif + + #define ASSERT_STRING_BUFFER_MAX 64 + +#endif/*__CONFIG_H__*/ diff --git a/tests/unittests/embunit/embUnit/embUnit.h b/tests/unittests/embunit/embUnit/embUnit.h new file mode 100644 index 0000000000..d727088ce6 --- /dev/null +++ b/tests/unittests/embunit/embUnit/embUnit.h @@ -0,0 +1,50 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: embUnit.h,v 1.4 2004/02/10 16:16:19 arms22 Exp $ + */ +#ifndef __EMBUNIT_H__ +#define __EMBUNIT_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif/*__EMBUNIT_H__*/ diff --git a/tests/unittests/embunit/embUnit/makefile b/tests/unittests/embunit/embUnit/makefile new file mode 100644 index 0000000000..6ed48380ed --- /dev/null +++ b/tests/unittests/embunit/embUnit/makefile @@ -0,0 +1,32 @@ +CC = gcc +CFLAGS = -O +AR = ar +ARFLAGS = ru +RANLIB = ranlib +RM = rm +OUTPUT = ../lib/ +TARGET = libembUnit.a +OBJS = AssertImpl.o RepeatedTest.o stdImpl.o TestCaller.o TestCase.o TestResult.o TestRunner.o TestSuite.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(AR) $(ARFLAGS) $(OUTPUT)$@ $(OBJS) + $(RANLIB) $(OUTPUT)$@ + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< + +AssertImpl.o: AssertImpl.h stdImpl.h +RepeatedTest.o: RepeatedTest.h Test.h +stdImpl.o: stdImpl.h +TestCaller.o: TestCaller.h TestResult.h TestListener.h TestCase.h Test.h +TestCase.o: TestCase.h TestResult.h TestListener.h Test.h +TestResult.o: TestResult.h TestListener.h Test.h +TestRunner.o: TestRunner.h TestResult.h TestListener.h Test.h stdImpl.h config.h +TestSuite.o: TestSuite.h TestResult.h TestListener.h Test.h + +clean: + -$(RM) $(OBJS) $(TARGET) + +.PHONY: clean all diff --git a/tests/unittests/embunit/embUnit/stdImpl.c b/tests/unittests/embunit/embUnit/stdImpl.c new file mode 100644 index 0000000000..082ebc1b43 --- /dev/null +++ b/tests/unittests/embunit/embUnit/stdImpl.c @@ -0,0 +1,141 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: stdImpl.c,v 1.3 2004/02/10 16:15:25 arms22 Exp $ + */ +#include "stdImpl.h" + +char* stdimpl_strcpy(char *dst, const char *src) +{ + char *start = dst; + char c; + do { + c = *src; + *dst = c; + src++; + dst++; + } while (c); + return start; +} + +char* stdimpl_strcat(char *dst, const char *src) +{ + char *start = dst; + char c; + do { + c = *dst; + dst++; + } while (c); + dst--; + do { + c = *src; + *dst = c; + src++; + dst++; + } while (c); + return start; +} + +char* stdimpl_strncat(char *dst, const char *src,unsigned int count) +{ + char *start = dst; + char c; + do { + c = *dst; + dst++; + } while (c); + dst--; + if (count) { + do { + c = *src; + *dst = c; + src++; + dst++; + count--; + } while (c && count); + *dst = '\0'; + } + return start; +} + +int stdimpl_strlen(const char *str) +{ + const char *estr = str; + char c; + do { + c = *estr; + estr++; + } while (c); + return ((int)(estr - str - 1)); +} + +int stdimpl_strcmp(const char *s1, const char *s2) +{ + char c1,c2; + do { + c1 = *s1++; + c2 = *s2++; + } while ((c1) && (c2) && (c1==c2)); + return c1 - c2; +} + +static char* _xtoa(unsigned long v,char *string, int r, int is_neg) +{ + char *start = string; + char buf[33],*p; + + p = buf; + + do { + *p++ = "0123456789abcdef"[(v % r) & 0xf]; + } while (v /= r); + + if (is_neg) { + *p++ = '-'; + } + + do { + *string++ = *--p; + } while (buf != p); + + *string = '\0'; + + return start; +} + +char* stdimpl_itoa(int v,char *string,int r) +{ + if ((r == 10) && (v < 0)) { + return _xtoa((unsigned long)(-v), string, r, 1); + } + return _xtoa((unsigned long)(v), string, r, 0); +} diff --git a/tests/unittests/embunit/embUnit/stdImpl.h b/tests/unittests/embunit/embUnit/stdImpl.h new file mode 100644 index 0000000000..f6ce267095 --- /dev/null +++ b/tests/unittests/embunit/embUnit/stdImpl.h @@ -0,0 +1,57 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: stdImpl.h,v 1.4 2004/02/10 16:15:25 arms22 Exp $ + */ +#ifndef __STDIMPL_H__ +#define __STDIMPL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#define NULL 0 +#endif + +char* stdimpl_strcpy(char *s1, const char *s2); +char* stdimpl_strcat(char *dst, const char *src); +char* stdimpl_strncat(char *dst, const char *src,unsigned int count); +int stdimpl_strlen(const char *str); +int stdimpl_strcmp(const char *s1, const char *s2); +char* stdimpl_itoa(int v,char *string,int r); + +#ifdef __cplusplus +} +#endif + +#endif/*__STDIMPL_H__*/ diff --git a/tests/unittests/embunit/makefile b/tests/unittests/embunit/makefile new file mode 100644 index 0000000000..c2a174fcfd --- /dev/null +++ b/tests/unittests/embunit/makefile @@ -0,0 +1,20 @@ +all: + -@mkdir lib + -@cd ./embUnit ;$(MAKE) + -@cd ./tests ;$(MAKE) + -@cd ./samples ;$(MAKE) + -@cd ./tools ;$(MAKE) + +test: + -@./tests/embUnitTest + +samples: + -@./samples/samples + +clean: + -@cd ./embUnit ;$(MAKE) clean + -@cd ./tests ;$(MAKE) clean + -@cd ./samples ;$(MAKE) clean + -@cd ./tools ;$(MAKE) clean + +.PHONY: clean samples test all diff --git a/tests/unittests/embunit/readme.txt b/tests/unittests/embunit/readme.txt new file mode 100644 index 0000000000..b24259e77f --- /dev/null +++ b/tests/unittests/embunit/readme.txt @@ -0,0 +1,132 @@ + + + == Embedded Unit == + https://sourceforge.jp/projects/embunit/ + +------------------------------------------------------------------------------ + +Embedded UnitはC言語を使った組み込み系開発向けのテストユニットフレームワークで +す。C標準ライブラリを使わないので実行資源の少ないターゲット環境で動作可能です。 +また、malloc関数も使用していません。すべてのオブジェクトはROM領域に確保されま +す。 + +------------------------------------------------------------------------------ + +1.ディレクトリ・ファイル構成 + [embUnit] + +- COPYING : ライセンス + +- makefile : メイクファイル + +- readme.txt : このファイル + +- [embUnit] : Embedded Unit ライブラリソース + +- [msvc] : MSVC++6.0 Project + +- [samples] : Embedded Unit サンプルソース + +- [tests] : Embedded Unit テストソース + +- [tools] : テストコードの雛形生成ツール + + +2.ターゲットシステムと開発環境 + + Embedded Unitの実行環境として次のものを想定している + + ・2KB以上のROM領域、128b以上のスタック領域を使用可能な環境 + ・標準Cライブラリが使用できない、したくない環境 + + また、開発環境として次のものを想定している + + ・Cコンパイラが使える環境 + + 補足 + + Embedded Unitの開発は次の環境で行われている + + ・Microsoft Windows XP Professional + ・VC++.NET or cygwin 1.3.22 + gcc 3.2 + ・Microsoft Windows 98 + ・VC++6.0 + ・Apple Computer MacOS X 10.1.5 + ・Project Builder 1.1.1 (gcc 2.95.2) + + +3.コンパイル + 3.1.UNIX系(cygwin) + - 必要に応じてembUnit/config.hを編集,以下のコマンドを実行. + + $ make + + - テストフレーム自身のテストを実行. + + $ make test + + - サンプルを実行. + + $ make samples + + 3.2.MSVC++6.0 + - msvc/embUnit.dsw を開いて各プロジェクトをビルドしてください. + + 3.3.MacOSX + - 必要に応じてembUnit/config.hを編集,CC変数をccに置き換えコマンド実行. + + $ make CC=cc + + +4.サポートする機能の概要 + + ・検証マクロ + TEST_ASSERT_EQUAL_STRING・・・文字列の検証 + TEST_ASSERT_EQUAL_INT・・・int型変数の検証 + TEST_ASSERT_NULL・・・NULLポインタの検証 + TEST_ASSERT_NOT_NULL・・・非NULLポインタの検証 + TEST_ASSERT_MESSAGE・・・検証とメッセージ + TEST_ASSERT・・・検証 + TEST_FAIL・・・失敗 + + ・ヘルパーマクロ + テストを記述するのに必要な作業をヘルパーマクロで簡略化します. + + +5.将来サポートする機能の概要 + + ・CUITestRunner + 対話型のTestRunnerの開発を予定しています. + ※標準Cライブラリが使える環境を想定して開発を行います. + 可能なら標準Cライブラリを使わないバージョンも開発します. + + ・GUITestRunner + GUIを利用したTestRunnerです. + + ・textui + Text形式、XML形式、Compiler形式のテスト結果を出力するTestRunnerを開発し + ます. + + +6.制限事項 + + Embedded Unitはテスト結果の出力に標準ライブラリのprintf関数を使用していま + す.もし標準ライブラリのprintf関数を使用したくない場合は、 + + void stdimpl_print(const char* string) + ※stdimpl_print関数は文字列の終わりに改行を出力しない関数 + + という関数を実装し、コンパイルオプションに"-DNO_STDIO_PRINTF"を追加してく + ださい.もしくはconfigヘッダの以下のコメントはずしてください. + + /*#define NO_STDIO_PRINTF*/ + + +7.ライセンス + + 7.1.ライセンス + Embedded Unitは + MIT/X Consortium License + に従うものとします. + + 7.2.日本語訳(参考) + http://xjman.dsl.gr.jp/xf86_3/CPYRIGHT-2.html + + 7.3.さまざまなライセンスとそれらについての解説 + http://www.gnu.org/licenses/license-list.ja.html + + +------------------------------------------------------------------------------ +$Id: readme.txt,v 1.10 2003/09/16 11:41:48 arms22 Exp $ diff --git a/tests/unittests/embunit/readme_en.txt b/tests/unittests/embunit/readme_en.txt new file mode 100644 index 0000000000..16244eaa9d --- /dev/null +++ b/tests/unittests/embunit/readme_en.txt @@ -0,0 +1,87 @@ + + + == Embedded Unit == + https://sourceforge.net/projects/embunit/ + +------------------------------------------------------------------------------ + +Embedded Unit is unit testing framework for Embedded C System. It's design was +copied from JUnit and CUnit and more, and then adapted somewhat for Embedded C +System. Embedded Unit does not require std C libs. All objects are allocated +to const area. + +------------------------------------------------------------------------------ + +1.Release Contetns + [embUnit] + +- COPYING : Copyright Notice + +- makefile : + +- readme.txt : japanese + +- readme_en.txt : this file + +- [embUnit] : Embedded Unit Source + +- [msvc] : MSVC++6.0 Project + +- [samples] : Embedded Unit Samples + +- [tests] : Embedded Unit Self Tests + +- [tools] : test template generation tools + + +2.Development environment and Execution environment + + 2.1.Required execution environment + - The ROM more than 2KB + - The Stack more than 128b + + 2.2.Required development environment + - C Compiler + + 2.3.Development of Embedded Unit is performed in the following environment + - Microsoft Windows XP Professional + - VC++.NET or cygwin 1.3.22 + gcc 3.2 + - Microsoft Windows 98 + - VC++6.0 + - Apple Computer MacOS X 10.1.5 + - Project Builder 1.1.1 (gcc 2.95.2) + + +3.Compile + Embedded Unit is using stdio print function for the output of a test + result message. Implement the following function, if you do not want + to use stdio print function. + + void stdimpl_print(const char *string) + * this function does not output a new-line in the end of a string. + + And then add compile-option '-DNO_STDIO_PRINTF', or release the following + comments of a embUnit/config.h. + + /*#define NO_STDIO_PRINTF*/ + + 3.1.GNU building tools + - edit embUnit/config.h if needed and execute the following commands. + + $ make + + - running self tests + + $ make test + + - running samples + + $ make samples + + 3.2.MSVC++6.0 + - open msvc/embUnit.dsw and build each project. + + 3.3.MacOSX + - edit embUnit/config.h if needed and execute the following commands. + + $ make CC=cc + + +4.License + + MIT/X Consortium License + + +------------------------------------------------------------------------------ +$Id: readme_en.txt,v 1.6 2003/09/16 11:08:45 arms22 Exp $ diff --git a/tests/unittests/embunit/samples/AllTests.c b/tests/unittests/embunit/samples/AllTests.c new file mode 100644 index 0000000000..8665cc447c --- /dev/null +++ b/tests/unittests/embunit/samples/AllTests.c @@ -0,0 +1,13 @@ +#include + +TestRef CounterTest_tests(void); +TestRef PersonTest_tests(void); + +int main (int argc, const char* argv[]) +{ + TestRunner_start(); + TestRunner_runTest(CounterTest_tests()); + TestRunner_runTest(PersonTest_tests()); + TestRunner_end(); + return 0; +} diff --git a/tests/unittests/embunit/samples/counter.c b/tests/unittests/embunit/samples/counter.c new file mode 100644 index 0000000000..36a5826e1c --- /dev/null +++ b/tests/unittests/embunit/samples/counter.c @@ -0,0 +1,50 @@ +#include +#include "counter.h" + +CounterRef Counter_alloc(void) +{ + return (CounterRef)malloc(sizeof(Counter)); +} + +void Counter_dealloc(CounterRef self) +{ + free(self); +} + +CounterRef Counter_init(CounterRef self) +{ + self->value = 0; + return self; +} + +CounterRef Counter_counter(void) +{ + return Counter_init(Counter_alloc()); +} + +int Counter_value(CounterRef self) +{ + return self->value; +} + +void Counter_setValue(CounterRef self,int value) +{ + self->value = value; +} + +int Counter_inc(CounterRef self) +{ + self->value++; + return self->value; +} + +int Counter_dec(CounterRef self) +{ + self->value--; + return self->value; +} + +void Counter_clr(CounterRef self) +{ + self->value = 0; +} diff --git a/tests/unittests/embunit/samples/counter.h b/tests/unittests/embunit/samples/counter.h new file mode 100644 index 0000000000..d9eb99be13 --- /dev/null +++ b/tests/unittests/embunit/samples/counter.h @@ -0,0 +1,21 @@ +#ifndef __COUNTER_H__ +#define __COUNTER_H__ + +typedef struct __Counter Counter; +typedef struct __Counter* CounterRef; + +struct __Counter { + int value; +}; + +CounterRef Counter_alloc(void); +void Counter_dealloc(CounterRef); +CounterRef Counter_init(CounterRef); +CounterRef Counter_counter(void); +int Counter_value(CounterRef); +void Counter_setValue(CounterRef,int); +int Counter_inc(CounterRef); +int Counter_dec(CounterRef); +void Counter_clr(CounterRef); + +#endif/*__COUNTER_H__*/ diff --git a/tests/unittests/embunit/samples/counterTest.c b/tests/unittests/embunit/samples/counterTest.c new file mode 100644 index 0000000000..5c59129fa4 --- /dev/null +++ b/tests/unittests/embunit/samples/counterTest.c @@ -0,0 +1,69 @@ +#include +#include "counter.h" + +CounterRef counterRef; + +static void setUp(void) +{ + counterRef = Counter_counter(); +} + +static void tearDown(void) +{ + Counter_dealloc(counterRef); +} + +static void testInit(void) +{ + TEST_ASSERT_EQUAL_INT(0, Counter_value(counterRef)); +} + +static void testSetValue(void) +{ + Counter_setValue(counterRef,1); + TEST_ASSERT_EQUAL_INT(1, Counter_value(counterRef)); + + Counter_setValue(counterRef,-1); + TEST_ASSERT_EQUAL_INT(-1, Counter_value(counterRef)); +} + +static void testInc(void) +{ + Counter_inc(counterRef); + TEST_ASSERT_EQUAL_INT(1, Counter_value(counterRef)); + + Counter_inc(counterRef); + TEST_ASSERT_EQUAL_INT(2, Counter_value(counterRef)); +} + +static void testDec(void) +{ + Counter_dec(counterRef); + TEST_ASSERT_EQUAL_INT(-1, Counter_value(counterRef)); + + Counter_dec(counterRef); + TEST_ASSERT_EQUAL_INT(-2, Counter_value(counterRef)); +} + +static void testClr(void) +{ + Counter_inc(counterRef); + TEST_ASSERT_EQUAL_INT(1, Counter_value(counterRef)); + + Counter_clr(counterRef); + TEST_ASSERT_EQUAL_INT(0, Counter_value(counterRef)); +} + +TestRef CounterTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testInit",testInit), + new_TestFixture("testSetValue",testSetValue), + new_TestFixture("testInc",testInc), + new_TestFixture("testDec",testDec), + new_TestFixture("testClr",testClr), + }; + EMB_UNIT_TESTCALLER(CounterTest,"CounterTest",setUp,tearDown,fixtures); + + return (TestRef)&CounterTest; +} diff --git a/tests/unittests/embunit/samples/makefile b/tests/unittests/embunit/samples/makefile new file mode 100644 index 0000000000..85bf7e962c --- /dev/null +++ b/tests/unittests/embunit/samples/makefile @@ -0,0 +1,20 @@ +CC = gcc +CFLAGS = -O +INCLUDES = .. +LIBS = ../lib +RM = rm +TARGET = samples +OBJS = AllTests.o counter.o counterTest.o person.o personTest.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) -L$(LIBS) -lembUnit + +.c.o: + $(CC) $(CFLAGS) -I$(INCLUDES) -c $< + +clean: + -$(RM) $(TARGET) $(OBJS) + +.PHONY: clean all diff --git a/tests/unittests/embunit/samples/person.c b/tests/unittests/embunit/samples/person.c new file mode 100644 index 0000000000..ff1c83dac4 --- /dev/null +++ b/tests/unittests/embunit/samples/person.c @@ -0,0 +1,179 @@ +#include +#include +#include +#include "person.h" + +PersonRef Person_alloc(void) +{ + return (PersonRef)malloc(sizeof(Person)); +} + +PersonRef Person_init(PersonRef self) +{ + return Person_initWithName(self, NULL); +} + +PersonRef Person_initWithName(PersonRef self,char *fullname) +{ + self->fullname = NULL; + self->firstname = NULL; + self->lastname = NULL; + Person_setFullName(self,fullname); + return self; +} + +PersonRef Person_personWithName(char *fullname) +{ + return Person_initWithName(Person_alloc(),fullname); +} + +void Person_dealloc(PersonRef self) +{ + if (self) { + free(self->fullname); + free(self->firstname); + free(self->lastname); + free(self); + } +} + +static void setfullname(PersonRef self,char *fullname) +{ + free(self->fullname); + self->fullname = NULL; + if (fullname) { + self->fullname = (char*)malloc(strlen(fullname)+1); + strcpy(self->fullname,fullname); + } +} + +static void setfirstname(PersonRef self,char *firstname) +{ + free(self->firstname); + self->firstname = NULL; + if (firstname) { + self->firstname = (char*)malloc(strlen(firstname)+1); + strcpy(self->firstname,firstname); + } +} + +static void setlastname(PersonRef self,char *lastname) +{ + free(self->lastname); + self->lastname = NULL; + if (lastname) { + self->lastname = (char*)malloc(strlen(lastname)+1); + strcpy(self->lastname,lastname); + } +} + +static void makefullname(PersonRef self) +{ + size_t fl,ll,fulllen,pos; + fl = ll = fulllen = pos = 0; + if (self->firstname) { + fl = strlen(self->firstname); + } + if (self->lastname) { + ll = strlen(self->lastname); + } + if (fl) { + fulllen = fl + 1; /* + space */ + } + if (ll) { + fulllen = fulllen + ll + 1; /* + null */ + } + if (fulllen) { + self->fullname = (char*)malloc(fulllen); + if (fl && ll) { + sprintf(self->fullname,"%s %s",self->firstname,self->lastname); + } else { + if (fl) { + strcpy(self->fullname,self->firstname); + } + if (ll) { + strcpy(self->fullname,self->lastname); + } + } + } +} + +static void makefirstname(PersonRef self) +{ + if (self->fullname) { + char *p; + int len; + p = strchr(self->fullname, ' '); + if (p) { + len = (int)(p - self->fullname); + p = (char*)malloc(len + 1); + strncpy(p,self->fullname,len); + p[len] = '\0'; + setfirstname(self,p); + free(p); + } else { + setfirstname(self,self->fullname); + } + } +} + +static void makelastname(PersonRef self) +{ + if (self->fullname) { + char *p = strchr(self->fullname, ' '); + if (p) { + setlastname(self,p+1); + } else { + setlastname(self,""); + } + } +} + +char* Person_fullName(PersonRef self) +{ + if (self->fullname == NULL) { + makefullname(self); + } + return self->fullname; +} + +char* Person_firstName(PersonRef self) +{ + if (self->firstname == NULL) { + makefirstname(self); + } + return self->firstname; +} + +char* Person_lastName(PersonRef self) +{ + if (self->lastname == NULL) { + makelastname(self); + } + return self->lastname; +} + +void Person_setFullName(PersonRef self,char *fullname) +{ + setfullname(self,fullname); + setfirstname(self,NULL); + setlastname(self,NULL); +} + +void Person_setFirstName(PersonRef self,char *firstname) +{ + if (self->lastname == NULL) { + makelastname(self); + } + setfirstname(self,firstname); + setfullname(self,NULL); +} + +void Person_setLastName(PersonRef self,char *lastname) +{ + if (self->firstname == NULL) { + makefirstname(self); + } + setlastname(self,lastname); + setfullname(self,NULL); +} diff --git a/tests/unittests/embunit/samples/person.h b/tests/unittests/embunit/samples/person.h new file mode 100644 index 0000000000..698e5e4a50 --- /dev/null +++ b/tests/unittests/embunit/samples/person.h @@ -0,0 +1,25 @@ +#ifndef __PERSON_H__ +#define __PERSON_H__ + +typedef struct __Person Person; +typedef struct __Person* PersonRef; + +struct __Person { + char *fullname; + char *firstname; + char *lastname; +}; + +PersonRef Person_alloc(void); +PersonRef Person_init(PersonRef); +PersonRef Person_initWithName(PersonRef,char*); +PersonRef Person_personWithName(char*); +void Person_dealloc(PersonRef); +char* Person_fullName(PersonRef); +char* Person_firstName(PersonRef); +char* Person_lastName(PersonRef); +void Person_setFullName(PersonRef,char*); +void Person_setFirstName(PersonRef,char*); +void Person_setLastName(PersonRef,char*); + +#endif/*__PERSON_H__*/ diff --git a/tests/unittests/embunit/samples/personTest.c b/tests/unittests/embunit/samples/personTest.c new file mode 100644 index 0000000000..862a385ef8 --- /dev/null +++ b/tests/unittests/embunit/samples/personTest.c @@ -0,0 +1,111 @@ +#include +#include "person.h" + +PersonRef personRef; + +static void setUp(void) +{ + personRef = Person_personWithName("test tarou"); +} + +static void tearDown(void) +{ + Person_dealloc(personRef); +} + +static void testfullname(void) +{ + TEST_ASSERT_EQUAL_STRING("test tarou", Person_fullName(personRef)); +} + +static void testfirstname(void) +{ + TEST_ASSERT_EQUAL_STRING("test", Person_firstName(personRef)); +} + +static void testlastname(void) +{ + TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef)); +} + +static void testsetfullname(void) +{ + Person_setFullName(personRef, "sample hanako"); + + TEST_ASSERT_EQUAL_STRING("sample hanako", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("hanako", Person_lastName(personRef)); +} + +static void testsetfirstname(void) +{ + Person_setFirstName(personRef, "sample"); + + TEST_ASSERT_EQUAL_STRING("sample tarou", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef)); +} + +static void testsetlastname(void) +{ + Person_setLastName(personRef, "hanako"); + + TEST_ASSERT_EQUAL_STRING("test hanako", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("test", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("hanako", Person_lastName(personRef)); +} + +static void testnullcharfullname(void) +{ + Person_setFullName(personRef, ""); + + TEST_ASSERT_EQUAL_STRING("", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("", Person_lastName(personRef)); +} + +static void testnullpointerfullname(void) +{ + Person_setFullName(personRef, NULL); + + TEST_ASSERT_NULL(Person_fullName(personRef)); + TEST_ASSERT_NULL(Person_firstName(personRef)); + TEST_ASSERT_NULL(Person_lastName(personRef)); +} + +static void testnosepfullname(void) +{ + Person_setFullName(personRef, "sample"); + + TEST_ASSERT_EQUAL_STRING("sample", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("", Person_lastName(personRef)); + + Person_setLastName(personRef, "tarou"); + TEST_ASSERT_EQUAL_STRING("sample tarou", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef)); + + Person_setFirstName(personRef, "test"); + TEST_ASSERT_EQUAL_STRING("test tarou", Person_fullName(personRef)); + TEST_ASSERT_EQUAL_STRING("test", Person_firstName(personRef)); + TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef)); +} + +TestRef PersonTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testfullname",testfullname), + new_TestFixture("testfirstname",testfirstname), + new_TestFixture("testlastname",testlastname), + new_TestFixture("testsetfullname",testsetfullname), + new_TestFixture("testsetfirstname",testsetfirstname), + new_TestFixture("testsetlastname",testsetlastname), + new_TestFixture("testnullcharfullname",testnullcharfullname), + new_TestFixture("testnullpointerfullname",testnullpointerfullname), + new_TestFixture("testnosepfullname",testnosepfullname), + }; + EMB_UNIT_TESTCALLER(PersonTest,"PersonTest",setUp,tearDown,fixtures); + + return (TestRef)&PersonTest; +} diff --git a/tests/unittests/embunit/tests/AllTests.c b/tests/unittests/embunit/tests/AllTests.c new file mode 100644 index 0000000000..dba06e9622 --- /dev/null +++ b/tests/unittests/embunit/tests/AllTests.c @@ -0,0 +1,21 @@ +#include + +extern TestRef assertTest_tests(void); +extern TestRef stdImplTest_tests(void); +extern TestRef TestCaseTest_tests(void); +extern TestRef TestCallerTest_tests(void); +extern TestRef TestResultTest_tests(void); +extern TestRef RepeatedTestTest_tests(void); + +int main (int argc, const char* argv[]) +{ + TestRunner_start(); + TestRunner_runTest(assertTest_tests()); + TestRunner_runTest(stdImplTest_tests()); + TestRunner_runTest(TestCaseTest_tests()); + TestRunner_runTest(TestCallerTest_tests()); + TestRunner_runTest(TestResultTest_tests()); + TestRunner_runTest(RepeatedTestTest_tests()); + TestRunner_end(); + return 0; +} diff --git a/tests/unittests/embunit/tests/MockTestCase.c b/tests/unittests/embunit/tests/MockTestCase.c new file mode 100644 index 0000000000..5d92fd2b6a --- /dev/null +++ b/tests/unittests/embunit/tests/MockTestCase.c @@ -0,0 +1,12 @@ +#include +#include "MockTestCase.h" + +static void runTest(void) +{ +} + +TestCaseRef MockTestCase_case(void) +{ + EMB_UNIT_TESTCASE(MockTestCase,"MockTestCase",NULL,NULL,runTest); + return (TestCaseRef)&MockTestCase; +} diff --git a/tests/unittests/embunit/tests/MockTestCase.h b/tests/unittests/embunit/tests/MockTestCase.h new file mode 100644 index 0000000000..81de8e3b1c --- /dev/null +++ b/tests/unittests/embunit/tests/MockTestCase.h @@ -0,0 +1,6 @@ +#ifndef __MOCKTESTCASE_H__ +#define __MOCKTESTCASE_H__ + +TestCaseRef MockTestCase_case(void); + +#endif/*__MOCKTESTCASE_H__*/ diff --git a/tests/unittests/embunit/tests/RepeatedTestTest.c b/tests/unittests/embunit/tests/RepeatedTestTest.c new file mode 100644 index 0000000000..a68e04ad19 --- /dev/null +++ b/tests/unittests/embunit/tests/RepeatedTestTest.c @@ -0,0 +1,57 @@ +#include +#include "MockTestCase.h" + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void testRepeatedOnce(void) +{ + RepeatedTest test = new_RepeatedTest(MockTestCase_case(),1); + TestResult result = new_TestResult(NULL); + + test.isa->run(&test,&result); + + TEST_ASSERT_EQUAL_INT(1, result.runCount); + TEST_ASSERT_EQUAL_INT(1, test.isa->countTestCases(&test)); +} + +static void testRepeatedMoreThanOnce(void) +{ + RepeatedTest test = new_RepeatedTest(MockTestCase_case(),100); + TestResult result = new_TestResult(NULL); + + test.isa->run(&test,&result); + + + TEST_ASSERT_EQUAL_INT(100, result.runCount); + TEST_ASSERT_EQUAL_INT(100, test.isa->countTestCases(&test)); +} + +static void testRepeatedZero(void) +{ + RepeatedTest test = new_RepeatedTest(MockTestCase_case(),0); + TestResult result = new_TestResult(NULL); + + test.isa->run(&test,&result); + + + TEST_ASSERT_EQUAL_INT(0, result.runCount); + TEST_ASSERT_EQUAL_INT(0, test.isa->countTestCases(&test)); +} + +TestRef RepeatedTestTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testRepeatedOnce",testRepeatedOnce), + new_TestFixture("testRepeatedMoreThanOnce",testRepeatedMoreThanOnce), + new_TestFixture("testRepeatedZero",testRepeatedZero), + }; + EMB_UNIT_TESTCALLER(RepeatedTestTest,"RepeatedTestTest",setUp,tearDown,fixtures); + + return (TestRef)&RepeatedTestTest; +} diff --git a/tests/unittests/embunit/tests/TestCallerTest.c b/tests/unittests/embunit/tests/TestCallerTest.c new file mode 100644 index 0000000000..b8b9d9e1a8 --- /dev/null +++ b/tests/unittests/embunit/tests/TestCallerTest.c @@ -0,0 +1,64 @@ +#include + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void testOneFixture(void) +{ + TestFixture fixtures[] = { + new_TestFixture(NULL,NULL), + }; + TestCaller caller = new_TestCaller(NULL,NULL,NULL,1,fixtures); + TestResult result = new_TestResult(NULL); + + caller.isa->run(&caller,&result); + + TEST_ASSERT_EQUAL_INT(1, result.runCount); + TEST_ASSERT_EQUAL_INT(1, caller.isa->countTestCases(&caller)); +} + +static void testMoreThanOne(void) +{ + TestFixture fixtures[] = { + new_TestFixture(NULL,NULL), + new_TestFixture(NULL,NULL), + new_TestFixture(NULL,NULL), + new_TestFixture(NULL,NULL), + new_TestFixture(NULL,NULL), + }; + TestCaller caller = new_TestCaller(NULL,NULL,NULL,5,fixtures); + TestResult result = new_TestResult(NULL); + + caller.isa->run(&caller,&result); + + TEST_ASSERT_EQUAL_INT(5, result.runCount); + TEST_ASSERT_EQUAL_INT(5, caller.isa->countTestCases(&caller)); +} + +static void testZeroFixture(void) +{ + TestCaller caller = new_TestCaller(NULL,NULL,NULL,0,NULL); + TestResult result = new_TestResult(NULL); + + caller.isa->run(&caller,&result); + + TEST_ASSERT_EQUAL_INT(0, result.runCount); + TEST_ASSERT_EQUAL_INT(0, caller.isa->countTestCases(&caller)); +} + +TestRef TestCallerTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testOneFixture",testOneFixture), + new_TestFixture("testMoreThanOne",testMoreThanOne), + new_TestFixture("testZeroFixture",testZeroFixture), + }; + EMB_UNIT_TESTCALLER(TestCallerTest,"TestCallerTest",setUp,tearDown,fixtures); + + return (TestRef)&TestCallerTest; +} diff --git a/tests/unittests/embunit/tests/TestCaseTest.c b/tests/unittests/embunit/tests/TestCaseTest.c new file mode 100644 index 0000000000..f8a637f757 --- /dev/null +++ b/tests/unittests/embunit/tests/TestCaseTest.c @@ -0,0 +1,66 @@ +#include +#include "MockTestCase.h" + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void testName(void) +{ + TestCaseRef mock = MockTestCase_case(); + TEST_ASSERT_EQUAL_STRING("MockTestCase", mock->isa->name(mock)); +} + +static void testCountTestCases(void) +{ + TestCaseRef mock = MockTestCase_case(); + TEST_ASSERT_EQUAL_INT(1, mock->isa->countTestCases(mock)); +} + +static void success_runTest(void) +{ +} + +static void testSuccess(void) +{ + TestCase tcase = new_TestCase("success",NULL,NULL,success_runTest); + TestResult result = new_TestResult(NULL); + + tcase.isa->run(&tcase,&result); + + TEST_ASSERT_EQUAL_INT(1, result.runCount); + TEST_ASSERT_EQUAL_INT(0, result.failureCount); +} + +static void failure_runTest(void) +{ + TEST_FAIL(""); +} + +static void testFailure(void) +{ + TestCase tcase = new_TestCase("failure",NULL,NULL,failure_runTest); + TestResult result = new_TestResult(NULL); + + tcase.isa->run(&tcase,&result); + + TEST_ASSERT_EQUAL_INT(1, result.runCount); + TEST_ASSERT_EQUAL_INT(1, result.failureCount); +} + +TestRef TestCaseTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testName",testName), + new_TestFixture("testCountTestCases",testCountTestCases), + new_TestFixture("testSuccess",testSuccess), + new_TestFixture("testFailure",testFailure), + }; + EMB_UNIT_TESTCALLER(TestCaseTest,"TestCaseTest",setUp,tearDown,fixtures); + + return (TestRef)&TestCaseTest; +} diff --git a/tests/unittests/embunit/tests/TestResultTest.c b/tests/unittests/embunit/tests/TestResultTest.c new file mode 100644 index 0000000000..a475b0833b --- /dev/null +++ b/tests/unittests/embunit/tests/TestResultTest.c @@ -0,0 +1,60 @@ +#include + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void testTestResult_result(void) +{ + TestResult result = new_TestResult(NULL); + + TEST_ASSERT_EQUAL_INT(0, result.runCount); + TEST_ASSERT_EQUAL_INT(0, result.failureCount); +} + +static void testTestResult_startTest(void) +{ + TestResult result = new_TestResult(NULL); + + TestResult_startTest(&result,NULL); + + TEST_ASSERT_EQUAL_INT(1, result.runCount); + TEST_ASSERT_EQUAL_INT(0, result.failureCount); +} + +static void testTestResult_endTest(void) +{ + TestResult result = new_TestResult(NULL); + + TestResult_endTest(&result,NULL); + + TEST_ASSERT_EQUAL_INT(0, result.runCount); + TEST_ASSERT_EQUAL_INT(0, result.failureCount); +} + +static void testTestResult_addFailure(void) +{ + TestResult result = new_TestResult(NULL); + + TestResult_addFailure(&result,NULL,"",0,""); + + TEST_ASSERT_EQUAL_INT(0, result.runCount); + TEST_ASSERT_EQUAL_INT(1, result.failureCount); +} + +TestRef TestResultTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testTestResult_result",testTestResult_result), + new_TestFixture("testTestResult_startTest",testTestResult_startTest), + new_TestFixture("testTestResult_endTest",testTestResult_endTest), + new_TestFixture("testTestResult_addFailure",testTestResult_addFailure), + }; + EMB_UNIT_TESTCALLER(TestResultTest,"TestResultTest",setUp,tearDown,fixtures); + + return (TestRef)&TestResultTest; +} diff --git a/tests/unittests/embunit/tests/assertTest.c b/tests/unittests/embunit/tests/assertTest.c new file mode 100644 index 0000000000..fde85977aa --- /dev/null +++ b/tests/unittests/embunit/tests/assertTest.c @@ -0,0 +1,103 @@ +#include + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void verify(TestCaseRef test) +{ + TestResult result = new_TestResult(NULL); + + test->isa->run(test,&result); + + if (result.failureCount == 0) { + TEST_FAIL("fail"); + } +} + +static void assert_equal_string_runTest(void) +{ + TEST_ASSERT_EQUAL_STRING("123","456"); +} + +static void assert_equal_int_runTest(void) +{ + TEST_ASSERT_EQUAL_INT(123,456); +} + +static void assert_null_runTest(void) +{ + char *p=""; + TEST_ASSERT_NULL(p); +} + +static void assert_not_null_runTest(void) +{ + char *p=NULL; + TEST_ASSERT_NOT_NULL(p); +} + +static void assert_message_runTest(void) +{ + TEST_ASSERT_MESSAGE(0,"0"); +} + +static void assert_runTest(void) +{ + TEST_ASSERT(0); +} + +static void testASSERT_EQUAL_STRING(void) +{ + TestCase tcase = new_TestCase("assert_equal_string",NULL,NULL,assert_equal_string_runTest); + verify(&tcase); +} + +static void testASSERT_EQUAL_INT(void) +{ + TestCase tcase = new_TestCase("assert_equal_int",NULL,NULL,assert_equal_int_runTest); + verify(&tcase); +} + +static void testASSERT_NULL(void) +{ + TestCase tcase = new_TestCase("assert_null",NULL,NULL,assert_null_runTest); + verify(&tcase); +} + +static void testASSERT_NOT_NULL(void) +{ + TestCase tcase = new_TestCase("assert_not_null",NULL,NULL,assert_not_null_runTest); + verify(&tcase); +} + +static void testASSERT_MESSAGE(void) +{ + TestCase tcase = new_TestCase("assert_message",NULL,NULL,assert_message_runTest); + verify(&tcase); +} + +static void testASSERT(void) +{ + TestCase tcase = new_TestCase("assert",NULL,NULL,assert_runTest); + verify(&tcase); +} + +TestRef assertTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("testASSERT_EQUAL_STRING",testASSERT_EQUAL_STRING), + new_TestFixture("testASSERT_EQUAL_INT",testASSERT_EQUAL_INT), + new_TestFixture("testASSERT_NULL",testASSERT_NULL), + new_TestFixture("testASSERT_NOT_NULL",testASSERT_NOT_NULL), + new_TestFixture("testASSERT_MESSAGE",testASSERT_MESSAGE), + new_TestFixture("testASSERT",testASSERT), + }; + EMB_UNIT_TESTCALLER(AssertTest,"AssertTest",setUp,tearDown,fixtures); + + return (TestRef)&AssertTest; +} diff --git a/tests/unittests/embunit/tests/makefile b/tests/unittests/embunit/tests/makefile new file mode 100644 index 0000000000..27c8ea2283 --- /dev/null +++ b/tests/unittests/embunit/tests/makefile @@ -0,0 +1,21 @@ +CC = gcc +CFLAGS = -O +LDFLAGS = +INCLUDES = .. +LIBS = ../lib +RM = rm +TARGET = embUnitTest +OBJS = AllTests.o RepeatedTestTest.o assertTest.o stdImplTest.o TestCallerTest.o TestCaseTest.o TestResultTest.o MockTestCase.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) -L$(LIBS) -lembUnit + +.c.o: + $(CC) $(CFLAGS) -I$(INCLUDES) -c $< + +clean: + -$(RM) $(TARGET) $(OBJS) + +.PHONY: clean all diff --git a/tests/unittests/embunit/tests/stdImplTest.c b/tests/unittests/embunit/tests/stdImplTest.c new file mode 100644 index 0000000000..4dc73dadf2 --- /dev/null +++ b/tests/unittests/embunit/tests/stdImplTest.c @@ -0,0 +1,114 @@ +#include + +static void setUp(void) +{ +} + +static void tearDown(void) +{ +} + +static void teststrcpy(void) +{ + char buf[32]; + char *p; + + p = stdimpl_strcpy(buf, "test"); + TEST_ASSERT_EQUAL_STRING("test", buf); + TEST_ASSERT( p == buf ); +} + +static void teststrcat(void) +{ + char buf[64]; + + stdimpl_strcpy(buf,"sample"); + stdimpl_strcat(buf," extra string"); + TEST_ASSERT_EQUAL_STRING("sample extra string", buf); + + stdimpl_strcpy(buf,""); + stdimpl_strcat(buf,"sample"); + TEST_ASSERT_EQUAL_STRING("sample", buf); +} + +static void teststrncat(void) +{ + char buf[64]; + + stdimpl_strcpy(buf,"sample"); + stdimpl_strncat(buf," extra string",13); + TEST_ASSERT_EQUAL_STRING("sample extra string", buf); + + stdimpl_strcpy(buf,"This is the initial string!"); + stdimpl_strncat(buf," extra text to add to the string", 19); + TEST_ASSERT_EQUAL_STRING("This is the initial string! extra text to add ", buf); +} + +static void teststrlen(void) +{ + TEST_ASSERT( stdimpl_strlen("test")==4 ); + TEST_ASSERT( stdimpl_strlen("")==0 ); +} + +static void teststrcmp(void) +{ + TEST_ASSERT( stdimpl_strcmp("aaa","aaa") == 0 ); + TEST_ASSERT( stdimpl_strcmp("aaa","bbb") != 0 ); + TEST_ASSERT( stdimpl_strcmp("aaa","AAA") != 0 ); + TEST_ASSERT( stdimpl_strcmp("Test","TestCase") != 0 ); + TEST_ASSERT( stdimpl_strcmp("TestCase","Test") != 0 ); + TEST_ASSERT( stdimpl_strcmp("","") == 0 ); +} + +static void testitoa(void) +{ + char buf[33]; + char *p; + + p = stdimpl_itoa(10, buf, 2); + TEST_ASSERT_EQUAL_STRING("1010", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(10, buf, 8); + TEST_ASSERT_EQUAL_STRING("12", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(10, buf, 10); + TEST_ASSERT_EQUAL_STRING("10", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(10, buf, 16); + TEST_ASSERT_EQUAL_STRING("a", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(-10, buf, 2); + TEST_ASSERT_EQUAL_STRING("11111111111111111111111111110110", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(-10, buf, 8); + TEST_ASSERT_EQUAL_STRING("37777777766", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(-10, buf, 10); + TEST_ASSERT_EQUAL_STRING("-10", buf); + TEST_ASSERT(p == buf); + + p = stdimpl_itoa(-10, buf, 16); + TEST_ASSERT_EQUAL_STRING("fffffff6", buf); + TEST_ASSERT(p == buf); +} + +TestRef stdImplTest_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture("teststrcpy",teststrcpy), + new_TestFixture("teststrcat",teststrcat), + new_TestFixture("teststrncat",teststrncat), + new_TestFixture("teststrlen",teststrlen), + new_TestFixture("teststrcmp",teststrcmp), + new_TestFixture("testitoa",testitoa), + }; + EMB_UNIT_TESTCALLER(StdImplTest,"stdImplTest",setUp,tearDown,fixtures); + + return (TestRef)&StdImplTest; +} diff --git a/tests/unittests/embunit/textui/CompilerOutputter.c b/tests/unittests/embunit/textui/CompilerOutputter.c new file mode 100644 index 0000000000..1a380a7b73 --- /dev/null +++ b/tests/unittests/embunit/textui/CompilerOutputter.c @@ -0,0 +1,79 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: CompilerOutputter.c,v 1.2 2003/09/06 13:28:27 arms22 Exp $ + */ +#include +#include "CompilerOutputter.h" + +static void CompilerOutputter_printHeader(OutputterRef self,TestRef test) +{ +} + +static void CompilerOutputter_printStartTest(OutputterRef self,TestRef test) +{ +} + +static void CompilerOutputter_printEndTest(OutputterRef self,TestRef test) +{ +} + +static void CompilerOutputter_printSuccessful(OutputterRef self,TestRef test,int runCount) +{ +} + +static void CompilerOutputter_printFailure(OutputterRef self,TestRef test,char *msg,int line,char *file,int runCount) +{ + fprintf(stdout,"%s %d: %s: %s\n", file, line, Test_name(test), msg); +} + +static void CompilerOutputter_printStatistics(OutputterRef self,TestResultRef result) +{ +} + +static const OutputterImplement CompilerOutputterImplement = { + (OutputterPrintHeaderFunction) CompilerOutputter_printHeader, + (OutputterPrintStartTestFunction) CompilerOutputter_printStartTest, + (OutputterPrintEndTestFunction) CompilerOutputter_printEndTest, + (OutputterPrintSuccessfulFunction) CompilerOutputter_printSuccessful, + (OutputterPrintFailureFunction) CompilerOutputter_printFailure, + (OutputterPrintStatisticsFunction) CompilerOutputter_printStatistics, +}; + +static const Outputter CompilerOutputter = { + (OutputterImplementRef)&CompilerOutputterImplement, +}; + +OutputterRef CompilerOutputter_outputter(void) +{ + return (OutputterRef)&CompilerOutputter; +} diff --git a/tests/unittests/embunit/textui/CompilerOutputter.h b/tests/unittests/embunit/textui/CompilerOutputter.h new file mode 100644 index 0000000000..7ee690db8d --- /dev/null +++ b/tests/unittests/embunit/textui/CompilerOutputter.h @@ -0,0 +1,42 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: CompilerOutputter.h,v 1.2 2003/09/06 13:28:27 arms22 Exp $ + */ +#ifndef __COMPILEROUTPUTTER_H__ +#define __COMPILEROUTPUTTER_H__ + +#include "Outputter.h" + +OutputterRef CompilerOutputter_outputter(void); + +#endif/*__COMPILEROUTPUTTER_H__*/ diff --git a/tests/unittests/embunit/textui/Outputter.h b/tests/unittests/embunit/textui/Outputter.h new file mode 100644 index 0000000000..36a83d29dd --- /dev/null +++ b/tests/unittests/embunit/textui/Outputter.h @@ -0,0 +1,74 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: Outputter.h,v 1.2 2003/09/06 13:28:27 arms22 Exp $ + */ +#ifndef __OUTPUTTER_H__ +#define __OUTPUTTER_H__ + +#include + +typedef struct __OutputterImplement OutputterImplement; +typedef struct __OutputterImplement* OutputterImplementRef; + +typedef void(*OutputterPrintHeaderFunction)(void*); +typedef void(*OutputterPrintStartTestFunction)(void*,TestRef); +typedef void(*OutputterPrintEndTestFunction)(void*,TestRef); +typedef void(*OutputterPrintSuccessfulFunction)(void*,TestRef,int); +typedef void(*OutputterPrintFailureFunction)(void*,TestRef,char*,int,char*,int); +typedef void(*OutputterPrintStatisticsFunction)(void*,TestResultRef); + + +struct __OutputterImplement { + OutputterPrintHeaderFunction printHeader; + OutputterPrintStartTestFunction printStartTest; + OutputterPrintEndTestFunction printEndTest; + OutputterPrintSuccessfulFunction printSuccessful; + OutputterPrintFailureFunction printFailure; + OutputterPrintStatisticsFunction printStatistics; +}; + +typedef struct __Outputter Outputter; +typedef struct __Outputter* OutputterRef; + +struct __Outputter { + OutputterImplementRef isa; +}; + +#define Outputter_printHeader(o) (o)->isa->printHeader(o) +#define Outputter_printStartTest(o,t) (o)->isa->printStartTest(o,t) +#define Outputter_printEndTest(o,t) (o)->isa->printEndTest(o,t) +#define Outputter_printSuccessful(o,t,c) (o)->isa->printSuccessful(o,t,c) +#define Outputter_printFailure(o,t,m,l,f,c) (o)->isa->printFailure(o,t,m,l,f,c) +#define Outputter_printStatistics(o,r) (o)->isa->printStatistics(o,r) + +#endif/*__OUTPUTTER_H__*/ diff --git a/tests/unittests/embunit/textui/TextOutputter.c b/tests/unittests/embunit/textui/TextOutputter.c new file mode 100644 index 0000000000..de717f6f4d --- /dev/null +++ b/tests/unittests/embunit/textui/TextOutputter.c @@ -0,0 +1,86 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TextOutputter.c,v 1.4 2003/09/06 13:28:27 arms22 Exp $ + */ +#include +#include "TextOutputter.h" + +static void TextOutputter_printHeader(OutputterRef self) +{ +} + +static void TextOutputter_printStartTest(OutputterRef self,TestRef test) +{ + fprintf(stdout,"- %s\n",Test_name(test)); +} + +static void TextOutputter_printEndTest(OutputterRef self,TestRef test) +{ +} + +static void TextOutputter_printSuccessful(OutputterRef self,TestRef test,int runCount) +{ + fprintf(stdout,"%d) OK %s\n", runCount, Test_name(test)); +} + +static void TextOutputter_printFailure(OutputterRef self,TestRef test,char *msg,int line,char *file,int runCount) +{ + fprintf(stdout,"%d) NG %s (%s %d) %s\n", runCount, Test_name(test), file, line, msg); +} + +static void TextOutputter_printStatistics(OutputterRef self,TestResultRef result) +{ + if (result->failureCount) { + fprintf(stdout,"\nrun %d failures %d\n",result->runCount,result->failureCount); + } else { + fprintf(stdout,"\nOK (%d tests)\n",result->runCount); + } +} + +static const OutputterImplement TextOutputterImplement = { + (OutputterPrintHeaderFunction) TextOutputter_printHeader, + (OutputterPrintStartTestFunction) TextOutputter_printStartTest, + (OutputterPrintEndTestFunction) TextOutputter_printEndTest, + (OutputterPrintSuccessfulFunction) TextOutputter_printSuccessful, + (OutputterPrintFailureFunction) TextOutputter_printFailure, + (OutputterPrintStatisticsFunction) TextOutputter_printStatistics, +}; + +static const Outputter TextOutputter = { + (OutputterImplementRef)&TextOutputterImplement, +}; + +OutputterRef TextOutputter_outputter(void) +{ + return (OutputterRef)&TextOutputter; +} diff --git a/tests/unittests/embunit/textui/TextOutputter.h b/tests/unittests/embunit/textui/TextOutputter.h new file mode 100644 index 0000000000..5c6487fb04 --- /dev/null +++ b/tests/unittests/embunit/textui/TextOutputter.h @@ -0,0 +1,42 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TextOutputter.h,v 1.2 2003/09/06 13:28:27 arms22 Exp $ + */ +#ifndef __TEXTOUTPUTTER_H__ +#define __TEXTOUTPUTTER_H__ + +#include "Outputter.h" + +OutputterRef TextOutputter_outputter(void); + +#endif/*__TEXTOUTPUTTER_H__*/ diff --git a/tests/unittests/embunit/textui/TextUIRunner.c b/tests/unittests/embunit/textui/TextUIRunner.c new file mode 100644 index 0000000000..7dade444a7 --- /dev/null +++ b/tests/unittests/embunit/textui/TextUIRunner.c @@ -0,0 +1,103 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TextUIRunner.c,v 1.4 2004/02/10 16:20:43 arms22 Exp $ + */ +#include "TextOutputter.h" +#include "TextUIRunner.h" + +/* Private + */ +static TestResult result_; +static OutputterRef outputterRef_ = 0; +static int wasfailure_ = 0; + +static void TextUIRunner_startTest(TestListnerRef self,TestRef test) +{ + wasfailure_ = 0; +} + +static void TextUIRunner_endTest(TestListnerRef self,TestRef test) +{ + if (!wasfailure_) + Outputter_printSuccessful(outputterRef_,test,result_.runCount); +} + +static void TextUIRunner_addFailure(TestListnerRef self,TestRef test,char *msg,int line,char *file) +{ + wasfailure_ = 1; + Outputter_printFailure(outputterRef_,test,msg,line,file,result_.runCount); +} + +static const TestListnerImplement TextUIRunnerImplement = { + (TestListnerStartTestCallBack) TextUIRunner_startTest, + (TestListnerEndTestCallBack) TextUIRunner_endTest, + (TestListnerAddFailureCallBack) TextUIRunner_addFailure, +}; + +static const TestListner testuirunner_ = { + (TestListnerImplement*)&TextUIRunnerImplement, +}; + +/* Public + */ +void TextUIRunner_setOutputter(OutputterRef outputter) +{ + outputterRef_ = outputter; +} + +void TextUIRunner_startWithOutputter(OutputterRef outputter) +{ + TestResult_init(&result_, (TestListnerRef)&testuirunner_); + TextUIRunner_setOutputter(outputter); + Outputter_printHeader(outputter); + +} + +void TextUIRunner_start(void) +{ + if (!outputterRef_) + outputterRef_ = TextOutputter_outputter(); + TextUIRunner_startWithOutputter(outputterRef_); +} + +void TextUIRunner_runTest(TestRef test) +{ + Outputter_printStartTest(outputterRef_,test); + Test_run(test, &result_); + Outputter_printEndTest(outputterRef_,test); +} + +void TextUIRunner_end(void) +{ + Outputter_printStatistics(outputterRef_,&result_); +} diff --git a/tests/unittests/embunit/textui/TextUIRunner.h b/tests/unittests/embunit/textui/TextUIRunner.h new file mode 100644 index 0000000000..3fdf9ef155 --- /dev/null +++ b/tests/unittests/embunit/textui/TextUIRunner.h @@ -0,0 +1,46 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: TextUIRunner.h,v 1.3 2003/09/06 13:28:27 arms22 Exp $ + */ +#ifndef __TEXTUIRUNNER_H__ +#define __TEXTUIRUNNER_H__ + +#include + +void TextUIRunner_setOutputter(OutputterRef outputter); +void TextUIRunner_startWithOutputter(OutputterRef outputter); +void TextUIRunner_start(void); +void TextUIRunner_runTest(TestRef test); +void TextUIRunner_end(void); + +#endif/*__TEXTUIRUNNER_H__*/ diff --git a/tests/unittests/embunit/textui/XMLOutputter.c b/tests/unittests/embunit/textui/XMLOutputter.c new file mode 100644 index 0000000000..7e0087b5ca --- /dev/null +++ b/tests/unittests/embunit/textui/XMLOutputter.c @@ -0,0 +1,109 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: XMLOutputter.c,v 1.6 2003/09/26 16:32:01 arms22 Exp $ + */ +#include +#include "XMLOutputter.h" + +static char *stylesheet_; + +static void XMLOutputter_printHeader(OutputterRef self) +{ + fprintf(stdout,"\n"); + if (stylesheet_) + fprintf(stdout,"\n",stylesheet_); + fprintf(stdout,"\n"); +} + +static void XMLOutputter_printStartTest(OutputterRef self,TestRef test) +{ + fprintf(stdout,"<%s>\n",Test_name(test)); +} + +static void XMLOutputter_printEndTest(OutputterRef self,TestRef test) +{ + fprintf(stdout,"\n",Test_name(test)); +} + +static void XMLOutputter_printSuccessful(OutputterRef self,TestRef test,int runCount) +{ + fprintf(stdout,"\n",runCount); + fprintf(stdout,"%s\n",Test_name(test)); + fprintf(stdout,"\n"); +} + +static void XMLOutputter_printFailure(OutputterRef self,TestRef test,char *msg,int line,char *file,int runCount) +{ + fprintf(stdout,"\n",runCount); + fprintf(stdout,"%s\n",Test_name(test)); + fprintf(stdout,"\n"); + fprintf(stdout,"%s\n",file); + fprintf(stdout,"%d\n",line); + fprintf(stdout,"\n"); + fprintf(stdout,"%s\n",msg); + fprintf(stdout,"\n"); +} + +static void XMLOutputter_printStatistics(OutputterRef self,TestResultRef result) +{ + fprintf(stdout,"\n"); + fprintf(stdout,"%d\n",result->runCount); + if (result->failureCount) { + fprintf(stdout,"%d\n",result->failureCount); + } + fprintf(stdout,"\n"); + fprintf(stdout,"\n"); +} + +static const OutputterImplement XMLOutputterImplement = { + (OutputterPrintHeaderFunction) XMLOutputter_printHeader, + (OutputterPrintStartTestFunction) XMLOutputter_printStartTest, + (OutputterPrintEndTestFunction) XMLOutputter_printEndTest, + (OutputterPrintSuccessfulFunction) XMLOutputter_printSuccessful, + (OutputterPrintFailureFunction) XMLOutputter_printFailure, + (OutputterPrintStatisticsFunction) XMLOutputter_printStatistics, +}; + +static const Outputter XMLOutputter = { + (OutputterImplementRef)&XMLOutputterImplement, +}; + +void XMLOutputter_setStyleSheet(char *style) +{ + stylesheet_ = style; +} + +OutputterRef XMLOutputter_outputter(void) +{ + return (OutputterRef)&XMLOutputter; +} diff --git a/tests/unittests/embunit/textui/XMLOutputter.h b/tests/unittests/embunit/textui/XMLOutputter.h new file mode 100644 index 0000000000..68b2aaee6f --- /dev/null +++ b/tests/unittests/embunit/textui/XMLOutputter.h @@ -0,0 +1,43 @@ +/* + * COPYRIGHT AND PERMISSION NOTICE + * + * Copyright (c) 2003 Embedded Unit Project + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies + * of the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written + * authorization of the copyright holder. + * + * $Id: XMLOutputter.h,v 1.3 2003/09/06 13:28:27 arms22 Exp $ + */ +#ifndef __XMLOUTPUTTER_H__ +#define __XMLOUTPUTTER_H__ + +#include "Outputter.h" + +void XMLOutputter_setStyleSheet(char *style); +OutputterRef XMLOutputter_outputter(void); + +#endif/*__XMLOUTPUTTER_H__*/ diff --git a/tests/unittests/embunit/textui/makefile b/tests/unittests/embunit/textui/makefile new file mode 100644 index 0000000000..746dd791a1 --- /dev/null +++ b/tests/unittests/embunit/textui/makefile @@ -0,0 +1,30 @@ +CC = gcc +CFLAGS = -O +INCLUDES = .. +LIBS = ../lib +AR = ar +ARFLAGS = ru +RANLIB = ranlib +RM = rm +OUTPUT = ../lib/ +TARGET = libtextui.a +OBJS = TextUIRunner.o XMLOutputter.o TextOutputter.o CompilerOutputter.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(AR) $(ARFLAGS) $(OUTPUT)$@ $(OBJS) + $(RANLIB) $(OUTPUT)$@ + +.c.o: + $(CC) $(CFLAGS) -I$(INCLUDES) -c $< + +TextUIRunner.o: TextUIRunner.h XMLOutputter.h TextOutputter.h CompilerOutputter.h Outputter.h +XMLOutputter.o: XMLOutputter.h Outputter.h +TextOutputter.o: TextOutputter.h Outputter.h +CompilerOutputter.o: CompilerOutputter.h Outputter.h + +clean: + -$(RM) $(TARGET) $(OBJS) + +.PHONY: clean all diff --git a/tests/unittests/embunit/tools/COPYING b/tests/unittests/embunit/tools/COPYING new file mode 100644 index 0000000000..b5064458ae --- /dev/null +++ b/tests/unittests/embunit/tools/COPYING @@ -0,0 +1,21 @@ +Copyright (c) 2003 Embedded Unit Project +Copyright (c) 2002 cuppa project + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tests/unittests/embunit/tools/makefile b/tests/unittests/embunit/tools/makefile new file mode 100644 index 0000000000..bec4eece6f --- /dev/null +++ b/tests/unittests/embunit/tools/makefile @@ -0,0 +1,23 @@ +CC = gcc +CFLAGS = -O +INCLUDE =-I./tbcuppa/ +RM = rm + +all: bcuppa tcuppa buma tuma + +bcuppa:./tbcuppa/bcuppa.c ./tbcuppa/strvec.c + $(CC) -o $@ $(INCLUDE) ./tbcuppa/bcuppa.c ./tbcuppa/strvec.c + +tcuppa:./tbcuppa/tcuppa.c ./tbcuppa/strvec.c + $(CC) -o $@ $(INCLUDE) ./tbcuppa/tcuppa.c ./tbcuppa/strvec.c + +buma:./tbuma/buma.c ./tbcuppa/strvec.c + $(CC) -o $@ $(INCLUDE) ./tbuma/buma.c ./tbcuppa/strvec.c + +tuma:./tbuma/tuma.c ./tbcuppa/strvec.c + $(CC) -o $@ $(INCLUDE) ./tbuma/tuma.c ./tbcuppa/strvec.c + +clean: + $(RM) bcuppa tcuppa buma tuma + +.PHONY: clean all diff --git a/tests/unittests/embunit/tools/readme.txt b/tests/unittests/embunit/tools/readme.txt new file mode 100644 index 0000000000..7402173c35 --- /dev/null +++ b/tests/unittests/embunit/tools/readme.txt @@ -0,0 +1,84 @@ + +1.概要 + + ちび河童&ちび馬は河童プロジェクトで作られたCUnit対応テストコード雛型 + 生成ツールです. + このちび河童&ちび馬の吐き出すコードをEmbedded Unit用に書き換えました. + + オリジナルのちび河童&ちび馬は以下のURLから入手可能です. + + 河童プロジェクト + http://sourceforge.jp/projects/cuppa/ + + 河童(CppUnit PreProcess Aid) + http://www.unittest.org/ + + +2.ファイル構成 + + [tools] + +- readme.txt :このファイル + +- makefile :メイクファイル + +- COPYING :著作権表示 + +- [tbcuppa] :ちび河童改ソースコード + +- [tbuma] :ちび馬改ソースコード + + +3.コンパイル + + toolsディレクトに移動して'make'コマンドを実行してください. + toolsディレクトリに以下の4つのアプリケーションが作成されます. + + tcuppa :テストグループの雛形を生成します. + bcuppa :tcuppaで生成されたテストグループを実行するmainを作成します. + tuma :tcuppaで生成されたテストグループにテストを追加します. + buma :bcuppaで生成されたmainにテスト実行コードを追加します. + + +4.使い方 + +4.1.tcuppa + My.hに定義されている関数をテストするテストグループ MyTest を生成したい場合 + + $ tcuppa My.h MyTest testXxx testYyy + + と入力する.そうするとMy.hをインクルードし空のテスト関数 + + static void testXxx(void) + static void testYyy(void) + + を実装したMyTest.c が生成される.ヘッダは省略可能,また複数指定可能. + +4.2.bcuppa + bcuppaはtcuppaによって生成されたテストグループを順次実行する + メインルーチンを生成します. + 先ほど作成した MyTest を実行するコード AllTests を生成するには + + $ bcuppa AllTests MyTest + + と入力する.またカレントディレクトリに ATest.c BTest.cと在った場合 + + $ bcuppa AllTests *Test.c + + のようなコマンドの指定が可能です. + +4.3.tuma + tcuppaで生成されたテストグループにテストを追加します. + やはり先ほど作成した MyTest にテスト testZzz を追加したい場合、 + + $ tuma MyTest testZzz + + と入力します. + +4.4.buma + bcuppaで生成された AllTests に実行コードを追加します. + 新しく YourTest と言うテストグループを生成します. + + $ tcuppa YourTest testXxx testYyy + + そして YourTest を AllTests に追加します. + + $ buma AllTests YourTest + +------------------------------------------------------------------------------ +$Id: readme.txt,v 1.1 2003/09/02 12:07:44 arms22 Exp $ diff --git a/tests/unittests/embunit/tools/readme_en.txt b/tests/unittests/embunit/tools/readme_en.txt new file mode 100644 index 0000000000..532b89929e --- /dev/null +++ b/tests/unittests/embunit/tools/readme_en.txt @@ -0,0 +1,73 @@ +1.Overview + + This tools generates the test template code for the Embedded Unit. + The following four tools are distributed. + + tcuppa : generate test template source file + bcuppa : generate the main file, included main() + tuma : add a code to the code generated by tcuppa. + buma : add a code to the code generated by bcuppa. + + Original tcuppa, bcuppa, tuma, buma is developed by cuppa project. + It is generate the test template code for the CUnit. + It can be downloaded from the following URL. + + cuppa project + http://sourceforge.jp/projects/cuppa/ + + cuppa (CppUnit PreProcess Aid) + http://www.unittest.org/ + + +2.Contents + [tools] + +- readme.txt : japanese + +- readme_en.txt : this file + +- makefile : makefile + +- COPYING : copyright notice + +- [tbcuppa] : tcuppa & bcuppa source code + +- [tbuma] : tuma & buma source code + + +3.Compile + + $ cd + $ make + + +4.Usage + +4.1.tcuppa + The following commands generate the "MyTest.c" file which tests the + function defined as My.h. + * It does not mean that the function of My.h is searched automatically. + + $ tcuppa My.h MyTest testXxx testYyy + + The file containing '.' is added to a code as a header file. + +4.2.bcuppa + bcuppa generates the main routine which performs the test generated by + tcuppa. The following commands generate the "AllTests.c" file which + performs MyTest. + + $ bcuppa AllTests MyTest + +4.3.tuma + The following commands add a "textZzz" test function to MyTest. + + $ tuma MyTest testZzz + +4.4.buma + The following commands generate "YourTest.c" containing "testXxx" and + "testYyy" test function. + + $ tcuppa YourTest testXxx testYyy + + And, then the following commands add the code which performs "YourTest.c" to + "AllTest.c". + + $ buma AllTests YourTest + +------------------------------------------------------------------------------ +$Id: readme_en.txt,v 1.3 2003/09/10 11:34:17 arms22 Exp $ diff --git a/tests/unittests/embunit/tools/tbcuppa/bcuppa.c b/tests/unittests/embunit/tools/tbcuppa/bcuppa.c new file mode 100644 index 0000000000..26b68222bf --- /dev/null +++ b/tests/unittests/embunit/tools/tbcuppa/bcuppa.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include "strvec.h" + +int main(int argc, char* argv[]) { + strvec* groups; + char* name; + FILE* file; + char path[256]; + int i; + + groups = strvec_new(4); + name = 0; + + for ( i = 1; i < argc; ++i ) { + char arg[256]; + strcpy(arg,argv[i]); + if ( strchr(arg,'.') ) { + *strchr(arg,'.') = '\0'; + strvec_push_back(groups,arg); + } else if ( name ) { + strvec_push_back(groups,arg); + } else { + name = argv[i]; + } + } + + if ( !name ) { + return 0; + } + + strcpy(path, name); + strcat(path, ".c"); + + file = fopen(path, "wt"); + if ( !file ) { + fprintf(stderr, "%s open failure.\n", path); + return 1; + } + + fprintf(file, "#include \n\n"); + + fprintf(file, "/*embunit:extern=+ */\n"); + for ( i = 0; i < strvec_size(groups); ++i ) { + fprintf(file, "extern TestRef %s_tests(void);\n" + ,strvec_get(groups,i)); + } + fprintf(file, "/*embunit:extern=- */\n\n"); + + fprintf(file, "int main(int argc,char *argv[])\n" + "{\n" + " TestRunner_start();\n" + ); + + fprintf(file, " /*embunit:run=+ */\n"); + for ( i = 0; i < strvec_size(groups); ++i ) { + fprintf(file, " TestRunner_runTest(%s_tests());\n", strvec_get(groups,i)); + } + fprintf(file, " /*embunit:run=- */\n"); + + fprintf(file, " TestRunner_end();\n" + " return 0;\n" + "}\n" + ); + + fclose(file); + + strvec_del(groups); + + return 0; + +} diff --git a/tests/unittests/embunit/tools/tbcuppa/strvec.c b/tests/unittests/embunit/tools/tbcuppa/strvec.c new file mode 100644 index 0000000000..693d3e0521 --- /dev/null +++ b/tests/unittests/embunit/tools/tbcuppa/strvec.c @@ -0,0 +1,108 @@ +#include "strvec.h" + +#include /* str... */ +#include /* malloc, free */ + +strvec* +strvec_new(int initial_capacity) { + strvec* result = (strvec*)malloc(sizeof(strvec)); + if ( result ) { + result->size = 0; + result->capa = 0; + result->body = (char**)malloc(sizeof(char*)*initial_capacity); + if ( result->body ) { + result->capa = initial_capacity; + } + } + return result; +} + +void +strvec_clear(strvec* sv) { + int i; + for ( i = 0; i < sv->size; ++i ) { + free(sv->body[i]); + } + sv->size = 0; +} + +void +strvec_del(strvec* sv) { + strvec_clear(sv); + free(sv); +} + +static void +strvec_grow(strvec* sv) { + if ( sv->size >= sv->capa ) { + int new_capa = sv->capa + 8; + char** new_body = (char**)malloc(sizeof(char*) * new_capa); + if ( new_body ) { + int i; + for ( i = 0; i < sv->size; ++i ) { + new_body[i] = sv->body[i]; + } + free(sv->body); + sv->body = new_body; + sv->capa = new_capa; + } + } +} + +void +strvec_push_back(strvec* sv, const char* str) { + strvec_grow(sv); + sv->body[sv->size++] = strdup(str); +} + +void +strvec_insert_before(strvec* sv, int pos, const char* str) { + int i; + if ( pos < 0 ) return; + if ( pos >= sv->size ) return; + strvec_grow(sv); + for ( i = sv->size; i > pos; --i ) { + sv->body[i] = sv->body[i-1]; + } + sv->body[pos] = strdup(str); + ++sv->size; +} + +int +strvec_size(const strvec* sv) { + return sv->size; +} + +void +strvec_erase(strvec* sv, int pos) { + int i; + if ( pos < 0 ) return; + if ( pos >= sv->size ) return; + free(sv->body[pos]); + for ( i = pos; i < sv->size - 1; ++i ) { + sv->body[i] = sv->body[i+1]; + } + --sv->size; +} + +int +strvec_capacity(const strvec* sv) { + return sv->capa; +} + +const +char* strvec_get(const strvec* sv, int index) { + if ( index >= 0 || index < sv->size ) { + return sv->body[index]; + } + return 0; +} + +int +strvec_find(const strvec* sv, const char* str) { + int i; + for ( i = 0; i < sv->size; ++i ) { + if ( strcmp(str, sv->body[i]) == 0 ) return i; + } + return -1; +} diff --git a/tests/unittests/embunit/tools/tbcuppa/strvec.h b/tests/unittests/embunit/tools/tbcuppa/strvec.h new file mode 100644 index 0000000000..9363b5d680 --- /dev/null +++ b/tests/unittests/embunit/tools/tbcuppa/strvec.h @@ -0,0 +1,32 @@ +#ifndef STRVEC_H +#define STRVEC_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct strvec_t { + char** body; + int size; + int capa; +}; + +typedef struct strvec_t strvec; + +strvec* strvec_new(int initial_capacity); +void strvec_del(strvec* sv); + +void strvec_push_back(strvec* sv, const char* str); +void strvec_insert_before(strvec* sv, int n, const char* str); +void strvec_erase(strvec* sv, int n); +int strvec_size(const strvec* sv); +int strvec_capacity(const strvec* sv); +const char* strvec_get(const strvec* sv, int n); +void strvec_clear(strvec* sv); +int strvec_find(const strvec* sv, const char* str); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tests/unittests/embunit/tools/tbcuppa/tcuppa.c b/tests/unittests/embunit/tools/tbcuppa/tcuppa.c new file mode 100644 index 0000000000..cfc9332bb2 --- /dev/null +++ b/tests/unittests/embunit/tools/tbcuppa/tcuppa.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include "strvec.h" + +int main(int argc, char* argv[]) { + strvec* includes; + strvec* cases; + char* group; + FILE* file; + char path[256]; + int i; + + includes = strvec_new(4); + cases = strvec_new(4); + group = 0; + + for ( i = 1; i < argc; ++i ) { + char* arg = argv[i]; + if ( strchr(arg,'.') ) { + strvec_push_back(includes,arg); + } else if ( group ) { + strvec_push_back(cases,arg); + } else { + group = arg; + } + } + + if ( !group ) { + return 0; + } + + strcpy(path, group); + strcat(path, ".c"); + file = fopen(path, "rt"); + if ( file ) { + fclose(file); + fprintf(stderr, "%s already exists. (skip)\n", path); + return 0; + } + + file = fopen(path, "wt"); + if ( !file ) { + fprintf(stderr, "%s open failure.\n", path); + return 1; + } + + fprintf(file, "#include \n\n"); + + fprintf(file, "/*embunit:include=+ */\n"); + for ( i = 0; i < strvec_size(includes); ++i ) { + fprintf(file, "#include \"%s\"\n",strvec_get(includes,i)); + } + fprintf(file, "/*embunit:include=- */\n\n"); + + fprintf(file, "static void setUp(void)\n" + "{\n" + "\t/* initialize */\n" + "}\n\n" + "static void tearDown(void)\n" + "{\n" + "\t/* terminate */\n" + "}\n\n" + ); + + fprintf(file, "/*embunit:impl=+ */\n"); + for ( i = 0; i < strvec_size(cases); ++i ) { + fprintf(file, "static void %s(void)\n" + "{\n" + " TEST_FAIL(\"no implementation\");\n" + "}\n\n" + ,strvec_get(cases, i) + ); + } + fprintf(file, "/*embunit:impl=- */\n"); + + fprintf(file, "TestRef %s_tests(void)\n" + "{\n" + " EMB_UNIT_TESTFIXTURES(fixtures) {\n" + ,group + ); + + fprintf(file, " /*embunit:fixtures=+ */\n"); + for ( i = 0; i < strvec_size(cases); ++i ) { + fprintf(file, " new_TestFixture(\x22%s\x22,%s),\n" + ,strvec_get(cases, i), strvec_get(cases, i) + ); + } + fprintf(file, " /*embunit:fixtures=- */\n"); + + fprintf(file, " };\n" + " EMB_UNIT_TESTCALLER(%s,\x22%s\x22,setUp,tearDown,fixtures);\n" + " return (TestRef)&%s;\n" + "};\n" + ,group,group,group + ); + + fclose(file); + + strvec_del(includes); + strvec_del(cases); + + return 0; + +} diff --git a/tests/unittests/embunit/tools/tbuma/buma.c b/tests/unittests/embunit/tools/tbuma/buma.c new file mode 100644 index 0000000000..f14d0a9541 --- /dev/null +++ b/tests/unittests/embunit/tools/tbuma/buma.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include "strvec.h" + +int main(int argc, char* argv[]) { + strvec* groups; + strvec* target; + char* runner; + FILE* file; + char path[256]; + char line[1024]; + int i; + int decl_pos; + int reg_pos; + + groups = strvec_new(4); + target = strvec_new(40); + runner = 0; + + for ( i = 1; i < argc; ++i ) { + char* arg = argv[i]; + if ( runner ) { + strvec_push_back(groups,arg); + } else { + runner = arg; + } + } + + if ( !runner ) { + return 0; + } + + strcpy(path, runner); + strcat(path, ".c"); + file = fopen(path, "rt"); + if ( !file ) { + fprintf(stderr, "can't open %s\n", path); + return 1; + } + + for ( i = 0; fgets(line, 1023, file); ++i ) { + strvec_push_back(target, line); + if ( strstr(line,"embunit:extern=-") ) decl_pos = i; + if ( strstr(line,"embunit:run=-" ) ) reg_pos = i; + } + + fclose(file); + + for ( i = 0; i < strvec_size(groups); ++i ) { + const char* name = strvec_get(groups,i); + sprintf(line," TestRunner_runTest(%s_tests());\n", name); + strvec_insert_before(target, reg_pos++, line); + } + + for ( i = 0; i < strvec_size(groups); ++i ) { + const char* name = strvec_get(groups,i); + sprintf(line,"extern TestRef %s_tests(void);\n", name); + strvec_insert_before(target, decl_pos++, line); + } + + file = fopen(path, "wt"); + if ( !file ) { + fprintf(stderr, "can't open %s\n", path); + return 1; + } + + for ( i = 0; i < strvec_size(target); ++i ) { + fprintf(file,"%s", strvec_get(target,i)); + } + fclose(file); + + strvec_del(target); + strvec_del(groups); + + return 0; + +} diff --git a/tests/unittests/embunit/tools/tbuma/tuma.c b/tests/unittests/embunit/tools/tbuma/tuma.c new file mode 100644 index 0000000000..bf9c1f9698 --- /dev/null +++ b/tests/unittests/embunit/tools/tbuma/tuma.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include "strvec.h" + +int main(int argc, char* argv[]) { + strvec* includes; + strvec* cases; + strvec* target; + char* group; + FILE* file; + char path[256]; + char line[1024]; + int i; + int incl_pos; + int impl_pos; + int suite_pos; + int in_incl; + int in_suite; + + includes = strvec_new(4); + cases = strvec_new(4); + target = strvec_new(40); + group = 0; + + for ( i = 1; i < argc; ++i ) { + char* arg = argv[i]; + if ( strchr(arg,'.') ) { + strvec_push_back(includes, arg); + } else if ( group ) { + strvec_push_back(cases,arg); + } else { + group = arg; + } + } + + if ( !group ) { + return 0; + } + + strcpy(path, group); + strcat(path, ".c"); + file = fopen(path, "rt"); + if ( !file ) { + fprintf(stderr, "can't open %s\n", path); + return 1; + } + + in_incl = 0; + in_suite = 0; + for ( i = 0; fgets(line, 1023, file); ++i ) { + char* token; + strvec_push_back(target, line); + if ( strstr(line,"embunit:include=+") ) in_incl = 1; + if ( strstr(line,"embunit:fixtures=+" ) ) in_suite = 1; + if ( strstr(line,"embunit:include=-") ) { incl_pos = i; in_incl = 0; } + if ( strstr(line,"embunit:impl=-" ) ) impl_pos = i; + if ( strstr(line,"embunit:fixtures=-" ) ) { suite_pos = i; in_suite = 0; } + else { + if ( in_incl ) { + strtok(line,"\"<>"); token = strtok(0, "\"<>"); + if ( token ) { + int i = strvec_find(includes, token); + if ( i >= 0 ) { + strvec_erase(includes,i); + break; + } + } + } + else if ( in_suite ) { + strtok(line,", \t"); token = strtok(0, ", \t"); token = strtok(0, ", \t)"); + if ( token ) { + int i = strvec_find(cases, token); + if ( i >= 0 ) { + strvec_erase(cases,i); + break; + } + } + } + } + } + + fclose(file); + + for ( i = 0; i < strvec_size(cases); ++i ) { + const char* name = strvec_get(cases,i); + sprintf(line," new_TestFixture(\x22%s\x22,%s),\n", name, name); + strvec_insert_before(target, suite_pos++, line); + } + + for ( i = 0; i < strvec_size(cases); ++i ) { + const char* name = strvec_get(cases,i); + sprintf(line,"static void %s(void)\n{\n\tTEST_FAIL(\"no implementation\");\n}\n\n", name); + strvec_insert_before(target, impl_pos++, line); + } + + for ( i = 0; i < strvec_size(includes); ++i ) { + const char* name = strvec_get(includes,i); + sprintf(line,"#include \"%s\"\n", name); + strvec_insert_before(target, incl_pos++, line); + } + + file = fopen(path, "wt"); + if ( !file ) { + fprintf(stderr, "can't open %s\n", path); + return 1; + } + + for ( i = 0; i < strvec_size(target); ++i ) { + fprintf(file,"%s", strvec_get(target,i)); + } + fclose(file); + + strvec_del(target); + strvec_del(includes); + strvec_del(cases); + + return 0; + +}