Add a test for the Event class

This commit is contained in:
Pierre Pronchery 2015-10-15 00:52:47 +02:00
parent 569b844e25
commit 550a64b390
3 changed files with 63 additions and 2 deletions

53
tests/event.c Normal file
View File

@ -0,0 +1,53 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include "System/event.h"
/* event */
static int _event_on_idle(void * data);
static int _event(char const * progname)
{
int ret;
Event * event;
printf("%s: Testing event_new()\n", progname);
if((event = event_new()) == NULL)
return -1;
printf("%s: Testing event_loop()\n", progname);
event_register_idle(event, _event_on_idle, event);
ret = event_loop(event);
event_delete(event);
return ret;
}
static int _event_on_idle(void * data)
{
Event * event = data;
event_loop_quit(event);
return 0;
}
/* main */
int main(int argc, char * argv[])
{
return (_event(argv[0]) == 0) ? 0 : 2;
}

View File

@ -1,4 +1,4 @@
targets=array,config,includes,pylint.log,string,variable,tests.log
targets=array,config,event,includes,pylint.log,string,variable,tests.log
cppflags_force=-I ../include
cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all
ldflags_force=-L../src -L$(OBJDIR)../src -Wl,-rpath,$(OBJDIR)../src -lSystem
@ -19,6 +19,13 @@ sources=config.c
[config.c]
depends=../src/config.c
[event]
type=binary
sources=event.c
[event.c]
depends=../src/event.c
[includes]
type=binary
sources=includes.c
@ -38,7 +45,7 @@ depends=../src/string.c
[tests.log]
type=script
script=./tests.sh
depends=$(OBJDIR)array,$(OBJDIR)config,config.conf,config-noeol.conf,$(OBJDIR)includes,python.sh,$(OBJDIR)string,tests.sh,$(OBJDIR)variable,$(OBJDIR)../src/libSystem.a
depends=$(OBJDIR)array,$(OBJDIR)config,config.conf,config-noeol.conf,$(OBJDIR)event,$(OBJDIR)includes,python.sh,$(OBJDIR)string,tests.sh,$(OBJDIR)variable,$(OBJDIR)../src/libSystem.a
[variable]
type=binary

View File

@ -102,6 +102,7 @@ FAILED=
echo "Performing tests:" 1>&2
_test "array"
_test "config"
_test "event"
_test "includes"
_test "string"
_test "variable"