From c02e69308be66f0ec82faa7772a3987d34f9197c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 15 Oct 2012 20:28:29 +0000 Subject: [PATCH] Added some tests (e-mail recognition) --- Makefile | 6 +++++- project.conf | 2 +- tests/.cvsignore | 2 ++ tests/Makefile | 43 ++++++++++++++++++++++++++++++++++++++ tests/email.c | 42 +++++++++++++++++++++++++++++++++++++ tests/project.conf | 19 +++++++++++++++++ tests/tests.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 tests/.cvsignore create mode 100644 tests/Makefile create mode 100644 tests/email.c create mode 100644 tests/project.conf create mode 100755 tests/tests.sh diff --git a/Makefile b/Makefile index f4d0ec6..cf6bfb2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = Mailer VERSION = 0.1.5 -SUBDIRS = data doc include po src src/plugins +SUBDIRS = data doc include po src src/plugins tests RM ?= rm -f LN ?= ln -f TAR ?= tar -czvf @@ -107,6 +107,10 @@ dist: $(PACKAGE)-$(VERSION)/src/plugins/search.c \ $(PACKAGE)-$(VERSION)/src/plugins/Makefile \ $(PACKAGE)-$(VERSION)/src/plugins/project.conf \ + $(PACKAGE)-$(VERSION)/tests/email.c \ + $(PACKAGE)-$(VERSION)/tests/Makefile \ + $(PACKAGE)-$(VERSION)/tests/tests.sh \ + $(PACKAGE)-$(VERSION)/tests/project.conf \ $(PACKAGE)-$(VERSION)/Makefile \ $(PACKAGE)-$(VERSION)/COPYING \ $(PACKAGE)-$(VERSION)/config.h \ diff --git a/project.conf b/project.conf index f6fa2a1..bb9c712 100644 --- a/project.conf +++ b/project.conf @@ -2,5 +2,5 @@ package=Mailer version=0.1.5 config=h,sh -subdirs=data,doc,include,po,src,src/plugins +subdirs=data,doc,include,po,src,src/plugins,tests dist=Makefile,COPYING,config.h,config.sh diff --git a/tests/.cvsignore b/tests/.cvsignore new file mode 100644 index 0000000..57df12f --- /dev/null +++ b/tests/.cvsignore @@ -0,0 +1,2 @@ +email +tests.log diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..ceb6b44 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,43 @@ +TARGETS = email tests.log +PREFIX = /usr/local +DESTDIR = +BINDIR = $(PREFIX)/bin +CC ?= cc +CPPFLAGSF= -I ../include +CPPFLAGS?= +CFLAGSF = -W +CFLAGS = -Wall -g -O2 -ffreestanding +LDFLAGSF= -L ../src -Wl,-rpath,../src -lMailer +LDFLAGS = +RM ?= rm -f +LN ?= ln -f +MKDIR ?= mkdir -p +INSTALL ?= install + + +all: $(TARGETS) + +email_OBJS = email.o +email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +email: $(email_OBJS) + $(CC) -o email $(email_OBJS) $(email_LDFLAGS) + +tests.log: email + ./tests.sh -P "$(PREFIX)" -- "tests.log" + +email.o: email.c ../src/libMailer.a + $(CC) $(email_CFLAGS) -c email.c + +clean: + $(RM) -- $(email_OBJS) $(tests.log_OBJS) + +distclean: clean + $(RM) -- $(TARGETS) + +install: $(TARGETS) + +uninstall: + +.PHONY: all clean distclean install uninstall diff --git a/tests/email.c b/tests/email.c new file mode 100644 index 0000000..31b1263 --- /dev/null +++ b/tests/email.c @@ -0,0 +1,42 @@ +/* $Id$ */ + + + +#include +#include +#include "Mailer.h" + + +/* email */ +static int _email(char const * progname, char const * name, char const * email, + char const * str) +{ + int ret = 0; + char * n; + char * e; + + n = mailer_helper_get_name(str); + e = mailer_helper_get_email(str); + if(strcmp(name, n) != 0) + fprintf(stderr, "%s: %s: %s (\"%s\")\n", progname, str, + "The name does not match", n); + if(strcmp(email, e) != 0) + fprintf(stderr, "%s: %s: %s (\"%s\")\n", progname, str, + "The e-mail does not match", e); + free(e); + free(n); + return ret; +} + + +/* main */ +int main(int argc, char * argv[]) +{ + int ret = 0; + + ret |= _email(argv[0], "John Doe", "john@doe.com", + "john@doe.com (John Doe)"); + ret |= _email(argv[0], "John Doe", "john@doe.com", + "John Doe "); + return ret; +} diff --git a/tests/project.conf b/tests/project.conf new file mode 100644 index 0000000..4df78a0 --- /dev/null +++ b/tests/project.conf @@ -0,0 +1,19 @@ +targets=email,tests.log +cppflags_force=-I ../include +cflags_force=-W +cflags=-Wall -g -O2 -ffreestanding +ldflags_force=-L ../src -Wl,-rpath,../src -lMailer +ldflags= +dist=Makefile,tests.sh + +[email] +type=binary +sources=email.c + +[email.c] +depends=../src/libMailer.a + +[tests.log] +type=script +script=./tests.sh +depends=email diff --git a/tests/tests.sh b/tests/tests.sh new file mode 100755 index 0000000..d6919c2 --- /dev/null +++ b/tests/tests.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env sh +#$Id$ +#Copyright (c) 2012 Pierre Pronchery +#This file is part of DeforaOS System libc +#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 . + + +#functions +#usage +_usage() +{ + echo "Usage: tests.sh" 1>&2 + return 1 +} + + +#main +while getopts "P:" "name"; do + case "$name" in + P) + #XXX ignored + ;; + ?) + _usage + exit $? + ;; + esac +done +shift $((OPTIND - 1)) +if [ $# -ne 1 ]; then + _usage + exit $? +fi +target="$1" + +> "$target" +FAILED= +./email >> "$target" || FAILED="$FAILED email(error $?)" +[ -z "$FAILED" ] && exit 0 +echo "Failed tests:$FAILED" 1>&2 +#XXX ignore errors for now +#exit 2