-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from authmillenon/unittests
Unittests via embUnit
- Loading branch information
Showing
39 changed files
with
2,369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export PROJECT = unittests | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += embunit | ||
|
||
INCLUDES += -I$(RIOTBASE)/tests/unittests/embunit | ||
|
||
ifeq ($(OUTPUT),XML) | ||
CFLAGS += -DOUTPUT=OUTPUT_XML | ||
USEMODULE += embunit_textui | ||
else ifeq ($(OUTPUT),TEXT) | ||
CFLAGS += -DOUTPUT=OUTPUT_TEXT | ||
USEMODULE += embunit_textui | ||
else ifeq ($(OUTPUT),COMPILER) | ||
CFLAGS += -DOUTPUT=OUTPUT_COMPILER | ||
USEMODULE += embunit_textui | ||
endif | ||
|
||
.PHONY : all clean core | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Unittests | ||
|
||
see [Wiki][Testing-RIOT] | ||
|
||
|
||
[Testing-RIOT]: https://github.com/RIOT-OS/RIOT/wiki/Testing-RIOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
arms22<arms22@users.sourceforge.jp> <arms22@users.sourceforge.net> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,sup,tdw,run) \ | ||
static const TestCase ca = new_TestCase(#ca,sup,tdw,run) | ||
|
||
#define EMB_UNIT_TESTSUITE(su,array) \ | ||
static const TestSuite su = new_TestSuite(#su,(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,sup,tdw,fixtures) \ | ||
static const TestCaller caller = new_TestCaller(#caller,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__*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MODULE = embunit | ||
|
||
INCLUDES += -I$(RIOTBASE)/tests/unittests/embunit | ||
|
||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; i<self->timesRepeat; 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, | ||
}; |
Oops, something went wrong.