Testing the plug-ins for conformance (some currently do not define an icon)

This commit is contained in:
Pierre Pronchery 2013-10-26 21:44:43 +02:00
parent c4ff4aea3b
commit 3167a5dfd4
5 changed files with 146 additions and 5 deletions

View File

@ -111,6 +111,7 @@ dist:
$(PACKAGE)-$(VERSION)/tests/date.c \
$(PACKAGE)-$(VERSION)/tests/email.c \
$(PACKAGE)-$(VERSION)/tests/imap4.c \
$(PACKAGE)-$(VERSION)/tests/plugins.c \
$(PACKAGE)-$(VERSION)/tests/Makefile \
$(PACKAGE)-$(VERSION)/tests/tests.sh \
$(PACKAGE)-$(VERSION)/tests/project.conf \

View File

@ -1,4 +1,4 @@
TARGETS = date email imap4 tests.log
TARGETS = date email imap4 plugins tests.log
PREFIX = /usr/local
DESTDIR =
BINDIR = $(PREFIX)/bin
@ -38,7 +38,14 @@ imap4_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs glib-2.0 libSystem` `p
imap4: $(imap4_OBJS)
$(CC) -o imap4 $(imap4_OBJS) $(imap4_LDFLAGS)
tests.log: date email imap4
plugins_OBJS = plugins.o
plugins_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags gtk+-2.0`
plugins_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs gtk+-2.0`
plugins: $(plugins_OBJS)
$(CC) -o plugins $(plugins_OBJS) $(plugins_LDFLAGS)
tests.log: date email imap4 plugins tests.sh
./tests.sh -P "$(PREFIX)" -- "tests.log"
date.o: date.c ../src/helper.c
@ -50,8 +57,11 @@ email.o: email.c ../src/libMailer.a
imap4.o: imap4.c ../src/account/imap4.c
$(CC) $(imap4_CFLAGS) -c imap4.c
plugins.o: plugins.c
$(CC) $(plugins_CFLAGS) -c plugins.c
clean:
$(RM) -- $(date_OBJS) $(email_OBJS) $(imap4_OBJS) $(tests.log_OBJS)
$(RM) -- $(date_OBJS) $(email_OBJS) $(imap4_OBJS) $(plugins_OBJS) $(tests.log_OBJS)
./tests.sh -c -P "$(PREFIX)" -- "tests.log"
distclean: clean

123
tests/plugins.c Normal file
View File

@ -0,0 +1,123 @@
/* $Id$ */
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Mailer */
/* 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 <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include "Mailer/plugin.h"
/* private */
/* prototypes */
static int _plugins(void);
static int _dlerror(char const * message, int ret);
static int _error(char const * message, char const * error, int ret);
static int _perror(char const * message, int ret);
/* functions */
/* plugins */
static int _plugins(void)
{
int ret = 0;
const char path[] = "../src/plugins";
#ifdef __APPLE__
const char ext[] = ".dylib";
#else
const char ext[] = ".so";
#endif
DIR * dir;
struct dirent * de;
size_t len;
char * s;
void * p;
MailerPluginDefinition * mpd;
if((dir = opendir(path)) == NULL)
return -_perror(path, 1);
while((de = readdir(dir)) != NULL)
{
if((len = strlen(de->d_name)) < sizeof(ext))
continue;
if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0)
continue;
if((s = malloc(sizeof(path) + len + 1)) == NULL)
{
ret += _perror(de->d_name, 1);
continue;
}
snprintf(s, sizeof(path) + len + 1, "%s/%s", path, de->d_name);
if((p = dlopen(s, RTLD_LAZY)) == NULL)
{
ret += _dlerror(s, 1);
free(s);
continue;
}
if((mpd = dlsym(p, "plugin")) == NULL)
ret += _dlerror(s, 1);
else if(mpd->icon == NULL)
ret += _error(s, "No icon defined", 1);
else
printf("\n%s: %s (%s)\n%s\n", de->d_name, mpd->name,
mpd->icon, (mpd->description != NULL)
? mpd->description
: "(no description)");
free(s);
dlclose(p);
}
closedir(dir);
return ret;
}
/* dlerror */
static int _dlerror(char const * message, int ret)
{
fputs("plugins: ", stderr);
fprintf(stderr, "%s: %s\n", message, dlerror());
return ret;
}
/* error */
static int _error(char const * message, char const * error, int ret)
{
fputs("plugins: ", stderr);
fprintf(stderr, "%s: %s\n", message, error);
return ret;
}
/* perror */
static int _perror(char const * message, int ret)
{
fputs("plugins: ", stderr);
perror(message);
return ret;
}
/* public */
/* functions */
/* main */
int main(void)
{
return (_plugins() == 0) ? 0 : 2;
}

View File

@ -1,4 +1,4 @@
targets=date,email,imap4,tests.log
targets=date,email,imap4,plugins,tests.log
cppflags_force=-I ../include
cflags_force=-W
cflags=-Wall -g -O2 -ffreestanding
@ -29,7 +29,13 @@ ldflags=`pkg-config --libs glib-2.0 libSystem` `pkg-config --libs openssl` -lssl
[imap4.c]
depends=../src/account/imap4.c
[plugins]
type=binary
cflags=`pkg-config --cflags gtk+-2.0`
ldflags=`pkg-config --libs gtk+-2.0`
sources=plugins.c
[tests.log]
type=script
script=./tests.sh
depends=date,email,imap4
depends=date,email,imap4,plugins,tests.sh

View File

@ -54,6 +54,7 @@ FAILED=
./date >> "$target" || FAILED="$FAILED date(error $?)"
./email >> "$target" || FAILED="$FAILED email(error $?)"
./imap4 >> "$target" || FAILED="$FAILED imap4(error $?)"
./plugins >> "$target" || FAILED="$FAILED plugins(error $?)"
[ -z "$FAILED" ] && exit 0
echo "Failed tests:$FAILED" 1>&2
exit 2