Adapt embunit for RIOT

This commit is contained in:
Martin Lenders 2014-03-31 13:59:02 +02:00
parent ca75e01105
commit 0c6b5ba671
44 changed files with 337 additions and 2229 deletions

View File

@ -1,5 +1,14 @@
DIRS = $(RIOTCPU)/$(CPU) core drivers sys
ifneq (,$(filter embunit,$(USEMODULE)))
DIRS += tests/unittests/embunit/embUnit
endif
ifneq (,$(filter embunit_textui,$(USEMODULE)))
DIRS += tests/unittests/embunit/textui
endif
.PHONY: all clean doc
all:

View File

@ -35,11 +35,11 @@
#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_TESTCASE(ca,sup,tdw,run) \
static const TestCase ca = new_TestCase(#ca,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_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[] =
@ -47,8 +47,8 @@
#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_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[] =

View File

@ -0,0 +1,5 @@
MODULE = embunit
INCLUDES += -I$(RIOTBASE)/tests/unittests/embunit
include $(RIOTBASE)/Makefile.base

View File

@ -43,11 +43,7 @@ struct __TestFixture {
void(*test)(void);
};
#define new_TestFixture(name,test)\
{\
name,\
test,\
}
#define new_TestFixture(test) { #test, test }
typedef struct __TestCaller TestCaller;
typedef struct __TestCaller* TestCallerRef;/*downward compatible*/

View File

@ -67,6 +67,7 @@ void TestCase_run(TestCase* self,TestResult* result)
int TestCase_countTestCases(TestCase* self)
{
(void)self;
return 1;
}

View File

@ -44,15 +44,20 @@ static Test* root_;
static void TestRunner_startTest(TestListner* self,Test* test)
{
(void)self;
(void)test;
stdimpl_print(".");
}
static void TestRunner_endTest(TestListner* self,Test* test)
{
(void)self;
(void)test;
}
static void TestRunner_addFailure(TestListner* self,Test* test,char* msg,int line,char* file)
{
(void)self;
stdimpl_print("\n");
stdimpl_print(Test_name(root_));
stdimpl_print(".");

View File

@ -40,7 +40,7 @@
extern void stdimpl_print(const char *string);
#else
#include<stdio.h>
#define stdimpl_print printf
#define stdimpl_print(s) printf("%s", s);
#endif
#define ASSERT_STRING_BUFFER_MAX 64

View File

@ -1,32 +0,0 @@
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

View File

@ -1,20 +0,0 @@
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

View File

@ -1,132 +0,0 @@
== 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 $

View File

@ -1,13 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,50 +0,0 @@
#include <stdlib.h>
#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;
}

View File

@ -1,21 +0,0 @@
#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__*/

View File

@ -1,69 +0,0 @@
#include <embUnit/embUnit.h>
#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;
}

View File

@ -1,20 +0,0 @@
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

View File

@ -1,179 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View File

@ -1,25 +0,0 @@
#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__*/

View File

@ -1,111 +0,0 @@
#include <embUnit/embUnit.h>
#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;
}

View File

@ -1,21 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,12 +0,0 @@
#include <embUnit/embUnit.h>
#include "MockTestCase.h"
static void runTest(void)
{
}
TestCaseRef MockTestCase_case(void)
{
EMB_UNIT_TESTCASE(MockTestCase,"MockTestCase",NULL,NULL,runTest);
return (TestCaseRef)&MockTestCase;
}

View File

@ -1,6 +0,0 @@
#ifndef __MOCKTESTCASE_H__
#define __MOCKTESTCASE_H__
TestCaseRef MockTestCase_case(void);
#endif/*__MOCKTESTCASE_H__*/

View File

@ -1,57 +0,0 @@
#include <embUnit/embUnit.h>
#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;
}

View File

@ -1,64 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,66 +0,0 @@
#include <embUnit/embUnit.h>
#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;
}

View File

@ -1,60 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,103 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,21 +0,0 @@
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

View File

@ -1,114 +0,0 @@
#include <embUnit/embUnit.h>
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;
}

View File

@ -1,79 +1,92 @@
/*
* 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 <stdio.h>
#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;
}
/*
* 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